diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/PopularTVSeriesRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/PopularTVSeriesRequest.swift new file mode 100644 index 00000000..9bf4811c --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/PopularTVSeriesRequest.swift @@ -0,0 +1,43 @@ +// +// PopularTVSeriesRequest.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 + +final class PopularTVSeriesRequest: DecodableAPIRequest { + + init(page: Int? = nil) { + let path = "/tv/popular" + let queryItems = APIRequestQueryItems(page: page) + + super.init(path: path, queryItems: queryItems) + } + +} + +private extension APIRequestQueryItems { + + init(page: Int?) { + self.init() + + if let page { + self[.page] = page + } + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/SimilarTVSeriesRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/SimilarTVSeriesRequest.swift new file mode 100644 index 00000000..1f48eb04 --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/SimilarTVSeriesRequest.swift @@ -0,0 +1,43 @@ +// +// SimilarTVSeriesRequest.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 + +final class SimilarTVSeriesRequest: DecodableAPIRequest { + + init(id: TVSeries.ID, page: Int? = nil) { + let path = "/tv/\(id)/similar" + let queryItems = APIRequestQueryItems(page: page) + + super.init(path: path, queryItems: queryItems) + } + +} + +private extension APIRequestQueryItems { + + init(page: Int?) { + self.init() + + if let page { + self[.page] = page + } + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesCreditsRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesCreditsRequest.swift new file mode 100644 index 00000000..03e351c6 --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesCreditsRequest.swift @@ -0,0 +1,30 @@ +// +// TVSeriesCreditsRequest.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 + +final class TVSeriesCreditsRequest: DecodableAPIRequest { + + init(id: TVSeries.ID) { + let path = "/tv/\(id)/credits" + + super.init(path: path) + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesExternalLinksRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesExternalLinksRequest.swift new file mode 100644 index 00000000..06220229 --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesExternalLinksRequest.swift @@ -0,0 +1,30 @@ +// +// TVSeriesExternalLinksRequest.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 + +final class TVSeriesExternalLinksRequest: DecodableAPIRequest { + + init(id: TVSeries.ID) { + let path = "/tv/\(id)/external_ids" + + super.init(path: path) + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesImagesRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesImagesRequest.swift new file mode 100644 index 00000000..eb2d03c6 --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesImagesRequest.swift @@ -0,0 +1,43 @@ +// +// TVSeriesImagesRequest.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 + +final class TVSeriesImagesRequest: DecodableAPIRequest { + + init(id: TVSeries.ID, languageCode: String? = nil) { + let path = "/tv/\(id)/images" + let queryItems = APIRequestQueryItems(languageCode: languageCode) + + super.init(path: path, queryItems: queryItems) + } + +} + +private extension APIRequestQueryItems { + + init(languageCode: String?) { + self.init() + + if let languageCode { + self[.includeImageLanguage] = [languageCode, "null"].joined(separator: ",") + } + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesRecommendationsRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesRecommendationsRequest.swift new file mode 100644 index 00000000..ebb1b15f --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesRecommendationsRequest.swift @@ -0,0 +1,43 @@ +// +// TVSeriesRecommendationsRequest.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 + +final class TVSeriesRecommendationsRequest: DecodableAPIRequest { + + init(id: TVSeries.ID, page: Int? = nil) { + let path = "/tv/\(id)/recommendations" + let queryItems = APIRequestQueryItems(page: page) + + super.init(path: path, queryItems: queryItems) + } + +} + +private extension APIRequestQueryItems { + + init(page: Int?) { + self.init() + + if let page { + self[.page] = page + } + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesRequest.swift new file mode 100644 index 00000000..f3974137 --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesRequest.swift @@ -0,0 +1,30 @@ +// +// TVSeriesRequest.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 + +final class TVSeriesRequest: DecodableAPIRequest { + + init(id: TVSeries.ID) { + let path = "/tv/\(id)" + + super.init(path: path) + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesReviewsRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesReviewsRequest.swift new file mode 100644 index 00000000..890f76cf --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesReviewsRequest.swift @@ -0,0 +1,43 @@ +// +// TVSeriesReviewsRequest.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 + +final class TVSeriesReviewsRequest: DecodableAPIRequest { + + init(id: TVSeries.ID, page: Int? = nil) { + let path = "/tv/\(id)/reviews" + let queryItems = APIRequestQueryItems(page: page) + + super.init(path: path, queryItems: queryItems) + } + +} + +private extension APIRequestQueryItems { + + init(page: Int?) { + self.init() + + if let page { + self[.page] = page + } + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesVideosRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesVideosRequest.swift new file mode 100644 index 00000000..dafb54ea --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesVideosRequest.swift @@ -0,0 +1,43 @@ +// +// TVSeriesVideosRequest.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 + +final class TVSeriesVideosRequest: DecodableAPIRequest { + + init(id: TVSeries.ID, languageCode: String? = nil) { + let path = "/tv/\(id)/videos" + let queryItems = APIRequestQueryItems(languageCode: languageCode) + + super.init(path: path, queryItems: queryItems) + } + +} + +private extension APIRequestQueryItems { + + init(languageCode: String?) { + self.init() + + if let languageCode { + self[.includeVideoLanguage] = [languageCode, "null"].joined(separator: ",") + } + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesWatchProvidersRequest.swift b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesWatchProvidersRequest.swift new file mode 100644 index 00000000..091cee52 --- /dev/null +++ b/Sources/TMDb/Domain/Services/TVSeries/Requests/TVSeriesWatchProvidersRequest.swift @@ -0,0 +1,30 @@ +// +// TVSeriesWatchProvidersRequest.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 + +final class TVSeriesWatchProvidersRequest: DecodableAPIRequest { + + init(id: TVSeries.ID) { + let path = "/tv/\(id)/watch/providers" + + super.init(path: path) + } + +} diff --git a/Sources/TMDb/Domain/Services/TVSeries/TVSeriesEndpoint.swift b/Sources/TMDb/Domain/Services/TVSeries/TVSeriesEndpoint.swift deleted file mode 100644 index ce24bf80..00000000 --- a/Sources/TMDb/Domain/Services/TVSeries/TVSeriesEndpoint.swift +++ /dev/null @@ -1,99 +0,0 @@ -// -// TVSeriesEndpoint.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 - -enum TVSeriesEndpoint { - - case details(tvSeriesID: TVSeries.ID) - case credits(tvSeriesID: TVSeries.ID) - case reviews(tvSeriesID: TVSeries.ID, page: Int? = nil) - case images(tvSeriesID: TVSeries.ID, languageCode: String?) - case videos(tvSeriesID: TVSeries.ID, languageCode: String?) - case recommendations(tvSeriesID: TVSeries.ID, page: Int? = nil) - case similar(tvSeriesID: TVSeries.ID, page: Int? = nil) - case popular(page: Int? = nil) - case watch(tvSeriesID: TVSeries.ID) - case externalIDs(tvSeriesID: TVSeries.ID) - -} - -extension TVSeriesEndpoint: Endpoint { - - private static let basePath = URL(string: "/tv")! - - var path: URL { - switch self { - case let .details(tvSeriesID): - Self.basePath - .appendingPathComponent(tvSeriesID) - - case let .credits(tvSeriesID): - Self.basePath - .appendingPathComponent(tvSeriesID) - .appendingPathComponent("credits") - - case let .reviews(tvSeriesID, page): - Self.basePath - .appendingPathComponent(tvSeriesID) - .appendingPathComponent("reviews") - .appendingPage(page) - - case let .images(tvSeriesID, languageCode): - Self.basePath - .appendingPathComponent(tvSeriesID) - .appendingPathComponent("images") - .appendingImageLanguage(languageCode) - - case let .videos(tvSeriesID, languageCode): - Self.basePath - .appendingPathComponent(tvSeriesID) - .appendingPathComponent("videos") - .appendingVideoLanguage(languageCode) - - case let .recommendations(tvSeriesID, page): - Self.basePath - .appendingPathComponent(tvSeriesID) - .appendingPathComponent("recommendations") - .appendingPage(page) - - case let .similar(tvSeriesID, page): - Self.basePath - .appendingPathComponent(tvSeriesID) - .appendingPathComponent("similar") - .appendingPage(page) - - case let .popular(page): - Self.basePath - .appendingPathComponent("popular") - .appendingPage(page) - - case let .watch(tvSeriesID): - Self.basePath - .appendingPathComponent(tvSeriesID) - .appendingPathComponent("watch/providers") - - case let .externalIDs(tvSeriesID): - Self.basePath - .appendingPathComponent(tvSeriesID) - .appendingPathComponent("external_ids") - } - } - -} diff --git a/Sources/TMDb/Domain/Services/TVSeries/TVSeriesService.swift b/Sources/TMDb/Domain/Services/TVSeries/TVSeriesService.swift index d2786716..e1e1cbe2 100644 --- a/Sources/TMDb/Domain/Services/TVSeries/TVSeriesService.swift +++ b/Sources/TMDb/Domain/Services/TVSeries/TVSeriesService.swift @@ -58,9 +58,11 @@ public final class TVSeriesService { /// - Returns: The matching TV series. /// public func details(forTVSeries id: TVSeries.ID) async throws -> TVSeries { + let request = TVSeriesRequest(id: id) + let tvSeries: TVSeries do { - tvSeries = try await apiClient.get(endpoint: TVSeriesEndpoint.details(tvSeriesID: id)) + tvSeries = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -81,9 +83,11 @@ public final class TVSeriesService { /// - Returns: Show credits for the matching TV series. /// public func credits(forTVSeries tvSeriesID: TVSeries.ID) async throws -> ShowCredits { + let request = TVSeriesCreditsRequest(id: tvSeriesID) + let credits: ShowCredits do { - credits = try await apiClient.get(endpoint: TVSeriesEndpoint.credits(tvSeriesID: tvSeriesID)) + credits = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -107,9 +111,11 @@ public final class TVSeriesService { /// - Returns: Reviews for the matching TV series as a pageable list. /// public func reviews(forTVSeries tvSeriesID: TVSeries.ID, page: Int? = nil) async throws -> ReviewPageableList { + let request = TVSeriesReviewsRequest(id: tvSeriesID, page: page) + let reviewList: ReviewPageableList do { - reviewList = try await apiClient.get(endpoint: TVSeriesEndpoint.reviews(tvSeriesID: tvSeriesID, page: page)) + reviewList = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -131,11 +137,11 @@ public final class TVSeriesService { /// public func images(forTVSeries tvSeriesID: TVSeries.ID) async throws -> ImageCollection { let languageCode = localeProvider.languageCode + let request = TVSeriesImagesRequest(id: tvSeriesID, languageCode: languageCode) + let imageCollection: ImageCollection do { - imageCollection = try await apiClient.get( - endpoint: TVSeriesEndpoint.images(tvSeriesID: tvSeriesID, languageCode: languageCode) - ) + imageCollection = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -157,11 +163,11 @@ public final class TVSeriesService { /// public func videos(forTVSeries tvSeriesID: TVSeries.ID) async throws -> VideoCollection { let languageCode = localeProvider.languageCode + let request = TVSeriesVideosRequest(id: tvSeriesID, languageCode: languageCode) + let videoCollection: VideoCollection do { - videoCollection = try await apiClient.get( - endpoint: TVSeriesEndpoint.videos(tvSeriesID: tvSeriesID, languageCode: languageCode) - ) + videoCollection = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -188,11 +194,11 @@ public final class TVSeriesService { forTVSeries tvSeriesID: TVSeries.ID, page: Int? = nil ) async throws -> TVSeriesPageableList { + let request = TVSeriesRecommendationsRequest(id: tvSeriesID, page: page) + let tvSeriesList: TVSeriesPageableList do { - tvSeriesList = try await apiClient.get( - endpoint: TVSeriesEndpoint.recommendations(tvSeriesID: tvSeriesID, page: page) - ) + tvSeriesList = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -218,11 +224,11 @@ public final class TVSeriesService { /// - Returns: Similar TV series for the matching TV series as a pageable list. /// public func similar(toTVSeries tvSeriesID: TVSeries.ID, page: Int? = nil) async throws -> TVSeriesPageableList { + let request = SimilarTVSeriesRequest(id: tvSeriesID, page: page) + let tvSeriesList: TVSeriesPageableList do { - tvSeriesList = try await apiClient.get( - endpoint: TVSeriesEndpoint.similar(tvSeriesID: tvSeriesID, page: page) - ) + tvSeriesList = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -245,9 +251,11 @@ public final class TVSeriesService { /// - Returns: Current popular TV series as a pageable list. /// public func popular(page: Int? = nil) async throws -> TVSeriesPageableList { + let request = PopularTVSeriesRequest(page: page) + let tvSeriesList: TVSeriesPageableList do { - tvSeriesList = try await apiClient.get(endpoint: TVSeriesEndpoint.popular(page: page)) + tvSeriesList = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -271,9 +279,12 @@ public final class TVSeriesService { guard let regionCode = localeProvider.regionCode else { return nil } + + let request = TVSeriesWatchProvidersRequest(id: tvSeriesID) + let result: ShowWatchProviderResult do { - result = try await apiClient.get(endpoint: TVSeriesEndpoint.watch(tvSeriesID: tvSeriesID)) + result = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } @@ -292,9 +303,11 @@ public final class TVSeriesService { /// - Returns: A collection of external links for the specificed TV series. /// public func externalLinks(forTVSeries tvSeriesID: TVSeries.ID) async throws -> TVSeriesExternalLinksCollection { + let request = TVSeriesExternalLinksRequest(id: tvSeriesID) + let linksCollection: TVSeriesExternalLinksCollection do { - linksCollection = try await apiClient.get(endpoint: TVSeriesEndpoint.externalIDs(tvSeriesID: tvSeriesID)) + linksCollection = try await apiClient.perform(request) } catch let error { throw TMDbError(error: error) } diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/PopularTVSeriesRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/PopularTVSeriesRequestTests.swift new file mode 100644 index 00000000..5755275f --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/PopularTVSeriesRequestTests.swift @@ -0,0 +1,67 @@ +// +// PopularTVSeriesRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class PopularTVSeriesRequestTests: XCTestCase { + + func testPath() { + let request = PopularTVSeriesRequest() + + XCTAssertEqual(request.path, "/tv/popular") + } + + func testQueryItemsWhenPageIsNilQueryItemsAreEmpty() { + let request = PopularTVSeriesRequest() + + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testQueryItemsWhenPageQueryItemsHasPage() { + let request = PopularTVSeriesRequest(page: 3) + + XCTAssertEqual(request.queryItems, ["page": "3"]) + } + + func testMethodIsGet() { + let request = PopularTVSeriesRequest() + + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + let request = PopularTVSeriesRequest() + + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + let request = PopularTVSeriesRequest() + + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + let request = PopularTVSeriesRequest() + + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/SimilarTVSeriesRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/SimilarTVSeriesRequestTests.swift new file mode 100644 index 00000000..2d980bfe --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/SimilarTVSeriesRequestTests.swift @@ -0,0 +1,67 @@ +// +// SimilarTVSeriesRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class SimilarTVSeriesRequestTests: XCTestCase { + + func testPath() { + let request = SimilarTVSeriesRequest(id: 1) + + XCTAssertEqual(request.path, "/tv/1/similar") + } + + func testQueryItemsWhenPageIsNilQueryItemsAreEmpty() { + let request = SimilarTVSeriesRequest(id: 1) + + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testQueryItemsWhenPageQueryItemsHasPage() { + let request = SimilarTVSeriesRequest(id: 1, page: 3) + + XCTAssertEqual(request.queryItems, ["page": "3"]) + } + + func testMethodIsGet() { + let request = SimilarTVSeriesRequest(id: 1) + + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + let request = SimilarTVSeriesRequest(id: 1) + + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + let request = SimilarTVSeriesRequest(id: 1) + + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + let request = SimilarTVSeriesRequest(id: 1) + + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesCreditsRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesCreditsRequestTests.swift new file mode 100644 index 00000000..033dfa89 --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesCreditsRequestTests.swift @@ -0,0 +1,61 @@ +// +// TVSeriesCreditsRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class TVSeriesCreditsRequestTests: XCTestCase { + + var request: TVSeriesCreditsRequest! + + override func setUp() { + super.setUp() + request = TVSeriesCreditsRequest(id: 1) + } + + override func tearDown() { + request = nil + super.tearDown() + } + + func testPath() { + XCTAssertEqual(request.path, "/tv/1/credits") + } + + func testQueryItemsAreEmpty() { + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testMethodIsGet() { + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesExternalLinksRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesExternalLinksRequestTests.swift new file mode 100644 index 00000000..80bafa43 --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesExternalLinksRequestTests.swift @@ -0,0 +1,61 @@ +// +// TVSeriesExternalLinksRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class TVSeriesExternalLinksRequestTests: XCTestCase { + + var request: TVSeriesExternalLinksRequest! + + override func setUp() { + super.setUp() + request = TVSeriesExternalLinksRequest(id: 1) + } + + override func tearDown() { + request = nil + super.tearDown() + } + + func testPath() { + XCTAssertEqual(request.path, "/tv/1/external_ids") + } + + func testQueryItemsAreEmpty() { + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testMethodIsGet() { + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesImagesRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesImagesRequestTests.swift new file mode 100644 index 00000000..b4f4c5ce --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesImagesRequestTests.swift @@ -0,0 +1,68 @@ +// +// TVSeriesImagesRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class TVSeriesImagesRequestTests: XCTestCase { + + func testPath() { + let request = TVSeriesImagesRequest(id: 1) + + XCTAssertEqual(request.path, "/tv/1/images") + } + + func testQueryItemsWhenLanguageCodeIsNilQueryItemsAreEmpty() { + let request = TVSeriesImagesRequest(id: 1) + + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testQueryItemsWhenLanguageCodeQueryItemsHasLanguageCode() { + let request = TVSeriesImagesRequest(id: 1, languageCode: "en") + + XCTAssertEqual(request.queryItems.count, 1) + XCTAssertEqual(request.queryItems["include_image_language"], "en,null") + } + + func testMethodIsGet() { + let request = TVSeriesImagesRequest(id: 1) + + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + let request = TVSeriesImagesRequest(id: 1) + + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + let request = TVSeriesImagesRequest(id: 1) + + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + let request = TVSeriesImagesRequest(id: 1) + + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesRequestTests.swift new file mode 100644 index 00000000..26a5e24a --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesRequestTests.swift @@ -0,0 +1,61 @@ +// +// TVSeriesRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class TVSeriesRequestTests: XCTestCase { + + var request: TVSeriesRequest! + + override func setUp() { + super.setUp() + request = TVSeriesRequest(id: 1) + } + + override func tearDown() { + request = nil + super.tearDown() + } + + func testPath() { + XCTAssertEqual(request.path, "/tv/1") + } + + func testQueryItemsAreEmpty() { + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testMethodIsGet() { + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesReviewsRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesReviewsRequestTests.swift new file mode 100644 index 00000000..38a2710a --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesReviewsRequestTests.swift @@ -0,0 +1,67 @@ +// +// TVSeriesReviewsRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class TVSeriesReviewsRequestTests: XCTestCase { + + func testPath() { + let request = TVSeriesReviewsRequest(id: 1) + + XCTAssertEqual(request.path, "/tv/1/reviews") + } + + func testQueryItemsWhenPageIsNilQueryItemsAreEmpty() { + let request = TVSeriesReviewsRequest(id: 1) + + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testQueryItemsWhenPageQueryItemsHasPage() { + let request = TVSeriesReviewsRequest(id: 1, page: 3) + + XCTAssertEqual(request.queryItems, ["page": "3"]) + } + + func testMethodIsGet() { + let request = TVSeriesReviewsRequest(id: 1) + + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + let request = TVSeriesReviewsRequest(id: 1) + + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + let request = TVSeriesReviewsRequest(id: 1) + + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + let request = TVSeriesReviewsRequest(id: 1) + + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesVideosRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesVideosRequestTests.swift new file mode 100644 index 00000000..dd325250 --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesVideosRequestTests.swift @@ -0,0 +1,68 @@ +// +// TVSeriesVideosRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class TVSeriesVideosRequestTests: XCTestCase { + + func testPath() { + let request = TVSeriesVideosRequest(id: 1) + + XCTAssertEqual(request.path, "/tv/1/videos") + } + + func testQueryItemsWhenLanguageCodeIsNilQueryItemsAreEmpty() { + let request = TVSeriesVideosRequest(id: 1) + + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testQueryItemsWhenLanguageCodeQueryItemsHasLanguageCode() { + let request = TVSeriesVideosRequest(id: 1, languageCode: "en") + + XCTAssertEqual(request.queryItems.count, 1) + XCTAssertEqual(request.queryItems["include_video_language"], "en,null") + } + + func testMethodIsGet() { + let request = TVSeriesVideosRequest(id: 1) + + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + let request = TVSeriesVideosRequest(id: 1) + + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + let request = TVSeriesVideosRequest(id: 1) + + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + let request = TVSeriesVideosRequest(id: 1) + + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesWatchProvidersRequestTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesWatchProvidersRequestTests.swift new file mode 100644 index 00000000..c08e37ed --- /dev/null +++ b/Tests/TMDbTests/Domain/Services/TVSeries/Requests/TVSeriesWatchProvidersRequestTests.swift @@ -0,0 +1,61 @@ +// +// TVSeriesWatchProvidersRequestTests.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. +// + +@testable import TMDb +import XCTest + +final class TVSeriesWatchProvidersRequestTests: XCTestCase { + + var request: TVSeriesWatchProvidersRequest! + + override func setUp() { + super.setUp() + request = TVSeriesWatchProvidersRequest(id: 1) + } + + override func tearDown() { + request = nil + super.tearDown() + } + + func testPath() { + XCTAssertEqual(request.path, "/tv/1/watch/providers") + } + + func testQueryItemsAreEmpty() { + XCTAssertTrue(request.queryItems.isEmpty) + } + + func testMethodIsGet() { + XCTAssertEqual(request.method, .get) + } + + func testHeadersIsEmpty() { + XCTAssertTrue(request.headers.isEmpty) + } + + func testBodyIsNil() { + XCTAssertNil(request.body) + } + + func testSerialiserIsTMDbJSON() { + XCTAssertTrue(request.serialiser is TMDbJSONSerialiser) + } + +} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TVSeriesEndpointTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TVSeriesEndpointTests.swift deleted file mode 100644 index 626575c3..00000000 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TVSeriesEndpointTests.swift +++ /dev/null @@ -1,141 +0,0 @@ -// -// TVSeriesEndpointTests.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. -// - -@testable import TMDb -import XCTest - -final class TVSeriesEndpointTests: XCTestCase { - - func testTVSeriesDetailsEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1")) - - let url = TVSeriesEndpoint.details(tvSeriesID: 1).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesCreditsEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/credits")) - - let url = TVSeriesEndpoint.credits(tvSeriesID: 1).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesReviewsEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/reviews")) - - let url = TVSeriesEndpoint.reviews(tvSeriesID: 1).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesReviewsEndpointWithPageReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/reviews?page=2")) - - let url = TVSeriesEndpoint.reviews(tvSeriesID: 1, page: 2).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesImagesEndpointReturnsURL() throws { - let languageCode = "en" - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/images?include_image_language=\(languageCode),null")) - - let url = TVSeriesEndpoint.images(tvSeriesID: 1, languageCode: languageCode).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesVideosEndpointReturnsURL() throws { - let languageCode = "en" - let expectedURL = try XCTUnwrap(URL( - string: "/tv/1/videos?include_video_language=\(languageCode),null" - )) - - let url = TVSeriesEndpoint.videos(tvSeriesID: 1, languageCode: languageCode).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesRecommendationsEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/recommendations")) - - let url = TVSeriesEndpoint.recommendations(tvSeriesID: 1).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesRecommendationsEndpointWithPageReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/recommendations?page=2")) - - let url = TVSeriesEndpoint.recommendations(tvSeriesID: 1, page: 2).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesSimilarEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/similar")) - - let url = TVSeriesEndpoint.similar(tvSeriesID: 1).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesSimilarEndpointWithPageReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/similar?page=2")) - - let url = TVSeriesEndpoint.similar(tvSeriesID: 1, page: 2).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesPopularEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/popular")) - - let url = TVSeriesEndpoint.popular().path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesPopularEndpointWithPageReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/popular?page=1")) - - let url = TVSeriesEndpoint.popular(page: 1).path - - XCTAssertEqual(url, expectedURL) - } - - func testTVSeriesWatchEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/watch/providers")) - - let url = TVSeriesEndpoint.watch(tvSeriesID: 1).path - - XCTAssertEqual(url, expectedURL) - } - - func testMovieExternalIDsEndpointReturnsURL() throws { - let expectedURL = try XCTUnwrap(URL(string: "/tv/1/external_ids")) - - let url = TVSeriesEndpoint.externalIDs(tvSeriesID: 1).path - - XCTAssertEqual(url, expectedURL) - } - -} diff --git a/Tests/TMDbTests/Domain/Services/TVSeries/TVSeriesServiceTests.swift b/Tests/TMDbTests/Domain/Services/TVSeries/TVSeriesServiceTests.swift index 54c66cb3..78bb7c24 100644 --- a/Tests/TMDbTests/Domain/Services/TVSeries/TVSeriesServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/TVSeries/TVSeriesServiceTests.swift @@ -44,48 +44,48 @@ final class TVSeriesServiceTests: XCTestCase { let expectedResult = TVSeries.theSandman let tvSeriesID = expectedResult.id apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesRequest(id: tvSeriesID) let result = try await service.details(forTVSeries: tvSeriesID) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.details(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesRequest, expectedRequest) } func testCreditsReturnsShowsCredits() async throws { let expectedResult = ShowCredits.mock() let tvSeriesID = expectedResult.id apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesCreditsRequest(id: tvSeriesID) let result = try await service.credits(forTVSeries: tvSeriesID) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.credits(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesCreditsRequest, expectedRequest) } func testReviewsWithDefaultParametersReturnsReviews() async throws { let tvSeriesID = Int.randomID let expectedResult = ReviewPageableList.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesReviewsRequest(id: tvSeriesID, page: nil) let result = try await service.reviews(forTVSeries: tvSeriesID) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.reviews(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesReviewsRequest, expectedRequest) } func testReviewsReturnsReviews() async throws { let tvSeriesID = Int.randomID let expectedResult = ReviewPageableList.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesReviewsRequest(id: tvSeriesID, page: nil) let result = try await service.reviews(forTVSeries: tvSeriesID, page: nil) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.reviews(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesReviewsRequest, expectedRequest) } func testReviewsWithPageReturnsReviews() async throws { @@ -93,66 +93,60 @@ final class TVSeriesServiceTests: XCTestCase { let expectedResult = ReviewPageableList.mock() let page = expectedResult.page apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesReviewsRequest(id: tvSeriesID, page: page) let result = try await service.reviews(forTVSeries: tvSeriesID, page: page) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.reviews(tvSeriesID: tvSeriesID, page: page).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesReviewsRequest, expectedRequest) } func testImagesReturnsImages() async throws { let tvSeriesID = Int.randomID let expectedResult = ImageCollection.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesImagesRequest(id: tvSeriesID, languageCode: localeProvider.languageCode) let result = try await service.images(forTVSeries: tvSeriesID) XCTAssertEqual(result, expectedResult) - XCTAssertEqual( - apiClient.lastRequestURL, - TVSeriesEndpoint.images(tvSeriesID: tvSeriesID, languageCode: localeProvider.languageCode).path - ) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesImagesRequest, expectedRequest) } func testVideosReturnsVideos() async throws { let expectedResult = VideoCollection.mock() let tvSeriesID = expectedResult.id apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesVideosRequest(id: tvSeriesID, languageCode: localeProvider.languageCode) let result = try await service.videos(forTVSeries: tvSeriesID) XCTAssertEqual(result, expectedResult) - XCTAssertEqual( - apiClient.lastRequestURL, - TVSeriesEndpoint.videos(tvSeriesID: tvSeriesID, languageCode: localeProvider.languageCode).path - ) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesVideosRequest, expectedRequest) } func testRecommendationsWithDefaultParametersReturnsTVSeries() async throws { let tvSeriesID = Int.randomID let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesRecommendationsRequest(id: tvSeriesID, page: nil) let result = try await service.recommendations(forTVSeries: tvSeriesID) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.recommendations(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesRecommendationsRequest, expectedRequest) } func testRecommendationsReturnsTVSeries() async throws { let tvSeriesID = Int.randomID let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesRecommendationsRequest(id: tvSeriesID, page: nil) let result = try await service.recommendations(forTVSeries: tvSeriesID, page: nil) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.recommendations(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesRecommendationsRequest, expectedRequest) } func testRecommendationsWithPageReturnsTVSeries() async throws { @@ -160,39 +154,36 @@ final class TVSeriesServiceTests: XCTestCase { let expectedResult = TVSeriesPageableList.mock() let page = expectedResult.page apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesRecommendationsRequest(id: tvSeriesID, page: page) let result = try await service.recommendations(forTVSeries: tvSeriesID, page: page) XCTAssertEqual(result, expectedResult) - XCTAssertEqual( - apiClient.lastRequestURL, - TVSeriesEndpoint.recommendations(tvSeriesID: tvSeriesID, page: page).path - ) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesRecommendationsRequest, expectedRequest) } func testSimilarWithDefaultParametersReturnsTVSeries() async throws { let tvSeriesID = Int.randomID let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = SimilarTVSeriesRequest(id: tvSeriesID, page: nil) let result = try await service.similar(toTVSeries: tvSeriesID) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.similar(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? SimilarTVSeriesRequest, expectedRequest) } func testSimilarReturnsTVSeries() async throws { let tvSeriesID = Int.randomID let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = SimilarTVSeriesRequest(id: tvSeriesID, page: nil) let result = try await service.similar(toTVSeries: tvSeriesID, page: nil) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.similar(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? SimilarTVSeriesRequest, expectedRequest) } func testSimilarWithPageReturnsTVSeries() async throws { @@ -200,71 +191,71 @@ final class TVSeriesServiceTests: XCTestCase { let expectedResult = TVSeriesPageableList.mock() let page = expectedResult.page apiClient.addResponse(.success(expectedResult)) + let expectedRequest = SimilarTVSeriesRequest(id: tvSeriesID, page: page) let result = try await service.similar(toTVSeries: tvSeriesID, page: page) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.similar(tvSeriesID: tvSeriesID, page: page).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? SimilarTVSeriesRequest, expectedRequest) } func testPopularWithDefaultParametersReturnsTVSeries() async throws { let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = PopularTVSeriesRequest(page: nil) let result = try await service.popular() XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.popular().path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? PopularTVSeriesRequest, expectedRequest) } func testPopularReturnsTVSeries() async throws { let expectedResult = TVSeriesPageableList.mock() apiClient.addResponse(.success(expectedResult)) + let expectedRequest = PopularTVSeriesRequest(page: nil) let result = try await service.popular(page: nil) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.popular().path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? PopularTVSeriesRequest, expectedRequest) } func testPopularWithPageReturnsTVSeries() async throws { let expectedResult = TVSeriesPageableList.mock() let page = expectedResult.page apiClient.addResponse(.success(expectedResult)) + let expectedRequest = PopularTVSeriesRequest(page: page) let result = try await service.popular(page: page) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.popular(page: page).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? PopularTVSeriesRequest, expectedRequest) } func testWatchReturnsWatchProviders() async throws { let expectedResult = ShowWatchProviderResult.mock() let tvSeriesID = 1 apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesWatchProvidersRequest(id: tvSeriesID) let result = try await service.watchProviders(forTVSeries: tvSeriesID) let regionCode = try XCTUnwrap(localeProvider.regionCode) XCTAssertEqual(result, expectedResult.results[regionCode]) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.watch(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesWatchProvidersRequest, expectedRequest) } func testExternalLinksReturnsExternalLinks() async throws { let expectedResult = TVSeriesExternalLinksCollection.lockeAndKey let tvSeriesID = 86423 apiClient.addResponse(.success(expectedResult)) + let expectedRequest = TVSeriesExternalLinksRequest(id: tvSeriesID) let result = try await service.externalLinks(forTVSeries: tvSeriesID) XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequestURL, TVSeriesEndpoint.externalIDs(tvSeriesID: tvSeriesID).path) - XCTAssertEqual(apiClient.lastRequestMethod, .get) + XCTAssertEqual(apiClient.lastRequest as? TVSeriesExternalLinksRequest, expectedRequest) } } diff --git a/Tests/TMDbTests/Domain/Services/WatchProviders/Requests/WatchProvidersForTVSeriesRequestTests.swift b/Tests/TMDbTests/Domain/Services/WatchProviders/Requests/WatchProvidersForTVSeriesRequestTests.swift index d9c2b03b..08356da8 100644 --- a/Tests/TMDbTests/Domain/Services/WatchProviders/Requests/WatchProvidersForTVSeriesRequestTests.swift +++ b/Tests/TMDbTests/Domain/Services/WatchProviders/Requests/WatchProvidersForTVSeriesRequestTests.swift @@ -20,7 +20,7 @@ @testable import TMDb import XCTest -final class TVSeriesWatchProvidersRequestTests: XCTestCase { +final class WatchProvidersForTVSeriesRequestTests: XCTestCase { func testPath() { let request = WatchProvidersForTVSeriesRequest(regionCode: nil)