testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase)

I am trying to test this simulated Error.

The issue is, I can't get this to trigger through the simulatedError function.

Error will always end up as an unknown error

Example code snippet:

@available(iOS 17.0, *)
func testPurchase_InvalidQuantity() async throws {
    // Arrange
    testSession.clearTransactions()
    testSession.resetToDefaultState()

    let productID = "consumable_1"

    try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase)

    guard let product = await fetchProduct(identifier: productID) else {
        XCTFail("Failed to fetch test product")
        return
    }

    let option = Product.PurchaseOption.quantity(4)

    let result = await manager.purchase(product: product, options: option)

    switch result {
        case .success:
            XCTFail("Expected failure due to invalid quantity")
        case .failure(let error):
            print("Received error: \(error.localizedDescription)")
            switch error {
                case .purchaseError(let purchaseError):
                    XCTAssertEqual(purchaseError.code, StoreKitPurchaseError.invalidQuantity.code)
                default:
                    XCTFail("Unexpected error: \(error)")
            }
    }
}

In the above code snippet, I have an Unexpected Error.

But if i remove try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase) I will receive a XCTFail in the success of my result.

So when I set the quantity to a -1, only then can I correctly receive an invalidQuantity.

Does anyone know why the try await testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase) would fail to work as directed? I have tests for all the generic errors for loadProducts API and the simulatedError works great for them

testSession.setSimulatedError(.purchase(.invalidQuantity), forAPI: .purchase)
 
 
Q