-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a simple cache for TMDB Configuration
- Loading branch information
1 parent
0256aab
commit 75527ec
Showing
7 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
CouchTrackerCoreTests/Configuration/ConfigurationCachedRepositoryTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@testable import CouchTrackerCore | ||
import RxTest | ||
import TMDBSwift | ||
import XCTest | ||
|
||
final class ConfigurationCachedRepositoryTests: XCTestCase { | ||
func testConfigurationCachedRepository_fetchFromCache_whenCacheIsAvailable() { | ||
// Given | ||
let tmdb = TMDBProviderMock() | ||
let repository = ConfigurationCachedRepository(tmdbProvider: tmdb) | ||
let scheduler = TestSchedulers() | ||
|
||
// When | ||
let observer1 = scheduler.start { repository.fetchConfiguration() } | ||
let observer2 = scheduler.start { repository.fetchConfiguration() } | ||
|
||
// Then | ||
let mockConfig = Configuration.mockDefaultConfiguration() | ||
let expectedEvents1 = [Recorded.next(200, mockConfig), | ||
Recorded.completed(200)] | ||
let expectedEvents2 = [Recorded.next(1000, mockConfig), | ||
Recorded.completed(1000)] | ||
|
||
XCTAssertEqual(observer1.events, expectedEvents1) | ||
XCTAssertEqual(observer2.events, expectedEvents2) | ||
|
||
let mockProvider = tmdb.configuration as! MoyaProviderMock | ||
XCTAssertEqual(mockProvider.requestInvokedCount, 1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import TMDBSwift | ||
|
||
extension Configuration { | ||
static func mockDefaultConfiguration(decoder _: JSONDecoder = .init()) -> Configuration { | ||
return Fixtures.TMDBConfiguration.modelFor(file: "default_configuration", ofType: Configuration.self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
CouchTrackerCoreTests/Fixtures/TMDBConfiguration/default_configuration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"images": { | ||
"base_url": "http://image.tmdb.org/t/p/", | ||
"secure_base_url": "https://image.tmdb.org/t/p/", | ||
"backdrop_sizes": [ | ||
"w300", | ||
"w780", | ||
"w1280", | ||
"original" | ||
], | ||
"logo_sizes": [ | ||
"w45", | ||
"w92", | ||
"w154", | ||
"w185", | ||
"w300", | ||
"w500", | ||
"original" | ||
], | ||
"poster_sizes": [ | ||
"w92", | ||
"w154", | ||
"w185", | ||
"w342", | ||
"w500", | ||
"w780", | ||
"original" | ||
], | ||
"profile_sizes": [ | ||
"w45", | ||
"w185", | ||
"h632", | ||
"original" | ||
], | ||
"still_sizes": [ | ||
"w92", | ||
"w185", | ||
"w300", | ||
"original" | ||
] | ||
}, | ||
"change_keys": [ | ||
"adult", | ||
"air_date", | ||
"also_known_as", | ||
"alternative_titles", | ||
"biography", | ||
"birthday", | ||
"budget", | ||
"cast", | ||
"certifications", | ||
"character_names", | ||
"created_by", | ||
"crew", | ||
"deathday", | ||
"episode", | ||
"episode_number", | ||
"episode_run_time", | ||
"freebase_id", | ||
"freebase_mid", | ||
"general", | ||
"genres", | ||
"guest_stars", | ||
"homepage", | ||
"images", | ||
"imdb_id", | ||
"languages", | ||
"name", | ||
"network", | ||
"origin_country", | ||
"original_name", | ||
"original_title", | ||
"overview", | ||
"parts", | ||
"place_of_birth", | ||
"plot_keywords", | ||
"production_code", | ||
"production_companies", | ||
"production_countries", | ||
"releases", | ||
"revenue", | ||
"runtime", | ||
"season", | ||
"season_number", | ||
"season_regular", | ||
"spoken_languages", | ||
"status", | ||
"tagline", | ||
"title", | ||
"translations", | ||
"tvdb_id", | ||
"tvrage_id", | ||
"type", | ||
"video", | ||
"videos" | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters