From f48a356d04d51eec9d36a78db79e4660d3bdc985 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Tue, 17 Sep 2024 20:52:51 +0100 Subject: [PATCH] REFACTOR: Migrate Person tests to Swift Testing --- .../PersonCombinedCreditsRequestTests.swift | 36 ++-- .../PersonExternalLinksRequestTests.swift | 41 ++-- .../Requests/PersonImagesRequestTests.swift | 41 ++-- .../PersonMovieCreditsRequestTests.swift | 36 ++-- .../People/Requests/PersonRequestTests.swift | 36 ++-- .../PersonTVSeriesCreditsRequestTests.swift | 36 ++-- .../Requests/PopularPeopleRequestTests.swift | 46 +++-- .../People/TMDbPersonServiceTests.swift | 187 +++++++----------- Tests/TMDbTests/TestUtils/Tags.swift | 1 + 9 files changed, 235 insertions(+), 225 deletions(-) diff --git a/Tests/TMDbTests/Domain/Services/People/Requests/PersonCombinedCreditsRequestTests.swift b/Tests/TMDbTests/Domain/Services/People/Requests/PersonCombinedCreditsRequestTests.swift index fb59e9a1..8b999a8b 100644 --- a/Tests/TMDbTests/Domain/Services/People/Requests/PersonCombinedCreditsRequestTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/Requests/PersonCombinedCreditsRequestTests.swift @@ -17,45 +17,53 @@ // limitations under the License. // +import Foundation +import Testing @testable import TMDb -import XCTest -final class PersonCombinedCreditsRequestTests: XCTestCase { +@Suite(.tags(.requests, .people)) +struct PersonCombinedCreditsRequestTests { - func testPath() { + @Test("path is correct") + func path() { let request = PersonCombinedCreditsRequest(id: 1) - XCTAssertEqual(request.path, "/person/1/combined_credits") + #expect(request.path == "/person/1/combined_credits") } - func testQueryItemsIsEmpty() { + @Test("queryItems is empty") + func queryItemsIsEmpty() { let request = PersonCombinedCreditsRequest(id: 1) - XCTAssertTrue(request.queryItems.isEmpty) + #expect(request.queryItems.isEmpty) } - func testQueryItemsWithLanguage() { + @Test("queryItems with language") + func queryItemsWithLanguage() { let request = PersonCombinedCreditsRequest(id: 1, language: "en") - XCTAssertEqual(request.queryItems, ["language": "en"]) + #expect(request.queryItems == ["language": "en"]) } - func testMethodIsGet() { + @Test("method is GET") + func methodIsGet() { let request = PersonCombinedCreditsRequest(id: 1) - XCTAssertEqual(request.method, .get) + #expect(request.method == .get) } - func testHeadersIsEmpty() { + @Test("headers is empty") + func headersIsEmpty() { let request = PersonCombinedCreditsRequest(id: 1) - XCTAssertTrue(request.headers.isEmpty) + #expect(request.headers.isEmpty) } - func testBodyIsNil() { + @Test("body is nil") + func bodyIsNil() { let request = PersonCombinedCreditsRequest(id: 1) - XCTAssertNil(request.body) + #expect(request.body == nil) } } diff --git a/Tests/TMDbTests/Domain/Services/People/Requests/PersonExternalLinksRequestTests.swift b/Tests/TMDbTests/Domain/Services/People/Requests/PersonExternalLinksRequestTests.swift index 03975974..26aaf803 100644 --- a/Tests/TMDbTests/Domain/Services/People/Requests/PersonExternalLinksRequestTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/Requests/PersonExternalLinksRequestTests.swift @@ -17,41 +17,42 @@ // limitations under the License. // +import Foundation +import Testing @testable import TMDb -import XCTest -final class PersonExternalLinksRequestTests: XCTestCase { +@Suite(.tags(.requests, .people)) +struct PersonExternalLinksRequestTests { var request: PersonExternalLinksRequest! - override func setUp() { - super.setUp() - request = PersonExternalLinksRequest(id: 1) + init() { + self.request = PersonExternalLinksRequest(id: 1) } - override func tearDown() { - request = nil - super.tearDown() + @Test("path is correct") + func path() { + #expect(request.path == "/person/1/external_ids") } - func testPath() { - XCTAssertEqual(request.path, "/person/1/external_ids") + @Test("queryItems is empty") + func queryItemsIsEmpty() { + #expect(request.queryItems.isEmpty) } - func testQueryItemsIsEmpty() { - XCTAssertTrue(request.queryItems.isEmpty) + @Test("method is GET") + func methodIsGet() { + #expect(request.method == .get) } - func testMethodIsGet() { - XCTAssertEqual(request.method, .get) + @Test("headers is empty") + func headersIsEmpty() { + #expect(request.headers.isEmpty) } - func testHeadersIsEmpty() { - XCTAssertTrue(request.headers.isEmpty) - } - - func testBodyIsNil() { - XCTAssertNil(request.body) + @Test("body is nil") + func bodyIsNil() { + #expect(request.body == nil) } } diff --git a/Tests/TMDbTests/Domain/Services/People/Requests/PersonImagesRequestTests.swift b/Tests/TMDbTests/Domain/Services/People/Requests/PersonImagesRequestTests.swift index 4c2410c9..b1de89ad 100644 --- a/Tests/TMDbTests/Domain/Services/People/Requests/PersonImagesRequestTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/Requests/PersonImagesRequestTests.swift @@ -17,41 +17,42 @@ // limitations under the License. // +import Foundation +import Testing @testable import TMDb -import XCTest -final class PersonImagesRequestTests: XCTestCase { +@Suite(.tags(.requests, .people)) +struct PersonImagesRequestTests { var request: PersonImagesRequest! - override func setUp() { - super.setUp() - request = PersonImagesRequest(id: 1) + init() { + self.request = PersonImagesRequest(id: 1) } - override func tearDown() { - request = nil - super.tearDown() + @Test("path is correct") + func path() { + #expect(request.path == "/person/1/images") } - func testPath() { - XCTAssertEqual(request.path, "/person/1/images") + @Test("queryItems is empty") + func queryItemsIsEmpty() { + #expect(request.queryItems.isEmpty) } - func testQueryItemsIsEmpty() { - XCTAssertTrue(request.queryItems.isEmpty) + @Test("method is GET") + func methodIsGet() { + #expect(request.method == .get) } - func testMethodIsGet() { - XCTAssertEqual(request.method, .get) + @Test("headers is empty") + func headersIsEmpty() { + #expect(request.headers.isEmpty) } - func testHeadersIsEmpty() { - XCTAssertTrue(request.headers.isEmpty) - } - - func testBodyIsNil() { - XCTAssertNil(request.body) + @Test("body is nil") + func bodyIsNil() { + #expect(request.body == nil) } } diff --git a/Tests/TMDbTests/Domain/Services/People/Requests/PersonMovieCreditsRequestTests.swift b/Tests/TMDbTests/Domain/Services/People/Requests/PersonMovieCreditsRequestTests.swift index 8668e676..6c06b8ec 100644 --- a/Tests/TMDbTests/Domain/Services/People/Requests/PersonMovieCreditsRequestTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/Requests/PersonMovieCreditsRequestTests.swift @@ -17,45 +17,53 @@ // limitations under the License. // +import Foundation +import Testing @testable import TMDb -import XCTest -final class PersonMovieCreditsRequestTests: XCTestCase { +@Suite(.tags(.requests, .people)) +struct PersonMovieCreditsRequestTests { - func testPath() { + @Test("path is correct") + func path() { let request = PersonMovieCreditsRequest(id: 1) - XCTAssertEqual(request.path, "/person/1/movie_credits") + #expect(request.path == "/person/1/movie_credits") } - func testQueryItemsIsEmpty() { + @Test("queryItems is empty") + func queryItemsIsEmpty() { let request = PersonMovieCreditsRequest(id: 1) - XCTAssertTrue(request.queryItems.isEmpty) + #expect(request.queryItems.isEmpty) } - func testQueryItemsWithLanguage() { + @Test("queryItems with language") + func queryItemsWithLanguage() { let request = PersonMovieCreditsRequest(id: 1, language: "en") - XCTAssertEqual(request.queryItems, ["language": "en"]) + #expect(request.queryItems == ["language": "en"]) } - func testMethodIsGet() { + @Test("method is GET") + func methodIsGet() { let request = PersonMovieCreditsRequest(id: 1) - XCTAssertEqual(request.method, .get) + #expect(request.method == .get) } - func testHeadersIsEmpty() { + @Test("headers is empty") + func headersIsEmpty() { let request = PersonMovieCreditsRequest(id: 1) - XCTAssertTrue(request.headers.isEmpty) + #expect(request.headers.isEmpty) } - func testBodyIsNil() { + @Test("body is nil") + func bodyIsNil() { let request = PersonMovieCreditsRequest(id: 1) - XCTAssertNil(request.body) + #expect(request.body == nil) } } diff --git a/Tests/TMDbTests/Domain/Services/People/Requests/PersonRequestTests.swift b/Tests/TMDbTests/Domain/Services/People/Requests/PersonRequestTests.swift index fcd1c0b2..b610a991 100644 --- a/Tests/TMDbTests/Domain/Services/People/Requests/PersonRequestTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/Requests/PersonRequestTests.swift @@ -17,45 +17,53 @@ // limitations under the License. // +import Foundation +import Testing @testable import TMDb -import XCTest -final class PersonRequestTests: XCTestCase { +@Suite(.tags(.requests, .people)) +struct PersonRequestTests { - func testPath() { + @Test("path is correct") + func path() { let request = PersonRequest(id: 1) - XCTAssertEqual(request.path, "/person/1") + #expect(request.path == "/person/1") } - func testQueryItemsIsEmpty() { + @Test("queryItems is empty") + func queryItemsIsEmpty() { let request = PersonRequest(id: 1) - XCTAssertTrue(request.queryItems.isEmpty) + #expect(request.queryItems.isEmpty) } - func testQueryItemsWithLanguage() { + @Test("queryItems with language") + func queryItemsWithLanguage() { let request = PersonRequest(id: 1, language: "en") - XCTAssertEqual(request.queryItems, ["language": "en"]) + #expect(request.queryItems == ["language": "en"]) } - func testMethodIsGet() { + @Test("method is GET") + func methodIsGet() { let request = PersonRequest(id: 1) - XCTAssertEqual(request.method, .get) + #expect(request.method == .get) } - func testHeadersIsEmpty() { + @Test("headers is empty") + func headersIsEmpty() { let request = PersonRequest(id: 1) - XCTAssertTrue(request.headers.isEmpty) + #expect(request.headers.isEmpty) } - func testBodyIsNil() { + @Test("body is nil") + func bodyIsNil() { let request = PersonRequest(id: 1) - XCTAssertNil(request.body) + #expect(request.body == nil) } } diff --git a/Tests/TMDbTests/Domain/Services/People/Requests/PersonTVSeriesCreditsRequestTests.swift b/Tests/TMDbTests/Domain/Services/People/Requests/PersonTVSeriesCreditsRequestTests.swift index fe2925e0..2b0acc37 100644 --- a/Tests/TMDbTests/Domain/Services/People/Requests/PersonTVSeriesCreditsRequestTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/Requests/PersonTVSeriesCreditsRequestTests.swift @@ -17,45 +17,53 @@ // limitations under the License. // +import Foundation +import Testing @testable import TMDb -import XCTest -final class PersonTVSeriesCreditsRequestTests: XCTestCase { +@Suite(.tags(.requests, .people)) +struct PersonTVSeriesCreditsRequestTests { - func testPath() { + @Test("path is correct") + func path() { let request = PersonTVSeriesCreditsRequest(id: 1) - XCTAssertEqual(request.path, "/person/1/tv_credits") + #expect(request.path == "/person/1/tv_credits") } - func testQueryItemsIsEmpty() { + @Test("queryItems is empty") + func queryItemsIsEmpty() { let request = PersonTVSeriesCreditsRequest(id: 1) - XCTAssertTrue(request.queryItems.isEmpty) + #expect(request.queryItems.isEmpty) } - func testQueryItemsWithLanguage() { + @Test("queryItems with language") + func queryItemsWithLanguage() { let request = PersonTVSeriesCreditsRequest(id: 1, language: "en") - XCTAssertEqual(request.queryItems, ["language": "en"]) + #expect(request.queryItems == ["language": "en"]) } - func testMethodIsGet() { + @Test("method is GET") + func methodIsGet() { let request = PersonTVSeriesCreditsRequest(id: 1) - XCTAssertEqual(request.method, .get) + #expect(request.method == .get) } - func testHeadersIsEmpty() { + @Test("headers is empty") + func headersIsEmpty() { let request = PersonTVSeriesCreditsRequest(id: 1) - XCTAssertTrue(request.headers.isEmpty) + #expect(request.headers.isEmpty) } - func testBodyIsNil() { + @Test("body is nil") + func bodyIsNil() { let request = PersonTVSeriesCreditsRequest(id: 1) - XCTAssertNil(request.body) + #expect(request.body == nil) } } diff --git a/Tests/TMDbTests/Domain/Services/People/Requests/PopularPeopleRequestTests.swift b/Tests/TMDbTests/Domain/Services/People/Requests/PopularPeopleRequestTests.swift index c345c381..5410ecfd 100644 --- a/Tests/TMDbTests/Domain/Services/People/Requests/PopularPeopleRequestTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/Requests/PopularPeopleRequestTests.swift @@ -17,57 +17,67 @@ // limitations under the License. // +import Foundation +import Testing @testable import TMDb -import XCTest -final class PopularPeopleRequestTests: XCTestCase { +@Suite(.tags(.requests, .people)) +struct PopularPeopleRequestTests { - func testPath() { + @Test("path is correct") + func path() { let request = PopularPeopleRequest() - XCTAssertEqual(request.path, "/person/popular") + #expect(request.path == "/person/popular") } - func testQueryItemsIsEmpty() { + @Test("queryItems is empty") + func queryItemsIsEmpty() { let request = PopularPeopleRequest() - XCTAssertTrue(request.queryItems.isEmpty) + #expect(request.queryItems.isEmpty) } - func testQueryItemsWithPage() { + @Test("queryItems with page") + func queryItemsWithPage() { let request = PopularPeopleRequest(page: 3) - XCTAssertEqual(request.queryItems, ["page": "3"]) + #expect(request.queryItems == ["page": "3"]) } - func testQueryItemsWithLanguage() { + @Test("queryItems with language") + func queryItemsWithLanguage() { let request = PopularPeopleRequest(language: "en") - XCTAssertEqual(request.queryItems, ["language": "en"]) + #expect(request.queryItems == ["language": "en"]) } - func testQueryItemsWithPageAndLanguage() { + @Test("queryItems with page and language") + func queryItemsWithPageAndLanguage() { let request = PopularPeopleRequest(page: 3, language: "en") - XCTAssertEqual(request.queryItems, ["page": "3", "language": "en"]) + #expect(request.queryItems == ["page": "3", "language": "en"]) } - func testMethodIsGet() { + @Test("method is GET") + func methodIsGet() { let request = PopularPeopleRequest() - XCTAssertEqual(request.method, .get) + #expect(request.method == .get) } - func testHeadersIsEmpty() { + @Test("headers is empty") + func headersIsEmpty() { let request = PopularPeopleRequest() - XCTAssertTrue(request.headers.isEmpty) + #expect(request.headers.isEmpty) } - func testBodyIsNil() { + @Test("body is nil") + func bodyIsNil() { let request = PopularPeopleRequest() - XCTAssertNil(request.body) + #expect(request.body == nil) } } diff --git a/Tests/TMDbTests/Domain/Services/People/TMDbPersonServiceTests.swift b/Tests/TMDbTests/Domain/Services/People/TMDbPersonServiceTests.swift index acc2fa19..a16566bb 100644 --- a/Tests/TMDbTests/Domain/Services/People/TMDbPersonServiceTests.swift +++ b/Tests/TMDbTests/Domain/Services/People/TMDbPersonServiceTests.swift @@ -17,27 +17,23 @@ // limitations under the License. // +import Foundation +import Testing @testable import TMDb -import XCTest -final class TMDbPersonServiceTests: XCTestCase { +@Suite(.tags(.requests, .people)) +struct TMDbPersonServiceTests { var service: TMDbPersonService! var apiClient: MockAPIClient! - override func setUp() { - super.setUp() - apiClient = MockAPIClient() - service = TMDbPersonService(apiClient: apiClient) + init() { + self.apiClient = MockAPIClient() + self.service = TMDbPersonService(apiClient: apiClient) } - override func tearDown() { - apiClient = nil - service = nil - super.tearDown() - } - - func testDetailsReturnsPerson() async throws { + @Test("details returns person") + func detailsReturnsPerson() async throws { let expectedResult = Person.johnnyDepp let personID = expectedResult.id apiClient.addResponse(.success(expectedResult)) @@ -45,11 +41,12 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.details(forPerson: personID) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonRequest == expectedRequest) } - func testDetailsWithLanguageReturnsPerson() async throws { + @Test("details with language returns person") + func detailsWithLanguageReturnsPerson() async throws { let expectedResult = Person.johnnyDepp let personID = expectedResult.id let language = "en" @@ -58,27 +55,22 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.details(forPerson: personID, language: language) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonRequest == expectedRequest) } - func testDetailsWhenErrorsThrowsError() async throws { + @Test("details when errors throws error") + func detailsWhenErrorsThrowsError() async throws { let personID = 1 apiClient.addResponse(.failure(.unknown)) - var error: Error? - do { + await #expect(throws: TMDbError.unknown) { _ = try await service.details(forPerson: personID) - } catch let err { - error = err } - - let tmdbAPIError = try XCTUnwrap(error as? TMDbError) - - XCTAssertEqual(tmdbAPIError, .unknown) } - func testCombinedCreditsReturnsCombinedCredits() async throws { + @Test("combinedCredits returns combinedCredits") + func combinedCreditsReturnsCombinedCredits() async throws { let mock = PersonCombinedCredits.mock() let expectedResult = PersonCombinedCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id @@ -87,11 +79,12 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.combinedCredits(forPerson: personID) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonCombinedCreditsRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonCombinedCreditsRequest == expectedRequest) } - func testCombinedCreditsWithLanguageReturnsCombinedCredits() async throws { + @Test("combinedCredits with language returns combinedCredits") + func combinedCreditsWithLanguageReturnsCombinedCredits() async throws { let mock = PersonCombinedCredits.mock() let expectedResult = PersonCombinedCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id @@ -101,27 +94,22 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.combinedCredits(forPerson: personID, language: language) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonCombinedCreditsRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonCombinedCreditsRequest == expectedRequest) } - func testCombinedCreditsWhenErrorsThrowsError() async throws { + @Test("combinedCredits when errors throws error") + func combinedCreditsWhenErrorsThrowsError() async throws { let personID = 1 apiClient.addResponse(.failure(.unknown)) - var error: Error? - do { + await #expect(throws: TMDbError.unknown) { _ = try await service.combinedCredits(forPerson: personID) - } catch let err { - error = err } - - let tmdbAPIError = try XCTUnwrap(error as? TMDbError) - - XCTAssertEqual(tmdbAPIError, .unknown) } - func testMovieCreditsReturnsMovieCredits() async throws { + @Test("movieCredits returns movie credits") + func movieCreditsReturnsMovieCredits() async throws { let mock = PersonMovieCredits.mock() let expectedResult = PersonMovieCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id @@ -130,11 +118,12 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.movieCredits(forPerson: personID) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonMovieCreditsRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonMovieCreditsRequest == expectedRequest) } - func testMovieCreditsWithLanguageReturnsMovieCredits() async throws { + @Test("movieCredits with language returns movie credits") + func movieCreditsWithLanguageReturnsMovieCredits() async throws { let mock = PersonMovieCredits.mock() let expectedResult = PersonMovieCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id @@ -144,27 +133,22 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.movieCredits(forPerson: personID, language: language) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonMovieCreditsRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonMovieCreditsRequest == expectedRequest) } - func testMovieCreditsWhenErrorsThrowsError() async throws { + @Test("movieCredits when errors throws error") + func movieCreditsWhenErrorsThrowsError() async throws { let personID = 1 apiClient.addResponse(.failure(.unknown)) - var error: Error? - do { + await #expect(throws: TMDbError.unknown) { _ = try await service.movieCredits(forPerson: personID) - } catch let err { - error = err } - - let tmdbAPIError = try XCTUnwrap(error as? TMDbError) - - XCTAssertEqual(tmdbAPIError, .unknown) } - func testTVSeriesCreditsReturnsTVSeriesCredits() async throws { + @Test("tvSeriesCredits returns tv series credits") + func tvSeriesCreditsReturnsTVSeriesCredits() async throws { let mock = PersonTVSeriesCredits.mock() let expectedResult = PersonTVSeriesCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id @@ -173,11 +157,12 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.tvSeriesCredits(forPerson: personID) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonTVSeriesCreditsRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonTVSeriesCreditsRequest == expectedRequest) } - func testTVSeriesCreditsWithLanguageReturnsTVSeriesCredits() async throws { + @Test("tvSeriesCredits with language returns tv series credits") + func tvSeriesCreditsWithLanguageReturnsTVSeriesCredits() async throws { let mock = PersonTVSeriesCredits.mock() let expectedResult = PersonTVSeriesCredits(id: mock.id, cast: mock.cast, crew: mock.crew) let personID = expectedResult.id @@ -187,27 +172,22 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.tvSeriesCredits(forPerson: personID, language: language) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonTVSeriesCreditsRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonTVSeriesCreditsRequest == expectedRequest) } - func testTVSeriesCreditsWhenErrorsThrowsError() async throws { + @Test("tvSeriesCredits when errors throws error") + func tvSeriesCreditsWhenErrorsThrowsError() async throws { let personID = 1 apiClient.addResponse(.failure(.unknown)) - var error: Error? - do { + await #expect(throws: TMDbError.unknown) { _ = try await service.tvSeriesCredits(forPerson: personID) - } catch let err { - error = err } - - let tmdbAPIError = try XCTUnwrap(error as? TMDbError) - - XCTAssertEqual(tmdbAPIError, .unknown) } - func testImagesReturnsImageCollection() async throws { + @Test("images returns image collection") + func imagesReturnsImageCollection() async throws { let expectedResult = PersonImageCollection.mock() let personID = expectedResult.id apiClient.addResponse(.success(expectedResult)) @@ -215,38 +195,34 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.images(forPerson: personID) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonImagesRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonImagesRequest == expectedRequest) } - func testImagesWhenErrorsThrowsError() async throws { + @Test("images when errors throws error") + func imagesWhenErrorsThrowsError() async throws { let personID = 1 apiClient.addResponse(.failure(.unknown)) - var error: Error? - do { + await #expect(throws: TMDbError.unknown) { _ = try await service.images(forPerson: personID) - } catch let err { - error = err } - - let tmdbAPIError = try XCTUnwrap(error as? TMDbError) - - XCTAssertEqual(tmdbAPIError, .unknown) } - func testPopularReturnsPeople() async throws { + @Test("popular returns people") + func popularReturnsPeople() async throws { let expectedResult = PersonPageableList.mock() apiClient.addResponse(.success(expectedResult)) let expectedRequest = PopularPeopleRequest(page: nil, language: nil) let result = try await service.popular() - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PopularPeopleRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PopularPeopleRequest == expectedRequest) } - func testPopularWithPageAndLanguageReturnsPeople() async throws { + @Test("popular with page and language returns people") + func popularWithPageAndLanguageReturnsPeople() async throws { let page = 2 let language = "en" let expectedResult = PersonPageableList.mock() @@ -255,26 +231,21 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.popular(page: page, language: language) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PopularPeopleRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PopularPeopleRequest == expectedRequest) } - func testPopularWhenErrorsThrowsError() async throws { + @Test("popular when errors throws error") + func popularWhenErrorsThrowsError() async throws { apiClient.addResponse(.failure(.unknown)) - var error: Error? - do { + await #expect(throws: TMDbError.unknown) { _ = try await service.popular() - } catch let err { - error = err } - - let tmdbAPIError = try XCTUnwrap(error as? TMDbError) - - XCTAssertEqual(tmdbAPIError, .unknown) } - func testExternalLinksReturnsExternalLinks() async throws { + @Test("externalLinks returns external links") + func externalLinksReturnsExternalLinks() async throws { let expectedResult = PersonExternalLinksCollection.sydneySweeney let personID = 115_440 apiClient.addResponse(.success(expectedResult)) @@ -282,24 +253,18 @@ final class TMDbPersonServiceTests: XCTestCase { let result = try await service.externalLinks(forPerson: personID) - XCTAssertEqual(result, expectedResult) - XCTAssertEqual(apiClient.lastRequest as? PersonExternalLinksRequest, expectedRequest) + #expect(result == expectedResult) + #expect(apiClient.lastRequest as? PersonExternalLinksRequest == expectedRequest) } - func testExternalLinksWhenErrorsThrowsError() async throws { + @Test("externalLinks when errors throws error") + func externalLinksWhenErrorsThrowsError() async throws { let personID = 115_440 apiClient.addResponse(.failure(.unknown)) - var error: Error? - do { + await #expect(throws: TMDbError.unknown) { _ = try await service.externalLinks(forPerson: personID) - } catch let err { - error = err } - - let tmdbAPIError = try XCTUnwrap(error as? TMDbError) - - XCTAssertEqual(tmdbAPIError, .unknown) } } diff --git a/Tests/TMDbTests/TestUtils/Tags.swift b/Tests/TMDbTests/TestUtils/Tags.swift index 375855c5..9e3cc7ba 100644 --- a/Tests/TMDbTests/TestUtils/Tags.swift +++ b/Tests/TMDbTests/TestUtils/Tags.swift @@ -40,5 +40,6 @@ extension Tag { @Tag static var discover: Self @Tag static var genre: Self @Tag static var movie: Self + @Tag static var people: Self }