@@ -11,8 +11,8 @@ class MockWKWebView: WKWebView {
1111 mockAction = MockNavigationAction ( url: callbackURL) as WKNavigationAction
1212 }
1313
14- if let delegate = self . navigationDelegate {
15- delegate. webView ? ( self , decidePolicyFor: mockAction! , decisionHandler: { _ in } )
14+ if let delegate = self . navigationDelegate, let action = mockAction {
15+ delegate. webView ? ( self , decidePolicyFor: action , decisionHandler: { _ in } )
1616 }
1717 return nil
1818 }
@@ -25,18 +25,21 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
2525 // Given
2626 let mockWebView = MockWKWebView ( )
2727 let coordinator = DomainDiscoveryCoordinator ( )
28- let credentials = OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) !
28+ let credentials = try XCTUnwrap ( OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) )
2929
3030 let expectedDomain = " foo.my.salesforce.com "
3131 let mockDomain = " https:// \( expectedDomain) "
3232 let expectedLoginHint = " [email protected] " 33- let callbackURLString = " sfdc://discocallback?my_domain= \( mockDomain. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) !) &login_hint= \( expectedLoginHint. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) !) "
34- let callbackURL = URL ( string: callbackURLString) !
33+ let encodedDomain = try XCTUnwrap ( mockDomain. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) )
34+ let encodedHint = try XCTUnwrap ( expectedLoginHint. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) )
35+ let callbackURLString = " sfdc://discocallback?my_domain= \( encodedDomain) &login_hint= \( encodedHint) "
36+ let callbackURL = try XCTUnwrap ( URL ( string: callbackURLString) )
3537 mockWebView. simulatedCallbackURL = callbackURL
3638
3739 // When
3840 coordinator. runMyDomainsDiscovery ( on: mockWebView, with: credentials)
39- let results = coordinator. handle ( action: mockWebView. mockAction!)
41+ let mockAction = try XCTUnwrap ( mockWebView. mockAction)
42+ let results = coordinator. handle ( action: mockAction)
4043
4144 // Then
4245 XCTAssertEqual ( results? . myDomain, expectedDomain)
@@ -47,15 +50,17 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
4750 // Given
4851 let mockWebView = MockWKWebView ( )
4952 let coordinator = DomainDiscoveryCoordinator ( )
50- let credentials = OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) !
53+ let credentials = try XCTUnwrap ( OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) )
5154 let expectedLoginHint = " [email protected] " 52- let callbackURLString = " sfdc://discocallback?login_hint= \( expectedLoginHint. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) !) "
53- let callbackURL = URL ( string: callbackURLString) !
55+ let encodedHint = try XCTUnwrap ( expectedLoginHint. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) )
56+ let callbackURLString = " sfdc://discocallback?login_hint= \( encodedHint) "
57+ let callbackURL = try XCTUnwrap ( URL ( string: callbackURLString) )
5458 mockWebView. simulatedCallbackURL = callbackURL
5559
5660 // When
5761 coordinator. runMyDomainsDiscovery ( on: mockWebView, with: credentials)
58- let results = coordinator. handle ( action: mockWebView. mockAction!)
62+ let mockAction = try XCTUnwrap ( mockWebView. mockAction)
63+ let results = coordinator. handle ( action: mockAction)
5964
6065 // Then
6166 XCTAssertNil ( results)
@@ -65,16 +70,18 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
6570 // Given
6671 let mockWebView = MockWKWebView ( )
6772 let coordinator = DomainDiscoveryCoordinator ( )
68- let credentials = OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) !
73+ let credentials = try XCTUnwrap ( OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) )
6974 let expectedDomain = " foo.my.salesforce.com "
7075 let mockDomain = " https:// \( expectedDomain) "
71- let callbackURLString = " sfdc://discocallback?my_domain= \( mockDomain. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) !) "
72- let callbackURL = URL ( string: callbackURLString) !
76+ let encodedDomain = try XCTUnwrap ( mockDomain. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) )
77+ let callbackURLString = " sfdc://discocallback?my_domain= \( encodedDomain) "
78+ let callbackURL = try XCTUnwrap ( URL ( string: callbackURLString) )
7379 mockWebView. simulatedCallbackURL = callbackURL
7480
7581 // When
7682 coordinator. runMyDomainsDiscovery ( on: mockWebView, with: credentials)
77- let results = coordinator. handle ( action: mockWebView. mockAction!)
83+ let mockAction = try XCTUnwrap ( mockWebView. mockAction)
84+ let results = coordinator. handle ( action: mockAction)
7885
7986 // Then
8087 XCTAssertNil ( results)
@@ -84,14 +91,15 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
8491 // Given
8592 let mockWebView = MockWKWebView ( )
8693 let coordinator = DomainDiscoveryCoordinator ( )
87- let credentials = OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) !
94+ let credentials = try XCTUnwrap ( OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) )
8895 let callbackURLString = " sfdc://discocallback?my_domain=&login_hint= "
89- let callbackURL = URL ( string: callbackURLString) !
96+ let callbackURL = try XCTUnwrap ( URL ( string: callbackURLString) )
9097 mockWebView. simulatedCallbackURL = callbackURL
9198
9299 // When
93100 coordinator. runMyDomainsDiscovery ( on: mockWebView, with: credentials)
94- let results = coordinator. handle ( action: mockWebView. mockAction!)
101+ let mockAction = try XCTUnwrap ( mockWebView. mockAction)
102+ let results = coordinator. handle ( action: mockAction)
95103
96104 // Then
97105 XCTAssertEqual ( results? . myDomain, " " )
@@ -102,13 +110,14 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
102110 // Given
103111 let mockWebView = MockWKWebView ( )
104112 let coordinator = DomainDiscoveryCoordinator ( )
105- let credentials = OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) !
106- let nonCallbackURL = URL ( string: " https://example.com " ) !
113+ let credentials = try XCTUnwrap ( OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) )
114+ let nonCallbackURL = try XCTUnwrap ( URL ( string: " https://example.com " ) )
107115 mockWebView. simulatedCallbackURL = nonCallbackURL
108116
109117 // When
110118 coordinator. runMyDomainsDiscovery ( on: mockWebView, with: credentials)
111- let results = coordinator. handle ( action: mockWebView. mockAction!)
119+ let mockAction = try XCTUnwrap ( mockWebView. mockAction)
120+ let results = coordinator. handle ( action: mockAction)
112121
113122 // Then
114123 XCTAssertNil ( results)
@@ -118,17 +127,20 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
118127 // Given
119128 let mockWebView = MockWKWebView ( )
120129 let coordinator = DomainDiscoveryCoordinator ( )
121- let credentials = OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) !
130+ let credentials = try XCTUnwrap ( OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) )
122131 let expectedDomain = " foo.my.salesforce.com "
123132 let mockDomain = " https:// \( expectedDomain) "
124133 let expectedLoginHint = " [email protected] " 125- let callbackURLString = " sfdc://discocallback?my_domain= \( mockDomain. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) !) &login_hint= \( expectedLoginHint. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) !) "
126- let callbackURL = URL ( string: callbackURLString) !
134+ let encodedDomain = try XCTUnwrap ( mockDomain. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) )
135+ let encodedHint = try XCTUnwrap ( expectedLoginHint. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) )
136+ let callbackURLString = " sfdc://discocallback?my_domain= \( encodedDomain) &login_hint= \( encodedHint) "
137+ let callbackURL = try XCTUnwrap ( URL ( string: callbackURLString) )
127138 mockWebView. simulatedCallbackURL = callbackURL
128139
129140 // When
130141 coordinator. runMyDomainsDiscovery ( on: mockWebView, with: credentials)
131- let results = coordinator. handle ( action: mockWebView. mockAction!)
142+ let mockAction = try XCTUnwrap ( mockWebView. mockAction)
143+ let results = coordinator. handle ( action: mockAction)
132144
133145 // Then
134146 XCTAssertEqual ( results? . myDomain, expectedDomain)
@@ -139,21 +151,25 @@ final class DomainDiscoveryCoordinatorTests: XCTestCase {
139151 // Given
140152 let mockWebView = MockWKWebView ( )
141153 let coordinator = DomainDiscoveryCoordinator ( )
142- let credentials = OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) !
154+ let credentials = try XCTUnwrap ( OAuthCredentials ( identifier: " test " , clientId: " client123 " , encrypted: false ) )
143155 let expectedDomain = " foo.my.salesforce.com "
144156 let mockDomain = " https:// \( expectedDomain) "
145157 let expectedLoginHint = " [email protected] " 146- let callbackURLString = " sfdc://discocallback?my_domain= \( mockDomain. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) !) &login_hint= \( expectedLoginHint. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) !) &extra=foo&another=bar "
147- let callbackURL = URL ( string: callbackURLString) !
158+ let encodedDomain = try XCTUnwrap ( mockDomain. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) )
159+ let encodedHint = try XCTUnwrap ( expectedLoginHint. addingPercentEncoding ( withAllowedCharacters: . urlQueryAllowed) )
160+ let callbackURLString = " sfdc://discocallback?my_domain= \( encodedDomain) &login_hint= \( encodedHint) &extra=foo&another=bar "
161+ let callbackURL = try XCTUnwrap ( URL ( string: callbackURLString) )
148162 mockWebView. simulatedCallbackURL = callbackURL
149163
150164 // When
151165 coordinator. runMyDomainsDiscovery ( on: mockWebView, with: credentials)
152- let results = coordinator. handle ( action: mockWebView. mockAction!)
166+
167+ let populatedAction = try XCTUnwrap ( mockWebView. mockAction)
168+ let results = try XCTUnwrap ( coordinator. handle ( action: populatedAction) )
153169
154170 // Then
155- XCTAssertEqual ( results? . myDomain, expectedDomain)
156- XCTAssertEqual ( results? . loginHint, expectedLoginHint)
171+ XCTAssertEqual ( results. myDomain, expectedDomain)
172+ XCTAssertEqual ( results. loginHint, expectedLoginHint)
157173 }
158174
159175 func testDiscoveryFlag( ) throws {
0 commit comments