Skip to content

Commit 4d4668a

Browse files
committed
Add CustomerRemote unit tests
1 parent 9e29b05 commit 4d4668a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Networking/Networking.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@
323323
57BE08D82409B63800F6DCED /* reviews-missing-avatar-urls.json in Resources */ = {isa = PBXBuildFile; fileRef = 57BE08D72409B63700F6DCED /* reviews-missing-avatar-urls.json */; };
324324
57E8FED3246616AC0057CD68 /* Result+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E8FED2246616AC0057CD68 /* Result+Extensions.swift */; };
325325
6647C0161DAC6AB6570C53A7 /* Pods_Networking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3F25DC15EC1D7C631169CB5 /* Pods_Networking.framework */; };
326+
68BD37B328D9B8BD00C2A517 /* CustomerRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68BD37B228D9B8BD00C2A517 /* CustomerRemoteTests.swift */; };
326327
68C87B342862D40E00A99054 /* setting-all-except-countries.json in Resources */ = {isa = PBXBuildFile; fileRef = 68C87B332862D40E00A99054 /* setting-all-except-countries.json */; };
327328
68CB800C28D87BC800E169F8 /* Customer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68CB800B28D87BC800E169F8 /* Customer.swift */; };
328329
68CB800E28D8901B00E169F8 /* CustomerMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68CB800D28D8901B00E169F8 /* CustomerMapper.swift */; };
@@ -1015,6 +1016,7 @@
10151016
5726F7332460A8F00031CAAC /* CopiableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopiableTests.swift; sourceTree = "<group>"; };
10161017
57BE08D72409B63700F6DCED /* reviews-missing-avatar-urls.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "reviews-missing-avatar-urls.json"; sourceTree = "<group>"; };
10171018
57E8FED2246616AC0057CD68 /* Result+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Result+Extensions.swift"; sourceTree = "<group>"; };
1019+
68BD37B228D9B8BD00C2A517 /* CustomerRemoteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerRemoteTests.swift; sourceTree = "<group>"; };
10181020
68C87B332862D40E00A99054 /* setting-all-except-countries.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "setting-all-except-countries.json"; sourceTree = "<group>"; };
10191021
68CB800B28D87BC800E169F8 /* Customer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Customer.swift; sourceTree = "<group>"; };
10201022
68CB800D28D8901B00E169F8 /* CustomerMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomerMapper.swift; sourceTree = "<group>"; };
@@ -1626,6 +1628,7 @@
16261628
FE28F6EB268436C9004465C7 /* UserRemoteTests.swift */,
16271629
077F39D926A58ED700ABEADC /* SystemStatusRemoteTests.swift */,
16281630
DE34051E28BDFB0B00CF0D97 /* JetpackConnectionRemoteTests.swift */,
1631+
68BD37B228D9B8BD00C2A517 /* CustomerRemoteTests.swift */,
16291632
);
16301633
path = Remote;
16311634
sourceTree = "<group>";
@@ -3218,6 +3221,7 @@
32183221
45CCFCE827A2E5020012E8CB /* InboxNoteListMapperTests.swift in Sources */,
32193222
74002D6C2118B88200A63C19 /* SiteVisitStatsRemoteTests.swift in Sources */,
32203223
0212683524C046CB00F8A892 /* MockNetwork+Path.swift in Sources */,
3224+
68BD37B328D9B8BD00C2A517 /* CustomerRemoteTests.swift in Sources */,
32213225
B554FA932180C17200C54DFF /* NoteHashListMapperTests.swift in Sources */,
32223226
CC07866526790B1100BA9AC1 /* ShippingLabelPurchaseMapperTests.swift in Sources */,
32233227
74002D6A2118B26100A63C19 /* SiteVisitStatsMapperTests.swift in Sources */,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import XCTest
2+
@testable import Networking
3+
4+
class CustomerRemoteTests: XCTestCase {
5+
6+
/// Dummy Network Wrapper
7+
///
8+
private var network: MockNetwork!
9+
10+
/// Dummy Site ID
11+
///
12+
private let sampleSiteID: Int64 = 123
13+
14+
/// Dummy Customer ID
15+
private let sampleCustomerID: Int64 = 25
16+
17+
override func setUp() {
18+
super.setUp()
19+
network = MockNetwork()
20+
}
21+
22+
override func tearDown() {
23+
network = nil
24+
super.tearDown()
25+
}
26+
27+
/// Verifies that retrieveCustomer properly parses the `wc/v3/customers/{customerID}` endpoint sample response.
28+
///
29+
func test_retrieveCustomer_returns_parsed_customer_successfully() throws {
30+
// Given
31+
let remote = CustomerRemote(network: network)
32+
network.simulateResponse(requestUrlSuffix: "customers/\(sampleCustomerID)", filename: "customer")
33+
34+
// When
35+
let result = waitFor { promise in
36+
remote.retrieveCustomer(for: self.sampleSiteID, with: self.sampleCustomerID) { result in
37+
promise(result)
38+
}
39+
}
40+
41+
// Then
42+
XCTAssert(result.isSuccess)
43+
let customer = try XCTUnwrap(result.get())
44+
XCTAssertNotNil(customer)
45+
}
46+
}

0 commit comments

Comments
 (0)