@@ -1591,116 +1591,95 @@ class AuthTests: RPCBaseTests {
15911591 @brief Tests the flow of a successful @c sendPasswordReset call.
15921592 */
15931593 func testSendPasswordResetEmailSuccess( ) throws {
1594- let expectation = self . expectation ( description: #function)
1595-
1596- // 1. Setup respond block to test and fake send request.
1597- rpcIssuer. respondBlock = {
1598- // 2. Validate the created Request instance.
1599- let request = try XCTUnwrap ( self . rpcIssuer. request as? GetOOBConfirmationCodeRequest )
1600- XCTAssertEqual ( request. email, self . kEmail)
1601- XCTAssertEqual ( request. apiKey, AuthTests . kFakeAPIKey)
1602-
1603- // 3. Send the response from the fake backend.
1604- return try self . rpcIssuer. respond ( withJSON: [ : ] )
1605- }
1606- auth? . sendPasswordReset ( withEmail: kEmail) { error in
1607- // 4. After the response triggers the callback, verify success.
1608- XCTAssertTrue ( Thread . isMainThread)
1609- XCTAssertNil ( error)
1610- expectation. fulfill ( )
1611- }
1612- waitForExpectations ( timeout: 5 )
1594+ try checkSendPasswordResetWithLinkDomain (
1595+ customAuthDomain: nil ,
1596+ actionCodeSettings: nil ,
1597+ expectedLinkDomain: nil ,
1598+ description: #function
1599+ )
16131600 }
16141601
16151602 /** @fn testSendPasswordResetEmailWithActionCodeSettingsLinkDomainSet
16161603 @brief Tests the flow of a successful @c sendPasswordReset call with actionCodeSettings and
16171604 linkDomain set.
16181605 */
16191606 func testSendPasswordResetEmailWithActionCodeSettingsLinkDomainSet( ) throws {
1620- let expectation = self . expectation ( description: #function)
16211607 let kCustomAuthDomain = " test.page.link "
16221608 let kActionCodeSettingsLinkDomain = " actioncode.page.link "
16231609 auth. customAuthDomain = kCustomAuthDomain
16241610
16251611 let actionCodeSettings = ActionCodeSettings ( )
16261612 actionCodeSettings. linkDomain = kActionCodeSettingsLinkDomain
1627- actionCodeSettings. url = URL ( string: " https:// \( kActionCodeSettingsLinkDomain) /_next/verify?mode=resetPassword&oobCode=oobCode " ) !
1613+ actionCodeSettings. url =
1614+ URL (
1615+ string: " https:// \( kActionCodeSettingsLinkDomain) /_next/verify?mode=resetPassword&oobCode=oobCode "
1616+ ) !
16281617 actionCodeSettings. handleCodeInApp = true
16291618
1630- // 1. Setup respond block to test and fake send request.
1631- rpcIssuer. respondBlock = {
1632- // 2. Validate the created Request instance.
1633- let request = try XCTUnwrap ( self . rpcIssuer. request as? GetOOBConfirmationCodeRequest )
1634- XCTAssertEqual ( request. email, self . kEmail)
1635- XCTAssertEqual ( request. apiKey, AuthTests . kFakeAPIKey)
1636- XCTAssertEqual ( request. linkDomain, kActionCodeSettingsLinkDomain)
1637-
1638- // 3. Send the response from the fake backend.
1639- return try self . rpcIssuer. respond ( withJSON: [ : ] )
1640- }
1641- auth? . sendPasswordReset ( withEmail: kEmail, actionCodeSettings: actionCodeSettings) { error in
1642- // 4. After the response triggers the callback, verify success.
1643- XCTAssertTrue ( Thread . isMainThread)
1644- XCTAssertNil ( error)
1645- expectation. fulfill ( )
1646- }
1647- waitForExpectations ( timeout: 5 )
1619+ try checkSendPasswordResetWithLinkDomain (
1620+ customAuthDomain: kCustomAuthDomain,
1621+ actionCodeSettings: actionCodeSettings,
1622+ expectedLinkDomain: kActionCodeSettingsLinkDomain,
1623+ description: #function
1624+ )
16481625 }
16491626
16501627 /** @fn testSendPasswordResetEmailWithActionCodeSettingsLinkDomainNil
16511628 @brief Tests the flow of a successful @c sendPasswordReset call with actionCodeSettings and
16521629 linkDomain explicitly nil.
16531630 */
16541631 func testSendPasswordResetEmailWithActionCodeSettingsLinkDomainNil( ) throws {
1655- let expectation = self . expectation ( description: #function)
16561632 let kCustomAuthDomain = " test.page.link "
16571633 auth. customAuthDomain = kCustomAuthDomain
16581634
16591635 let actionCodeSettings = ActionCodeSettings ( )
16601636 actionCodeSettings. linkDomain = nil // Explicitly nil
1661- actionCodeSettings. url = URL ( string: " https://some.other.domain/_next/verify?mode=resetPassword&oobCode=oobCode " ) !
1637+ actionCodeSettings. url =
1638+ URL ( string: " https://some.other.domain/_next/verify?mode=resetPassword&oobCode=oobCode " ) !
16621639 actionCodeSettings. handleCodeInApp = true
16631640
1664- // 1. Setup respond block to test and fake send request.
1665- rpcIssuer. respondBlock = {
1666- // 2. Validate the created Request instance.
1667- let request = try XCTUnwrap ( self . rpcIssuer. request as? GetOOBConfirmationCodeRequest )
1668- XCTAssertEqual ( request. email, self . kEmail)
1669- XCTAssertEqual ( request. apiKey, AuthTests . kFakeAPIKey)
1670- XCTAssertEqual ( request. linkDomain, kCustomAuthDomain)
1671-
1672- // 3. Send the response from the fake backend.
1673- return try self . rpcIssuer. respond ( withJSON: [ : ] )
1674- }
1675- auth? . sendPasswordReset ( withEmail: kEmail, actionCodeSettings: actionCodeSettings) { error in
1676- // 4. After the response triggers the callback, verify success.
1677- XCTAssertTrue ( Thread . isMainThread)
1678- XCTAssertNil ( error)
1679- expectation. fulfill ( )
1680- }
1681- waitForExpectations ( timeout: 5 )
1641+ try checkSendPasswordResetWithLinkDomain (
1642+ customAuthDomain: kCustomAuthDomain,
1643+ actionCodeSettings: actionCodeSettings,
1644+ expectedLinkDomain: kCustomAuthDomain,
1645+ description: #function
1646+ )
16821647 }
16831648
16841649 /** @fn testSendPasswordResetEmailWithCustomAuthDomain
16851650 @brief Tests the flow of a successful @c sendPasswordReset call with custom auth domain.
16861651 */
16871652 func testSendPasswordResetEmailWithCustomAuthDomain( ) throws {
1688- let expectation = self . expectation ( description: #function)
16891653 let kCustomAuthDomain = " test.page.link "
1690- auth. customAuthDomain = kCustomAuthDomain
1654+ try checkSendPasswordResetWithLinkDomain (
1655+ customAuthDomain: kCustomAuthDomain,
1656+ actionCodeSettings: nil ,
1657+ expectedLinkDomain: kCustomAuthDomain,
1658+ description: #function
1659+ )
1660+ }
1661+
1662+ private func checkSendPasswordResetWithLinkDomain( customAuthDomain: String ? ,
1663+ actionCodeSettings: ActionCodeSettings ? ,
1664+ expectedLinkDomain: String ? ,
1665+ description: String ) throws {
1666+ let expectation = self . expectation ( description: description)
1667+ if let customAuthDomain = customAuthDomain {
1668+ auth. customAuthDomain = customAuthDomain
1669+ }
16911670
16921671 // 1. Setup respond block to test and fake send request.
16931672 rpcIssuer. respondBlock = {
16941673 // 2. Validate the created Request instance.
16951674 let request = try XCTUnwrap ( self . rpcIssuer. request as? GetOOBConfirmationCodeRequest )
16961675 XCTAssertEqual ( request. email, self . kEmail)
16971676 XCTAssertEqual ( request. apiKey, AuthTests . kFakeAPIKey)
1698- XCTAssertEqual ( request. linkDomain, kCustomAuthDomain )
1677+ XCTAssertEqual ( request. linkDomain, expectedLinkDomain )
16991678
17001679 // 3. Send the response from the fake backend.
17011680 return try self . rpcIssuer. respond ( withJSON: [ : ] )
17021681 }
1703- auth? . sendPasswordReset ( withEmail: kEmail) { error in
1682+ auth? . sendPasswordReset ( withEmail: kEmail, actionCodeSettings : actionCodeSettings ) { error in
17041683 // 4. After the response triggers the callback, verify success.
17051684 XCTAssertTrue ( Thread . isMainThread)
17061685 XCTAssertNil ( error)
0 commit comments