Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
adamayoung committed Sep 16, 2024
1 parent 9fa909b commit e612f6c
Show file tree
Hide file tree
Showing 13 changed files with 408 additions and 278 deletions.
66 changes: 34 additions & 32 deletions Tests/TMDbIntegrationTests/AccountIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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)

Expand All @@ -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

Expand All @@ -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,
Expand All @@ -151,7 +153,7 @@ final class AccountIntegrationTests: XCTestCase {
let isTVSeriesInWatchlistAfterRemoved = tvSeriesListAfterRemovedFromWatchlist.results.contains {
$0.id == tvSeriesID
}
XCTAssertFalse(isTVSeriesInWatchlistAfterRemoved)
#expect(!isTVSeriesInWatchlistAfterRemoved)
}

}
56 changes: 31 additions & 25 deletions Tests/TMDbIntegrationTests/AuthenticationIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
35 changes: 18 additions & 17 deletions Tests/TMDbIntegrationTests/CertificationIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
30 changes: 15 additions & 15 deletions Tests/TMDbIntegrationTests/CompanyIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

}
Loading

0 comments on commit e612f6c

Please sign in to comment.