Skip to content

Commit 7396115

Browse files
Add unit tests for DefaultApplicationPasswordUseCase
1 parent 9e8b404 commit 7396115

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@
736736
EE54C8A729486B6800A9BF61 /* ApplicationPasswordMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE54C8A629486B6800A9BF61 /* ApplicationPasswordMapper.swift */; };
737737
EE8A86F1286C5226003E8AA4 /* media-update-product-id-in-wordpress-site.json in Resources */ = {isa = PBXBuildFile; fileRef = EE8A86F0286C5226003E8AA4 /* media-update-product-id-in-wordpress-site.json */; };
738738
EE8DE42F294AFC58005054E7 /* generate-application-password-using-wpcom-token-success.json in Resources */ = {isa = PBXBuildFile; fileRef = EE8DE42E294AFC58005054E7 /* generate-application-password-using-wpcom-token-success.json */; };
739+
EE8DE432294B17CD005054E7 /* DefaultApplicationPasswordUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE8DE431294B17CD005054E7 /* DefaultApplicationPasswordUseCaseTests.swift */; };
739740
EECB7EE8286555180028C888 /* media-update-product-id.json in Resources */ = {isa = PBXBuildFile; fileRef = EECB7EE7286555180028C888 /* media-update-product-id.json */; };
740741
FE28F6E226840DED004465C7 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE28F6E126840DED004465C7 /* User.swift */; };
741742
FE28F6E426842848004465C7 /* UserMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE28F6E326842848004465C7 /* UserMapper.swift */; };
@@ -1503,6 +1504,7 @@
15031504
EE54C8A629486B6800A9BF61 /* ApplicationPasswordMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationPasswordMapper.swift; sourceTree = "<group>"; };
15041505
EE8A86F0286C5226003E8AA4 /* media-update-product-id-in-wordpress-site.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "media-update-product-id-in-wordpress-site.json"; sourceTree = "<group>"; };
15051506
EE8DE42E294AFC58005054E7 /* generate-application-password-using-wpcom-token-success.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "generate-application-password-using-wpcom-token-success.json"; sourceTree = "<group>"; };
1507+
EE8DE431294B17CD005054E7 /* DefaultApplicationPasswordUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultApplicationPasswordUseCaseTests.swift; sourceTree = "<group>"; };
15061508
EECB7EE7286555180028C888 /* media-update-product-id.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "media-update-product-id.json"; sourceTree = "<group>"; };
15071509
F3F25DC15EC1D7C631169CB5 /* Pods_Networking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Networking.framework; sourceTree = BUILT_PRODUCTS_DIR; };
15081510
F6CEE1CA2AD376C0C28AE9F6 /* Pods-NetworkingTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NetworkingTests.release.xcconfig"; path = "../Pods/Target Support Files/Pods-NetworkingTests/Pods-NetworkingTests.release.xcconfig"; sourceTree = "<group>"; };
@@ -1847,6 +1849,7 @@
18471849
B557D9F0209753AA005962F4 /* NetworkingTests */ = {
18481850
isa = PBXGroup;
18491851
children = (
1852+
EE8DE430294B17BA005054E7 /* ApplicationPassword */,
18501853
DE97C3902861B8CD0042E973 /* Encoder */,
18511854
5726F7322460A8E30031CAAC /* Copiable */,
18521855
B559EBA820A0B5B100836CD4 /* Responses */,
@@ -2609,6 +2612,14 @@
26092612
path = ApplicationPassword;
26102613
sourceTree = "<group>";
26112614
};
2615+
EE8DE430294B17BA005054E7 /* ApplicationPassword */ = {
2616+
isa = PBXGroup;
2617+
children = (
2618+
EE8DE431294B17CD005054E7 /* DefaultApplicationPasswordUseCaseTests.swift */,
2619+
);
2620+
path = ApplicationPassword;
2621+
sourceTree = "<group>";
2622+
};
26122623
/* End PBXGroup section */
26132624

26142625
/* Begin PBXHeadersBuildPhase section */
@@ -3398,6 +3409,7 @@
33983409
02BDB83723EA9C4D00BCC63E /* String+HTMLTests.swift in Sources */,
33993410
74CF5E8421402C04000CED0A /* TopEarnerStatsRemoteTests.swift in Sources */,
34003411
45B204BA24890A8C00FE6526 /* ProductCategoryMapperTests.swift in Sources */,
3412+
EE8DE432294B17CD005054E7 /* DefaultApplicationPasswordUseCaseTests.swift in Sources */,
34013413
74749B9522413119005C4CF2 /* ProductsRemoteTests.swift in Sources */,
34023414
B524194321AC622500D6FC0A /* DotcomDeviceMapperTests.swift in Sources */,
34033415
E1A5C27228F93ED900081046 /* InAppPurchaseOrderResultMapperTests.swift in Sources */,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import XCTest
2+
@testable import Networking
3+
4+
5+
/// DefaultApplicationPasswordUseCase Unit Tests
6+
///
7+
final class DefaultApplicationPasswordUseCaseTests: XCTestCase {
8+
/// Mock Network: Allows us to inject predefined responses!
9+
///
10+
private var network: MockNetwork!
11+
12+
/// Testing SiteID
13+
///
14+
private let sampleSiteID: Int64 = 123
15+
16+
/// Dummy WPCOM auth token
17+
///
18+
private let credentials = Credentials(authToken: "dummy-token")
19+
20+
/// Dummy WPCOM auth token
21+
///
22+
private let applicationPasswordURLSuffix = Credentials(authToken: "dummy-token")
23+
24+
/// URL suffixes
25+
///
26+
private enum URLSuffix {
27+
static let generateApplicationPassword = "users/me/application-passwords"
28+
static let usersMe = "users/me"
29+
}
30+
31+
32+
override func setUp() {
33+
super.setUp()
34+
network = MockNetwork(useResponseQueue: true)
35+
}
36+
37+
override func tearDown() {
38+
network = nil
39+
super.tearDown()
40+
}
41+
42+
func test_password_is_generated_with_correct_values_upon_success_response() async throws {
43+
// Given
44+
network.simulateResponse(requestUrlSuffix: URLSuffix.generateApplicationPassword,
45+
filename: "generate-application-password-using-wpcom-token-success")
46+
network.simulateResponse(requestUrlSuffix: URLSuffix.usersMe, filename: "user-complete")
47+
48+
let sut = DefaultApplicationPasswordUseCase(siteID: sampleSiteID,
49+
networkcredentials: credentials,
50+
network: network)
51+
52+
let password = try await sut.generateNewPassword()
53+
XCTAssertEqual(password.password.secretValue, "passwordvalue")
54+
XCTAssertEqual(password.wpOrgUsername, "test-username")
55+
}
56+
}

0 commit comments

Comments
 (0)