◉RORK LABJP
●GPT-6.1 SOL — Added to Rork's model menu (09-29) with Low, Medium and High effort; included on Pro and Max●SONNET 5.5 — Claude Sonnet 5.5 is selectable: strong at UI design and faster than Sonnet 5 (09-28)●SDK 58 — Beta since 09/15 with no stable date yet; running projects in Expo Go has required login since 09/03●WIDGET — A write-up traces an iOS widget that renders black only in production builds●OBSERVE — EAS Observe now records native crashes too (SDK 57.0.21 or later, 10/07)●NEW — My App Open Ad Only Showed When the App…●GPT-6.1 SOL — Added to Rork's model menu (09-29) with Low, Medium and High effort; included on Pro and Max●SONNET 5.5 — Claude Sonnet 5.5 is selectable: strong at UI design and faster than Sonnet 5 (09-28)●SDK 58 — Beta since 09/15 with no stable date yet; running projects in Expo Go has required login since 09/03●WIDGET — A write-up traces an iOS widget that renders black only in production builds●OBSERVE — EAS Observe now records native crashes too (SDK 57.0.21 or later, 10/07)●NEW — My App Open Ad Only Showed When the App…
Articles/Dev Tools
⬡ Dev Tools/2026-07-16Advanced

Test Generated Purchase Code Before You Touch Sandbox — Automating Refunds, Expiration, and Failures with SKTestSession

Rork Max generates StoreKit 2 code that proves people can buy. It does not prove refunds, expiration, or failed purchases are handled. Here is how to cover those paths with SKTestSession before you ever open Sandbox.

StoreKit 217StoreKitTestSKTestSessionRork Max236Testing3In-App Purchase7

✦ Premium Article

The first thing I noticed in the purchase code Rork Max produced was a fifteen-line function that walked Transaction.currentEntitlements and returned a Bool. Nothing about it was wrong. Buy the product, the feature unlocks.

The problem was everything downstream. What happens on a refund? What happens when renewal fails? Create a Sandbox account, buy, wait a month — that is not a workflow.

Billing bugs are frightening for an indie developer because they do not announce themselves. Paying customers see nothing wrong. What is broken is the entitlement of the handful of people who got refunded, and those people leave without saying a word.

StoreKitTest is Apple's answer to that blind spot. It stands up a fake App Store inside your test process, and lets you trigger refunds and expiration with your own hands.

Some Bugs Die Before Sandbox

Billing verification tends to start at Sandbox, but Sandbox answers a different question: can my app talk to Apple's servers correctly? It does not answer whether my own code reacts correctly to a change in state.

Conflating the two makes the process far too heavy for what you want to learn. Testing one refund means creating a Sandbox account, purchasing, issuing a refund from App Store Connect, and waiting for the notification. Tens of minutes per scenario — and when it fails, you cannot tell whether your code or the environment is at fault.

StoreKitTest owns the second question. No network, no servers. Everything stays inside the test process.

I draw the line like this:

What you want to verifyWhereCost per run
Refund removes entitlementSKTestSessionMilliseconds
Expiration removes entitlementSKTestSessionMilliseconds
Failed purchases are surfacedSKTestSessionMilliseconds
Signature verification on your serverSandboxMinutes
Server notifications arrive and processSandboxMinutes and up
Real charges and localized pricingSandbox / ProductionMinutes and up

The top three are technically possible in Sandbox, but there is little reason to spend the time there. The bottom three are impossible in SKTestSession. That is where the line belongs.

StoreKitTest Stands Up a Fake App Store On-Device

You need a .storekit configuration file and import StoreKitTest in your test target. You can build the configuration by hand in Xcode, but for a Rork Max project it is faster to sync it from your App Store Connect product definitions.

The moment you create an SKTestSession, every StoreKit 2 API in that process points at it. Product.products(for:) and Transaction.currentEntitlements are answered by the session, not by Apple.

import XCTest
import StoreKit
import StoreKitTest
@testable import MyApp
 
final class EntitlementTests: XCTestCase {
    var session: SKTestSession!
 
    override func setUpWithError() throws {
        try super.setUpWithError()
        // Products.storekit must be a member of the test target
        session = try SKTestSession(configurationFileNamed: "Products")
 
        // No confirmation dialogs. Otherwise the test waits for a human finger.
        session.disableDialogs = true
 
        // Do not carry transactions across tests
        session.clearTransactions()
        session.resetToDefaultState()
    }
 
    override func tearDownWithError() throws {
        session = nil
        try super.tearDownWithError()
    }
}

disableDialogs and clearTransactions() are the two lines that will hurt you if you skip them. Drop the first and your test hangs on a dialog forever. Drop the second and a subscription bought in an earlier test leaks into the next one, producing a pass you cannot explain. When a test passes "somehow," this is usually why.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦If you have verified that purchases work but never tested refunds or expiration, you can walk away today with working XCTest cases that reproduce both in milliseconds
✦You will learn how timeRate, expireSubscription, refundTransaction, and setSimulatedError collapse a month-long Sandbox renewal scenario into a single test
✦You can close the refund gap that generated code almost always leaves open, and verify billing logic before paying the $99 Apple Developer Program fee
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⬡ Dev Tools2026-07-18
The Generated Screen That Quietly Jams at AX5 and in German — Putting Layout Resilience Checks on Rork Max SwiftUI
A record of running every Rork Max generated SwiftUI screen through pseudolocalization and the largest text size to find exactly where it jams. Covers when to reach for ViewThatFits, ScaledMetric and layoutPriority, plus the snapshot checks that catch regressions every time you regenerate.
⬡ Dev Tools2026-05-17
Testing Rork Max SwiftUI Features on a Real Wallpaper App — What Worked, What Needed Fixes
I benchmarked Rork Max's SwiftUI generation against the production code of a wallpaper app I actually run. Here is what shipped as-is, what needed fixing, and what I ended up writing by hand — with working code and on-device measurements.
⬡ Dev Tools2026-05-16
Migrating Firebase CocoaPods to SPM in Rork Max Apps
Firebase Apple SDK's CocoaPods distribution ends in October 2026. Here's a detailed migration log from moving 4 Rork Max iOS apps to Swift Package Manager — including dSYM failures, module errors, and the Dropbox conflict copy problem you'll definitely hit.