Skip to content

Commit

Permalink
Refactor async tests to use wait(for expectations:)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewheard committed Sep 21, 2023
1 parent 90cc00d commit 6fad0db
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,38 @@ final class AppCheckE2ETests: XCTestCase {
XCTAssertNotNil(appAttestProvider)
}

func testGetToken() async throws {
func testGetToken() throws {
guard let appCheck = AppCheck.appCheck(app: app) else {
XCTFail("AppCheck instance is nil.")
return
}

let token = try await appCheck.token(forcingRefresh: true)
let expectation = XCTestExpectation()
appCheck.token(forcingRefresh: true) { token, error in
XCTAssertNil(error)
XCTAssertNotNil(token)
XCTAssertEqual(token!.token, TestAppCheckProvider.tokenValue)
expectation.fulfill()
}

XCTAssertEqual(token.token, TestAppCheckProvider.tokenValue)
wait(for: [expectation], timeout: 0.5)
}

func testGetLimitedUseToken() async throws {
func testGetLimitedUseToken() throws {
guard let appCheck = AppCheck.appCheck(app: app) else {
XCTFail("AppCheck instance is nil.")
return
}

let token = try await appCheck.limitedUseToken()
let expectation = XCTestExpectation()
appCheck.limitedUseToken { token, error in
XCTAssertNil(error)
XCTAssertNotNil(token)
XCTAssertEqual(token!.token, TestAppCheckProvider.limitedUseTokenValue)
expectation.fulfill()
}

XCTAssertEqual(token.token, TestAppCheckProvider.limitedUseTokenValue)
wait(for: [expectation], timeout: 0.5)
}
}

Expand Down

0 comments on commit 6fad0db

Please sign in to comment.