Skip to content

Commit c7f177c

Browse files
Remove unchecked Sendable test helpers
1 parent ac8762f commit c7f177c

15 files changed

Lines changed: 170 additions & 52 deletions

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Internal/StorefrontAPI/StorefrontAPIMutationsTests.swift

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,40 @@ final class StorefrontAPIMutationsTests: XCTestCase {
4343
// MARK: - Mock URLProtocol for Network Mocking
4444

4545
class MockURLProtocol: URLProtocol {
46-
static var mockResponseData: Data?
47-
static var mockError: Error?
48-
static var mockStatusCode: Int = 200
49-
static var capturedRequest: URLRequest?
50-
static var capturedRequestBody: Data?
46+
private struct State {
47+
var mockResponseData: Data?
48+
var mockError: Error?
49+
var mockStatusCode = 200
50+
var capturedRequest: URLRequest?
51+
var capturedRequestBody: Data?
52+
}
53+
54+
private static let state = LockedTestValue(State())
55+
56+
static var mockResponseData: Data? {
57+
get { state.get().mockResponseData }
58+
set { state.update { $0.mockResponseData = newValue } }
59+
}
60+
61+
static var mockError: Error? {
62+
get { state.get().mockError }
63+
set { state.update { $0.mockError = newValue } }
64+
}
65+
66+
static var mockStatusCode: Int {
67+
get { state.get().mockStatusCode }
68+
set { state.update { $0.mockStatusCode = newValue } }
69+
}
70+
71+
static var capturedRequest: URLRequest? {
72+
get { state.get().capturedRequest }
73+
set { state.update { $0.capturedRequest = newValue } }
74+
}
75+
76+
static var capturedRequestBody: Data? {
77+
get { state.get().capturedRequestBody }
78+
set { state.update { $0.capturedRequestBody = newValue } }
79+
}
5180

5281
override class func canInit(with _: URLRequest) -> Bool {
5382
return true

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Internal/StorefrontAPI/StorefrontAPIQueriesTests.swift

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,40 @@ final class StorefrontAPIQueriesTests: XCTestCase {
66
// MARK: - Mock URLProtocol for Network Mocking
77

88
class MockURLProtocol: URLProtocol {
9-
static var mockResponseData: Data?
10-
static var mockError: Error?
11-
static var mockStatusCode: Int = 200
12-
static var capturedRequest: URLRequest?
13-
static var capturedRequestBody: Data?
9+
private struct State {
10+
var mockResponseData: Data?
11+
var mockError: Error?
12+
var mockStatusCode = 200
13+
var capturedRequest: URLRequest?
14+
var capturedRequestBody: Data?
15+
}
16+
17+
private static let state = LockedTestValue(State())
18+
19+
static var mockResponseData: Data? {
20+
get { state.get().mockResponseData }
21+
set { state.update { $0.mockResponseData = newValue } }
22+
}
23+
24+
static var mockError: Error? {
25+
get { state.get().mockError }
26+
set { state.update { $0.mockError = newValue } }
27+
}
28+
29+
static var mockStatusCode: Int {
30+
get { state.get().mockStatusCode }
31+
set { state.update { $0.mockStatusCode = newValue } }
32+
}
33+
34+
static var capturedRequest: URLRequest? {
35+
get { state.get().capturedRequest }
36+
set { state.update { $0.capturedRequest = newValue } }
37+
}
38+
39+
static var capturedRequestBody: Data? {
40+
get { state.get().capturedRequestBody }
41+
set { state.update { $0.capturedRequestBody = newValue } }
42+
}
1443

1544
override class func canInit(with _: URLRequest) -> Bool {
1645
return true
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@testable import ShopifyCheckoutKit
2+
3+
final class LockedTestValue<Value: Sendable>: Sendable {
4+
private let value: LockedValue<Value>
5+
6+
init(_ value: Value) {
7+
self.value = LockedValue(value)
8+
}
9+
10+
func get() -> Value {
11+
value.get()
12+
}
13+
14+
func set(_ newValue: Value) {
15+
value.set(newValue)
16+
}
17+
18+
func update(_ block: (inout Value) -> Void) {
19+
value.update(block)
20+
}
21+
}

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/ShopifyAcceleratedCheckoutsTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import os.log
44
import XCTest
55

66
@available(iOS 17.0, *)
7+
@MainActor
78
class ShopifyAcceleratedCheckoutsTests: XCTestCase {
89
var originalLogLevel: LogLevel!
910

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/TestHelpers.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import XCTest
66

77
// MARK: - Configuration Helpers
88

9+
@MainActor
910
func XCTAssertThrowsErrorAsync(
1011
_ expression: @autoclosure () async throws -> some Any,
1112
_ errorHandler: (Error) -> Void,

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/AcceleratedCheckoutButtonsRenderStateTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33
import XCTest
44

55
@available(iOS 17.0, *)
6+
@MainActor
67
final class AcceleratedCheckoutButtonsRenderStateTests: XCTestCase {
78
// MARK: - Render State Change Callback Tests
89

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayAuthorizationDelegate/ApplePayAuthorizationDelegateControllerTests.swift

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,46 @@ final class ApplePayAuthorizationDelegateControllerTests: XCTestCase {
612612
"\"cost\":{\"totalAmount\":{\"amount\":\"0.00\",\"currencyCode\":\"USD\"}}," +
613613
"\"discountCodes\":[],\"discountAllocations\":[]}"
614614

615-
static var failReplace = false
616-
static var failDeliveryUpdate = false
617-
static var failPrepareForCompletion = false
618-
static var returnMappableCartUserError = false
619-
static var returnInvalidCart = false
620-
static var lastOperation: String?
615+
private struct State {
616+
var failReplace = false
617+
var failDeliveryUpdate = false
618+
var failPrepareForCompletion = false
619+
var returnMappableCartUserError = false
620+
var returnInvalidCart = false
621+
var lastOperation: String?
622+
}
623+
624+
private static let state = LockedTestValue(State())
625+
626+
static var failReplace: Bool {
627+
get { state.get().failReplace }
628+
set { state.update { $0.failReplace = newValue } }
629+
}
630+
631+
static var failDeliveryUpdate: Bool {
632+
get { state.get().failDeliveryUpdate }
633+
set { state.update { $0.failDeliveryUpdate = newValue } }
634+
}
635+
636+
static var failPrepareForCompletion: Bool {
637+
get { state.get().failPrepareForCompletion }
638+
set { state.update { $0.failPrepareForCompletion = newValue } }
639+
}
640+
641+
static var returnMappableCartUserError: Bool {
642+
get { state.get().returnMappableCartUserError }
643+
set { state.update { $0.returnMappableCartUserError = newValue } }
644+
}
645+
646+
static var returnInvalidCart: Bool {
647+
get { state.get().returnInvalidCart }
648+
set { state.update { $0.returnInvalidCart = newValue } }
649+
}
650+
651+
static var lastOperation: String? {
652+
get { state.get().lastOperation }
653+
set { state.update { $0.lastOperation = newValue } }
654+
}
621655

622656
static func response(for op: String) -> Data {
623657
if op == "cartPrepareForCompletion" {

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayCallbackTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ final class ApplePayCallbackTests: XCTestCase {
1515

1616
// MARK: - Setup
1717

18-
override func setUp() {
19-
super.setUp()
18+
override func setUp() async throws {
19+
try await super.setUp()
2020

2121
// Create mock configuration
2222
let commonConfig = ShopifyAcceleratedCheckouts.Configuration(
@@ -53,13 +53,13 @@ final class ApplePayCallbackTests: XCTestCase {
5353
)
5454
}
5555

56-
override func tearDown() {
56+
override func tearDown() async throws {
5757
viewController = nil
5858
mockConfiguration = nil
5959
mockIdentifier = nil
6060
errorExpectation = nil
6161
cancelExpectation = nil
62-
super.tearDown()
62+
try await super.tearDown()
6363
}
6464

6565
// MARK: - Error Callback Tests

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayIntegrationTests.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SwiftUI
44
import XCTest
55

66
@available(iOS 17.0, *)
7+
@MainActor
78
final class ApplePayIntegrationTests: XCTestCase {
89
// MARK: - Properties
910

@@ -14,8 +15,8 @@ final class ApplePayIntegrationTests: XCTestCase {
1415

1516
// MARK: - Setup
1617

17-
override func setUp() {
18-
super.setUp()
18+
override func setUp() async throws {
19+
try await super.setUp()
1920

2021
mockCommonConfiguration = ShopifyAcceleratedCheckouts.Configuration(
2122
storefrontDomain: "test-shop.myshopify.com",
@@ -46,12 +47,12 @@ final class ApplePayIntegrationTests: XCTestCase {
4647
)
4748
}
4849

49-
override func tearDown() {
50+
override func tearDown() async throws {
5051
mockConfiguration = nil
5152
mockCommonConfiguration = nil
5253
mockApplePayConfiguration = nil
5354
mockShopSettings = nil
54-
super.tearDown()
55+
try await super.tearDown()
5556
}
5657

5758
// MARK: - Integration Tests
@@ -123,13 +124,13 @@ final class ApplePayIntegrationTests: XCTestCase {
123124
// The view should essentially be empty/minimal due to invariant case
124125
}
125126

126-
func testCallbackPersistenceAcrossViewUpdates() async {
127+
func testCallbackPersistenceAcrossViewUpdates() {
127128
var failCount = 0
128129
let failHandler = { (_: CheckoutError) in
129130
failCount += 1
130131
}
131132

132-
let button = await ApplePayButton(
133+
let button = ApplePayButton(
133134
identifier: .cart(cartID: "gid://Shopify/Cart/test-cart"),
134135
eventHandlers: EventHandlers(checkoutDidFail: failHandler),
135136
cornerRadius: nil

platforms/swift/Tests/ShopifyAcceleratedCheckoutsTests/Wallets/ApplePay/ApplePayViewControllerTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class ApplePayViewControllerTests: XCTestCase {
1111
var mockStorefront: TestStorefrontAPI!
1212
var mockAuthorizationDelegate: MockApplePayAuthorizationDelegate!
1313

14-
override func setUp() {
15-
super.setUp()
14+
override func setUp() async throws {
15+
try await super.setUp()
1616

1717
// Create mock shop settings
1818
let paymentSettings = PaymentSettings(
@@ -69,12 +69,12 @@ class ApplePayViewControllerTests: XCTestCase {
6969
viewController.setMockAuthorizationDelegate(mockAuthorizationDelegate)
7070
}
7171

72-
override func tearDown() {
72+
override func tearDown() async throws {
7373
viewController = nil
7474
mockConfiguration = nil
7575
mockStorefront = nil
7676
mockAuthorizationDelegate = nil
77-
super.tearDown()
77+
try await super.tearDown()
7878
}
7979

8080
class MockApplePayAuthorizationDelegate: ApplePayAuthorizationDelegate {

0 commit comments

Comments
 (0)