Skip to content

Commit 90d1e8f

Browse files
committed
Update settingsStoreMethods in PointOfSaleCouponService
1 parent 34177e4 commit 90d1e8f

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

Yosemite/Yosemite.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
012848DC2D9ED55B00A9C69B /* SettingStoreMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012848DB2D9ED55700A9C69B /* SettingStoreMethods.swift */; };
1111
012848DE2D9EDAC100A9C69B /* MockCouponStoreMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012848DD2D9EDAC100A9C69B /* MockCouponStoreMethods.swift */; };
12+
012848E22D9EDF2D00A9C69B /* MockSettingStoreMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 012848E12D9EDF2D00A9C69B /* MockSettingStoreMethods.swift */; };
1213
0139C2B02D91D1C600C78FDE /* POSCart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0139C2AF2D91D1C400C78FDE /* POSCart.swift */; };
1314
016A776B2D9D30C90004FCD6 /* PointOfSaleCouponServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A776A2D9D30C10004FCD6 /* PointOfSaleCouponServiceTests.swift */; };
1415
016A89D82D9D6DB50004FCD6 /* CouponStoreMethods.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016A89D72D9D6DAE0004FCD6 /* CouponStoreMethods.swift */; };
@@ -560,6 +561,7 @@
560561
/* Begin PBXFileReference section */
561562
012848DB2D9ED55700A9C69B /* SettingStoreMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingStoreMethods.swift; sourceTree = "<group>"; };
562563
012848DD2D9EDAC100A9C69B /* MockCouponStoreMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCouponStoreMethods.swift; sourceTree = "<group>"; };
564+
012848E12D9EDF2D00A9C69B /* MockSettingStoreMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSettingStoreMethods.swift; sourceTree = "<group>"; };
563565
0139C2AF2D91D1C400C78FDE /* POSCart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSCart.swift; sourceTree = "<group>"; };
564566
016A776A2D9D30C10004FCD6 /* PointOfSaleCouponServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PointOfSaleCouponServiceTests.swift; sourceTree = "<group>"; };
565567
016A89D72D9D6DAE0004FCD6 /* CouponStoreMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponStoreMethods.swift; sourceTree = "<group>"; };
@@ -2003,6 +2005,7 @@
20032005
B5C9DE1D2087FF20006B910A /* Mocks */ = {
20042006
isa = PBXGroup;
20052007
children = (
2008+
012848E12D9EDF2D00A9C69B /* MockSettingStoreMethods.swift */,
20062009
012848DD2D9EDAC100A9C69B /* MockCouponStoreMethods.swift */,
20072010
20CF75B72CF4C3AD00ACCF4A /* MockPOSOrdersRemote.swift */,
20082011
6801E41B2D1007D000F9DF46 /* MockPOSReceiptsRemote.swift */,
@@ -2856,6 +2859,7 @@
28562859
DE87F40C2D2F839700869522 /* AppSettingsStoreTests+ProductFilterHistory.swift in Sources */,
28572860
20D210C12B177EEF0099E517 /* WooPaymentsPayoutServiceTests.swift in Sources */,
28582861
D87F615E2265B1BC0031A13B /* AppSettingsStoreTests.swift in Sources */,
2862+
012848E22D9EDF2D00A9C69B /* MockSettingStoreMethods.swift in Sources */,
28592863
207D2D1B2CFA06BD00F79204 /* POSCartItemTests.swift in Sources */,
28602864
02E7FFD52562226B00C53030 /* ShippingLabelStoreTests.swift in Sources */,
28612865
031FD8A026FC970400B315C7 /* RosettaTestingHelper.swift in Sources */,

Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol {
1919
private let currencyFormatter: CurrencyFormatter
2020
private let storage: StorageManagerType?
2121
private let couponStoreMethods: CouponStoreMethodsProtocol
22+
private let settingsStoreMethods: SettingStoreMethodsProtocol
2223

2324
init(siteID: Int64,
2425
currencySettings: CurrencySettings,
2526
couponStoreMethods: CouponStoreMethodsProtocol,
27+
settingStoreMethods: SettingStoreMethodsProtocol,
2628
storage: StorageManagerType) {
2729
self.siteID = siteID
2830
self.currencyFormatter = CurrencyFormatter(currencySettings: currencySettings)
2931
self.storage = storage
3032
self.couponStoreMethods = couponStoreMethods
33+
self.settingsStoreMethods = settingStoreMethods
3134
}
3235

3336
public convenience init(siteID: Int64,
@@ -39,6 +42,7 @@ public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol {
3942
self.init(siteID: siteID,
4043
currencySettings: currencySettings,
4144
couponStoreMethods: CouponStoreMethods(storageManager: storage, remote: remote),
45+
settingStoreMethods: SettingStoreMethods(storageManager: storage, network: network),
4246
storage: storage)
4347
}
4448

@@ -111,7 +115,17 @@ private extension PointOfSaleCouponService {
111115
}
112116

113117
private func checkStoreCouponSettings() async -> Bool {
114-
// TODO: WOOMOB-250
115-
return true
118+
await withCheckedContinuation { continuation in
119+
settingsStoreMethods.retrieveCouponSetting(siteID: siteID) { result in
120+
switch result {
121+
case let .success(isEnabled):
122+
debugPrint("Coupons enabled? \(isEnabled)")
123+
continuation.resume(returning: isEnabled)
124+
case let .failure(error):
125+
debugPrint("Coupons settings error: \(error)")
126+
continuation.resume(returning: false)
127+
}
128+
}
129+
}
116130
}
117131
}

Yosemite/Yosemite/Stores/CouponStore.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import Storage
55
// MARK: - CouponStore
66
//
77
public final class CouponStore: Store {
8-
private let remote: CouponsRemoteProtocol
98
private let methods: CouponStoreMethods
109

1110
init(dispatcher: Dispatcher,
1211
storageManager: StorageManagerType,
1312
network: Network,
1413
remote: CouponsRemoteProtocol) {
15-
self.remote = remote
1614
self.methods = CouponStoreMethods(storageManager: storageManager, remote: remote)
1715
super.init(dispatcher: dispatcher, storageManager: storageManager, network: network)
1816
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
11
@testable import Yosemite
22

33
final class MockSettingStoreMethods: SettingStoreMethodsProtocol {
4+
var generalSiteSettingsSyncCalled = false
5+
var productSiteSettingsSyncCalled = false
6+
var retrieveSiteAPICalled = false
7+
var retrieveCouponSettingCalled = false
8+
var enableCouponSettingCalled = false
9+
var retrieveAnalyticsSettingCalled = false
10+
var enableAnalyticsSettingCalled = false
11+
var retrieveTaxBasedOnSettingCalled = false
412

13+
func synchronizeGeneralSiteSettings(siteID: Int64,
14+
onCompletion: @escaping (Error?) -> Void) {
15+
generalSiteSettingsSyncCalled = true
16+
onCompletion(nil)
17+
}
18+
19+
func synchronizeProductSiteSettings(siteID: Int64,
20+
onCompletion: @escaping (Error?) -> Void) {
21+
productSiteSettingsSyncCalled = true
22+
onCompletion(nil)
23+
}
24+
25+
func retrieveSiteAPI(siteID: Int64,
26+
onCompletion: @escaping (Result<Yosemite.SiteAPI, Error>) -> Void) {
27+
retrieveSiteAPICalled = true
28+
}
29+
30+
func retrieveCouponSetting(siteID: Int64,
31+
onCompletion: @escaping (Result<Bool, Error>) -> Void) {
32+
retrieveCouponSettingCalled = true
33+
onCompletion(.success(true))
34+
}
35+
36+
func enableCouponSetting(siteID: Int64,
37+
onCompletion: @escaping (Result<Void, Error>) -> Void) {
38+
enableCouponSettingCalled = true
39+
onCompletion(.success(()))
40+
}
41+
42+
func retrieveAnalyticsSetting(siteID: Int64,
43+
onCompletion: @escaping (Result<Bool, Error>) -> Void) {
44+
retrieveAnalyticsSettingCalled = true
45+
onCompletion(.success(true))
46+
}
47+
48+
func enableAnalyticsSetting(siteID: Int64,
49+
onCompletion: @escaping (Result<Void, Error>) -> Void) {
50+
enableAnalyticsSettingCalled = true
51+
onCompletion(.success(()))
52+
}
53+
54+
func retrieveTaxBasedOnSetting(siteID: Int64,
55+
onCompletion: @escaping (Result<Yosemite.TaxBasedOnSetting, Error>) -> Void) {
56+
retrieveTaxBasedOnSettingCalled = true
57+
}
558
}

Yosemite/YosemiteTests/PointOfSale/PointOfSaleCouponServiceTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ import class WooFoundation.CurrencySettings
55
struct PointOfSaleCouponServiceTests {
66
private let sut: PointOfSaleCouponService
77
private let couponStoreMethods: MockCouponStoreMethods
8+
private let settingStoreMethods: MockSettingStoreMethods
89
private let storage: MockStorageManager
910

1011
init() {
1112
self.couponStoreMethods = MockCouponStoreMethods()
13+
self.settingStoreMethods = MockSettingStoreMethods()
1214
self.storage = MockStorageManager()
1315
self.sut = .init(siteID: 123,
1416
currencySettings: CurrencySettings(),
1517
couponStoreMethods: couponStoreMethods,
18+
settingStoreMethods: settingStoreMethods,
1619
storage: storage
1720
)
1821
}

0 commit comments

Comments
 (0)