Skip to content

Commit 9967e2f

Browse files
committed
Add mocks and tests
1 parent 181c23c commit 9967e2f

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

Yosemite/Yosemite.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
D87F614C22657B150031A13B /* AppSettingsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87F614B22657B150031A13B /* AppSettingsStore.swift */; };
110110
D87F615E2265B1BC0031A13B /* AppSettingsStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87F615D2265B1BC0031A13B /* AppSettingsStoreTests.swift */; };
111111
D87F61602265B2400031A13B /* shipment-provider.plist in Resources */ = {isa = PBXBuildFile; fileRef = D87F615F2265B2400031A13B /* shipment-provider.plist */; };
112+
D8BD6A4C229D07C9007CAD6C /* custom-shipment-provider.plist in Resources */ = {isa = PBXBuildFile; fileRef = D8BD6A4B229D07C8007CAD6C /* custom-shipment-provider.plist */; };
112113
/* End PBXBuildFile section */
113114

114115
/* Begin PBXContainerItemProxy section */
@@ -231,6 +232,7 @@
231232
D87F614B22657B150031A13B /* AppSettingsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettingsStore.swift; sourceTree = "<group>"; };
232233
D87F615D2265B1BC0031A13B /* AppSettingsStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettingsStoreTests.swift; sourceTree = "<group>"; };
233234
D87F615F2265B2400031A13B /* shipment-provider.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "shipment-provider.plist"; sourceTree = "<group>"; };
235+
D8BD6A4B229D07C8007CAD6C /* custom-shipment-provider.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "custom-shipment-provider.plist"; sourceTree = "<group>"; };
234236
/* End PBXFileReference section */
235237

236238
/* Begin PBXFrameworksBuildPhase section */
@@ -475,6 +477,7 @@
475477
B5C9DE1D2087FF20006B910A /* Mockups */ = {
476478
isa = PBXGroup;
477479
children = (
480+
D8BD6A4B229D07C8007CAD6C /* custom-shipment-provider.plist */,
478481
D87F615F2265B2400031A13B /* shipment-provider.plist */,
479482
B5C9DE1E2087FF20006B910A /* MockupProcessor.swift */,
480483
B5C9DE202087FF20006B910A /* MockupAcount.swift */,
@@ -627,6 +630,7 @@
627630
isa = PBXResourcesBuildPhase;
628631
buildActionMask = 2147483647;
629632
files = (
633+
D8BD6A4C229D07C9007CAD6C /* custom-shipment-provider.plist in Resources */,
630634
B5BC71DD21139EDD005CF5AA /* Responses in Resources */,
631635
D87F61602265B2400031A13B /* shipment-provider.plist in Resources */,
632636
);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<array>
5+
<dict>
6+
<key>providerURL</key>
7+
<string>http://some.where</string>
8+
<key>providerName</key>
9+
<string>post.at</string>
10+
<key>siteID</key>
11+
<integer>156590080</integer>
12+
</dict>
13+
<dict>
14+
<key>providerURL</key>
15+
<string>http://some.where</string>
16+
<key>providerName</key>
17+
<string>A mock provider</string>
18+
<key>siteID</key>
19+
<integer>1234</integer>
20+
</dict>
21+
</array>
22+
</plist>

Yosemite/YosemiteTests/Stores/AppSettingsStoreTests.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import XCTest
88
private struct TestConstants {
99
static let fileURL = Bundle(for: AppSettingsStoreTests.self)
1010
.url(forResource: "shipment-provider", withExtension: "plist")
11+
static let customFileURL = Bundle(for: AppSettingsStoreTests.self)
12+
.url(forResource: "custom-shipment-provider", withExtension: "plist")
1113
static let siteID = 156590080
1214
static let providerName = "post.at"
15+
static let providerURL = "http://some.where"
1316

1417
static let newSiteID = 1234
1518
static let newProviderName = "Some provider"
19+
static let newProviderURL = "http://some.where"
1620
}
1721

1822

@@ -42,6 +46,7 @@ final class AppSettingsStoreTests: XCTestCase {
4246
fileStorage = MockFileLoader()
4347
subject = AppSettingsStore(dispatcher: dispatcher!, storageManager: storageManager!, fileStorage: fileStorage!)
4448
subject?.selectedProvidersURL = TestConstants.fileURL!
49+
subject?.customSelectedProvidersURL = TestConstants.customFileURL!
4550
}
4651

4752
override func tearDown() {
@@ -69,6 +74,23 @@ final class AppSettingsStoreTests: XCTestCase {
6974
waitForExpectations(timeout: 2, handler: nil)
7075
}
7176

77+
func testFileStorageIsRequestedToWriteWhenAddingANewCustomShipmentProvider() {
78+
let expectation = self.expectation(description: "A write is requested")
79+
80+
let action = AppSettingsAction.addCustomTrackingProvider(siteID: TestConstants.newSiteID,
81+
providerName: TestConstants.newProviderName, providerURL: TestConstants.newProviderURL) { error in
82+
XCTAssertNil(error)
83+
84+
if self.fileStorage?.dataWriteIsHit == true {
85+
expectation.fulfill()
86+
}
87+
}
88+
89+
subject?.onAction(action)
90+
91+
waitForExpectations(timeout: 2, handler: nil)
92+
}
93+
7294
func testFileStorageIsRequestedToWriteWhenAddingAShipmentProviderForExistingSite() {
7395
let expectation = self.expectation(description: "A write is requested")
7496

@@ -86,6 +108,24 @@ final class AppSettingsStoreTests: XCTestCase {
86108
waitForExpectations(timeout: 2, handler: nil)
87109
}
88110

111+
func testFileStorageIsRequestedToWriteWhenAddingACustomShipmentProviderForExistingSite() {
112+
let expectation = self.expectation(description: "A write is requested")
113+
114+
let action = AppSettingsAction.addCustomTrackingProvider(siteID: TestConstants.siteID,
115+
providerName: TestConstants.providerName,
116+
providerURL: TestConstants.providerURL) { error in
117+
XCTAssertNil(error)
118+
119+
if self.fileStorage?.dataWriteIsHit == true {
120+
expectation.fulfill()
121+
}
122+
}
123+
124+
subject?.onAction(action)
125+
126+
waitForExpectations(timeout: 2, handler: nil)
127+
}
128+
89129
func testAddingNewProviderToExistingSiteUpdatesFile() {
90130
let expectation = self.expectation(description: "File is updated")
91131

@@ -107,6 +147,28 @@ final class AppSettingsStoreTests: XCTestCase {
107147
waitForExpectations(timeout: 2, handler: nil)
108148
}
109149

150+
func testAddingNewCustomProviderToExistingSiteUpdatesFile() {
151+
let expectation = self.expectation(description: "File is updated")
152+
153+
let action = AppSettingsAction
154+
.addCustomTrackingProvider(siteID: TestConstants.siteID,
155+
providerName: TestConstants.newProviderName,
156+
providerURL: TestConstants.newProviderURL) { error in
157+
XCTAssertNil(error)
158+
let fileData = self.fileStorage?.fileData
159+
let updatedProvider = fileData?.filter({ $0.siteID == TestConstants.siteID}).first
160+
161+
if updatedProvider?.providerName == TestConstants.newProviderName {
162+
expectation.fulfill()
163+
}
164+
165+
}
166+
167+
subject?.onAction(action)
168+
169+
waitForExpectations(timeout: 2, handler: nil)
170+
}
171+
110172
func testRestoreResetProvidersHitsClearFile() {
111173
let expectation = self.expectation(description: "File is updated")
112174

0 commit comments

Comments
 (0)