|
1 | 1 | import XCTest |
2 | 2 | @testable import Networking |
3 | | - |
| 3 | +import Alamofire |
4 | 4 |
|
5 | 5 | /// DefaultApplicationPasswordUseCase Unit Tests |
6 | 6 | /// |
@@ -43,4 +43,50 @@ final class DefaultApplicationPasswordUseCaseTests: XCTestCase { |
43 | 43 | XCTAssertEqual(password.password.secretValue, "passwordvalue") |
44 | 44 | XCTAssertEqual(password.wpOrgUsername, username) |
45 | 45 | } |
| 46 | + |
| 47 | + func test_applicationPasswordsDisabled_error_is_thrown_if_generating_password_fails_with_501_error() async throws { |
| 48 | + // Given |
| 49 | + let error = AFError.responseValidationFailed(reason: .unacceptableStatusCode(code: 501)) |
| 50 | + network.simulateError(requestUrlSuffix: URLSuffix.generateApplicationPassword, error: error) |
| 51 | + let username = "demo" |
| 52 | + let siteAddress = "https://test.com" |
| 53 | + let sut = try DefaultApplicationPasswordUseCase(username: username, |
| 54 | + password: "qeWOhQ5RUV8W", |
| 55 | + siteAddress: siteAddress, |
| 56 | + network: network) |
| 57 | + |
| 58 | + // When |
| 59 | + var failure: ApplicationPasswordUseCaseError? |
| 60 | + do { |
| 61 | + let _ = try await sut.generateNewPassword() |
| 62 | + } catch { |
| 63 | + failure = error as? ApplicationPasswordUseCaseError |
| 64 | + } |
| 65 | + |
| 66 | + // Then |
| 67 | + XCTAssertTrue(failure == .applicationPasswordsDisabled) |
| 68 | + } |
| 69 | + |
| 70 | + func test_unauthorizedRequest_error_is_thrown_if_generating_password_fails_with_401_error() async throws { |
| 71 | + // Given |
| 72 | + let error = AFError.responseValidationFailed(reason: .unacceptableStatusCode(code: 401)) |
| 73 | + network.simulateError(requestUrlSuffix: URLSuffix.generateApplicationPassword, error: error) |
| 74 | + let username = "demo" |
| 75 | + let siteAddress = "https://test.com" |
| 76 | + let sut = try DefaultApplicationPasswordUseCase(username: username, |
| 77 | + password: "qeWOhQ5RUV8W", |
| 78 | + siteAddress: siteAddress, |
| 79 | + network: network) |
| 80 | + |
| 81 | + // When |
| 82 | + var failure: ApplicationPasswordUseCaseError? |
| 83 | + do { |
| 84 | + let _ = try await sut.generateNewPassword() |
| 85 | + } catch { |
| 86 | + failure = error as? ApplicationPasswordUseCaseError |
| 87 | + } |
| 88 | + |
| 89 | + // Then |
| 90 | + XCTAssertTrue(failure == .unauthorizedRequest) |
| 91 | + } |
46 | 92 | } |
0 commit comments