Skip to content

Commit

Permalink
REFACTOR: Migrate integration tests to Swift Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung committed Sep 16, 2024
1 parent e612f6c commit 8ab395a
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 116 deletions.
48 changes: 25 additions & 23 deletions Tests/TMDbIntegrationTests/TVEpisodeServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
// limitations under the License.
//

import TMDb
import XCTest
import Foundation
import Testing
@testable import TMDb

final class TVEpisodeServiceTests: XCTestCase {
@Suite(
.tags(.tvEpisode),
.enabled(if: CredentialHelper.shared.hasAPIKey)
)
struct TVEpisodeServiceTests {

var tvEpisodeService: (any TVEpisodeService)!

override func setUpWithError() throws {
try super.setUpWithError()
let apiKey = try tmdbAPIKey()
tvEpisodeService = TMDbClient(apiKey: apiKey).tvEpisodes
init() {
let apiKey = CredentialHelper.shared.tmdbAPIKey()
self.tvEpisodeService = TMDbClient(apiKey: apiKey).tvEpisodes
}

override func tearDown() {
tvEpisodeService = nil
super.tearDown()
}

func testDetails() async throws {
@Test("details")
func details() async throws {
let episodeNumber = 3
let seasonNumber = 2
let tvSeriesID = 1399
Expand All @@ -46,13 +46,14 @@ final class TVEpisodeServiceTests: XCTestCase {
inTVSeries: tvSeriesID
)

XCTAssertEqual(episode.id, 63068)
XCTAssertEqual(episode.episodeNumber, episodeNumber)
XCTAssertEqual(episode.seasonNumber, seasonNumber)
XCTAssertEqual(episode.name, "What is Dead May Never Die")
#expect(episode.id == 63068)
#expect(episode.episodeNumber == episodeNumber)
#expect(episode.seasonNumber == seasonNumber)
#expect(episode.name == "What is Dead May Never Die")
}

func testImages() async throws {
@Test("images")
func images() async throws {
let episodeNumber = 3
let seasonNumber = 2
let tvSeriesID = 1399
Expand All @@ -63,11 +64,12 @@ final class TVEpisodeServiceTests: XCTestCase {
inTVSeries: tvSeriesID
)

XCTAssertEqual(imageCollection.id, 63068)
XCTAssertFalse(imageCollection.stills.isEmpty)
#expect(imageCollection.id == 63068)
#expect(!imageCollection.stills.isEmpty)
}

func testVideos() async throws {
@Test("videos")
func videos() async throws {
let episodeNumber = 3
let seasonNumber = 1
let tvSeriesID = 1399
Expand All @@ -78,8 +80,8 @@ final class TVEpisodeServiceTests: XCTestCase {
inTVSeries: tvSeriesID
)

XCTAssertEqual(videoCollection.id, 63058)
XCTAssertFalse(videoCollection.results.isEmpty)
#expect(videoCollection.id == 63058)
#expect(!videoCollection.results.isEmpty)
}

}
47 changes: 25 additions & 22 deletions Tests/TMDbIntegrationTests/TVSeasonIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,64 @@
// limitations under the License.
//

import TMDb
import XCTest
import Foundation
import Testing
@testable import TMDb

final class TVSeasonIntegrationTests: XCTestCase {
@Suite(
.tags(.tvSeason),
.enabled(if: CredentialHelper.shared.hasAPIKey)
)
struct TVSeasonIntegrationTests {

var tvSeasonService: (any TVSeasonService)!

override func setUpWithError() throws {
try super.setUpWithError()
let apiKey = try tmdbAPIKey()
tvSeasonService = TMDbClient(apiKey: apiKey).tvSeasons
}

override func tearDown() {
tvSeasonService = nil
super.tearDown()
init() {
let apiKey = CredentialHelper.shared.tmdbAPIKey()
self.tvSeasonService = TMDbClient(apiKey: apiKey).tvSeasons
}

@Test("details")
func testDetails() async throws {
let seasonNumber = 2
let tvSeriesID = 1399

let season = try await tvSeasonService.details(forSeason: seasonNumber, inTVSeries: tvSeriesID)

XCTAssertEqual(season.seasonNumber, seasonNumber)
XCTAssertFalse((season.episodes ?? []).isEmpty)
#expect(season.seasonNumber == seasonNumber)
#expect(!(season.episodes ?? []).isEmpty)
}

func testAggregateCredits() async throws {
@Test("aggregateCredits")
func aggregateCredits() async throws {
let seasonNumber = 2
let tvSeriesID = 1399

let credits = try await tvSeasonService.aggregateCredits(forSeason: seasonNumber, inTVSeries: tvSeriesID)

XCTAssertEqual(credits.id, 3625)
XCTAssertFalse(credits.cast.isEmpty)
XCTAssertFalse(credits.crew.isEmpty)
#expect(credits.id == 3625)
#expect(!credits.cast.isEmpty)
#expect(!credits.crew.isEmpty)
}

func testImages() async throws {
@Test("images")
func images() async throws {
let seasonNumber = 1
let tvSeriesID = 1399

let imagesCollection = try await tvSeasonService.images(forSeason: seasonNumber, inTVSeries: tvSeriesID)

XCTAssertFalse(imagesCollection.posters.isEmpty)
#expect(!imagesCollection.posters.isEmpty)
}

func testVideos() async throws {
@Test("videos")
func videos() async throws {
let seasonNumber = 1
let tvSeriesID = 1399

let videoCollection = try await tvSeasonService.videos(forSeason: seasonNumber, inTVSeries: tvSeriesID)

XCTAssertFalse(videoCollection.results.isEmpty)
#expect(!videoCollection.results.isEmpty)
}

}
110 changes: 58 additions & 52 deletions Tests/TMDbIntegrationTests/TVSeriesServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,124 +17,130 @@
// limitations under the License.
//

import TMDb
import XCTest
import Foundation
import Testing
@testable import TMDb

final class TVSeriesServiceTests: XCTestCase {
@Suite(
.tags(.tvSeason),
.enabled(if: CredentialHelper.shared.hasAPIKey)
)
struct TVSeriesServiceTests {

var tvSeriesService: (any TVSeriesService)!

override func setUpWithError() throws {
try super.setUpWithError()
let apiKey = try tmdbAPIKey()
tvSeriesService = TMDbClient(apiKey: apiKey).tvSeries
init() {
let apiKey = CredentialHelper.shared.tmdbAPIKey()
self.tvSeriesService = TMDbClient(apiKey: apiKey).tvSeries
}

override func tearDown() {
tvSeriesService = nil
super.tearDown()
}

func testDetails() async throws {
@Test("details")
func details() async throws {
let tvSeriesID = 84958

let tvSeries = try await tvSeriesService.details(forTVSeries: tvSeriesID)

XCTAssertEqual(tvSeries.id, tvSeriesID)
XCTAssertEqual(tvSeries.name, "Loki")
#expect(tvSeries.id == tvSeriesID)
#expect(tvSeries.name == "Loki")
}

func testCredits() async throws {
@Test("credits")
func credits() async throws {
let tvSeriesID = 4604

let credits = try await tvSeriesService.credits(forTVSeries: tvSeriesID)

XCTAssertFalse(credits.cast.isEmpty)
XCTAssertFalse(credits.crew.isEmpty)
#expect(!credits.cast.isEmpty)
#expect(!credits.crew.isEmpty)
}

func testAggregateCredits() async throws {
@Test("aggregateCredits")
func aggregateCredits() async throws {
let tvSeriesID = 4604

let credits = try await tvSeriesService.aggregateCredits(forTVSeries: tvSeriesID)

XCTAssertFalse(credits.cast.isEmpty)
XCTAssertFalse(credits.crew.isEmpty)
#expect(!credits.cast.isEmpty)
#expect(!credits.crew.isEmpty)
}

func testReviews() async throws {
@Test("reviews")
func reviews() async throws {
let tvSeriesID = 76479

let reviewList = try await tvSeriesService.reviews(forTVSeries: tvSeriesID)

XCTAssertFalse(reviewList.results.isEmpty)
#expect(!reviewList.results.isEmpty)
}

func testImages() async throws {
@Test("images")
func images() async throws {
let tvSeriesID = 76479

let imageCollection = try await tvSeriesService.images(forTVSeries: tvSeriesID)

XCTAssertEqual(imageCollection.id, tvSeriesID)
XCTAssertFalse(imageCollection.backdrops.isEmpty)
XCTAssertFalse(imageCollection.logos.isEmpty)
XCTAssertFalse(imageCollection.posters.isEmpty)
#expect(imageCollection.id == tvSeriesID)
#expect(!imageCollection.backdrops.isEmpty)
#expect(!imageCollection.logos.isEmpty)
#expect(!imageCollection.posters.isEmpty)
}

func testVideos() async throws {
@Test("videos")
func videos() async throws {
let tvSeriesID = 76479

let videoCollection = try await tvSeriesService.videos(forTVSeries: tvSeriesID)

XCTAssertEqual(videoCollection.id, tvSeriesID)
XCTAssertFalse(videoCollection.results.isEmpty)
#expect(videoCollection.id == tvSeriesID)
#expect(!videoCollection.results.isEmpty)
}

func testRecommendations() async throws {
@Test("recommendations")
func recommendations() async throws {
let tvSeriesID = 549

let tvSeriesList = try await tvSeriesService.recommendations(forTVSeries: tvSeriesID)

XCTAssertFalse(tvSeriesList.results.isEmpty)
#expect(!tvSeriesList.results.isEmpty)
}

func testSimilar() async throws {
@Test("similar")
func similar() async throws {
let tvSeriesID = 76479

let tvSeriesList = try await tvSeriesService.similar(toTVSeries: tvSeriesID)

XCTAssertFalse(tvSeriesList.results.isEmpty)
#expect(!tvSeriesList.results.isEmpty)
}

func testPopular() async throws {
@Test("popular")
func popular() async throws {
let tvSeriesList = try await tvSeriesService.popular()

XCTAssertFalse(tvSeriesList.results.isEmpty)
#expect(!tvSeriesList.results.isEmpty)
}

func testExternalLinks() async throws {
@Test("externalLinks")
func externalLinks() async throws {
let tvSeriesID = 86423

let linksCollection = try await tvSeriesService.externalLinks(forTVSeries: tvSeriesID)

XCTAssertEqual(linksCollection.id, tvSeriesID)
XCTAssertNotNil(linksCollection.imdb)
XCTAssertNil(linksCollection.wikiData)
XCTAssertNotNil(linksCollection.facebook)
XCTAssertNotNil(linksCollection.instagram)
XCTAssertNotNil(linksCollection.twitter)
#expect(linksCollection.id == tvSeriesID)
#expect(linksCollection.imdb != nil)
#expect(linksCollection.wikiData == nil)
#expect(linksCollection.facebook != nil)
#expect(linksCollection.instagram != nil)
#expect(linksCollection.twitter != nil)
}

func testContentRatings() async throws {
@Test("contentRatings")
func contentRatings() async throws {
let tvSeriesID = 8592

let contentRatings = try await tvSeriesService.contentRatings(forTVSeries: tvSeriesID, country: "US")

XCTAssertNotNil(contentRatings)
let contentRatings = try #require(await tvSeriesService.contentRatings(forTVSeries: tvSeriesID, country: "US"))

if let contentRating = contentRatings {
XCTAssertEqual(contentRating.rating, "TV-14")
XCTAssertEqual(contentRating.countryCode, "US")
}
#expect(contentRatings.rating == "TV-14")
#expect(contentRatings.countryCode == "US")
}
}
4 changes: 4 additions & 0 deletions Tests/TMDbIntegrationTests/TestUtils/Tags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ extension Tag {
@Tag static var person: Self
@Tag static var search: Self
@Tag static var trending: Self
@Tag static var tvEpisode: Self
@Tag static var tvSeason: Self
@Tag static var tvSeries: Self
@Tag static var watchProvider: Self

}
2 changes: 1 addition & 1 deletion Tests/TMDbIntegrationTests/TrendingIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Testing
@testable import TMDb

@Suite(
.tags(.search),
.tags(.trending),
.enabled(if: CredentialHelper.shared.hasAPIKey)
)
struct TrendingIntegrationTests {
Expand Down
Loading

0 comments on commit 8ab395a

Please sign in to comment.