@@ -8,11 +8,15 @@ import XCTest
88private 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