Skip to content

Commit 0cf2444

Browse files
committed
Update unit tests for DefaultApplicationPasswordUseCase
1 parent fac2e94 commit 0cf2444

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

Networking/NetworkingTests/ApplicationPassword/DefaultApplicationPasswordUseCaseTests.swift

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import XCTest
22
@testable import Networking
3-
3+
import Alamofire
44

55
/// DefaultApplicationPasswordUseCase Unit Tests
66
///
@@ -43,4 +43,50 @@ final class DefaultApplicationPasswordUseCaseTests: XCTestCase {
4343
XCTAssertEqual(password.password.secretValue, "passwordvalue")
4444
XCTAssertEqual(password.wpOrgUsername, username)
4545
}
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+
}
4692
}

WooCommerce/WooCommerceTests/Authentication/PostSiteCredentialLoginCheckerTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ final class PostSiteCredentialLoginCheckerTests: XCTestCase {
183183
stores.whenReceivingAction(ofType: WordPressSiteAction.self) { action in
184184
switch action {
185185
case .fetchSiteInfo(_, let completion):
186-
let site = Site.fake().copy(isWooCommerceActive: false)
187186
completion(.failure(NetworkError.timeout))
188187
}
189188
}

0 commit comments

Comments
 (0)