From 6fad0db5ffd59235e5064eb779cc27191a15b352 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Thu, 21 Sep 2023 16:28:52 -0400 Subject: [PATCH] Refactor `async` tests to use `wait(for expectations:)` --- .../Tests/Integration/AppCheckE2ETests.swift | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift b/FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift index 9bc66a403b5..c29ef7120d6 100644 --- a/FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift +++ b/FirebaseAppCheck/Tests/Integration/AppCheckE2ETests.swift @@ -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) } }