Skip to content

Commit 812a0f3

Browse files
Test application password is generated upon retrying a request.
1 parent e828526 commit 812a0f3

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

Networking/NetworkingTests/ApplicationPassword/RequestProcessorTests.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ final class RequestProcessorTests: XCTestCase {
164164
// Then
165165
XCTAssertFalse(shouldRetry)
166166
}
167+
168+
// MARK: Generate application password
169+
//
170+
func test_application_password_is_generated_upon_retrying_a_request() throws {
171+
// Given
172+
let sessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.default)
173+
let request = try mockRequest()
174+
175+
// When
176+
let error = RequestAuthenticatorError.applicationPasswordNotAvailable
177+
waitFor { promise in
178+
self.sut.should(sessionManager, retry: request, with: error) { shouldRetry, timeDelay in
179+
promise(())
180+
}
181+
}
182+
183+
// Then
184+
XCTAssertTrue(mockRequestAuthenticator.generateApplicationPasswordCalled)
185+
}
186+
187+
func test_application_password_is_not_generated_when_a_request_is_not_eligible_for_retry() throws {
188+
// Given
189+
let sessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.default)
190+
let request = try mockRequest()
191+
192+
// When
193+
mockRequestAuthenticator.mockedShouldRetryValue = false
194+
waitFor { promise in
195+
self.sut.should(sessionManager, retry: request, with: RequestAuthenticatorError.applicationPasswordNotAvailable) { shouldRetry, timeDelay in
196+
promise(())
197+
}
198+
}
199+
200+
// Then
201+
XCTAssertFalse(mockRequestAuthenticator.generateApplicationPasswordCalled)
202+
}
167203
}
168204

169205
// MARK: Helpers
@@ -189,6 +225,7 @@ private class MockRequestAuthenticator: RequestAuthenticator {
189225
var mockedShouldRetryValue: Bool?
190226

191227
private(set) var authenticateCalled = false
228+
private(set) var generateApplicationPasswordCalled = false
192229

193230
var credentials: Networking.Credentials? = nil
194231

@@ -198,7 +235,7 @@ private class MockRequestAuthenticator: RequestAuthenticator {
198235
}
199236

200237
func generateApplicationPassword() async throws {
201-
// Do nothing
238+
generateApplicationPasswordCalled = true
202239
}
203240

204241
func shouldRetry(_ urlRequest: URLRequest) -> Bool {

0 commit comments

Comments
 (0)