Transaction state gets `.purchased` even I set `SKTestSession.askToBuyEnabled = true`

I was trying to write unit test of ask to buy for SKDemo app.

Even if I set SKTestSession.askToBuyEnabled = true, I got transaction state as .purchased after I call SKTestSession.buyProduct(identifier:).

import StoreKitTest
import XCTest

final class SKDemoTests: XCTestCase {

    private var session: SKTestSession!

    override func setUp() async throws {
        session = try .init(SKTestSession(configurationFileNamed: "Products"))
        session.disableDialogs = true
        session.resetToDefaultState()
        session.clearTransactions()
    }

    func test() async throws {
        session.askToBuyEnabled = true
        try await session.buyProduct(identifier: "consumable.fuel.octane89")
        XCTAssertEqual(session.allTransactions().first!.state, .deferred) // Gets error here. The actual state I get is .purchased
    }
}

I was using Xcode 15.0.1 (15A507), Simulator iPhone 15 Pro iOS 17.0.1 (21A342)

I couldn't find the problem so I'm happy to hear any solutions.

Found the same behavior in one of my old tests that started failing. I came here looking to see if this was an SKTestSession bug, and seems like it is. Filed feedback FB13330054, recent similar reports: none :/

Also not working for me either, even with XCode 16 beta 3.

Manual testing with transaction manager works as expected, but automated testing with SKTest does not work as expected :/

How is this still broken?

Transaction state gets `.purchased` even I set `SKTestSession.askToBuyEnabled = true`
 
 
Q