1- import XCTest
2- #if canImport(FoundationNetworking)
3- import FoundationNetworking
4- #endif
1+ import Foundation
2+ import Testing
53
64@testable import OAuthenticator
75
8- final class GoogleTests : XCTestCase {
6+ struct GoogleTests {
7+ @Test
98 func testOAuthResponseDecode( ) throws {
109 let content = """
1110{ " access_token " : " abc " , " expires_in " : 3, " refresh_token " : " def " , " scope " : " https://gmail.scope " , " token_type " : " bearer " }
1211"""
13- let data = try XCTUnwrap ( content. data ( using: . utf8) )
12+ let data = try #require ( content. data ( using: . utf8) )
1413 let response = try JSONDecoder ( ) . decode ( GoogleAPI . OAuthResponse. self, from: data)
1514
16- XCTAssertEqual ( response. accessToken, " abc " )
17-
15+ #expect ( response. accessToken == " abc " )
16+
1817 let login = response. login
19- XCTAssertEqual ( login. accessToken. value, " abc " )
20-
18+ #expect ( login. accessToken. value == " abc " )
19+
2120 // Sleep until access token expires
2221 sleep ( 5 )
23- XCTAssert ( !login. accessToken. valid)
22+ #expect ( !login. accessToken. valid)
2423 }
2524
2625 func testSuppliedParameters( ) async throws {
2726 let googleParameters = GoogleAPI . GoogleAPIParameters ( includeGrantedScopes: true , loginHint: " john@doe.com " )
2827
29- XCTAssertNotNil ( googleParameters. loginHint)
30- XCTAssertTrue ( googleParameters. includeGrantedScopes)
31-
32- let callback = URL ( string: " callback://google_api " )
33- XCTAssertNotNil ( callback)
34-
35- let creds = AppCredentials ( clientId: " client_id " , clientPassword: " client_pwd " , scopes: [ " scope1 " , " scope2 " ] , callbackURL: callback!)
28+ #expect( googleParameters. loginHint != nil )
29+ #expect( googleParameters. includeGrantedScopes)
30+
31+ let callback = try #require( URL ( string: " callback://google_api " ) )
32+
33+ let creds = AppCredentials ( clientId: " client_id " , clientPassword: " client_pwd " , scopes: [ " scope1 " , " scope2 " ] , callbackURL: callback)
3634 let tokenHandling = GoogleAPI . googleAPITokenHandling ( with: googleParameters)
3735 let config = Authenticator . Configuration (
3836 appCredentials: creds,
@@ -52,27 +50,24 @@ final class GoogleTests: XCTestCase {
5250 let googleURLProvider = try await config. tokenHandling. authorizationURLProvider ( params)
5351
5452 let urlComponent = URLComponents ( url: googleURLProvider, resolvingAgainstBaseURL: true )
55- XCTAssertNotNil ( urlComponent)
56- XCTAssertEqual ( urlComponent!. scheme, GoogleAPI . scheme)
57-
53+ #expect( urlComponent? . scheme == GoogleAPI . scheme)
54+
5855 // Validate query items inclusion and value
59- XCTAssertNotNil ( urlComponent!. queryItems)
60- XCTAssertTrue ( urlComponent!. queryItems!. contains ( where: { $0. name == GoogleAPI . includeGrantedScopeKey } ) )
61- XCTAssertTrue ( urlComponent!. queryItems!. contains ( where: { $0. name == GoogleAPI . loginHint } ) )
62- XCTAssertTrue ( urlComponent!. queryItems!. contains ( where: { $0. value == String ( true ) } ) )
63- XCTAssertTrue ( urlComponent!. queryItems!. contains ( where: { $0. value == " john@doe.com " } ) )
56+ #expect( urlComponent!. queryItems!. contains ( where: { $0. name == GoogleAPI . includeGrantedScopeKey } ) )
57+ #expect( urlComponent!. queryItems!. contains ( where: { $0. name == GoogleAPI . loginHint } ) )
58+ #expect( urlComponent!. queryItems!. contains ( where: { $0. value == String ( true ) } ) )
59+ #expect( urlComponent!. queryItems!. contains ( where: { $0. value == " john@doe.com " } ) )
6460 }
6561
6662 func testDefaultParameters( ) async throws {
6763 let googleParameters = GoogleAPI . GoogleAPIParameters ( )
6864
69- XCTAssertNil ( googleParameters. loginHint)
70- XCTAssertTrue ( googleParameters. includeGrantedScopes)
71-
72- let callback = URL ( string: " callback://google_api " )
73- XCTAssertNotNil ( callback)
65+ #expect( googleParameters. loginHint == nil )
66+ #expect( googleParameters. includeGrantedScopes)
67+
68+ let callback = try #require( URL ( string: " callback://google_api " ) )
7469
75- let creds = AppCredentials ( clientId: " client_id " , clientPassword: " client_pwd " , scopes: [ " scope1 " , " scope2 " ] , callbackURL: callback! )
70+ let creds = AppCredentials ( clientId: " client_id " , clientPassword: " client_pwd " , scopes: [ " scope1 " , " scope2 " ] , callbackURL: callback)
7671 let tokenHandling = GoogleAPI . googleAPITokenHandling ( with: googleParameters)
7772 let config = Authenticator . Configuration (
7873 appCredentials: creds,
@@ -92,14 +87,11 @@ final class GoogleTests: XCTestCase {
9287 let googleURLProvider = try await config. tokenHandling. authorizationURLProvider ( params)
9388
9489 let urlComponent = URLComponents ( url: googleURLProvider, resolvingAgainstBaseURL: true )
95- XCTAssertNotNil ( urlComponent)
96- XCTAssertEqual ( urlComponent!. scheme, GoogleAPI . scheme)
90+ #expect( urlComponent? . scheme == GoogleAPI . scheme)
9791
9892 // Validate query items inclusion and value
99- XCTAssertNotNil ( urlComponent!. queryItems)
100- XCTAssertTrue ( urlComponent!. queryItems!. contains ( where: { $0. name == GoogleAPI . includeGrantedScopeKey } ) )
101- XCTAssertFalse ( urlComponent!. queryItems!. contains ( where: { $0. name == GoogleAPI . loginHint } ) )
102- XCTAssertTrue ( urlComponent!. queryItems!. contains ( where: { $0. value == String ( true ) } ) )
93+ #expect( urlComponent!. queryItems!. contains ( where: { $0. name == GoogleAPI . includeGrantedScopeKey } ) )
94+ #expect( urlComponent!. queryItems!. contains ( where: { $0. name == GoogleAPI . loginHint } ) == false )
95+ #expect( urlComponent!. queryItems!. contains ( where: { $0. value == String ( true ) } ) )
10396 }
104-
10597}
0 commit comments