diff --git a/Sources/TMDb/Domain/Models/Media.swift b/Sources/TMDb/Domain/Models/Media.swift index 823bbeca..d1539aea 100644 --- a/Sources/TMDb/Domain/Models/Media.swift +++ b/Sources/TMDb/Domain/Models/Media.swift @@ -53,7 +53,7 @@ public enum Media: Identifiable, Codable, Equatable, Hashable, Sendable { /// /// Person. /// - case person(Person) + case person(PersonListItem) } @@ -93,7 +93,7 @@ extension Media { self = try .tvSeries(TVSeriesListItem(from: decoder)) case .person: - self = try .person(Person(from: decoder)) + self = try .person(PersonListItem(from: decoder)) } } diff --git a/Sources/TMDb/Domain/Services/TVSeries/TVSeriesService.swift b/Sources/TMDb/Domain/Services/TVSeries/TVSeriesService.swift index 851e8a23..86bcae36 100644 --- a/Sources/TMDb/Domain/Services/TVSeries/TVSeriesService.swift +++ b/Sources/TMDb/Domain/Services/TVSeries/TVSeriesService.swift @@ -93,8 +93,11 @@ public protocol TVSeriesService: Sendable { /// /// - Returns: Reviews for the matching TV series as a pageable list. /// - func reviews(forTVSeries tvSeriesID: TVSeries.ID, page: Int?, language: String?) async throws - -> ReviewPageableList + func reviews( + forTVSeries tvSeriesID: TVSeries.ID, + page: Int?, + language: String? + ) async throws -> ReviewPageableList /// /// Returns the images that belong to a TV series. @@ -109,8 +112,10 @@ public protocol TVSeriesService: Sendable { /// /// - Returns: A collection of images for the matching TV series. /// - func images(forTVSeries tvSeriesID: TVSeries.ID, filter: TVSeriesImageFilter?) async throws - -> ImageCollection + func images( + forTVSeries tvSeriesID: TVSeries.ID, + filter: TVSeriesImageFilter? + ) async throws -> ImageCollection /// /// Returns the videos that belong to a TV series. @@ -125,8 +130,10 @@ public protocol TVSeriesService: Sendable { /// /// - Returns: A collection of videos for the matching TV series. /// - func videos(forTVSeries tvSeriesID: TVSeries.ID, filter: TVSeriesVideoFilter?) async throws - -> VideoCollection + func videos( + forTVSeries tvSeriesID: TVSeries.ID, + filter: TVSeriesVideoFilter? + ) async throws -> VideoCollection /// /// Returns a list of recommended TV series for a TV series. @@ -209,8 +216,7 @@ public protocol TVSeriesService: Sendable { func watchProviders( forTVSeries tvSeriesID: TVSeries.ID, country: String - ) async throws - -> ShowWatchProvider? + ) async throws -> ShowWatchProvider? /// /// Returns a collection of media databases and social links for a TV series. @@ -225,8 +231,7 @@ public protocol TVSeriesService: Sendable { /// func externalLinks( forTVSeries tvSeriesID: TVSeries.ID - ) async throws - -> TVSeriesExternalLinksCollection + ) async throws -> TVSeriesExternalLinksCollection /// /// Returns the content rating of a TV series. @@ -241,8 +246,10 @@ public protocol TVSeriesService: Sendable { /// /// - Returns: A content rating for the specificed TV series. /// - func contentRatings(forTVSeries tvSeriesID: TVSeries.ID, country: String) async throws - -> ContentRating? + func contentRatings( + forTVSeries tvSeriesID: TVSeries.ID, + country: String + ) async throws -> ContentRating? } extension TVSeriesService { @@ -260,9 +267,10 @@ extension TVSeriesService { /// /// - Returns: The matching TV series. /// - public func details(forTVSeries id: TVSeries.ID, language: String? = nil) async throws - -> TVSeries - { + public func details( + forTVSeries id: TVSeries.ID, + language: String? = nil + ) async throws -> TVSeries { try await details(forTVSeries: id, language: language) } diff --git a/Tests/TMDbTests/Domain/Models/MediaPageableListTests.swift b/Tests/TMDbTests/Domain/Models/MediaPageableListTests.swift index 0cb4f8d9..3200d1a3 100644 --- a/Tests/TMDbTests/Domain/Models/MediaPageableListTests.swift +++ b/Tests/TMDbTests/Domain/Models/MediaPageableListTests.swift @@ -41,7 +41,7 @@ struct MediaPageableListTests { results: [ .movie(.theFirstOmen), .tvSeries(.bigBrother), - .person(Person(id: 51329, name: "Bradley Cooper", gender: .unknown)) + .person(.bradPitt) ], totalResults: 3, totalPages: 1 diff --git a/Tests/TMDbTests/Domain/Models/MediaTests.swift b/Tests/TMDbTests/Domain/Models/MediaTests.swift index f8aa576e..45ea4a3d 100644 --- a/Tests/TMDbTests/Domain/Models/MediaTests.swift +++ b/Tests/TMDbTests/Domain/Models/MediaTests.swift @@ -27,30 +27,72 @@ struct MediaTests { @Test("id when movie returns movieID") func idWhenMovieReturnsMovieID() { - #expect(media[0].id == 437_342) + let media = Media.movie(.theFirstOmen) + + #expect(media.id == 437_342) } @Test("id when TV series returns tvSeriesID") func idWhenTVSeriesReturnsTVSeriesID() { - #expect(media[1].id == 11366) + let media = Media.tvSeries(.bigBrother) + + #expect(media.id == 11366) } @Test("id when person returns personID") func idWhenPersonReturnsPersonID() { - #expect(media[2].id == 51329) + let media = Media.person(.bradPitt) + + #expect(media.id == 287) } @Test("JSON decoding of Media", .tags(.decoding)) - func testDecodeReturnsMedia() throws { + func decodeReturnsMedia() throws { + let media: [Media] = [ + .movie(.theFirstOmen), + .tvSeries(.bigBrother), + .person(.bradPitt) + ] + let result = try JSONDecoder.theMovieDatabase.decode([Media].self, fromResource: "media") #expect(result == media) } - private let media: [Media] = [ - .movie(.theFirstOmen), - .tvSeries(.bigBrother), - .person(Person(id: 51329, name: "Bradley Cooper", gender: .unknown)) - ] + @Test("JSON encoding of movie media", .tags(.encoding)) + func encodeMovieMedia() throws { + let movie = MovieListItem.theFirstOmen + let media = Media.movie(movie) + + let data = try JSONEncoder.theMovieDatabase.encode(media) + let decodedMedia = try JSONDecoder.theMovieDatabase.decode(MovieListItem.self, from: data) + + #expect(decodedMedia == movie) + } + + @Test("JSON encoding of TV series media", .tags(.encoding)) + func encodeTVSeriesMedia() throws { + let tvSeries = TVSeriesListItem.bigBrother + let media = Media.tvSeries(tvSeries) + + let data = try JSONEncoder.theMovieDatabase.encode(media) + let decodedMedia = try JSONDecoder.theMovieDatabase.decode( + TVSeriesListItem.self, + from: data + ) + + #expect(decodedMedia == tvSeries) + } + + @Test("JSON encoding of person media", .tags(.encoding)) + func encodePersonMedia() throws { + let person = PersonListItem.bradPitt + let media = Media.person(person) + + let data = try JSONEncoder.theMovieDatabase.encode(media) + let decodedMedia = try JSONDecoder.theMovieDatabase.decode(PersonListItem.self, from: data) + + #expect(decodedMedia == person) + } } diff --git a/Tests/TMDbTests/Domain/Services/Account/TMDbAccountServiceFavouriteTests.swift b/Tests/TMDbTests/Domain/Services/Account/TMDbAccountServiceFavouriteTests.swift index 64a36365..cf0cb665 100644 --- a/Tests/TMDbTests/Domain/Services/Account/TMDbAccountServiceFavouriteTests.swift +++ b/Tests/TMDbTests/Domain/Services/Account/TMDbAccountServiceFavouriteTests.swift @@ -39,8 +39,8 @@ struct TMDbAccountFavouriteServiceTests { extension TMDbAccountFavouriteServiceTests { - @Test("favouriteMovies returns movies list") - func favouriteMoviesReturnsMoviesList() async throws { + @Test("favouriteMovies with default parameter values returns movies list") + func favouriteMoviesWithDefaultParameterValuesReturnsMoviesList() async throws { let accountID = 123 let session = Session.mock() let expectedResult = MoviePageableList.mock() @@ -52,7 +52,10 @@ extension TMDbAccountFavouriteServiceTests { sessionID: session.sessionID ) - let result = try await service.favouriteMovies(accountID: accountID, session: session) + let result = try await (service as AccountService).favouriteMovies( + accountID: accountID, + session: session + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? FavouriteMoviesRequest == expectedRequest) @@ -212,8 +215,8 @@ extension TMDbAccountFavouriteServiceTests { extension TMDbAccountFavouriteServiceTests { - @Test("favouriteTVSeries returns TV series list") - func favouriteTVSeriesReturnsTVSeriesList() async throws { + @Test("favouriteTVSeries with default parameter values returns TV series list") + func favouriteTVSeriesWithDefaultParameterValuesReturnsTVSeriesList() async throws { let accountID = 123 let session = Session.mock() let expectedResult = TVSeriesPageableList.mock() @@ -225,7 +228,10 @@ extension TMDbAccountFavouriteServiceTests { sessionID: session.sessionID ) - let result = try await service.favouriteTVSeries(accountID: accountID, session: session) + let result = try await (service as AccountService).favouriteTVSeries( + accountID: accountID, + session: session + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? FavouriteTVSeriesRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Account/TMDbAccountServiceWatchlistTests.swift b/Tests/TMDbTests/Domain/Services/Account/TMDbAccountServiceWatchlistTests.swift index d1549b41..4a6e41e5 100644 --- a/Tests/TMDbTests/Domain/Services/Account/TMDbAccountServiceWatchlistTests.swift +++ b/Tests/TMDbTests/Domain/Services/Account/TMDbAccountServiceWatchlistTests.swift @@ -39,8 +39,8 @@ struct TMDbAccountServiceWatchlistTests { extension TMDbAccountServiceWatchlistTests { - @Test("movieWatchlist returns movies list") - func movieWatchlistReturnsMoviesList() async throws { + @Test("movieWatchlist with default parameter values returns movies list") + func movieWatchlistWithDefaultParameterValuesReturnsMoviesList() async throws { let accountID = 123 let session = Session.mock() let expectedResult = MoviePageableList.mock() @@ -52,7 +52,10 @@ extension TMDbAccountServiceWatchlistTests { sessionID: session.sessionID ) - let result = try await service.movieWatchlist(accountID: accountID, session: session) + let result = try await (service as AccountService).movieWatchlist( + accountID: accountID, + session: session + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieWatchlistRequest == expectedRequest) @@ -207,8 +210,8 @@ extension TMDbAccountServiceWatchlistTests { extension TMDbAccountServiceWatchlistTests { - @Test("TV series watchlist returns TV series list") - func tvSeriesWatchlistReturnsTVSeriesList() async throws { + @Test("TV series watchlist with default parameter values returns TV series list") + func tvSeriesWatchlistWithDefaultParameterValuesReturnsTVSeriesList() async throws { let accountID = 123 let session = Session.mock() let expectedResult = TVSeriesPageableList.mock() @@ -220,7 +223,10 @@ extension TMDbAccountServiceWatchlistTests { sessionID: session.sessionID ) - let result = try await service.tvSeriesWatchlist(accountID: accountID, session: session) + let result = try await (service as AccountService).tvSeriesWatchlist( + accountID: accountID, + session: session + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesWatchlistRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Authentication/TMDbAuthenticationServiceTests.swift b/Tests/TMDbTests/Domain/Services/Authentication/TMDbAuthenticationServiceTests.swift index 80dbd707..549c5037 100644 --- a/Tests/TMDbTests/Domain/Services/Authentication/TMDbAuthenticationServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/Authentication/TMDbAuthenticationServiceTests.swift @@ -78,14 +78,14 @@ struct TMDbAuthenticationServiceTests { } } - @Test("authenticateURL returns URL") - func authenticateURLReturnsURL() throws { + @Test("authenticateURL with default parameter values returns URL") + func authenticateURLWithDefaultParameterValuesReturnsURL() throws { let expiresAt = Date(timeIntervalSince1970: 1_705_956_596) let token = Token(success: true, requestToken: "abc123", expiresAt: expiresAt) let expectedURL = try #require(URL(string: "https://some.domain.com/authenticate/abc123")) authenticateURLBuilder.authenticateURLResult = expectedURL - let url = service.authenticateURL(for: token) + let url = (service as AuthenticationService).authenticateURL(for: token) #expect(url == expectedURL) #expect(authenticateURLBuilder.lastRequestToken == token.requestToken) diff --git a/Tests/TMDbTests/Domain/Services/Certifications/TMDbCertificationServiceTests.swift b/Tests/TMDbTests/Domain/Services/Certifications/TMDbCertificationServiceTests.swift index f045c7cc..0ccd3e31 100644 --- a/Tests/TMDbTests/Domain/Services/Certifications/TMDbCertificationServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/Certifications/TMDbCertificationServiceTests.swift @@ -70,6 +70,7 @@ struct TMDbCertificationServiceTests { #expect(apiClient.lastRequest as? TVSeriesCertificationsRequest == expectedRequest) } + @Test("tvSeriesCertifications when errors throw error") func tvSeriesCertificationsWhenErrorsThrowsError() async throws { apiClient.addResponse(.failure(.unknown)) diff --git a/Tests/TMDbTests/Domain/Services/Configuration/TMDbConfigurationServiceTests.swift b/Tests/TMDbTests/Domain/Services/Configuration/TMDbConfigurationServiceTests.swift index 9e46fba7..498c4dd0 100644 --- a/Tests/TMDbTests/Domain/Services/Configuration/TMDbConfigurationServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/Configuration/TMDbConfigurationServiceTests.swift @@ -54,13 +54,13 @@ struct TMDbConfigurationServiceTests { } } - @Test("countries returns countries") - func countriesReturnsCountries() async throws { + @Test("countries with default parameter values returns countries") + func countriesWithDefaultParameterValuesReturnsCountries() async throws { let expectedResult = [Country].mocks apiClient.addResponse(.success(expectedResult)) let expectedRequest = CountriesConfigurationRequest(language: nil) - let result = try await service.countries() + let result = try await (service as ConfigurationService).countries() #expect(result == expectedResult) #expect(apiClient.lastRequest as? CountriesConfigurationRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Discover/TMDbDiscoverServiceTests.swift b/Tests/TMDbTests/Domain/Services/Discover/TMDbDiscoverServiceTests.swift index 0689230f..bf89650d 100644 --- a/Tests/TMDbTests/Domain/Services/Discover/TMDbDiscoverServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/Discover/TMDbDiscoverServiceTests.swift @@ -33,14 +33,14 @@ struct TMDbDiscoverServiceTests { self.service = TMDbDiscoverService(apiClient: apiClient) } - @Test("movies returns movies") - func moviesReturnsMovies() async throws { + @Test("movies with default parameter values returns movies") + func moviesWithDefaultParameterValuesReturnsMovies() async throws { let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = DiscoverMoviesRequest( people: nil, sortedBy: nil, page: nil, language: nil) - let result = try await service.movies() + let result = try await (service as DiscoverService).movies() #expect(result == expectedResult) #expect(apiClient.lastRequest as? DiscoverMoviesRequest == expectedRequest) @@ -74,13 +74,13 @@ struct TMDbDiscoverServiceTests { } } - @Test("tvSeries returns TV series") - func tvSeriesReturnsTVSeries() async throws { + @Test("tvSeries with default parameter values returns TV series") + func tvSeriesWithDefaultParameterValuesReturnsTVSeries() async throws { let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = DiscoverTVSeriesRequest(sortedBy: nil, page: nil, language: nil) - let result = try await service.tvSeries() + let result = try await (service as DiscoverService).tvSeries() #expect(result == expectedResult) #expect(apiClient.lastRequest as? DiscoverTVSeriesRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Genres/TMDbGenreServiceTests.swift b/Tests/TMDbTests/Domain/Services/Genres/TMDbGenreServiceTests.swift index f0ae3359..5739171e 100644 --- a/Tests/TMDbTests/Domain/Services/Genres/TMDbGenreServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/Genres/TMDbGenreServiceTests.swift @@ -33,14 +33,14 @@ struct TMDbGenreServiceTests { self.service = TMDbGenreService(apiClient: apiClient) } - @Test("movieGenres returns genres") - func movieGenresReturnsGenres() async throws { + @Test("movieGenres with default parameter values returns genres") + func movieGenresWithDefaultParameterValuesReturnsGenres() async throws { let genreList = GenreList.mock() let expectedResult = genreList.genres apiClient.addResponse(.success(genreList)) let expectedRequest = MovieGenresRequest(language: nil) - let result = try await service.movieGenres() + let result = try await (service as GenreService).movieGenres() #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieGenresRequest == expectedRequest) @@ -69,14 +69,14 @@ struct TMDbGenreServiceTests { } } - @Test("tvSeriesGenres returns genres") - func tvSeriesGenresReturnsGenres() async throws { + @Test("tvSeriesGenres with default parameter values returns genres") + func tvSeriesGenresWithDefaultParameterValuesReturnsGenres() async throws { let genreList = GenreList.mock() let expectedResult = genreList.genres apiClient.addResponse(.success(genreList)) let expectedRequest = TVSeriesGenresRequest(language: nil) - let result = try await service.tvSeriesGenres() + let result = try await (service as GenreService).tvSeriesGenres() #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesGenresRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceCreditsTests.swift b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceCreditsTests.swift index de66f3aa..37f63a27 100644 --- a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceCreditsTests.swift +++ b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceCreditsTests.swift @@ -33,14 +33,14 @@ struct TMDbMovieServiceCreditsTests { self.service = TMDbMovieService(apiClient: apiClient) } - @Test("credits returns credits") - func creditsReturnsCredits() async throws { + @Test("credits with default parameter values returns credits") + func creditsWithDefaultParameterValuesReturnsCredits() async throws { let expectedResult = ShowCredits.mock() let movieID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = MovieCreditsRequest(id: movieID, language: nil) - let result = try await service.credits(forMovie: movieID) + let result = try await (service as MovieService).credits(forMovie: movieID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieCreditsRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceDetailsTests.swift b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceDetailsTests.swift index aa333371..e178f801 100644 --- a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceDetailsTests.swift +++ b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceDetailsTests.swift @@ -33,14 +33,14 @@ struct TMDbMovieServiceDetailsTests { self.service = TMDbMovieService(apiClient: apiClient) } - @Test("details returns movie") - func detailsReturnsMovie() async throws { + @Test("details with default parameter values returns movie") + func detailsWithDefaultParameterValuesReturnsMovie() async throws { let expectedResult = Movie.thorLoveAndThunder let movieID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = MovieRequest(id: movieID, language: nil) - let result = try await service.details(forMovie: movieID) + let result = try await (service as MovieService).details(forMovie: movieID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceListsTests.swift b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceListsTests.swift index 3ade9941..e63909d5 100644 --- a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceListsTests.swift +++ b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceListsTests.swift @@ -33,14 +33,14 @@ struct TMDbMovieServiceListsTests { self.service = TMDbMovieService(apiClient: apiClient) } - @Test("recommendations returns movies") - func recommendationsReturnsMovies() async throws { + @Test("recommendations with default parameter values returns movies") + func recommendationsWIthDefaultParametersReturnsMovies() async throws { let movieID = 1 let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = MovieRecommendationsRequest(id: movieID, page: nil, language: nil) - let result = try await service.recommendations(forMovie: movieID) + let result = try await (service as MovieService).recommendations(forMovie: movieID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieRecommendationsRequest == expectedRequest) @@ -73,14 +73,14 @@ struct TMDbMovieServiceListsTests { } } - @Test("similar returns movies") - func similarReturnsMovies() async throws { + @Test("similar with default parameter values returns movies") + func similarWithDefaultParameterValuesReturnsMovies() async throws { let movieID = 1 let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = SimilarMoviesRequest(id: movieID, page: nil, language: nil) - let result = try await service.similar(toMovie: movieID) + let result = try await (service as MovieService).similar(toMovie: movieID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? SimilarMoviesRequest == expectedRequest) @@ -111,13 +111,13 @@ struct TMDbMovieServiceListsTests { } } - @Test("nowPlaying returns movies") - func nowPlayingReturnsMovies() async throws { + @Test("nowPlaying with default parameter values returns movies") + func nowPlayingWithDefaultParameterValuesReturnsMovies() async throws { let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = MoviesNowPlayingRequest(page: nil) - let result = try await service.nowPlaying() + let result = try await (service as MovieService).nowPlaying() #expect(result == expectedResult) #expect(apiClient.lastRequest as? MoviesNowPlayingRequest == expectedRequest) @@ -148,13 +148,13 @@ struct TMDbMovieServiceListsTests { } } - @Test("popular returns movies") - func popularReturnsMovies() async throws { + @Test("popular with default parameter values returns movies") + func popularWithDefaultParameterValuesReturnsMovies() async throws { let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = PopularMoviesRequest(page: nil, country: nil, language: nil) - let result = try await service.popular() + let result = try await (service as MovieService).popular() #expect(result == expectedResult) #expect(apiClient.lastRequest as? PopularMoviesRequest == expectedRequest) @@ -184,13 +184,13 @@ struct TMDbMovieServiceListsTests { } } - @Test("topRated returns movies") - func topRatedReturnsMovies() async throws { + @Test("topRated with default parameter values returns movies") + func topRatedWithDefaultParameterValuesReturnsMovies() async throws { let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = TopRatedMoviesRequest(page: nil, country: nil, language: nil) - let result = try await service.topRated() + let result = try await (service as MovieService).topRated() #expect(result == expectedResult) #expect(apiClient.lastRequest as? TopRatedMoviesRequest == expectedRequest) @@ -221,13 +221,13 @@ struct TMDbMovieServiceListsTests { } } - @Test("upcoming returns movies") - func upcomingReturnsMovies() async throws { + @Test("upcoming with default parameter values returns movies") + func upcomingWithDefaultParameterValuesReturnsMovies() async throws { let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = UpcomingMoviesRequest(page: nil, country: nil, language: nil) - let result = try await service.upcoming() + let result = try await (service as MovieService).upcoming() #expect(result == expectedResult) #expect(apiClient.lastRequest as? UpcomingMoviesRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceMediaTests.swift b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceMediaTests.swift index f6ab482c..80ddb021 100644 --- a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceMediaTests.swift +++ b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceMediaTests.swift @@ -33,14 +33,14 @@ struct TMDbMovieServiceMediaTests { self.service = TMDbMovieService(apiClient: apiClient) } - @Test("images returns image collection") + @Test("images with default parameter values returns image collection") func imagesReturnsImageCollection() async throws { let expectedResult = ImageCollection.mock() let movieID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = MovieImagesRequest(id: movieID, languages: nil) - let result = try await service.images(forMovie: movieID) + let result = try await (service as MovieService).images(forMovie: movieID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieImagesRequest == expectedRequest) @@ -71,14 +71,14 @@ struct TMDbMovieServiceMediaTests { } } - @Test("videos returns video collection") + @Test("videos with default parameter values returns video collection") func videosReturnsVideoCollection() async throws { let expectedResult = VideoCollection.mock() let movieID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = MovieVideosRequest(id: movieID, languages: nil) - let result = try await service.videos(forMovie: movieID) + let result = try await (service as MovieService).videos(forMovie: movieID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieVideosRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceOthersTests.swift b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceOthersTests.swift index a7eb749c..02aed3fc 100644 --- a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceOthersTests.swift +++ b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceOthersTests.swift @@ -33,15 +33,32 @@ struct TMDbMovieServiceOthersTests { self.service = TMDbMovieService(apiClient: apiClient) } - @Test("watchProviders returns watch providers") - func watchProvidersReturnsWatchProviders() async throws { + @Test("watchProviders with default parameter values returns watch providers") + func watchProvidersWithDefaultParameterValuesReturnsWatchProviders() async throws { + let expectedResult = ShowWatchProviderResult.mock() + let movieID = 1 + let country = "US" + apiClient.addResponse(.success(expectedResult)) + let expectedRequest = MovieWatchProvidersRequest(id: movieID) + + let result = try await (service as MovieService).watchProviders(forMovie: movieID) + + #expect(result == expectedResult.results[country]) + #expect(apiClient.lastRequest as? MovieWatchProvidersRequest == expectedRequest) + } + + @Test("watchProviders with country returns watch providers") + func watchProvidersWithCountryReturnsWatchProviders() async throws { let expectedResult = ShowWatchProviderResult.mock() let movieID = 1 let country = "GB" apiClient.addResponse(.success(expectedResult)) let expectedRequest = MovieWatchProvidersRequest(id: movieID) - let result = try await service.watchProviders(forMovie: movieID, country: country) + let result = try await (service as MovieService).watchProviders( + forMovie: movieID, + country: country + ) #expect(result == expectedResult.results[country]) #expect(apiClient.lastRequest as? MovieWatchProvidersRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceReviewsTests.swift b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceReviewsTests.swift index dda025ef..48602f96 100644 --- a/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceReviewsTests.swift +++ b/Tests/TMDbTests/Domain/Services/Movies/TMDbMovieServiceReviewsTests.swift @@ -33,14 +33,14 @@ struct TMDbMovieServiceReviewsTests { self.service = TMDbMovieService(apiClient: apiClient) } - @Test("reviews returns reviews") + @Test("reviews with default parameter values returns reviews") func reviewsReturnsReviews() async throws { let movieID = 1 let expectedResult = ReviewPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = MovieReviewsRequest(id: movieID, page: nil, language: nil) - let result = try await service.reviews(forMovie: movieID) + let result = try await (service as MovieService).reviews(forMovie: movieID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieReviewsRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/People/TMDbPersonServiceTests.swift b/Tests/TMDbTests/Domain/Services/People/TMDbPersonServiceTests.swift index 2bd03419..0cc42d13 100644 --- a/Tests/TMDbTests/Domain/Services/People/TMDbPersonServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/TMDbPersonServiceTests.swift @@ -33,14 +33,14 @@ struct TMDbPersonServiceTests { self.service = TMDbPersonService(apiClient: apiClient) } - @Test("details returns person") - func detailsReturnsPerson() async throws { + @Test("details with parameter values returns person") + func detailsWithParameterValuesReturnsPerson() async throws { let expectedResult = Person.johnnyDepp let personID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = PersonRequest(id: personID, language: nil) - let result = try await service.details(forPerson: personID) + let result = try await (service as PersonService).details(forPerson: personID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? PersonRequest == expectedRequest) @@ -70,15 +70,15 @@ struct TMDbPersonServiceTests { } } - @Test("combinedCredits returns combinedCredits") - func combinedCreditsReturnsCombinedCredits() async throws { + @Test("combinedCredits with default parameter values returns combinedCredits") + func combinedCreditsWithDefaultParameterValuesReturnsCombinedCredits() async throws { let mock = PersonCombinedCredits.mock() let expectedResult = PersonCombinedCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = PersonCombinedCreditsRequest(id: personID, language: nil) - let result = try await service.combinedCredits(forPerson: personID) + let result = try await (service as PersonService).combinedCredits(forPerson: personID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? PersonCombinedCreditsRequest == expectedRequest) @@ -109,15 +109,15 @@ struct TMDbPersonServiceTests { } } - @Test("movieCredits returns movie credits") - func movieCreditsReturnsMovieCredits() async throws { + @Test("movieCredits with default parameter values returns movie credits") + func movieCreditsWithDefaultParameterValuesReturnsMovieCredits() async throws { let mock = PersonMovieCredits.mock() let expectedResult = PersonMovieCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = PersonMovieCreditsRequest(id: personID, language: nil) - let result = try await service.movieCredits(forPerson: personID) + let result = try await (service as PersonService).movieCredits(forPerson: personID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? PersonMovieCreditsRequest == expectedRequest) @@ -148,15 +148,15 @@ struct TMDbPersonServiceTests { } } - @Test("tvSeriesCredits returns tv series credits") - func tvSeriesCreditsReturnsTVSeriesCredits() async throws { + @Test("tvSeriesCredits with default parameter values returns tv series credits") + func tvSeriesCreditsWithDefaultParameterValuesReturnsTVSeriesCredits() async throws { let mock = PersonTVSeriesCredits.mock() let expectedResult = PersonTVSeriesCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = PersonTVSeriesCreditsRequest(id: personID, language: nil) - let result = try await service.tvSeriesCredits(forPerson: personID) + let result = try await (service as PersonService).tvSeriesCredits(forPerson: personID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? PersonTVSeriesCreditsRequest == expectedRequest) @@ -210,13 +210,13 @@ struct TMDbPersonServiceTests { } } - @Test("popular returns people") - func popularReturnsPeople() async throws { + @Test("popular with default parameter values returns people") + func popularWithDefaultParameterValuesReturnsPeople() async throws { let expectedResult = PersonPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = PopularPeopleRequest(page: nil, language: nil) - let result = try await service.popular() + let result = try await (service as PersonService).popular() #expect(result == expectedResult) #expect(apiClient.lastRequest as? PopularPeopleRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Search/TMDbSearchServiceTests.swift b/Tests/TMDbTests/Domain/Services/Search/TMDbSearchServiceTests.swift index 8da2fc5d..3676eb1e 100644 --- a/Tests/TMDbTests/Domain/Services/Search/TMDbSearchServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/Search/TMDbSearchServiceTests.swift @@ -33,15 +33,15 @@ struct TMDbSearchServiceTests { self.service = TMDbSearchService(apiClient: apiClient) } - @Test("searchAll returns media") - func searchAllReturnsMedia() async throws { + @Test("searchAll with default parameter values returns media") + func searchAllWithDefaultParameterValuesReturnsMedia() async throws { let query = "media search" let expectedResult = MediaPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = MultiSearchRequest( query: query, includeAdult: nil, page: nil, language: nil) - let result = try await service.searchAll(query: query) + let result = try await (service as SearchService).searchAll(query: query) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MultiSearchRequest == expectedRequest) @@ -80,8 +80,8 @@ struct TMDbSearchServiceTests { } } - @Test("searchMovies returns movies") - func searchMoviesReturnsMovies() async throws { + @Test("searchMovies with default parameter values returns movies") + func searchMoviesWithDefaultParameterValuesReturnsMovies() async throws { let query = "search movies" let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) @@ -93,7 +93,7 @@ struct TMDbSearchServiceTests { language: nil ) - let result = try await service.searchMovies(query: query) + let result = try await (service as SearchService).searchMovies(query: query) #expect(result == expectedResult) #expect(apiClient.lastRequest as? MovieSearchRequest == expectedRequest) @@ -140,8 +140,8 @@ struct TMDbSearchServiceTests { } } - @Test("searchTVSeries returns TV series") - func searchTVSeriesReturnsTVSeries() async throws { + @Test("searchTVSeries with default parameter values returns TV series") + func searchTVSeriesWithDefaultParameterValuesReturnsTVSeries() async throws { let query = "search tv series" let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) @@ -154,7 +154,7 @@ struct TMDbSearchServiceTests { language: nil ) - let result = try await service.searchTVSeries(query: query) + let result = try await (service as SearchService).searchTVSeries(query: query) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesSearchRequest == expectedRequest) @@ -198,15 +198,15 @@ struct TMDbSearchServiceTests { } } - @Test("searchPeople returns people") - func searchPeopleReturnsPeople() async throws { + @Test("searchPeople with default parameter values returns people") + func searchPeopleWithDefaultParameterValuesReturnsPeople() async throws { let query = "search people" let expectedResult = PersonPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = PersonSearchRequest( query: query, includeAdult: nil, page: nil, language: nil) - let result = try await service.searchPeople(query: query) + let result = try await (service as SearchService).searchPeople(query: query) #expect(result == expectedResult) #expect(apiClient.lastRequest as? PersonSearchRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/TVEpisodes/TMDbTVEpisodeServiceTests.swift b/Tests/TMDbTests/Domain/Services/TVEpisodes/TMDbTVEpisodeServiceTests.swift index 8b754db0..f1d139de 100644 --- a/Tests/TMDbTests/Domain/Services/TVEpisodes/TMDbTVEpisodeServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVEpisodes/TMDbTVEpisodeServiceTests.swift @@ -33,8 +33,8 @@ struct TMDbTVEpisodeServiceTests { self.service = TMDbTVEpisodeService(apiClient: apiClient) } - @Test("details returns TV episode") - func detailsReturnsTVEpisode() async throws { + @Test("details with default parameter values returns TV episode") + func detailsWithDefaultParameterValuesReturnsTVEpisode() async throws { let tvSeriesID = 1 let expectedResult = TVEpisode.mock() let seasonNumber = expectedResult.seasonNumber @@ -47,7 +47,7 @@ struct TMDbTVEpisodeServiceTests { language: nil ) - let result = try await service.details( + let result = try await (service as TVEpisodeService).details( forEpisode: episodeNumber, inSeason: seasonNumber, inTVSeries: tvSeriesID @@ -99,8 +99,8 @@ struct TMDbTVEpisodeServiceTests { } } - @Test("images returns images") - func imagesReturnsImages() async throws { + @Test("images with default parameter values returns images") + func imagesWithDefaultParameterValuesReturnsImages() async throws { let episodeNumber = 111 let seasonNumber = 11 let tvSeriesID = 1 @@ -113,7 +113,7 @@ struct TMDbTVEpisodeServiceTests { languages: nil ) - let result = try await service.images( + let result = try await (service as TVEpisodeService).images( forEpisode: episodeNumber, inSeason: seasonNumber, inTVSeries: tvSeriesID @@ -166,8 +166,8 @@ struct TMDbTVEpisodeServiceTests { } } - @Test("video returns videos") - func videosReturnsVideos() async throws { + @Test("video with default parameter values returns videos") + func videosWithDefaultParameterValuesReturnsVideos() async throws { let episodeNumber = 111 let seasonNumber = 11 let tvSeriesID = 1 @@ -180,7 +180,7 @@ struct TMDbTVEpisodeServiceTests { languages: nil ) - let result = try await service.videos( + let result = try await (service as TVEpisodeService).videos( forEpisode: episodeNumber, inSeason: seasonNumber, inTVSeries: tvSeriesID diff --git a/Tests/TMDbTests/Domain/Services/TVSeasons/TMDbTVSeasonServiceTests.swift b/Tests/TMDbTests/Domain/Services/TVSeasons/TMDbTVSeasonServiceTests.swift index 93729d93..8e68c1f0 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeasons/TMDbTVSeasonServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeasons/TMDbTVSeasonServiceTests.swift @@ -33,8 +33,8 @@ struct TMDbTVSeasonServiceTests { self.service = TMDbTVSeasonService(apiClient: apiClient) } - @Test("details returns TV season") - func detailsReturnsTVSeason() async throws { + @Test("details with default parameter values returns TV season") + func detailsWithDefaultParameterValuesReturnsTVSeason() async throws { let tvSeriesID = 1 let expectedResult = TVSeason.mock() let seasonNumber = expectedResult.seasonNumber @@ -45,7 +45,10 @@ struct TMDbTVSeasonServiceTests { language: nil ) - let result = try await service.details(forSeason: seasonNumber, inTVSeries: tvSeriesID) + let result = try await (service as TVSeasonService).details( + forSeason: seasonNumber, + inTVSeries: tvSeriesID + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeasonRequest == expectedRequest) @@ -82,8 +85,8 @@ struct TMDbTVSeasonServiceTests { } } - @Test("aggregateCredits returns TV season credits") - func aggregateCreditsReturnsTVSeasonCredits() async throws { + @Test("aggregateCredits with default parameter values returns TV season credits") + func aggregateCreditsWithDefaultParameterValuesReturnsTVSeasonCredits() async throws { let tvSeriesID = 1 let expectedResult = TVSeasonAggregateCredits(id: 1, cast: [], crew: []) let seasonNumber = 11 @@ -94,8 +97,10 @@ struct TMDbTVSeasonServiceTests { language: nil ) - let result = try await service.aggregateCredits( - forSeason: seasonNumber, inTVSeries: tvSeriesID) + let result = try await (service as TVSeasonService).aggregateCredits( + forSeason: seasonNumber, + inTVSeries: tvSeriesID + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeasonAggregateCreditsRequest == expectedRequest) @@ -135,8 +140,8 @@ struct TMDbTVSeasonServiceTests { } } - @Test("imagess returns images") - func imagesReturnsImages() async throws { + @Test("imagess with default parameter values returns images") + func imagesWithDefaultParameterValuesReturnsImages() async throws { let seasonNumber = 11 let tvSeriesID = 1 let expectedResult = TVSeasonImageCollection.mock() @@ -147,7 +152,10 @@ struct TMDbTVSeasonServiceTests { languages: nil ) - let result = try await service.images(forSeason: seasonNumber, inTVSeries: tvSeriesID) + let result = try await (service as TVSeasonService).images( + forSeason: seasonNumber, + inTVSeries: tvSeriesID + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeasonImagesRequest == expectedRequest) @@ -185,8 +193,8 @@ struct TMDbTVSeasonServiceTests { } } - @Test("videos returns videos") - func videosReturnsVideos() async throws { + @Test("videos with default parameter values returns videos") + func videosWithDefaultParameterValuesReturnsVideos() async throws { let seasonNumber = 11 let tvSeriesID = 1 let expectedResult = VideoCollection.mock() @@ -197,7 +205,10 @@ struct TMDbTVSeasonServiceTests { languages: nil ) - let result = try await service.videos(forSeason: seasonNumber, inTVSeries: tvSeriesID) + let result = try await (service as TVSeasonService).videos( + forSeason: seasonNumber, + inTVSeries: tvSeriesID + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeasonVideosRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceContentRatingTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceContentRatingTests.swift index 619daf31..b6d5ed31 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceContentRatingTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceContentRatingTests.swift @@ -33,11 +33,30 @@ struct TMDbTVSeriesServiceContentRatingTests { self.service = TMDbTVSeriesService(apiClient: apiClient) } + @Test("contentRatings with default parameter values returns TV series ratings") + func contentRatingsWithDefaultParameterValuesReturnsTVSeriesRatings() async throws { + let expectedResult = ContentRatingResult.mock + let tvSeriesID = expectedResult.id + let country = "US" + + let expectedRating = expectedResult.results.first { rating in + rating.countryCode == country + } + + apiClient.addResponse(.success(expectedResult)) + let expectedRequest = ContentRatingRequest(id: tvSeriesID) + + let result = try await (service as TVSeriesService).contentRatings(forTVSeries: tvSeriesID) + + #expect(result == expectedRating) + #expect(apiClient.lastRequest as? ContentRatingRequest == expectedRequest) + } + @Test("contentRatings with country returns TV series ratings") func contentRatingsWithCountryReturnsTVSeriesRatings() async throws { let expectedResult = ContentRatingResult.mock let tvSeriesID = expectedResult.id - let country = "US" + let country = "GB" let expectedRating = expectedResult.results.first { rating in rating.countryCode == country diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceCreditsTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceCreditsTests.swift index e78abf45..d6cd8a81 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceCreditsTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceCreditsTests.swift @@ -33,14 +33,14 @@ struct TMDbTVSeriesServiceCreditsTests { self.service = TMDbTVSeriesService(apiClient: apiClient) } - @Test("credits returns TV series credits") - func creditsReturnsTVSeriesCredits() async throws { + @Test("credits with default parameter values returns TV series credits") + func creditsWithDefaultParameterValuesReturnsTVSeriesCredits() async throws { let expectedResult = ShowCredits.mock() let tvSeriesID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = TVSeriesCreditsRequest(id: tvSeriesID, language: nil) - let result = try await service.credits(forTVSeries: tvSeriesID) + let result = try await (service as TVSeriesService).credits(forTVSeries: tvSeriesID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesCreditsRequest == expectedRequest) @@ -70,14 +70,16 @@ struct TMDbTVSeriesServiceCreditsTests { } } - @Test("aggregateCredits returns TV series credits") - func aggregateCreditsReturnsTVSeriesCredits() async throws { + @Test("aggregateCredits with default parameter values returns TV series credits") + func aggregateCreditsWithDefaultParameterValuesReturnsTVSeriesCredits() async throws { let expectedResult = TVSeriesAggregateCredits(id: 1, cast: [], crew: []) let tvSeriesID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = TVSeriesAggregateCreditsRequest(id: tvSeriesID, language: nil) - let result = try await service.aggregateCredits(forTVSeries: tvSeriesID) + let result = try await (service as TVSeriesService).aggregateCredits( + forTVSeries: tvSeriesID + ) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesAggregateCreditsRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceDetailsTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceDetailsTests.swift index c190c006..5973c8af 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceDetailsTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceDetailsTests.swift @@ -33,14 +33,14 @@ struct TMDbTVSeriesServiceTests { self.service = TMDbTVSeriesService(apiClient: apiClient) } - @Test("details returns TV series") + @Test("details with default parameter values returns TV series") func detailsReturnsTVSeries() async throws { let expectedResult = TVSeries.theSandman let tvSeriesID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = TVSeriesRequest(id: tvSeriesID, language: nil) - let result = try await service.details(forTVSeries: tvSeriesID) + let result = try await (service as TVSeriesService).details(forTVSeries: tvSeriesID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceListsTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceListsTests.swift index 3e8595c3..93044310 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceListsTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceListsTests.swift @@ -33,8 +33,8 @@ struct TMDbTVSeriesServiceListsTests { self.service = TMDbTVSeriesService(apiClient: apiClient) } - @Test("recommenendations returns TV series") - func recommendationsReturnsTVSeries() async throws { + @Test("recommenendations with default parameter values returns TV series") + func recommendationsWithDefaultParameterValuesReturnsTVSeries() async throws { let tvSeriesID = 1 let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) @@ -44,7 +44,7 @@ struct TMDbTVSeriesServiceListsTests { language: nil ) - let result = try await service.recommendations(forTVSeries: tvSeriesID) + let result = try await (service as TVSeriesService).recommendations(forTVSeries: tvSeriesID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesRecommendationsRequest == expectedRequest) @@ -77,14 +77,14 @@ struct TMDbTVSeriesServiceListsTests { } } - @Test("similar returns TV series") - func similarReturnsTVSeries() async throws { + @Test("similar with default parameter values returns TV series") + func similarWithDefaultParameterValuesReturnsTVSeries() async throws { let tvSeriesID = 1 let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = SimilarTVSeriesRequest(id: tvSeriesID, page: nil, language: nil) - let result = try await service.similar(toTVSeries: tvSeriesID) + let result = try await (service as TVSeriesService).similar(toTVSeries: tvSeriesID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? SimilarTVSeriesRequest == expectedRequest) @@ -116,13 +116,13 @@ struct TMDbTVSeriesServiceListsTests { } } - @Test("popular returns TV series") - func popularReturnsTVSeries() async throws { + @Test("popular with default parameter values returns TV series") + func popularWithDefaultParameterValuesReturnsTVSeries() async throws { let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = PopularTVSeriesRequest(page: nil, language: nil) - let result = try await service.popular() + let result = try await (service as TVSeriesService).popular() #expect(result == expectedResult) #expect(apiClient.lastRequest as? PopularTVSeriesRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceMediaTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceMediaTests.swift index b14eabef..d0c99a90 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceMediaTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceMediaTests.swift @@ -33,14 +33,14 @@ struct TMDbTVSeriesServiceMediaTests { self.service = TMDbTVSeriesService(apiClient: apiClient) } - @Test("images returns images") - func imagesReturnsImages() async throws { + @Test("images with default parameter values returns images") + func imagesWithDefaultParameterValuesReturnsImages() async throws { let tvSeriesID = 1 let expectedResult = ImageCollection.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = TVSeriesImagesRequest(id: tvSeriesID, languages: nil) - let result = try await service.images(forTVSeries: tvSeriesID) + let result = try await (service as TVSeriesService).images(forTVSeries: tvSeriesID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesImagesRequest == expectedRequest) @@ -71,14 +71,14 @@ struct TMDbTVSeriesServiceMediaTests { } } - @Test("video returns videos") - func videosReturnsVideos() async throws { + @Test("video with default parameter values returns videos") + func videosWithDefaultParameterValuesReturnsVideos() async throws { let expectedResult = VideoCollection.mock() let tvSeriesID = expectedResult.id apiClient.addResponse(.success(expectedResult)) let expectedRequest = TVSeriesVideosRequest(id: tvSeriesID, languages: nil) - let result = try await service.videos(forTVSeries: tvSeriesID) + let result = try await (service as TVSeriesService).videos(forTVSeries: tvSeriesID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesVideosRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceOthersTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceOthersTests.swift index 9cbf99f9..d15c2339 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceOthersTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceOthersTests.swift @@ -33,8 +33,22 @@ struct TMDbTVSeriesServiceOthersTests { self.service = TMDbTVSeriesService(apiClient: apiClient) } - @Test("watchProviders returns watch providers") - func watchProvidersReturnsWatchProviders() async throws { + @Test("watchProviders with default parameter values returns watch providers") + func watchProvidersWithDefaultParameterValuesReturnsWatchProviders() async throws { + let expectedResult = ShowWatchProviderResult.mock() + let tvSeriesID = 1 + let country = "US" + apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesWatchProvidersRequest(id: tvSeriesID) + + let result = try await (service as TVSeriesService).watchProviders(forTVSeries: tvSeriesID) + + #expect(result == expectedResult.results[country]) + #expect(apiClient.lastRequest as? TVSeriesWatchProvidersRequest == expectedRequest) + } + + @Test("watchProviders with country returns watch providers") + func watchProvidersWithCountryReturnsWatchProviders() async throws { let expectedResult = ShowWatchProviderResult.mock() let tvSeriesID = 1 let country = "GB" diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceReviewsTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceReviewsTests.swift index 9c52d79e..65678b16 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceReviewsTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeries/TMDbTVSeriesServiceReviewsTests.swift @@ -33,14 +33,14 @@ struct TMDbTVSeriesServiceReviewsTests { self.service = TMDbTVSeriesService(apiClient: apiClient) } - @Test("reviews returns reviews") - func reviewsReturnsReviews() async throws { + @Test("reviews with default parameter values returns reviews") + func reviewsWithDefaultParameterValuesReturnsReviews() async throws { let tvSeriesID = 1 let expectedResult = ReviewPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = TVSeriesReviewsRequest(id: tvSeriesID, page: nil, language: nil) - let result = try await service.reviews(forTVSeries: tvSeriesID) + let result = try await (service as TVSeriesService).reviews(forTVSeries: tvSeriesID) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TVSeriesReviewsRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/Trending/TMDbTrendingServiceTests.swift b/Tests/TMDbTests/Domain/Services/Trending/TMDbTrendingServiceTests.swift index 0bacb3e4..89d20f38 100644 --- a/Tests/TMDbTests/Domain/Services/Trending/TMDbTrendingServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/Trending/TMDbTrendingServiceTests.swift @@ -33,15 +33,15 @@ struct TMDbTrendingServiceTests { self.service = TMDbTrendingService(apiClient: apiClient) } - @Test("movies returns movies") - func moviesReturnsMovies() async throws { + @Test("movies with default parameter values returns movies") + func moviesWithDefaultParameterValuesReturnsMovies() async throws { let timeWindow = TrendingTimeWindowFilterType.day let expectedResult = MoviePageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = TrendingMoviesRequest( timeWindow: timeWindow, page: nil, language: nil) - let result = try await service.movies(inTimeWindow: timeWindow) + let result = try await (service as TrendingService).movies(inTimeWindow: timeWindow) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TrendingMoviesRequest == expectedRequest) @@ -74,15 +74,15 @@ struct TMDbTrendingServiceTests { } } - @Test("tvSeries returns tv series") - func tvSeriesReturnsTVSeries() async throws { + @Test("tvSeries with default parameter values returns tv series") + func tvSeriesWithDefaultParameterValuesReturnsTVSeries() async throws { let timeWindow = TrendingTimeWindowFilterType.day let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = TrendingTVSeriesRequest( timeWindow: timeWindow, page: nil, language: nil) - let result = try await service.tvSeries(inTimeWindow: timeWindow) + let result = try await (service as TrendingService).tvSeries(inTimeWindow: timeWindow) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TrendingTVSeriesRequest == expectedRequest) @@ -115,15 +115,15 @@ struct TMDbTrendingServiceTests { } } - @Test("people returns people") - func peopleReturnsPeople() async throws { + @Test("people with default parameter values returns people") + func peopleWithDefaultParameterValuesReturnsPeople() async throws { let timeWindow = TrendingTimeWindowFilterType.day let expectedResult = PersonPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = TrendingPeopleRequest( timeWindow: timeWindow, page: nil, language: nil) - let result = try await service.people(inTimeWindow: timeWindow) + let result = try await (service as TrendingService).people(inTimeWindow: timeWindow) #expect(result == expectedResult) #expect(apiClient.lastRequest as? TrendingPeopleRequest == expectedRequest) diff --git a/Tests/TMDbTests/Domain/Services/WatchProviders/TMDbWatchProviderServiceTests.swift b/Tests/TMDbTests/Domain/Services/WatchProviders/TMDbWatchProviderServiceTests.swift index a2acf335..f39efd2f 100644 --- a/Tests/TMDbTests/Domain/Services/WatchProviders/TMDbWatchProviderServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/WatchProviders/TMDbWatchProviderServiceTests.swift @@ -33,14 +33,14 @@ struct TMDbWatchProviderServiceTests { self.service = TMDbWatchProviderService(apiClient: apiClient) } - @Test("countries returns countries") - func countriesReturnsCountries() async throws { + @Test("countries with default parameter values returns countries") + func countriesWithDefaultParameterValuesReturnsCountries() async throws { let regions = WatchProviderRegions.mock let expectedResult = regions.results apiClient.addResponse(.success(regions)) let expectedRequest = WatchProviderRegionsRequest(language: nil) - let result = try await service.countries() + let result = try await (service as WatchProviderService).countries() #expect(result == expectedResult) #expect(apiClient.lastRequest as? WatchProviderRegionsRequest == expectedRequest) @@ -69,14 +69,14 @@ struct TMDbWatchProviderServiceTests { } } - @Test("movingWatchProviders returns watch providers") - func movieWatchProvidersReturnsWatchProviders() async throws { + @Test("movingWatchProviders with default parameter values returns watch providers") + func movieWatchProvidersWithDefaultParameterValuesReturnsWatchProviders() async throws { let watchProviderResult = WatchProviderResult.mock let expectedResult = watchProviderResult.results apiClient.addResponse(.success(watchProviderResult)) let expectedRequest = WatchProvidersForMoviesRequest(country: nil, language: nil) - let result = try await service.movieWatchProviders() + let result = try await (service as WatchProviderService).movieWatchProviders() #expect(result == expectedResult) #expect(apiClient.lastRequest as? WatchProvidersForMoviesRequest == expectedRequest) @@ -107,14 +107,14 @@ struct TMDbWatchProviderServiceTests { } } - @Test("tvSeriesWatchProviders returns watch providers") - func tvSeriesWatchProvidersReturnsWatchProviders() async throws { + @Test("tvSeriesWatchProviders with default parameter values returns watch providers") + func tvSeriesWatchProvidersWithDefaultParameterValuesReturnsWatchProviders() async throws { let watchProviderResult = WatchProviderResult.mock let expectedResult = watchProviderResult.results apiClient.addResponse(.success(watchProviderResult)) let expectedRequest = WatchProvidersForTVSeriesRequest(country: nil, language: nil) - let result = try await service.tvSeriesWatchProviders() + let result = try await (service as WatchProviderService).tvSeriesWatchProviders() #expect(result == expectedResult) #expect(apiClient.lastRequest as? WatchProvidersForTVSeriesRequest == expectedRequest) diff --git a/Tests/TMDbTests/Mocks/Models/PersonListItem+Mocks.swift b/Tests/TMDbTests/Mocks/Models/PersonListItem+Mocks.swift index d6798701..8a0c48ca 100644 --- a/Tests/TMDbTests/Mocks/Models/PersonListItem+Mocks.swift +++ b/Tests/TMDbTests/Mocks/Models/PersonListItem+Mocks.swift @@ -29,7 +29,9 @@ extension PersonListItem { knownForDepartment: String? = nil, gender: Gender = .unknown, profilePath: URL? = URL(string: "/t2yyOv40HZeVlLjYsCsPHnWLk4W.jpg"), - popularity: Double? = 5 + popularity: Double? = nil, + knownFor: [Show]? = nil, + isAdultOnly: Bool = false ) -> PersonListItem { PersonListItem( id: id, @@ -38,7 +40,9 @@ extension PersonListItem { knownForDepartment: knownForDepartment, gender: gender, profilePath: profilePath, - popularity: popularity + popularity: popularity, + knownFor: knownFor, + isAdultOnly: isAdultOnly ) } @@ -47,7 +51,12 @@ extension PersonListItem { } static var bradPitt: PersonListItem { - PersonListItem.mock(id: 287, name: "Brad Pitt", originalName: "Brad Pitt") + PersonListItem.mock( + id: 287, + name: "Brad Pitt", + originalName: "Brad Pitt", + gender: .male + ) } static var johnnyDepp: PersonListItem { diff --git a/Tests/TMDbTests/Networking/TMDbAPIErrorTests.swift b/Tests/TMDbTests/Networking/TMDbAPIErrorTests.swift new file mode 100644 index 00000000..34db1e8d --- /dev/null +++ b/Tests/TMDbTests/Networking/TMDbAPIErrorTests.swift @@ -0,0 +1,192 @@ +// +// TMDbErrorTMDbAPIErrorTests.swift +// TMDb +// +// Copyright © 2024 Adam Young. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an AS IS BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import Foundation +import Testing + +@testable import TMDb + +@Suite(.tags(.networking)) +struct TMDbAPIErrorTests { + + @Test("invalidURL errors equal") + func invalidURLErrorsEqual() { + let error1 = TMDbAPIError.invalidURL("message") + let error2 = TMDbAPIError.invalidURL("message") + + #expect(error1 == error2) + } + + @Test("network errors equal") + func networkErrorsEqual() { + let error1 = TMDbAPIError.network(MockError(message: "message")) + let error2 = TMDbAPIError.network(MockError(message: "message")) + + #expect(error1 == error2) + } + + @Test("badRequest errors equal") + func badRequestErrorsEqual() { + let error1 = TMDbAPIError.badRequest("message") + let error2 = TMDbAPIError.badRequest("message") + + #expect(error1 == error2) + } + + @Test("unauthorised errors equal") + func unauthorisedErrorsEqual() { + let error1 = TMDbAPIError.unauthorised("message") + let error2 = TMDbAPIError.unauthorised("message") + + #expect(error1 == error2) + } + + @Test("forbidden errors equal") + func forbiddenErrorsEqual() { + let error1 = TMDbAPIError.forbidden("message") + let error2 = TMDbAPIError.forbidden("message") + + #expect(error1 == error2) + } + + @Test("notFound errors equal") + func notFoundErrorsEqual() { + let error1 = TMDbAPIError.notFound("message") + let error2 = TMDbAPIError.notFound("message") + + #expect(error1 == error2) + } + + @Test("methodNotAllowed errors equal") + func methodNotAllowedErrorsEqual() { + let error1 = TMDbAPIError.methodNotAllowed("message") + let error2 = TMDbAPIError.methodNotAllowed("message") + + #expect(error1 == error2) + } + + @Test("notAcceptable errors equal") + func notAcceptableErrorsEqual() { + let error1 = TMDbAPIError.notAcceptable("message") + let error2 = TMDbAPIError.notAcceptable("message") + + #expect(error1 == error2) + } + + @Test("unprocessableContent errors equal") + func unprocessableContentErrorsEqual() { + let error1 = TMDbAPIError.unprocessableContent("message") + let error2 = TMDbAPIError.unprocessableContent("message") + + #expect(error1 == error2) + } + + @Test("tooManyRequests errors equal") + func tooManyRequestsErrorsEqual() { + let error1 = TMDbAPIError.tooManyRequests("message") + let error2 = TMDbAPIError.tooManyRequests("message") + + #expect(error1 == error2) + } + + @Test("internalServerError errors equal") + func internalServerErrorErrorsEqual() { + let error1 = TMDbAPIError.internalServerError("message") + let error2 = TMDbAPIError.internalServerError("message") + + #expect(error1 == error2) + } + + @Test("notImplemented errors equal") + func notImplementedErrorsEqual() { + let error1 = TMDbAPIError.notImplemented("message") + let error2 = TMDbAPIError.notImplemented("message") + + #expect(error1 == error2) + } + + @Test("badGateway errors equal") + func badGatewayErrorsEqual() { + let error1 = TMDbAPIError.badGateway("message") + let error2 = TMDbAPIError.badGateway("message") + + #expect(error1 == error2) + } + + @Test("serviceUnavailable errors equal") + func serviceUnavailableErrorsEqual() { + let error1 = TMDbAPIError.serviceUnavailable("message") + let error2 = TMDbAPIError.serviceUnavailable("message") + + #expect(error1 == error2) + } + + @Test("gatewayTimeout errors equal") + func gatewayTimeoutErrorsEqual() { + let error1 = TMDbAPIError.gatewayTimeout("message") + let error2 = TMDbAPIError.gatewayTimeout("message") + + #expect(error1 == error2) + } + + @Test("encode errors equal") + func encodeErrorsEqual() { + let error1 = TMDbAPIError.encode(MockError(message: "message")) + let error2 = TMDbAPIError.encode(MockError(message: "message")) + + #expect(error1 == error2) + } + + @Test("decode errors equal") + func decodeErrorsEqual() { + let error1 = TMDbAPIError.decode(MockError(message: "message")) + let error2 = TMDbAPIError.decode(MockError(message: "message")) + + #expect(error1 == error2) + } + + @Test("unknown errors equal") + func unknownErrorsEqual() { + let error1 = TMDbAPIError.unknown + let error2 = TMDbAPIError.unknown + + #expect(error1 == error2) + } + + @Test("encode and decode errors do not equal") + func encodeAndDecodeErrorsDoNotEqual() { + let error1 = TMDbAPIError.encode(MockError(message: "message 1")) + let error2 = TMDbAPIError.decode(MockError(message: "message 2")) + + #expect(error1 != error2) + } + +} + +extension TMDbAPIErrorTests { + + struct MockError: Error { + let message: String + + init(message: String = "some message") { + self.message = message + } + } + +} diff --git a/Tests/TMDbTests/Resources/json/media-pageable-list.json b/Tests/TMDbTests/Resources/json/media-pageable-list.json index 6a3dc137..0681f78d 100644 --- a/Tests/TMDbTests/Resources/json/media-pageable-list.json +++ b/Tests/TMDbTests/Resources/json/media-pageable-list.json @@ -42,8 +42,12 @@ "media_type": "tv", }, { - "id": 51329, - "name": "Bradley Cooper", + "id": 287, + "name": "Brad Pitt", + "originalName": "Brad Pitt", + "gender": 2, + "profile_path": "/t2yyOv40HZeVlLjYsCsPHnWLk4W.jpg", + "adult": false, "media_type": "person" } ], diff --git a/Tests/TMDbTests/Resources/json/media.json b/Tests/TMDbTests/Resources/json/media.json index a6f10395..1cb2569e 100644 --- a/Tests/TMDbTests/Resources/json/media.json +++ b/Tests/TMDbTests/Resources/json/media.json @@ -40,8 +40,12 @@ "media_type": "tv" }, { - "id": 51329, - "name": "Bradley Cooper", + "id": 287, + "name": "Brad Pitt", + "originalName": "Brad Pitt", + "gender": 2, + "profile_path": "/t2yyOv40HZeVlLjYsCsPHnWLk4W.jpg", + "adult": false, "media_type": "person" } ] diff --git a/Tests/TMDbTests/TestUtils/Tags.swift b/Tests/TMDbTests/TestUtils/Tags.swift index d885d2e2..127661d8 100644 --- a/Tests/TMDbTests/TestUtils/Tags.swift +++ b/Tests/TMDbTests/TestUtils/Tags.swift @@ -30,6 +30,7 @@ extension Tag { @Tag static var apiClient: Self @Tag static var decoding: Self + @Tag static var encoding: Self @Tag static var requests: Self @Tag static var account: Self