diff --git a/Tests/TMDbIntegrationTests/AccountIntegrationTests.swift b/Tests/TMDbIntegrationTests/AccountIntegrationTests.swift index 3d0533e4..19d8c027 100644 --- a/Tests/TMDbIntegrationTests/AccountIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/AccountIntegrationTests.swift @@ -17,42 +17,41 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class AccountIntegrationTests: XCTestCase { +@Suite( + .serialized, + .tags(.account), + .enabled(if: CredentialHelper.shared.hasAPIKey && CredentialHelper.shared.hasCredential) +) +struct AccountIntegrationTests { var accountService: (any AccountService)! var authenticationService: (any AuthenticationService)! var session: Session! - override func setUp() async throws { - try await super.setUp() - let apiKey = try tmdbAPIKey() + init() async throws { + let apiKey = CredentialHelper.shared.tmdbAPIKey() let tmdbClient = TMDbClient(apiKey: apiKey) - let credential = try tmdbCredential() + let credential = CredentialHelper.shared.tmdbCredential() - authenticationService = tmdbClient.authentication - accountService = tmdbClient.account + self.authenticationService = tmdbClient.authentication + self.accountService = tmdbClient.account - session = try await authenticationService.createSession(withCredential: credential) + self.session = try await authenticationService.createSession(withCredential: credential) } - override func tearDown() async throws { -// try await authenticationService.deleteSession(session) - accountService = nil - authenticationService = nil - session = nil - try await super.tearDown() - } - - func testDetails() async throws { + @Test("details") + func details() async throws { let details = try await accountService.details(session: session) - XCTAssertGreaterThan(details.id, 0) + #expect(details.id > 0) } - func testAddingAndRemovingFavouriteMovies() async throws { + @Test("adding and removing favourite movies") + func addingAndRemovingFavouriteMovies() async throws { let accountDetails = try await accountService.details(session: session) let movieID = 550 @@ -63,7 +62,7 @@ final class AccountIntegrationTests: XCTestCase { session: session ) let isMovieFavourited = movieListAfterFavorited.results.contains { $0.id == movieID } - XCTAssertTrue(isMovieFavourited) + #expect(isMovieFavourited) try await accountService.removeFavourite(movie: movieID, accountID: accountDetails.id, session: session) @@ -73,10 +72,11 @@ final class AccountIntegrationTests: XCTestCase { ) let isMovieFavouritedAfterRemoved = movieListAfterFavoriteRemoved.results.contains { $0.id == movieID } - XCTAssertFalse(isMovieFavouritedAfterRemoved) + #expect(!isMovieFavouritedAfterRemoved) } - func testAddingAndRemovingFavouriteTVSeries() async throws { + @Test("add and removing favourite TV series") + func addingAndRemovingFavouriteTVSeries() async throws { let accountDetails = try await accountService.details(session: session) let tvSeriesID = 2261 @@ -87,7 +87,7 @@ final class AccountIntegrationTests: XCTestCase { session: session ) let isTVSeriesFavourited = tvSeriesListAfterFavorited.results.contains { $0.id == tvSeriesID } - XCTAssertTrue(isTVSeriesFavourited) + #expect(isTVSeriesFavourited) try await accountService.removeFavourite(tvSeries: tvSeriesID, accountID: accountDetails.id, session: session) @@ -97,10 +97,11 @@ final class AccountIntegrationTests: XCTestCase { ) let isTVSeriesFavouritedAfterRemoved = tvSeriesListAfterFavoriteRemoved.results.contains { $0.id == tvSeriesID } - XCTAssertFalse(isTVSeriesFavouritedAfterRemoved) + #expect(!isTVSeriesFavouritedAfterRemoved) } - func testAddingAndRemovingToMoviesWatchlist() async throws { + @Test("add and removing to movies watchlist") + func addingAndRemovingToMoviesWatchlist() async throws { let accountDetails = try await accountService.details(session: session) let movieID = 550 @@ -111,7 +112,7 @@ final class AccountIntegrationTests: XCTestCase { session: session ) let isMovieAddedToWatchlist = movieListAfterAddToWatchlist.results.contains { $0.id == movieID } - XCTAssertTrue(isMovieAddedToWatchlist) + #expect(isMovieAddedToWatchlist) try await accountService.removeFromWatchlist(movie: movieID, accountID: accountDetails.id, session: session) @@ -121,10 +122,11 @@ final class AccountIntegrationTests: XCTestCase { ) let isMovieInWatchlistAfterRemoved = movieListAfterRemovedFromWatchlist.results.contains { $0.id == movieID } - XCTAssertFalse(isMovieInWatchlistAfterRemoved) + #expect(!isMovieInWatchlistAfterRemoved) } - func testAddingAndRemovingTVSeriesToWatchlist() async throws { + @Test("add and removing to TV series watchlist") + func addingAndRemovingTVSeriesToWatchlist() async throws { let accountDetails = try await accountService.details(session: session) let tvSeriesID = 2261 @@ -135,7 +137,7 @@ final class AccountIntegrationTests: XCTestCase { session: session ) let isTVSeriesAddedToWatchlist = tvSeriesListAfterAddedToWatchlist.results.contains { $0.id == tvSeriesID } - XCTAssertTrue(isTVSeriesAddedToWatchlist) + #expect(isTVSeriesAddedToWatchlist) try await accountService.removeFromWatchlist( tvSeries: tvSeriesID, @@ -151,7 +153,7 @@ final class AccountIntegrationTests: XCTestCase { let isTVSeriesInWatchlistAfterRemoved = tvSeriesListAfterRemovedFromWatchlist.results.contains { $0.id == tvSeriesID } - XCTAssertFalse(isTVSeriesInWatchlistAfterRemoved) + #expect(!isTVSeriesInWatchlistAfterRemoved) } } diff --git a/Tests/TMDbIntegrationTests/AuthenticationIntegrationTests.swift b/Tests/TMDbIntegrationTests/AuthenticationIntegrationTests.swift index 1107c115..20329438 100644 --- a/Tests/TMDbIntegrationTests/AuthenticationIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/AuthenticationIntegrationTests.swift @@ -17,58 +17,64 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class AuthenticationIntegrationTests: XCTestCase { +@Suite( + .tags(.authentication), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct AuthenticationIntegrationTests { var authenticationService: (any AuthenticationService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - authenticationService = TMDbClient(apiKey: apiKey).authentication + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.authenticationService = TMDbClient(apiKey: apiKey).authentication } - override func tearDown() { - authenticationService = nil - super.tearDown() - } - - func testGuestSession() async throws { + @Test("guestSession") + func guestSession() async throws { let session = try await authenticationService.guestSession() - XCTAssertTrue(session.success) - XCTAssertNotEqual(session.guestSessionID, "") + #expect(session.success) + #expect(session.guestSessionID != "") } - func testRequestToken() async throws { + @Test("requestToken") + func requestToken() async throws { let token = try await authenticationService.requestToken() - XCTAssertTrue(token.success) - XCTAssertNotEqual(token.requestToken, "") + #expect(token.success) + #expect(token.requestToken != "") } - func testCreateAndDeleteSessionWithCredential() async throws { - let credential = try tmdbCredential() + @Test( + "createSession with credential", + .enabled(if: CredentialHelper.shared.hasCredential) + ) + func createAndDeleteSessionWithCredential() async throws { + let credential = CredentialHelper.shared.tmdbCredential() let session = try await authenticationService.createSession(withCredential: credential) - XCTAssertTrue(session.success) - XCTAssertNotEqual(session.sessionID, "") + #expect(session.success) + #expect(session.sessionID != "") do { let deleteResult = try await authenticationService.deleteSession(session) - XCTAssertTrue(deleteResult) + #expect(deleteResult) } catch let error { print(error) } } - func testValidateKeyWhenValid() async throws { + @Test("validateKey") + func validateKeyWhenValid() async throws { let isValid = try await authenticationService.validateKey() - XCTAssertTrue(isValid) + #expect(isValid) } } diff --git a/Tests/TMDbIntegrationTests/CertificationIntegrationTests.swift b/Tests/TMDbIntegrationTests/CertificationIntegrationTests.swift index e6408d21..00821e62 100644 --- a/Tests/TMDbIntegrationTests/CertificationIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/CertificationIntegrationTests.swift @@ -17,38 +17,39 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class CertificationIntegrationTests: XCTestCase { +@Suite( + .tags(.certification), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct CertificationIntegrationTests { var certificationService: (any CertificationService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - certificationService = TMDbClient(apiKey: apiKey).certifications - } - - override func tearDown() { - certificationService = nil - super.tearDown() + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.certificationService = TMDbClient(apiKey: apiKey).certifications } + @Test("movieCertifications") func testMovieCertifications() async throws { let certifications = try await certificationService.movieCertifications() - let gbCertifications = try XCTUnwrap(certifications["GB"]) + let gbCertifications = try #require(certifications["GB"]) - XCTAssertEqual(gbCertifications.count, 7) + #expect(gbCertifications.count == 7) } - func testTVSeriesCertifications() async throws { + @Test("tvSeriesCertifications") + func tvSeriesCertifications() async throws { let certifications = try await certificationService.tvSeriesCertifications() - let gbCertifications = try XCTUnwrap(certifications["GB"]) + let gbCertifications = try #require(certifications["GB"]) - XCTAssertEqual(gbCertifications.count, 7) + #expect(gbCertifications.count == 7) } } diff --git a/Tests/TMDbIntegrationTests/CompanyIntegrationTests.swift b/Tests/TMDbIntegrationTests/CompanyIntegrationTests.swift index 263d3153..41af9eb2 100644 --- a/Tests/TMDbIntegrationTests/CompanyIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/CompanyIntegrationTests.swift @@ -17,31 +17,31 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class CompanyIntegrationTests: XCTestCase { +@Suite( + .tags(.company), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct CompanyIntegrationTests { var companyService: (any CompanyService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - companyService = TMDbClient(apiKey: apiKey).companies + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.companyService = TMDbClient(apiKey: apiKey).companies } - override func tearDown() { - companyService = nil - super.tearDown() - } - - func testDetails() async throws { + @Test("details") + func details() async throws { let companyID = 82968 let company = try await companyService.details(forCompany: companyID) - XCTAssertEqual(company.id, companyID) - XCTAssertEqual(company.name, "LuckyChap Entertainment") + #expect(company.id == companyID) + #expect(company.name == "LuckyChap Entertainment") } } diff --git a/Tests/TMDbIntegrationTests/ConfigurationIntegrationTests.swift b/Tests/TMDbIntegrationTests/ConfigurationIntegrationTests.swift index 9eb2fefd..e8601188 100644 --- a/Tests/TMDbIntegrationTests/ConfigurationIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/ConfigurationIntegrationTests.swift @@ -17,51 +17,54 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class ConfigurationIntegrationTests: XCTestCase { +@Suite( + .tags(.configuration), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct ConfigurationIntegrationTests { var configurationService: (any ConfigurationService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - configurationService = TMDbClient(apiKey: apiKey).configurations + init() throws { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.configurationService = TMDbClient(apiKey: apiKey).configurations } - override func tearDown() { - configurationService = nil - super.tearDown() - } - - func testAPIConfiguration() async throws { + @Test("apiConfiguration") + func apiConfiguration() async throws { let configuration = try await configurationService.apiConfiguration() - XCTAssertFalse(configuration.images.backdropSizes.isEmpty) - XCTAssertFalse(configuration.images.logoSizes.isEmpty) - XCTAssertFalse(configuration.images.posterSizes.isEmpty) - XCTAssertFalse(configuration.images.profileSizes.isEmpty) - XCTAssertFalse(configuration.images.stillSizes.isEmpty) - XCTAssertFalse(configuration.changeKeys.isEmpty) + #expect(!configuration.images.backdropSizes.isEmpty) + #expect(!configuration.images.logoSizes.isEmpty) + #expect(!configuration.images.posterSizes.isEmpty) + #expect(!configuration.images.profileSizes.isEmpty) + #expect(!configuration.images.stillSizes.isEmpty) + #expect(!configuration.changeKeys.isEmpty) } - func testCountries() async throws { + @Test("countries") + func countries() async throws { let countries = try await configurationService.countries() - XCTAssertFalse(countries.isEmpty) + #expect(!countries.isEmpty) } - func testJobsByDepartment() async throws { + @Test("jobsByDepartments") + func jobsByDepartment() async throws { let departments = try await configurationService.jobsByDepartment() - XCTAssertFalse(departments.isEmpty) + #expect(!departments.isEmpty) } - func testLanguages() async throws { + @Test("languages") + func languages() async throws { let languages = try await configurationService.languages() - XCTAssertFalse(languages.isEmpty) + #expect(!languages.isEmpty) } } diff --git a/Tests/TMDbIntegrationTests/DiscoverIntegrationTests.swift b/Tests/TMDbIntegrationTests/DiscoverIntegrationTests.swift index 1a8c046b..4dde3ee8 100644 --- a/Tests/TMDbIntegrationTests/DiscoverIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/DiscoverIntegrationTests.swift @@ -17,34 +17,35 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class DiscoverIntegrationTests: XCTestCase { +@Suite( + .tags(.discover), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct DiscoverIntegrationTests { var discoverService: (any DiscoverService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - discoverService = TMDbClient(apiKey: apiKey).discover + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.discoverService = TMDbClient(apiKey: apiKey).discover } - override func tearDown() { - discoverService = nil - super.tearDown() - } - - func testMovies() async throws { + @Test("movies") + func movies() async throws { let movieList = try await discoverService.movies() - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testTVSeries() async throws { + @Test("TV series") + func tvSeries() async throws { let tvSeriesList = try await discoverService.tvSeries() - XCTAssertFalse(tvSeriesList.results.isEmpty) + #expect(!tvSeriesList.results.isEmpty) } } diff --git a/Tests/TMDbIntegrationTests/GenreIntegrationTests.swift b/Tests/TMDbIntegrationTests/GenreIntegrationTests.swift index 2d127d27..579b2984 100644 --- a/Tests/TMDbIntegrationTests/GenreIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/GenreIntegrationTests.swift @@ -17,34 +17,35 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class GenreIntegrationTests: XCTestCase { +@Suite( + .tags(.genre), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct GenreIntegrationTests { var genreService: (any GenreService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - genreService = TMDbClient(apiKey: apiKey).genres + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.genreService = TMDbClient(apiKey: apiKey).genres } - override func tearDown() { - genreService = nil - super.tearDown() - } - - func testMovieGenres() async throws { + @Test("movieGenres") + func movieGenres() async throws { let genres = try await genreService.movieGenres() - XCTAssertFalse(genres.isEmpty) + #expect(!genres.isEmpty) } - func testTVSeriesGenres() async throws { + @Test("tvSeriesGenres") + func tvSeriesGenres() async throws { let genres = try await genreService.tvSeriesGenres() - XCTAssertFalse(genres.isEmpty) + #expect(!genres.isEmpty) } } diff --git a/Tests/TMDbIntegrationTests/MovieIntegrationTests.swift b/Tests/TMDbIntegrationTests/MovieIntegrationTests.swift index 55f26754..6d9afe8d 100644 --- a/Tests/TMDbIntegrationTests/MovieIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/MovieIntegrationTests.swift @@ -17,122 +17,133 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class MovieIntegrationTests: XCTestCase { +@Suite( + .tags(.movie), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct MovieIntegrationTests { var movieService: (any MovieService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - movieService = TMDbClient(apiKey: apiKey).movies + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.movieService = TMDbClient(apiKey: apiKey).movies } - override func tearDown() { - movieService = nil - super.tearDown() - } - - func testDetails() async throws { + @Test("details") + func details() async throws { let movieID = 346_698 let movie = try await movieService.details(forMovie: movieID) - XCTAssertEqual(movie.id, movieID) - XCTAssertEqual(movie.title, "Barbie") + #expect(movie.id == movieID) + #expect(movie.title == "Barbie") } - func testCredits() async throws { + @Test("credits") + func credits() async throws { let movieID = 346_698 let credits = try await movieService.credits(forMovie: movieID) - XCTAssertEqual(credits.id, movieID) - XCTAssertFalse(credits.cast.isEmpty) - XCTAssertFalse(credits.crew.isEmpty) + #expect(credits.id == movieID) + #expect(!credits.cast.isEmpty) + #expect(!credits.crew.isEmpty) } - func testReviews() async throws { + @Test("reviews") + func reviews() async throws { let movieID = 346_698 let reviewList = try await movieService.reviews(forMovie: movieID) - XCTAssertFalse(reviewList.results.isEmpty) + #expect(!reviewList.results.isEmpty) } - func testImages() async throws { + @Test("images") + func images() async throws { let movieID = 346_698 let imageCollection = try await movieService.images(forMovie: movieID) - XCTAssertEqual(imageCollection.id, movieID) - XCTAssertFalse(imageCollection.posters.isEmpty) - XCTAssertFalse(imageCollection.logos.isEmpty) - XCTAssertFalse(imageCollection.backdrops.isEmpty) + #expect(imageCollection.id == movieID) + #expect(!imageCollection.posters.isEmpty) + #expect(!imageCollection.logos.isEmpty) + #expect(!imageCollection.backdrops.isEmpty) } - func testVideos() async throws { + @Test("videos") + func videos() async throws { let movieID = 346_698 let videoCollection = try await movieService.videos(forMovie: movieID) - XCTAssertEqual(videoCollection.id, movieID) - XCTAssertFalse(videoCollection.results.isEmpty) + #expect(videoCollection.id == movieID) + #expect(!videoCollection.results.isEmpty) } - func testRecommendations() async throws { + @Test("recommendations") + func recommendations() async throws { let movieID = 921_636 let recommendationList = try await movieService.recommendations(forMovie: movieID) - XCTAssertFalse(recommendationList.results.isEmpty) + #expect(!recommendationList.results.isEmpty) } - func testSimilar() async throws { + @Test("similar") + func similar() async throws { let movieID = 921_636 let movieList = try await movieService.similar(toMovie: movieID) - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testNowPlaying() async throws { + @Test("nowPlaying") + func nowPlaying() async throws { let movieList = try await movieService.nowPlaying() - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testPopular() async throws { + @Test("popular") + func popular() async throws { let movieList = try await movieService.popular() - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testTopRated() async throws { + @Test("topRated") + func topRated() async throws { let movieList = try await movieService.topRated() - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testUpcoming() async throws { + @Test("upcoming") + func upcoming() async throws { let movieList = try await movieService.upcoming() - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testExternalLinks() async throws { + @Test("externalLinks") + func externalLinks() async throws { let movieID = 346_698 let linksCollection = try await movieService.externalLinks(forMovie: movieID) - XCTAssertEqual(linksCollection.id, movieID) - XCTAssertNotNil(linksCollection.imdb) - XCTAssertNotNil(linksCollection.wikiData) - XCTAssertNotNil(linksCollection.facebook) - XCTAssertNotNil(linksCollection.instagram) - XCTAssertNotNil(linksCollection.twitter) + #expect(linksCollection.id == movieID) + #expect(linksCollection.imdb != nil) + #expect(linksCollection.wikiData != nil) + #expect(linksCollection.facebook != nil) + #expect(linksCollection.instagram != nil) + #expect(linksCollection.twitter != nil) } } diff --git a/Tests/TMDbIntegrationTests/PersonIntegrationTests.swift b/Tests/TMDbIntegrationTests/PersonIntegrationTests.swift index 4e5078bd..41f02ed5 100644 --- a/Tests/TMDbIntegrationTests/PersonIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/PersonIntegrationTests.swift @@ -17,90 +17,96 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class PersonIntegrationTests: XCTestCase { +@Suite( + .tags(.person), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct PersonIntegrationTests { var personService: (any PersonService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - personService = TMDbClient(apiKey: apiKey).people + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.personService = TMDbClient(apiKey: apiKey).people } - override func tearDown() { - personService = nil - super.tearDown() - } - - func testDetails() async throws { + @Test("details") + func details() async throws { let personID = 500 let person = try await personService.details(forPerson: personID) - XCTAssertEqual(person.id, personID) - XCTAssertEqual(person.name, "Tom Cruise") + #expect(person.id == personID) + #expect(person.name == "Tom Cruise") } - func testCombinedCredits() async throws { + @Test("combinedCredits") + func combinedCredits() async throws { let personID = 500 let credits = try await personService.combinedCredits(forPerson: personID) - XCTAssertEqual(credits.id, personID) - XCTAssertFalse(credits.cast.isEmpty) - XCTAssertFalse(credits.crew.isEmpty) + #expect(credits.id == personID) + #expect(!credits.cast.isEmpty) + #expect(!credits.crew.isEmpty) } - func testMovieCredits() async throws { + @Test("movieCredits") + func movieCredits() async throws { let personID = 500 let credits = try await personService.movieCredits(forPerson: personID) - XCTAssertEqual(credits.id, personID) - XCTAssertFalse(credits.cast.isEmpty) - XCTAssertFalse(credits.crew.isEmpty) + #expect(credits.id == personID) + #expect(!credits.cast.isEmpty) + #expect(!credits.crew.isEmpty) } - func testTVSeriesCredits() async throws { + @Test("tvSeriesCredits") + func tvSeriesCredits() async throws { let personID = 500 let credits = try await personService.tvSeriesCredits(forPerson: personID) - XCTAssertEqual(credits.id, personID) - XCTAssertFalse(credits.cast.isEmpty) - XCTAssertFalse(credits.crew.isEmpty) + #expect(credits.id == personID) + #expect(!credits.cast.isEmpty) + #expect(!credits.crew.isEmpty) } - func testImages() async throws { + @Test("images") + func images() async throws { let personID = 500 let imageCollection = try await personService.images(forPerson: personID) - XCTAssertEqual(imageCollection.id, personID) - XCTAssertFalse(imageCollection.profiles.isEmpty) + #expect(imageCollection.id == personID) + #expect(!imageCollection.profiles.isEmpty) } - func testPopular() async throws { + @Test("popular") + func popular() async throws { let personList = try await personService.popular() - XCTAssertFalse(personList.results.isEmpty) + #expect(!personList.results.isEmpty) } - func testExternalLinks() async throws { + @Test("externalLinks") + func externalLinks() async throws { let personID = 115_440 let linksCollection = try await personService.externalLinks(forPerson: personID) - XCTAssertEqual(linksCollection.id, personID) - XCTAssertNotNil(linksCollection.imdb) - XCTAssertNotNil(linksCollection.wikiData) - XCTAssertNil(linksCollection.facebook) - XCTAssertNotNil(linksCollection.instagram) - XCTAssertNotNil(linksCollection.twitter) - XCTAssertNotNil(linksCollection.tikTok) + #expect(linksCollection.id == personID) + #expect(linksCollection.imdb != nil) + #expect(linksCollection.wikiData != nil) + #expect(linksCollection.facebook == nil) + #expect(linksCollection.instagram != nil) + #expect(linksCollection.twitter != nil) + #expect(linksCollection.tikTok != nil) } } diff --git a/Tests/TMDbIntegrationTests/SearchIntegrationTests.swift b/Tests/TMDbIntegrationTests/SearchIntegrationTests.swift index cc55d92a..0b3ff1a9 100644 --- a/Tests/TMDbIntegrationTests/SearchIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/SearchIntegrationTests.swift @@ -17,54 +17,57 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class SearchIntegrationTests: XCTestCase { +@Suite( + .tags(.search), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct SearchIntegrationTests { var searchService: (any SearchService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - searchService = TMDbClient(apiKey: apiKey).search + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.searchService = TMDbClient(apiKey: apiKey).search } - override func tearDown() { - searchService = nil - super.tearDown() - } - - func testSearchAll() async throws { + @Test("searchAll") + func searchAll() async throws { let query = "barbie" let mediaList = try await searchService.searchAll(query: query) - XCTAssertFalse(mediaList.results.isEmpty) + #expect(!mediaList.results.isEmpty) } - func testSearchMovies() async throws { + @Test("searchMovies") + func searchMovies() async throws { let query = "avengers" let movieList = try await searchService.searchMovies(query: query) - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testSearchTVSeries() async throws { + @Test("searchTVSeries") + func searchTVSeries() async throws { let query = "game of thrones" let tvSeriesList = try await searchService.searchTVSeries(query: query) - XCTAssertFalse(tvSeriesList.results.isEmpty) + #expect(!tvSeriesList.results.isEmpty) } - func testSearchPeople() async throws { + @Test("searchPeople") + func searchPeople() async throws { let query = "tom hardy" let personList = try await searchService.searchPeople(query: query) - XCTAssertFalse(personList.results.isEmpty) + #expect(!personList.results.isEmpty) } } diff --git a/Tests/TMDbIntegrationTests/TestUtils/Tags.swift b/Tests/TMDbIntegrationTests/TestUtils/Tags.swift new file mode 100644 index 00000000..52c4620f --- /dev/null +++ b/Tests/TMDbIntegrationTests/TestUtils/Tags.swift @@ -0,0 +1,36 @@ +// +// Tags.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 Testing + +extension Tag { + + @Tag static var account: Self + @Tag static var authentication: Self + @Tag static var certification: Self + @Tag static var company: Self + @Tag static var configuration: Self + @Tag static var discover: Self + @Tag static var genre: Self + @Tag static var movie: Self + @Tag static var person: Self + @Tag static var search: Self + @Tag static var trending: Self + +} diff --git a/Tests/TMDbIntegrationTests/TrendingIntegrationTests.swift b/Tests/TMDbIntegrationTests/TrendingIntegrationTests.swift index f15f3555..9626f5c2 100644 --- a/Tests/TMDbIntegrationTests/TrendingIntegrationTests.swift +++ b/Tests/TMDbIntegrationTests/TrendingIntegrationTests.swift @@ -17,58 +17,63 @@ // limitations under the License. // -import TMDb -import XCTest +import Foundation +import Testing +@testable import TMDb -final class TrendingIntegrationTests: XCTestCase { +@Suite( + .tags(.search), + .enabled(if: CredentialHelper.shared.hasAPIKey) +) +struct TrendingIntegrationTests { var trendingService: (any TrendingService)! - override func setUpWithError() throws { - try super.setUpWithError() - let apiKey = try tmdbAPIKey() - trendingService = TMDbClient(apiKey: apiKey).trending + init() { + let apiKey = CredentialHelper.shared.tmdbAPIKey() + self.trendingService = TMDbClient(apiKey: apiKey).trending } - override func tearDown() { - trendingService = nil - super.tearDown() - } - - func testMoviesTrendingByDay() async throws { + @Test("movies trending by day") + func moviesTrendingByDay() async throws { let movieList = try await trendingService.movies(inTimeWindow: .day) - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testMoviesTrendingByWeek() async throws { + @Test("movies trending by week") + func moviesTrendingByWeek() async throws { let movieList = try await trendingService.movies(inTimeWindow: .week) - XCTAssertFalse(movieList.results.isEmpty) + #expect(!movieList.results.isEmpty) } - func testTVSeriesTrendingByDay() async throws { + @Test("tvSeries trending by day") + func tvSeriesTrendingByDay() async throws { let tvSeriesList = try await trendingService.tvSeries(inTimeWindow: .day) - XCTAssertFalse(tvSeriesList.results.isEmpty) + #expect(!tvSeriesList.results.isEmpty) } - func testTVSeriesTrendingByWeek() async throws { + @Test("tvSeries trending by week") + func tvSeriesTrendingByWeek() async throws { let tvSeriesList = try await trendingService.tvSeries(inTimeWindow: .week) - XCTAssertFalse(tvSeriesList.results.isEmpty) + #expect(!tvSeriesList.results.isEmpty) } - func testPeopleTrendingByDay() async throws { + @Test("people trending by day") + func peopleTrendingByDay() async throws { let personList = try await trendingService.people(inTimeWindow: .day) - XCTAssertFalse(personList.results.isEmpty) + #expect(!personList.results.isEmpty) } - func testPeopleTrendingByWeek() async throws { + @Test("people trending by week") + func peopleTrendingByWeek() async throws { let personList = try await trendingService.people(inTimeWindow: .week) - XCTAssertFalse(personList.results.isEmpty) + #expect(!personList.results.isEmpty) } } diff --git a/Tests/TMDbIntegrationTests/Utility/CredentialHelper.swift b/Tests/TMDbIntegrationTests/Utility/CredentialHelper.swift new file mode 100644 index 00000000..028b17a0 --- /dev/null +++ b/Tests/TMDbIntegrationTests/Utility/CredentialHelper.swift @@ -0,0 +1,55 @@ +// +// CredentialHelper.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 TMDb + +struct CredentialHelper { + + static let shared = CredentialHelper() + + var hasCredential: Bool { + let credential = tmdbCredential() + + return !credential.username.isEmpty && !credential.password.isEmpty + } + + var hasAPIKey: Bool { + !tmdbAPIKey().isEmpty + } + + private let processInfo: ProcessInfo + + private init(processInto: ProcessInfo = ProcessInfo.processInfo) { + self.processInfo = processInto + } + + func tmdbCredential() -> Credential { + let username = processInfo.environment["TMDB_USERNAME"] ?? "" + let password = processInfo.environment["TMDB_PASSWORD"] ?? "" + let credential = Credential(username: username, password: password) + + return credential + } + + func tmdbAPIKey() -> String { + processInfo.environment["TMDB_API_KEY"] ?? "" + } + +}