◉RORK LABJP
●SUBDOMAIN — Rork can now connect your web app to a subdomain only, leaving your root domain and www untouched (12/1)●UPDATES — expo-updates 58.0.23 fixes Android release builds embedding a stale runtime version●FLASH END — Intro pricing for Gemini Flash models ends 12/31, 29 days from now. Time to recheck AI feature costs●HMR — Some report the dev server picking up another server's bundle and then exiting●FIRST VIEW — Map the first screen for a normal launch, a notification, and a link, and back navigation stops surprising you●CARBON — Gemini 4 Carbon and Argon are now at standard rates: $4.00 input, $20.00 output per 1M tokens●SUBDOMAIN — Rork can now connect your web app to a subdomain only, leaving your root domain and www untouched (12/1)●UPDATES — expo-updates 58.0.23 fixes Android release builds embedding a stale runtime version●FLASH END — Intro pricing for Gemini Flash models ends 12/31, 29 days from now. Time to recheck AI feature costs●HMR — Some report the dev server picking up another server's bundle and then exiting●FIRST VIEW — Map the first screen for a normal launch, a notification, and a link, and back navigation stops surprising you●CARBON — Gemini 4 Carbon and Argon are now at standard rates: $4.00 input, $20.00 output per 1M tokens
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 Purchase8

✦ 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
Reading Rork Max's SwiftUI Generation Through a Wallpaper App's Requirements — What to Trust, What to Fix, What to Write by Hand
Typical wallpaper-app requirements — grid, pinch-zoom, slideshow, photo-library permission, ads, in-app purchase — handed to Rork Max's SwiftUI generation: where the output tends to hold up and where it tends to break. For the memory failure that bites first, this note includes decode-time downsampling, a bounded cache, and a procedure for measuring on your own device.
⬡ Dev Tools2026-05-16
Migrating Firebase CocoaPods to SPM in Rork Max Apps
Since Firebase 13.0.0 (October 7, 2026) the Apple SDK ships only through Swift Package Manager and binaries, and CocoaPods trunk stops accepting podspecs on December 2. A migration log from moving Rork Max iOS apps to SPM, with a symptom-by-symptom troubleshooting table, the dSYM and Dropbox pitfalls, and what to check before moving to Firebase 13.