Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ final class StorefrontAPIMutationsTests: XCTestCase {
// MARK: - Mock URLProtocol for Network Mocking

class MockURLProtocol: URLProtocol {
static var mockResponseData: Data?
static var mockError: Error?
static var mockStatusCode: Int = 200
static var capturedRequest: URLRequest?
static var capturedRequestBody: Data?
nonisolated(unsafe) static var mockResponseData: Data?
nonisolated(unsafe) static var mockError: Error?
nonisolated(unsafe) static var mockStatusCode: Int = 200
nonisolated(unsafe) static var capturedRequest: URLRequest?
nonisolated(unsafe) static var capturedRequestBody: Data?

override class func canInit(with _: URLRequest) -> Bool {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ final class StorefrontAPIQueriesTests: XCTestCase {
// MARK: - Mock URLProtocol for Network Mocking

class MockURLProtocol: URLProtocol {
static var mockResponseData: Data?
static var mockError: Error?
static var mockStatusCode: Int = 200
static var capturedRequest: URLRequest?
static var capturedRequestBody: Data?
nonisolated(unsafe) static var mockResponseData: Data?
nonisolated(unsafe) static var mockError: Error?
nonisolated(unsafe) static var mockStatusCode: Int = 200
nonisolated(unsafe) static var capturedRequest: URLRequest?
nonisolated(unsafe) static var capturedRequestBody: Data?

override class func canInit(with _: URLRequest) -> Bool {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import XCTest

// MARK: - Configuration Helpers

@MainActor
func XCTAssertThrowsErrorAsync(
_ expression: @autoclosure () async throws -> some Any,
_ errorHandler: (Error) -> Void,
Expand Down Expand Up @@ -298,7 +299,7 @@ extension StorefrontAPI.Cart {
/// This class conforms to StorefrontAPIProtocol with not implemented errors
/// Extend this class and override only the methods you need, per test file
@available(iOS 16.0, *)
class MockStorefrontAPI: StorefrontAPIProtocol {
class MockStorefrontAPI: @unchecked Sendable, StorefrontAPIProtocol {
func cart(by _: GraphQLScalars.ID) async throws -> StorefrontAPI.Cart? {
fatalError("cart(by:) not implemented in test. Override this method in your test class.")
}
Expand Down Expand Up @@ -383,7 +384,7 @@ class MockStorefrontAPI: StorefrontAPIProtocol {
// MARK: - Test StorefrontAPI

@available(iOS 16.0, *)
class TestStorefrontAPI: MockStorefrontAPI {
class TestStorefrontAPI: MockStorefrontAPI, @unchecked Sendable {
var cartResult: Result<StorefrontAPI.Cart?, Error>?

override func cart(by _: GraphQLScalars.ID) async throws -> StorefrontAPI.Cart? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import SwiftUI
import XCTest

@available(iOS 17.0, *)
@MainActor
final class AcceleratedCheckoutButtonsRenderStateTests: XCTestCase {
// MARK: - Render State Change Callback Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,12 @@ final class ApplePayAuthorizationDelegateControllerTests: XCTestCase {
"\"cost\":{\"totalAmount\":{\"amount\":\"0.00\",\"currencyCode\":\"USD\"}}," +
"\"discountCodes\":[],\"discountAllocations\":[]}"

static var failReplace = false
static var failDeliveryUpdate = false
static var failPrepareForCompletion = false
static var returnMappableCartUserError = false
static var returnInvalidCart = false
static var lastOperation: String?
nonisolated(unsafe) static var failReplace = false
nonisolated(unsafe) static var failDeliveryUpdate = false
nonisolated(unsafe) static var failPrepareForCompletion = false
nonisolated(unsafe) static var returnMappableCartUserError = false
nonisolated(unsafe) static var returnInvalidCart = false
nonisolated(unsafe) static var lastOperation: String?

static func response(for op: String) -> Data {
if op == "cartPrepareForCompletion" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import XCTest

@available(iOS 17.0, *)
@MainActor
final class ApplePayCallbackTests: XCTestCase {
// MARK: - Properties

Expand All @@ -37,8 +38,8 @@ final class ApplePayCallbackTests: XCTestCase {

// MARK: - Setup

override func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()

// Create mock configuration
let commonConfig = ShopifyAcceleratedCheckouts.Configuration(
Expand Down Expand Up @@ -75,13 +76,13 @@ final class ApplePayCallbackTests: XCTestCase {
)
}

override func tearDown() {
override func tearDown() async throws {
viewController = nil
mockConfiguration = nil
mockIdentifier = nil
errorExpectation = nil
cancelExpectation = nil
super.tearDown()
try await super.tearDown()
}

// MARK: - Error Callback Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import SwiftUI
import XCTest

@available(iOS 17.0, *)
@MainActor
final class ApplePayIntegrationTests: XCTestCase {
// MARK: - Properties

Expand All @@ -37,8 +38,8 @@ final class ApplePayIntegrationTests: XCTestCase {

// MARK: - Setup

override func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()

mockCommonConfiguration = ShopifyAcceleratedCheckouts.Configuration(
storefrontDomain: "test-shop.myshopify.com",
Expand Down Expand Up @@ -69,12 +70,12 @@ final class ApplePayIntegrationTests: XCTestCase {
)
}

override func tearDown() {
override func tearDown() async throws {
mockConfiguration = nil
mockCommonConfiguration = nil
mockApplePayConfiguration = nil
mockShopSettings = nil
super.tearDown()
try await super.tearDown()
}

// MARK: - Integration Tests
Expand Down Expand Up @@ -152,7 +153,7 @@ final class ApplePayIntegrationTests: XCTestCase {
failCount += 1
}

let button = await ApplePayButton(
let button = ApplePayButton(
identifier: .cart(cartID: "gid://Shopify/Cart/test-cart"),
eventHandlers: EventHandlers(checkoutDidFail: failHandler),
cornerRadius: nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import UIKit
import XCTest

@available(iOS 17.0, *)
@MainActor
class ApplePayViewControllerTests: XCTestCase {
var viewController: MockApplePayViewController!
var mockConfiguration: ApplePayConfigurationWrapper!
var mockStorefront: TestStorefrontAPI!
var mockAuthorizationDelegate: MockApplePayAuthorizationDelegate!

override func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()

// Create mock shop settings
let paymentSettings = PaymentSettings(
Expand Down Expand Up @@ -91,12 +92,12 @@ class ApplePayViewControllerTests: XCTestCase {
viewController.setMockAuthorizationDelegate(mockAuthorizationDelegate)
}

override func tearDown() {
override func tearDown() async throws {
viewController = nil
mockConfiguration = nil
mockStorefront = nil
mockAuthorizationDelegate = nil
super.tearDown()
try await super.tearDown()
}

class MockApplePayAuthorizationDelegate: ApplePayAuthorizationDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import SwiftUI
import XCTest

@available(iOS 17.0, *)
@MainActor
final class ApplePayViewModifierTests: XCTestCase {
// MARK: - Properties

Expand All @@ -36,8 +37,8 @@ final class ApplePayViewModifierTests: XCTestCase {

// MARK: - Setup

override func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()

mockConfiguration = ShopifyAcceleratedCheckouts.Configuration(
storefrontDomain: "test-shop.myshopify.com",
Expand All @@ -59,11 +60,11 @@ final class ApplePayViewModifierTests: XCTestCase {
)
}

override func tearDown() {
override func tearDown() async throws {
mockConfiguration = nil
mockApplePayConfiguration = nil
mockShopSettings = nil
super.tearDown()
try await super.tearDown()
}

// MARK: - onCancel Modifier Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import ViewInspector
import XCTest

@available(iOS 17.0, *)
@MainActor
class ShopPayButtonTests: XCTestCase {
// MARK: - Test Setup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import XCTest

@available(iOS 17.0, *)
@MainActor
final class ShopPayCallbackTests: XCTestCase {
// MARK: - Properties

Expand All @@ -37,8 +38,8 @@ final class ShopPayCallbackTests: XCTestCase {

// MARK: - Setup

override func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()

mockConfiguration = ShopifyAcceleratedCheckouts.Configuration(
storefrontDomain: "test-shop.myshopify.com",
Expand All @@ -53,13 +54,13 @@ final class ShopPayCallbackTests: XCTestCase {
)
}

override func tearDown() {
override func tearDown() async throws {
viewController = nil
mockConfiguration = nil
mockIdentifier = nil
errorExpectation = nil
cancelExpectation = nil
super.tearDown()
try await super.tearDown()
}

// MARK: - Error Callback Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ import ShopifyCheckoutKit
import XCTest

@available(iOS 16.0, *)

@available(iOS 16.0, *)
@MainActor
final class ShopPayViewControllerTests: XCTestCase {
var viewController: MockShopPayViewController!
var mockConfiguration: ShopifyAcceleratedCheckouts.Configuration!
var mockStorefront: TestStorefrontAPI!

override func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()

mockConfiguration = ShopifyAcceleratedCheckouts.Configuration(
storefrontDomain: "test-shop.myshopify.com",
Expand All @@ -43,11 +42,11 @@ final class ShopPayViewControllerTests: XCTestCase {
mockStorefront = TestStorefrontAPI()
}

override func tearDown() {
override func tearDown() async throws {
viewController = nil
mockConfiguration = nil
mockStorefront = nil
super.tearDown()
try await super.tearDown()
}

@available(iOS 16.0, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ import UIKit
import XCTest

@available(iOS 16.0, *)
@MainActor
final class WalletControllerTests: XCTestCase {
var mockStorefront: TestStorefrontAPI!
var controller: MockWalletController!
override func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()
mockStorefront = TestStorefrontAPI()
}

override func tearDown() {
override func tearDown() async throws {
mockStorefront = nil
controller = nil
super.tearDown()
try await super.tearDown()
}

class MockWalletController: WalletController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import WebKit
import XCTest

@MainActor
class CheckoutBridgeTests: XCTestCase {
func testReturnsStandardUserAgent() {
let version = ShopifyCheckoutKit.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import WebKit
import XCTest

@MainActor
class CheckoutViewDelegateTests: XCTestCase {
private var customTitle: String?
private let checkoutURL = URL(string: "https://checkout-sdk.myshopify.com")!
private var viewController: MockCheckoutWebViewController!
private var navigationController: UINavigationController!

override func setUp() {
override func setUp() async throws {
try await super.setUp()
CheckoutWebView.invalidate()
ShopifyCheckoutKit.configure {
$0.preloading.enabled = true
$0.title = customTitle ?? "Checkout"
Expand All @@ -43,9 +46,10 @@ class CheckoutViewDelegateTests: XCTestCase {
navigationController = UINavigationController(rootViewController: viewController)
}

override func tearDown() {
override func tearDown() async throws {
CheckoutWebView.invalidate()
customTitle = nil
super.tearDown()
try await super.tearDown()
}

func testTitleIsSetToCheckout() {
Expand All @@ -54,7 +58,10 @@ class CheckoutViewDelegateTests: XCTestCase {

func testTitleCanBeCustomized() {
customTitle = "Custom title"
setUp()
ShopifyCheckoutKit.configure { $0.title = customTitle ?? "Checkout" }
viewController = MockCheckoutWebViewController(
checkoutURL: checkoutURL
)
XCTAssertEqual(viewController.title, "Custom title")
}

Expand Down Expand Up @@ -207,6 +214,7 @@ class CheckoutViewDelegateTests: XCTestCase {
}
}

@MainActor
protocol Dismissible: AnyObject {
func dismiss(animated flag: Bool, completion: (() -> Void)?)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TestableCheckoutWebViewController: CheckoutWebViewController {
}
}

@MainActor
class CheckoutWebViewControllerTests: XCTestCase {
private let url = URL(string: "http://shopify1.shopify.com/checkouts/cn/123")!
private let multipassURL = URL(string: "http://shopify1.shopify.com/checkouts/cn/123?multipass=token")!
Expand Down
Loading
Loading