-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathMockPOSOrderService.swift
53 lines (44 loc) · 2.1 KB
/
MockPOSOrderService.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Foundation
@testable import Yosemite
import WooFoundation
class MockPOSOrderService: POSOrderServiceProtocol {
var simulateSyncing = false
var orderToReturn: Order?
var errorToReturn: Error?
var syncOrderWasCalled = false
var updateOrderWasCalled = false
var spySyncOrderCurrency: CurrencyCode?
func syncOrder(cart: Yosemite.POSCart,
currency: CurrencyCode) async throws -> Yosemite.Order {
syncOrderWasCalled = true
spySyncOrderCurrency = currency
if simulateSyncing {
try await Task.sleep(nanoseconds: UInt64(1 * Double(NSEC_PER_SEC)))
}
if let error = errorToReturn {
throw error
}
guard let order = orderToReturn else {
throw MockPOSOrderServiceError.noOrderToReturn
}
return order
}
func updatePOSOrder(order: Order, recipientEmail: String) async throws {
updateOrderWasCalled = true
let orderWithUpdatedEmail = MockOrders().sampleOrder().copy(billingAddress: .init(firstName: "",
lastName: "",
company: nil,
address1: "",
address2: nil,
city: "",
state: "",
postcode: "",
country: "",
phone: nil,
email: recipientEmail))
orderToReturn = orderWithUpdatedEmail
}
}
enum MockPOSOrderServiceError: Error {
case noOrderToReturn
}