Skip to content

Test without a store account

Documents @snap4id-sdk/app-embed 1.0.0 · @snap4id-sdk/embed-protocol 1.0.0 · protocol 1.0

Test in layers: unit tests with in-memory fakes, simulator runs against the SDK’s fake Snap4ID page with a fake store, then the real store sandboxes on phones (App Store, Google Play).

Unit tests: @snap4id-sdk/app-embed/testing

Section titled “Unit tests: @snap4id-sdk/app-embed/testing”

Never import it in production code.

Export Use
createTestClient(overrides) a client with in-memory ports
FakeStore a purchase port: new FakeStore(dialog, store); the dialog answers succeed, cancel, fail or pending; approvePending() approves every pending purchase; receipts are kind: 'fake', testOnly: true
ScriptedDialog a FakeStore dialog your test scripts
MemoryJsonStore, MemoryFileStore, RecordingMedia, ManualClock storage, files, media library and time you control
RecordingSender records what the host sends to the page
FakeHostBackend a backend stand-in for backend-trust tests
OneShotDevHooks simulate a kill at a chosen point (config.devHooks, honoured only in development builds)

In a development build, replace the device store with the fake store: a “Test purchase” alert with Buy / Pending / Fail / Cancel, no store account needed. The host hello then says platform: 'test', and only a test deployment or the fake Snap4ID page accepts its receipts (kind: 'fake'); production refuses them.

Keep it in one file you delete before release, and load it only under __DEV__ (with require, so a release bundle never contains it). The EXPO_PUBLIC_* variables below are your app’s own build settings (the component reads no environment variables): name them as you like.

// src/dev-only.ts: DEVELOPMENT ONLY, delete before release.
import { createDevFakeStore } from '@snap4id-sdk/app-embed/dev';
/** `createSnap4IdClient` overrides for simulator runs; empty unless EXPO_PUBLIC_SNAP4ID_TEST_STORE=1. */
export function devOverrides() {
if (process.env.EXPO_PUBLIC_SNAP4ID_TEST_STORE !== '1') return {};
return { builtInStore: createDevFakeStore() };
}
/** A local Snap4ID origin (the fake page) from your build settings, else none (production). */
export const devOrigin = process.env.EXPO_PUBLIC_SNAP4ID_ORIGIN || undefined;

The client of quickstart step 2, with the two dev additions (the dev-only require and the second argument):

src/snap4id.ts
import { createSnap4IdClient } from '@snap4id-sdk/app-embed';
// eslint-disable-next-line @typescript-eslint/no-require-imports -- require keeps the file out of release bundles
const dev: typeof import('./dev-only') | null = __DEV__ ? require('./dev-only') : null;
export const snap4id = createSnap4IdClient(
{
partnerId: process.env.EXPO_PUBLIC_SNAP4ID_PARTNER_ID ?? 'your-partner-id',
...(dev?.devOrigin ? { origin: dev.devOrigin } : {}),
purchases: 'built-in',
onCompleted: async (completion) => {
// Called at least once per paid job until it resolves: key your work by completion.jobId.
await snap4id.downloadArtifacts(completion);
},
onError: (error) => console.warn(error.code, error.message),
},
dev?.devOverrides() ?? {},
);

Metro inlines EXPO_PUBLIC_* values when it bundles, not when the native app is built: start Metro (npx expo start or npx expo run:ios) with the same variables, or the fake store and the local origin are silently off.

The fake store sells whatever product the page requests (the fake page’s partners name dev.snap4id.test.photo) and prices every product at $4.99, so the page shows a price on its order button without any store setup (createDevFakeStore({ price: null }): no prices).

createDevFakeStore() keeps its transactions in a file (they survive a restart, like StoreKit’s unfinished purchases) and follows the device store’s rebuy rule (on Android a bought product stays owned until it is finished). For your own dialog or storage: createDevFakeStore({ dialog, store }), or new FakeStore(dialog, store) from ./testing (component API).

Native hosts test the same way: send platform: 'test' and a fake receipt from a debug build, against the fake page below.

The SDK repository ships a fake Snap4ID page in tools/fake-snap4id-page/: a small local server (:8090) that speaks the bridge protocol and the Partner API like Snap4ID, without processing or payments, and accepts the fake store’s receipts. In a checkout of the SDK repository (Node 22 or later):

Terminal window
npm ci
npm run fake-page # http://127.0.0.1:8090; FAKE_SNAP4ID_HOST=0.0.0.0 for a phone on the same network

/embed/{partnerId} starts a job, /embed/{partnerId}/job/{jobId} resumes one; ?auto=1 runs create, process and purchase by itself. Two partners are built in:

Partner id Who checks purchases
test-verifier the page’s verifier stand-in (as when Snap4ID checks purchases)
test-backend your own backend, through the page’s Partner API; it also sends signed job.paid webhooks to FAKE_SNAP4ID_WEBHOOK_URL

Both sell the product dev.snap4id.test.photo. Point a development build at it with origin: 'http://127.0.0.1:8090' (Android emulator: http://10.0.2.2:8090; a phone: your computer’s LAN address). Development builds allow these http origins; a release build allows only the loopback and emulator ones, and only with allowLocalOrigins: true in the client config (never in a build you ship). With the two files above:

Terminal window
EXPO_PUBLIC_SNAP4ID_ORIGIN=http://127.0.0.1:8090 \
EXPO_PUBLIC_SNAP4ID_PARTNER_ID=test-verifier \
EXPO_PUBLIC_SNAP4ID_TEST_STORE=1 \
npx expo run:ios

On the fake page, a run is: Create job → Process → Request purchase → Buy (the “Test purchase” alert) → Complete → Back to app; the files then appear in client.downloads (the fake page delivers three: the photo, the print sheet as JPG and as PDF; Snap4ID’s real list depends on the document). The page is taller than a phone screen: Back to app is below the fold after Complete (UI tests: scroll to it, e.g. Maestro scrollUntilVisible). Kill the app right after Buy and start it again: the photo still arrives (recovery). A development build may show the system “Open in …?” prompt and the Expo developer menu over your app, on the first launch and again after a relaunch (as in the recovery check): dismiss both (UI tests: tap them away after every launch). Every control of the page has a stable id for UI tests (Maestro, Detox, XCUITest); the list, the environment variables and the endpoints are in tools/fake-snap4id-page/README.md.

A complete app that runs against this page, with a Maestro UI test of the whole flow, is the SDK’s examples/partner-app: its README (examples/partner-app/README.md) has the commands.