@@ -62,9 +62,8 @@ class AcceleratedCheckouts_SupportedTests: XCTestCase {
6262 ShopifyCheckoutSheetKit . configuration. closeButtonTintColor = nil
6363 }
6464
65- private func configureAcceleratedCheckouts( includeApplePay: Bool , customerAccessToken: String ? = nil ) {
66- let expectation = self . expectation ( description: " configureAcceleratedCheckouts " )
67-
65+ @discardableResult
66+ private func configureAcceleratedCheckouts( includeApplePay: Bool , customerAccessToken: String ? = nil ) -> Bool {
6867 let storefrontDomain = " example.myshopify.com "
6968 let accessToken = " shpat_test_token "
7069 let email = " buyer@example.com "
@@ -73,20 +72,16 @@ class AcceleratedCheckouts_SupportedTests: XCTestCase {
7372 let contactFields : [ String ] ? = includeApplePay ? [ " email " , " phone " ] : nil
7473 let supportedShippingCountries : [ String ] ? = includeApplePay ? [ " IE " , " CA " ] : nil
7574
76- shopifyCheckoutSheetKit. configureAcceleratedCheckouts (
75+ return shopifyCheckoutSheetKit. configureAcceleratedCheckouts (
7776 storefrontDomain,
7877 storefrontAccessToken: accessToken,
7978 customerEmail: email,
8079 customerPhoneNumber: phone,
8180 customerAccessToken: customerAccessToken,
8281 applePayMerchantIdentifier: merchantIdentifier,
8382 applyPayContactFields: contactFields,
84- supportedShippingCountries: supportedShippingCountries,
85- resolve: { _ in expectation. fulfill ( ) } ,
86- reject: { _, _, _ in }
87- )
88-
89- wait ( for: [ expectation] , timeout: 2 )
83+ supportedShippingCountries: supportedShippingCountries
84+ ) . boolValue
9085 }
9186
9287 func testConfigureAcceleratedCheckoutsSetsSharedConfigsOnIOS16( ) throws {
@@ -98,58 +93,23 @@ class AcceleratedCheckouts_SupportedTests: XCTestCase {
9893 }
9994
10095 func testIsAcceleratedCheckoutAvailableBeforeAndAfterConfig( ) throws {
101- let beforeExpectation = expectation ( description: " isAcceleratedCheckoutAvailable before " )
102- var beforeValue : Bool = true
103- shopifyCheckoutSheetKit. isAcceleratedCheckoutAvailable ( { value in
104- beforeValue = ( value as? Bool ) ?? true
105- beforeExpectation. fulfill ( )
106- } , reject: { _, _, _ in } )
107- wait ( for: [ beforeExpectation] , timeout: 2 )
108- XCTAssertEqual ( beforeValue, false )
96+ XCTAssertEqual ( shopifyCheckoutSheetKit. isAcceleratedCheckoutAvailable ( ) . boolValue, false )
10997
11098 configureAcceleratedCheckouts ( includeApplePay: false )
11199
112- let afterExpectation = expectation ( description: " isAcceleratedCheckoutAvailable after " )
113- var afterValue : Bool = false
114- shopifyCheckoutSheetKit. isAcceleratedCheckoutAvailable ( { value in
115- afterValue = ( value as? Bool ) ?? false
116- afterExpectation. fulfill ( )
117- } , reject: { _, _, _ in } )
118- wait ( for: [ afterExpectation] , timeout: 2 )
119- XCTAssertEqual ( afterValue, true )
100+ XCTAssertEqual ( shopifyCheckoutSheetKit. isAcceleratedCheckoutAvailable ( ) . boolValue, true )
120101 }
121102
122103 func testIsApplePayAvailableRequiresApplePayConfig( ) throws {
123- let beforeExpectation = expectation ( description: " isApplePayAvailable before " )
124- var beforeValue : Bool = true
125- shopifyCheckoutSheetKit. isApplePayAvailable ( { value in
126- beforeValue = ( value as? Bool ) ?? true
127- beforeExpectation. fulfill ( )
128- } , reject: { _, _, _ in } )
129- wait ( for: [ beforeExpectation] , timeout: 2 )
130- XCTAssertEqual ( beforeValue, false )
104+ XCTAssertEqual ( shopifyCheckoutSheetKit. isApplePayAvailable ( ) . boolValue, false )
131105
132106 configureAcceleratedCheckouts ( includeApplePay: false )
133107
134- let withoutApplePayExpectation = expectation ( description: " isApplePayAvailable without Apple Pay " )
135- var withoutApplePayValue : Bool = true
136- shopifyCheckoutSheetKit. isApplePayAvailable ( { value in
137- withoutApplePayValue = ( value as? Bool ) ?? true
138- withoutApplePayExpectation. fulfill ( )
139- } , reject: { _, _, _ in } )
140- wait ( for: [ withoutApplePayExpectation] , timeout: 2 )
141- XCTAssertEqual ( withoutApplePayValue, false )
108+ XCTAssertEqual ( shopifyCheckoutSheetKit. isApplePayAvailable ( ) . boolValue, false )
142109
143110 configureAcceleratedCheckouts ( includeApplePay: true )
144111
145- let afterExpectation = expectation ( description: " isApplePayAvailable after " )
146- var afterValue : Bool = false
147- shopifyCheckoutSheetKit. isApplePayAvailable ( { value in
148- afterValue = ( value as? Bool ) ?? false
149- afterExpectation. fulfill ( )
150- } , reject: { _, _, _ in } )
151- wait ( for: [ afterExpectation] , timeout: 2 )
152- XCTAssertEqual ( afterValue, true )
112+ XCTAssertEqual ( shopifyCheckoutSheetKit. isApplePayAvailable ( ) . boolValue, true )
153113 }
154114
155115 func testConfigureAcceleratedCheckoutsStoresCustomerAccessToken( ) throws {
@@ -395,30 +355,21 @@ class AcceleratedCheckouts_SupportedTests: XCTestCase {
395355 XCTAssertTrue ( PayWithApplePayButtonLabel . from ( " unknown " , fallback: . buy) == . buy)
396356 }
397357
398- func testConfigureAcceleratedCheckoutsResolvesFalseForInvalidApplePayContactField( ) throws {
399- let expectation = self . expectation ( description: " configureAcceleratedCheckouts invalid contact field resolves false " )
400- var resolved : Bool = true
401-
358+ func testConfigureAcceleratedCheckoutsReturnsFalseForInvalidApplePayContactField( ) throws {
402359 let storefrontDomain = " example.myshopify.com "
403360 let accessToken = " shpat_test_token "
404361
405- shopifyCheckoutSheetKit. configureAcceleratedCheckouts (
362+ let resolved = shopifyCheckoutSheetKit. configureAcceleratedCheckouts (
406363 storefrontDomain,
407364 storefrontAccessToken: accessToken,
408365 customerEmail: nil ,
409366 customerPhoneNumber: nil ,
410367 customerAccessToken: nil ,
411368 applePayMerchantIdentifier: " merchant.com.shopify.reactnative.tests " ,
412369 applyPayContactFields: [ " email " , " not_a_field " ] ,
413- supportedShippingCountries: [ ] ,
414- resolve: { value in
415- resolved = ( value as? Bool ) ?? true
416- expectation. fulfill ( )
417- } ,
418- reject: { _, _, _ in }
419- )
420-
421- wait ( for: [ expectation] , timeout: 2 )
370+ supportedShippingCountries: [ ]
371+ ) . boolValue
372+
422373 XCTAssertEqual ( resolved, false )
423374 }
424375}
0 commit comments