@marktiderman/genesis-cli 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -1
- package/dist/cli.js +2769 -567
- package/dist/cli.js.map +1 -1
- package/dist/{config-CUdwT-nY.d.ts → config-CrZbM3jD.d.ts} +45 -2
- package/dist/doctor.d.ts +2 -2
- package/dist/doctor.js +133 -5
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +91 -8
- package/dist/expo.js +207 -14
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +502 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +140 -9
- package/dist/index.js.map +1 -1
- package/dist/scaffolder.d.ts +1 -1
- package/dist/scaffolder.js +7 -4
- package/dist/scaffolder.js.map +1 -1
- package/dist/starter/.eas/scripts/rollout-health.mjs +85 -0
- package/dist/starter/.eas/workflows/deploy-production.yml +149 -0
- package/dist/starter/.eas/workflows/e2e.yml +77 -0
- package/dist/starter/.eas/workflows/pr-preview.yml +117 -0
- package/dist/starter/.eas/workflows/rollout.yml +120 -0
- package/dist/starter/.env.example +11 -0
- package/dist/starter/.fingerprintignore +7 -0
- package/dist/starter/.maestro/README.md +38 -0
- package/dist/starter/.maestro/config.yaml +5 -0
- package/dist/starter/.maestro/flows/deep-link.yaml +22 -0
- package/dist/starter/.maestro/flows/launch.yaml +17 -0
- package/dist/starter/.maestro/flows/settings-version.yaml +28 -0
- package/dist/starter/.maestro/flows/sign-in-screen.yaml +17 -0
- package/dist/starter/.maestro/subflows/sign-in.yaml +20 -0
- package/dist/starter/README.md +314 -0
- package/dist/starter/__tests__/app-config.test.ts +51 -0
- package/dist/starter/__tests__/check-in-photos.test.ts +57 -0
- package/dist/starter/__tests__/components/css-stub.js +2 -0
- package/dist/starter/__tests__/components/fake-supabase.ts +136 -0
- package/dist/starter/__tests__/components/links.test.ts +25 -0
- package/dist/starter/__tests__/components/render-app.ts +22 -0
- package/dist/starter/__tests__/components/reports.ts +10 -0
- package/dist/starter/__tests__/components/resolver.js +12 -0
- package/dist/starter/__tests__/components/root-layout.test.tsx +55 -0
- package/dist/starter/__tests__/components/session-storage.test.tsx +81 -0
- package/dist/starter/__tests__/components/settings.test.tsx +134 -0
- package/dist/starter/__tests__/components/setup.ts +69 -0
- package/dist/starter/__tests__/components/sign-in.test.tsx +90 -0
- package/dist/starter/__tests__/components/tabs-feature-off.test.tsx +19 -0
- package/dist/starter/__tests__/components/tabs.test.tsx +43 -0
- package/dist/starter/__tests__/components/tabs.ts +12 -0
- package/dist/starter/__tests__/entry.test.ts +28 -0
- package/dist/starter/__tests__/inline-copy.ts +59 -0
- package/dist/starter/__tests__/starter.test.ts +319 -0
- package/dist/starter/_gitignore +13 -0
- package/dist/starter/app.config.ts +44 -0
- package/dist/starter/babel.config.js +9 -0
- package/dist/starter/eas.json +47 -0
- package/dist/starter/eslint.config.js +5 -0
- package/dist/starter/genesis.config.json +12 -0
- package/dist/starter/global.css +3 -0
- package/dist/starter/index.ts +14 -0
- package/dist/starter/jest.config.js +36 -0
- package/dist/starter/metro.config.js +38 -0
- package/dist/starter/package.json +93 -0
- package/dist/starter/pnpm-workspace.yaml +73 -0
- package/dist/starter/src/app/(app)/(home)/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/(home)/check-in.tsx +41 -0
- package/dist/starter/src/app/(app)/(home)/index.tsx +34 -0
- package/dist/starter/src/app/(app)/_layout.tsx +27 -0
- package/dist/starter/src/app/(app)/notifications/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/notifications/index.tsx +36 -0
- package/dist/starter/src/app/(app)/settings/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/settings/index.tsx +96 -0
- package/dist/starter/src/app/(app)/settings/notifications.tsx +16 -0
- package/dist/starter/src/app/(app)/settings/support/[id].tsx +23 -0
- package/dist/starter/src/app/(app)/settings/support/ideas.tsx +20 -0
- package/dist/starter/src/app/(app)/settings/support/index.tsx +20 -0
- package/dist/starter/src/app/(app)/settings/support/new.tsx +35 -0
- package/dist/starter/src/app/(app)/settings/support/shipped.tsx +20 -0
- package/dist/starter/src/app/+native-intent.ts +11 -0
- package/dist/starter/src/app/_layout.tsx +20 -0
- package/dist/starter/src/app/sign-in.tsx +69 -0
- package/dist/starter/src/copy.ts +118 -0
- package/dist/starter/src/forms/check-in.json +121 -0
- package/dist/starter/src/lib/account.ts +42 -0
- package/dist/starter/src/lib/app.ts +52 -0
- package/dist/starter/src/lib/auth.ts +80 -0
- package/dist/starter/src/lib/check-in-photos.ts +66 -0
- package/dist/starter/src/lib/check-in.ts +85 -0
- package/dist/starter/src/lib/define-starter.ts +148 -0
- package/dist/starter/src/lib/devtools-overlay.ts +34 -0
- package/dist/starter/src/lib/devtools.ts +23 -0
- package/dist/starter/src/lib/env.ts +33 -0
- package/dist/starter/src/lib/google-signin.ts +23 -0
- package/dist/starter/src/lib/links.ts +40 -0
- package/dist/starter/src/lib/native-modules.ts +27 -0
- package/dist/starter/src/lib/notifications.ts +15 -0
- package/dist/starter/src/lib/observability.ts +45 -0
- package/dist/starter/src/lib/push.ts +49 -0
- package/dist/starter/src/lib/supabase.ts +65 -0
- package/dist/starter/src/lib/support.ts +44 -0
- package/dist/starter/src/lib/updates.ts +61 -0
- package/dist/starter/starter.config.ts +37 -0
- package/dist/starter/supabase/config.toml +26 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +237 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/handler.ts +227 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/index.ts +55 -0
- package/dist/starter/supabase/functions/genesis-push-send/expo.ts +117 -0
- package/dist/starter/supabase/functions/genesis-push-send/handler.ts +462 -0
- package/dist/starter/supabase/functions/genesis-push-send/index.ts +54 -0
- package/dist/starter/supabase/migrations/20261024000000_genesis_account_deletion.sql +133 -0
- package/dist/starter/supabase/migrations/20261024000100_genesis_app_release_policy.sql +82 -0
- package/dist/starter/supabase/migrations/20261024000200_genesis_apple_token_revocation.sql +205 -0
- package/dist/starter/supabase/migrations/20261024000400_genesis_push.sql +524 -0
- package/dist/starter/supabase/migrations/20261024000600_genesis_support.sql +846 -0
- package/dist/starter/supabase/tests/database/genesis_account_deletion.test.sql +138 -0
- package/dist/starter/supabase/tests/database/genesis_app_release_policy.test.sql +148 -0
- package/dist/starter/supabase/tests/database/genesis_apple_token_revocation.test.sql +230 -0
- package/dist/starter/supabase/tests/database/genesis_push.test.sql +407 -0
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +552 -0
- package/dist/starter/tailwind.config.mjs +15 -0
- package/dist/starter/tsconfig.json +14 -0
- package/dist/starter/vitest.config.mts +7 -0
- package/dist/templates/ci/app-ci.yml +17 -0
- package/dist/templates/ci/genesis-upgrade.yml +21 -0
- package/dist/templates/ci/supabase-ci.yml +20 -0
- package/dist/templates/eas/eas.json +47 -0
- package/dist/templates/eas/scripts/rollout-health.mjs +85 -0
- package/dist/templates/eas/workflows/deploy-production.yml +149 -0
- package/dist/templates/eas/workflows/e2e.yml +77 -0
- package/dist/templates/eas/workflows/pr-preview.yml +117 -0
- package/dist/templates/eas/workflows/rollout.yml +120 -0
- package/dist/templates/maestro/config.yaml +5 -0
- package/dist/templates/maestro/flows/deep-link.yaml +22 -0
- package/dist/templates/maestro/flows/launch.yaml +17 -0
- package/dist/templates/maestro/flows/settings-version.yaml +28 -0
- package/dist/templates/maestro/flows/sign-in-screen.yaml +17 -0
- package/dist/templates/maestro/subflows/sign-in.yaml +20 -0
- package/dist/vite.js +133 -5
- package/dist/vite.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @feat:native-starter @feat:expo-config-plugin
|
|
2
|
+
/**
|
|
3
|
+
* The config Expo builds from app.config.ts and the Genesis plugin, per APP_VARIANT: each
|
|
4
|
+
* variant installs side by side and registers its own URL scheme, so a link opens the build it
|
|
5
|
+
* names. Resolved through Expo's own `getConfig`, plugins and all.
|
|
6
|
+
*/
|
|
7
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
11
|
+
|
|
12
|
+
const root = join(__dirname, "..");
|
|
13
|
+
const { getConfig } = createRequire(join(root, "package.json"))("expo/config") as typeof import("expo/config");
|
|
14
|
+
const saved = process.env.APP_VARIANT;
|
|
15
|
+
|
|
16
|
+
function configFor(variant: string | undefined) {
|
|
17
|
+
if (variant === undefined) delete process.env.APP_VARIANT;
|
|
18
|
+
else process.env.APP_VARIANT = variant;
|
|
19
|
+
// The plugin warns about the privacy manifest's data types; not this test's subject.
|
|
20
|
+
vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
21
|
+
return getConfig(root, { skipSDKVersionRequirement: true, isPublicConfig: true }).exp;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
vi.restoreAllMocks();
|
|
26
|
+
if (saved === undefined) delete process.env.APP_VARIANT;
|
|
27
|
+
else process.env.APP_VARIANT = saved;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("app.config.ts per APP_VARIANT", () => {
|
|
31
|
+
it.each([
|
|
32
|
+
["development", "genesis-starter-dev", "com.example.genesisstarter.dev", "Genesis Starter (Dev)"],
|
|
33
|
+
["preview", "genesis-starter-preview", "com.example.genesisstarter.preview", "Genesis Starter (Preview)"],
|
|
34
|
+
["production", "genesis-starter", "com.example.genesisstarter", "Genesis Starter"],
|
|
35
|
+
[undefined, "genesis-starter", "com.example.genesisstarter", "Genesis Starter"],
|
|
36
|
+
])("%s registers scheme %s", (variant, scheme, bundleId, name) => {
|
|
37
|
+
const config = configFor(variant);
|
|
38
|
+
expect(config.scheme).toBe(scheme);
|
|
39
|
+
expect(config.ios?.bundleIdentifier).toBe(bundleId);
|
|
40
|
+
expect(config.android?.package).toBe(bundleId);
|
|
41
|
+
expect(config.name).toBe(name);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("the Maestro flows open links with the development variant's scheme (the build they run on)", () => {
|
|
45
|
+
const scheme = configFor("development").scheme;
|
|
46
|
+
const flows = readdirSync(join(root, ".maestro/flows")).map((f) => readFileSync(join(root, ".maestro/flows", f), "utf8"));
|
|
47
|
+
const links = flows.flatMap((text) => [...text.matchAll(/openLink:\s*"?([a-z][a-z0-9+.-]*):\/\//g)].map((m) => m[1]));
|
|
48
|
+
expect(links.length).toBeGreaterThan(0);
|
|
49
|
+
expect(new Set(links)).toEqual(new Set([scheme]));
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @feat:native-starter @feat:forms-native
|
|
2
|
+
/**
|
|
3
|
+
* The check-in's photo host (`src/lib/check-in-photos.ts`): the sample's photo question can be
|
|
4
|
+
* answered, through the photo library, with a name and type the form accepts.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { describe, expect, it, vi } from "vitest";
|
|
9
|
+
import { createCheckInPhotos, photoFile, stubUpload, type LaunchLibrary } from "../src/lib/check-in-photos";
|
|
10
|
+
|
|
11
|
+
const field = { kind: "field", id: "photo", key: "photo", type: "photo", label: "A photo" } as never;
|
|
12
|
+
const read = (path: string) => readFileSync(join(__dirname, "..", path), "utf8");
|
|
13
|
+
|
|
14
|
+
describe("check-in photos", () => {
|
|
15
|
+
it("picks from the library, up to the room left, and hands the form files it accepts", async () => {
|
|
16
|
+
const launch = vi.fn<LaunchLibrary>(async () => ({
|
|
17
|
+
canceled: false as const,
|
|
18
|
+
assets: [
|
|
19
|
+
{ uri: "file:///tmp/IMG_0001.HEIC", fileName: "IMG_0001.HEIC", fileSize: 2048, mimeType: "image/jpeg" },
|
|
20
|
+
{ uri: "file:///tmp/extra.png", fileSize: 10 },
|
|
21
|
+
],
|
|
22
|
+
}));
|
|
23
|
+
const host = createCheckInPhotos(launch, stubUpload(() => "1"));
|
|
24
|
+
expect(host.camera).toBe(false);
|
|
25
|
+
const files = await host.pick(field, { max: 1, camera: false });
|
|
26
|
+
expect(launch).toHaveBeenCalledWith({ mediaTypes: ["images"], allowsMultipleSelection: false, selectionLimit: 1, quality: 0.8 });
|
|
27
|
+
expect(files).toEqual([{ uri: "file:///tmp/IMG_0001.HEIC", name: "IMG_0001.HEIC", type: "image/jpeg", size: 2048 }]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("answers nothing when the person cancels, and never opens the picker with no room", async () => {
|
|
31
|
+
const launch = vi.fn<LaunchLibrary>(async () => ({ canceled: true as const, assets: null }));
|
|
32
|
+
const host = createCheckInPhotos(launch, stubUpload(() => "1"));
|
|
33
|
+
expect(await host.pick(field, { max: 3, camera: false })).toEqual([]);
|
|
34
|
+
expect(await host.pick(field, { max: 0, camera: false })).toEqual([]);
|
|
35
|
+
expect(launch).toHaveBeenCalledTimes(1);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("names and types an asset the picker gave no name or type", () => {
|
|
39
|
+
expect(photoFile({ uri: "file:///a/b/shot.png?x=1" }, 0)).toEqual({ uri: "file:///a/b/shot.png?x=1", name: "shot.png", type: "image/png", size: 0 });
|
|
40
|
+
expect(photoFile({ uri: "" }, 2)).toMatchObject({ name: "photo-3.jpg", type: "image/jpeg" });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("stores through the upload and answers with a reference", async () => {
|
|
44
|
+
const host = createCheckInPhotos(vi.fn<LaunchLibrary>(), stubUpload(() => "abc"));
|
|
45
|
+
await expect(host.upload({ uri: "file:///x.jpg", name: "x.jpg", type: "image/jpeg", size: 5 }, field)).resolves.toEqual({
|
|
46
|
+
id: "local-abc",
|
|
47
|
+
name: "x.jpg",
|
|
48
|
+
type: "image/jpeg",
|
|
49
|
+
size: 5,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("is wired into the check-in screen, with a photo-library sentence and no camera permission", () => {
|
|
54
|
+
expect(read("src/app/(app)/(home)/check-in.tsx")).toMatch(/photos=\{checkInPhotos\}/);
|
|
55
|
+
expect(read("app.config.ts")).toMatch(/\["expo-image-picker", \{ photosPermission: "[^"]{20,}", cameraPermission: false, microphonePermission: false \}\]/);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Supabase client the component tests give the app in place of `src/lib/supabase.ts`
|
|
3
|
+
* (see `setup.ts`). It keeps one session and plays the auth events supabase-js plays:
|
|
4
|
+
* `INITIAL_SESSION` to each new listener, `SIGNED_IN` after a sign-in, `SIGNED_OUT` after a
|
|
5
|
+
* sign-out. `next` scripts the next answers.
|
|
6
|
+
*/
|
|
7
|
+
import { jest } from "@jest/globals";
|
|
8
|
+
|
|
9
|
+
export interface FakeUser {
|
|
10
|
+
id: string;
|
|
11
|
+
email: string;
|
|
12
|
+
}
|
|
13
|
+
export interface FakeSession {
|
|
14
|
+
access_token: string;
|
|
15
|
+
user: FakeUser;
|
|
16
|
+
}
|
|
17
|
+
type Listener = (event: string, session: FakeSession | null) => void;
|
|
18
|
+
type AuthError = { code: string; message: string };
|
|
19
|
+
type AuthResult = { data: { session: FakeSession | null; user: FakeUser | null }; error: AuthError | null };
|
|
20
|
+
type QueryResult = { data: unknown; error: { code: string; message: string } | null; count: number };
|
|
21
|
+
type Query = { [method: string]: unknown; then: Promise<QueryResult>["then"] };
|
|
22
|
+
|
|
23
|
+
const QUERY_METHODS = ["select", "insert", "update", "upsert", "delete", "eq", "neq", "in", "is", "gt", "gte", "lt", "lte", "match", "filter", "order", "limit", "range"];
|
|
24
|
+
|
|
25
|
+
const listeners = new Set<Listener>();
|
|
26
|
+
let current: FakeSession | null = null;
|
|
27
|
+
|
|
28
|
+
/** What the next calls answer. `resetSupabase` puts every field back. */
|
|
29
|
+
export const next: {
|
|
30
|
+
/** The next sign-in or sign-up fails with this Supabase error code. */
|
|
31
|
+
authError: string | null;
|
|
32
|
+
/** The next sign-up needs the email confirmed first: no session comes back. */
|
|
33
|
+
confirmEmail: boolean;
|
|
34
|
+
/** `delete_my_account` fails with this Postgres or app error code. */
|
|
35
|
+
deleteError: string | null;
|
|
36
|
+
/** `delete_my_account` doesn't answer until `releaseDelete()`. */
|
|
37
|
+
holdDelete: boolean;
|
|
38
|
+
} = { authError: null, confirmEmail: false, deleteError: null, holdDelete: false };
|
|
39
|
+
|
|
40
|
+
let releaseHeld: () => void = () => {};
|
|
41
|
+
/** Lets a `delete_my_account` held by `next.holdDelete` answer. */
|
|
42
|
+
export function releaseDelete(): void {
|
|
43
|
+
releaseHeld();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function sessionFor(email: string): FakeSession {
|
|
47
|
+
return { access_token: "test-token", user: { id: `user-${email}`, email } };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Plays an auth event to every listener, as supabase-js does after a sign-in or sign-out. */
|
|
51
|
+
export function emit(event: string, session: FakeSession | null): void {
|
|
52
|
+
current = session;
|
|
53
|
+
for (const listener of listeners) listener(event, session);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A PostgREST query on an empty table: every filter chains, and awaiting it gives no rows. */
|
|
57
|
+
function query(result: QueryResult | Promise<QueryResult>): Query {
|
|
58
|
+
const settle = Promise.resolve(result);
|
|
59
|
+
const q: Query = { then: (onFulfilled, onRejected) => settle.then(onFulfilled, onRejected) };
|
|
60
|
+
for (const method of QUERY_METHODS) q[method] = () => q;
|
|
61
|
+
q.single = () => query(settle.then((r) => ({ ...r, data: null })));
|
|
62
|
+
q.maybeSingle = () => query(settle.then((r) => ({ ...r, data: null })));
|
|
63
|
+
return q;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function signIn(email: string, confirm: boolean): Promise<AuthResult> {
|
|
67
|
+
const code = next.authError;
|
|
68
|
+
next.authError = null;
|
|
69
|
+
if (code) return { data: { session: null, user: null }, error: { code, message: `server text for ${code}` } };
|
|
70
|
+
const session = sessionFor(email);
|
|
71
|
+
if (confirm) return { data: { session: null, user: session.user }, error: null };
|
|
72
|
+
emit("SIGNED_IN", session);
|
|
73
|
+
return { data: { session, user: session.user }, error: null };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function deleteMyAccount(): Query {
|
|
77
|
+
const answer = (): QueryResult =>
|
|
78
|
+
next.deleteError
|
|
79
|
+
? { data: null, error: { code: next.deleteError, message: `refused: ${next.deleteError}` }, count: 0 }
|
|
80
|
+
: { data: null, error: null, count: 0 };
|
|
81
|
+
if (!next.holdDelete) return query(answer());
|
|
82
|
+
return query(new Promise<QueryResult>((resolve) => (releaseHeld = () => resolve(answer()))));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const fakeSupabase = {
|
|
86
|
+
auth: {
|
|
87
|
+
storageKey: "genesis-rn-starter-auth-token",
|
|
88
|
+
storage: { getItem: async (_key: string): Promise<string | null> => (current ? JSON.stringify(current) : null) },
|
|
89
|
+
getSession: jest.fn(async () => ({ data: { session: current }, error: null })),
|
|
90
|
+
onAuthStateChange: jest.fn((callback: Listener) => {
|
|
91
|
+
listeners.add(callback);
|
|
92
|
+
// supabase-js tells each new listener the session it has, a tick after it subscribes.
|
|
93
|
+
queueMicrotask(() => {
|
|
94
|
+
if (listeners.has(callback)) callback("INITIAL_SESSION", current);
|
|
95
|
+
});
|
|
96
|
+
return { data: { subscription: { unsubscribe: () => listeners.delete(callback) } } };
|
|
97
|
+
}),
|
|
98
|
+
signInWithPassword: jest.fn(({ email }: { email: string; password: string }) => signIn(email, false)),
|
|
99
|
+
signUp: jest.fn(({ email }: { email: string; password: string }) => signIn(email, next.confirmEmail)),
|
|
100
|
+
signOut: jest.fn(async (_options?: { scope?: string }) => {
|
|
101
|
+
emit("SIGNED_OUT", null);
|
|
102
|
+
return { error: null };
|
|
103
|
+
}),
|
|
104
|
+
updateUser: jest.fn(async () => ({ data: { user: current?.user ?? null }, error: null })),
|
|
105
|
+
},
|
|
106
|
+
from: jest.fn((_table: string) => query({ data: [], error: null, count: 0 })),
|
|
107
|
+
rpc: jest.fn((fn: string, _args?: object) => (fn === "delete_my_account" ? deleteMyAccount() : query({ data: null, error: null, count: 0 }))),
|
|
108
|
+
// Edge Functions (genesis-apple-revoke): every call succeeds.
|
|
109
|
+
functions: { invoke: jest.fn(async (_name: string, _options?: object) => ({ data: { ok: true }, error: null })) },
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** `sessionReady` from `src/lib/supabase.ts`, the boot step that wipes a session left by an earlier install. */
|
|
113
|
+
export const sessionReady = jest.fn(async (): Promise<unknown> => false);
|
|
114
|
+
|
|
115
|
+
/** Starts a test signed in as `email` (or signed out), with no listeners or scripted answers left from the last one. */
|
|
116
|
+
export function resetSupabase(email: string | null): void {
|
|
117
|
+
listeners.clear();
|
|
118
|
+
current = email ? sessionFor(email) : null;
|
|
119
|
+
Object.assign(next, { authError: null, confirmEmail: false, deleteError: null, holdDelete: false });
|
|
120
|
+
releaseHeld = () => {};
|
|
121
|
+
sessionReady.mockReset();
|
|
122
|
+
sessionReady.mockImplementation(async () => false);
|
|
123
|
+
for (const fn of [
|
|
124
|
+
fakeSupabase.auth.getSession,
|
|
125
|
+
fakeSupabase.auth.onAuthStateChange,
|
|
126
|
+
fakeSupabase.auth.signInWithPassword,
|
|
127
|
+
fakeSupabase.auth.signUp,
|
|
128
|
+
fakeSupabase.auth.signOut,
|
|
129
|
+
fakeSupabase.auth.updateUser,
|
|
130
|
+
fakeSupabase.from,
|
|
131
|
+
fakeSupabase.rpc,
|
|
132
|
+
fakeSupabase.functions.invoke,
|
|
133
|
+
]) {
|
|
134
|
+
fn.mockClear();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @feat:native-starter
|
|
2
|
+
import { describe, expect, it } from "@jest/globals";
|
|
3
|
+
import { normalizeLink } from "@marktiderman/genesis-native";
|
|
4
|
+
import { appSchemes, links } from "@/lib/links";
|
|
5
|
+
|
|
6
|
+
describe("deep links", () => {
|
|
7
|
+
it("opens the check-in from its documented link, gym and all", () => {
|
|
8
|
+
expect(normalizeLink("genesis-starter://check-in?gym=hilltop", links)).toBe("/check-in?gym=hilltop");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("answers to every variant's scheme, whatever config Metro served", () => {
|
|
12
|
+
const all = ["genesis-starter", "genesis-starter-dev", "genesis-starter-preview"];
|
|
13
|
+
expect(appSchemes("genesis-starter", undefined)).toEqual(all);
|
|
14
|
+
expect(appSchemes("genesis-starter", "genesis-starter")).toEqual(all);
|
|
15
|
+
expect(appSchemes("genesis-starter", ["genesis-starter-preview"])).toEqual(all);
|
|
16
|
+
expect(appSchemes("genesis-starter", "custom")).toEqual([...all, "custom"]);
|
|
17
|
+
// The app's own map, as built in this test (no APP_VARIANT): a development build's link still opens.
|
|
18
|
+
expect(normalizeLink("genesis-starter-dev://check-in?gym=hilltop", links)).toBe("/check-in?gym=hilltop");
|
|
19
|
+
expect(normalizeLink("genesis-starter-preview://settings", links)).toBe("/settings");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("still sends an unknown path home", () => {
|
|
23
|
+
expect(normalizeLink("genesis-starter://nowhere", links)).toBe("/");
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { expect } from "@jest/globals";
|
|
3
|
+
import { renderRouter, waitFor, type RenderRouterResult } from "expo-router/testing-library";
|
|
4
|
+
import { resetSupabase } from "./fake-supabase";
|
|
5
|
+
|
|
6
|
+
/** The starter's real route tree: root layout, GenesisNativeApp, tabs and screens, unchanged. */
|
|
7
|
+
export const APP_DIR = path.resolve(__dirname, "../../src/app");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Renders the whole app at `url`, signed in as `email` (or signed out with `null`).
|
|
11
|
+
* `script` runs after the fakes are reset and before the first render.
|
|
12
|
+
*/
|
|
13
|
+
export function renderApp(url: string, email: string | null, script?: () => void): Promise<RenderRouterResult> {
|
|
14
|
+
resetSupabase(email);
|
|
15
|
+
script?.();
|
|
16
|
+
return renderRouter(APP_DIR, { initialUrl: url });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Waits until the router is at `pathname` (a redirect or navigation lands a render later). */
|
|
20
|
+
export async function expectPathname(app: RenderRouterResult, pathname: string): Promise<void> {
|
|
21
|
+
await waitFor(() => expect(app.getPathname()).toBe(pathname));
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `setup.ts` fails a test when the app reports an error (`[push] …`, `[updates] …`,
|
|
3
|
+
* `[observability] …`) or React warns about an update outside act(). A test that provokes one
|
|
4
|
+
* on purpose names it here first; the list empties after every test.
|
|
5
|
+
*/
|
|
6
|
+
export const expectedReports: RegExp[] = [];
|
|
7
|
+
|
|
8
|
+
export function expectReport(pattern: RegExp): void {
|
|
9
|
+
expectedReports.push(pattern);
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Genesis packages are ES modules whose `exports` name an `import` entry and no `require`
|
|
3
|
+
* one. jest-expo resolves with the `require` and `react-native` conditions only, so it would
|
|
4
|
+
* find nothing; for `@marktiderman/*` (and only those) this adds `import`. Babel turns the
|
|
5
|
+
* module into CommonJS on the way in (`alsoTransform` in jest.config.js).
|
|
6
|
+
*/
|
|
7
|
+
module.exports = (request, options) => {
|
|
8
|
+
if (request.startsWith("@marktiderman/")) {
|
|
9
|
+
return options.defaultResolver(request, { ...options, conditions: [...(options.conditions ?? []), "import"] });
|
|
10
|
+
}
|
|
11
|
+
return options.defaultResolver(request, options);
|
|
12
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
|
2
|
+
import * as SplashScreen from "expo-splash-screen";
|
|
3
|
+
import { act, screen, userEvent } from "@testing-library/react-native";
|
|
4
|
+
import { fakeSupabase, sessionReady } from "./fake-supabase";
|
|
5
|
+
import { renderApp } from "./render-app";
|
|
6
|
+
import { expectReport } from "./reports";
|
|
7
|
+
|
|
8
|
+
jest.mock("expo-splash-screen", () => ({ preventAutoHideAsync: jest.fn(async () => true), hideAsync: jest.fn(async () => true) }));
|
|
9
|
+
|
|
10
|
+
const splash = jest.mocked(SplashScreen);
|
|
11
|
+
|
|
12
|
+
describe("root layout", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
splash.hideAsync.mockClear();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("boots through GenesisNativeApp: the boot steps run, the session is read, the splash goes and the route renders", async () => {
|
|
18
|
+
await renderApp("/", "person@example.com");
|
|
19
|
+
expect(await screen.findByTestId("home")).toBeOnTheScreen();
|
|
20
|
+
// `_layout.tsx` holds the splash as the module loads; GenesisNativeApp hides it after the boot.
|
|
21
|
+
expect(splash.preventAutoHideAsync).toHaveBeenCalled();
|
|
22
|
+
expect(splash.hideAsync).toHaveBeenCalled();
|
|
23
|
+
expect(sessionReady).toHaveBeenCalledTimes(1);
|
|
24
|
+
expect(fakeSupabase.auth.getSession).toHaveBeenCalled();
|
|
25
|
+
expect(fakeSupabase.auth.onAuthStateChange).toHaveBeenCalled();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("keeps the splash up and renders no route while a boot step is still running", async () => {
|
|
29
|
+
let finish: (value: unknown) => void = () => {};
|
|
30
|
+
await renderApp("/", "person@example.com", () => {
|
|
31
|
+
sessionReady.mockImplementationOnce(() => new Promise((resolve) => (finish = resolve)));
|
|
32
|
+
});
|
|
33
|
+
await act(async () => {}); // let the boot start
|
|
34
|
+
expect(sessionReady).toHaveBeenCalledTimes(1);
|
|
35
|
+
expect(screen.queryByTestId("home")).not.toBeOnTheScreen();
|
|
36
|
+
expect(splash.hideAsync).not.toHaveBeenCalled();
|
|
37
|
+
await act(async () => finish(false));
|
|
38
|
+
expect(await screen.findByTestId("home")).toBeOnTheScreen();
|
|
39
|
+
expect(splash.hideAsync).toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("shows the fatal screen when a boot step fails, reports it, and Try again runs it again", async () => {
|
|
43
|
+
expectReport(/^\[observability\] fatal boot: keychain unavailable$/);
|
|
44
|
+
await renderApp("/", "person@example.com", () => {
|
|
45
|
+
sessionReady.mockRejectedValueOnce(new Error("keychain unavailable"));
|
|
46
|
+
});
|
|
47
|
+
expect(await screen.findByTestId("genesis-fatal")).toBeOnTheScreen();
|
|
48
|
+
expect(screen.queryByTestId("home")).not.toBeOnTheScreen();
|
|
49
|
+
// The fatal screen replaces the splash, so a person can see it and retry.
|
|
50
|
+
expect(splash.hideAsync).toHaveBeenCalled();
|
|
51
|
+
await userEvent.setup().press(screen.getByTestId("genesis-fatal-retry"));
|
|
52
|
+
expect(await screen.findByTestId("home")).toBeOnTheScreen();
|
|
53
|
+
expect(sessionReady).toHaveBeenCalledTimes(2);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The real `src/lib/supabase.ts` (every other file here swaps it for the fake): the reinstall
|
|
3
|
+
* wipe that the boot waits for, and the session storage that waits for the wipe.
|
|
4
|
+
*/
|
|
5
|
+
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
|
6
|
+
|
|
7
|
+
jest.unmock("@/lib/supabase");
|
|
8
|
+
|
|
9
|
+
type Storage = { getItem(key: string): Promise<string | null>; setItem(key: string, value: string): Promise<void>; removeItem(key: string): Promise<void> };
|
|
10
|
+
type Wipe = (options: object) => Promise<boolean>;
|
|
11
|
+
|
|
12
|
+
// jest.mock factories may only reach variables whose names start with `mock`.
|
|
13
|
+
const mockKeychain = {
|
|
14
|
+
getItem: jest.fn(async (_key: string): Promise<string | null> => "stored-session"),
|
|
15
|
+
setItem: jest.fn(async () => {}),
|
|
16
|
+
removeItem: jest.fn(async () => {}),
|
|
17
|
+
};
|
|
18
|
+
const mockWipe = jest.fn<Wipe>();
|
|
19
|
+
const mockCreated: { storage?: Storage } = {};
|
|
20
|
+
|
|
21
|
+
jest.mock("@marktiderman/genesis-supabase/native", () => ({
|
|
22
|
+
keychainStorage: () => mockKeychain,
|
|
23
|
+
refreshWhileActive: () => {},
|
|
24
|
+
wipeSessionOnReinstall: (options: object) => mockWipe(options),
|
|
25
|
+
}));
|
|
26
|
+
jest.mock("@marktiderman/genesis-supabase", () => ({
|
|
27
|
+
createGenesisSupabase: (options: { storage: Storage }) => {
|
|
28
|
+
mockCreated.storage = options.storage;
|
|
29
|
+
return { auth: {} };
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
/** A fresh copy of the module, so each test starts before any wipe. */
|
|
34
|
+
function load(): typeof import("@/lib/supabase") {
|
|
35
|
+
let mod: typeof import("@/lib/supabase") | undefined;
|
|
36
|
+
jest.isolateModules(() => {
|
|
37
|
+
mod = jest.requireActual<typeof import("@/lib/supabase")>("@/lib/supabase");
|
|
38
|
+
});
|
|
39
|
+
if (!mod) throw new Error("src/lib/supabase.ts didn't load");
|
|
40
|
+
return mod;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function storage(): Storage {
|
|
44
|
+
if (!mockCreated.storage) throw new Error("createGenesisSupabase wasn't given a storage");
|
|
45
|
+
return mockCreated.storage;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe("session storage (src/lib/supabase.ts)", () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
mockWipe.mockReset();
|
|
51
|
+
mockKeychain.getItem.mockClear();
|
|
52
|
+
mockCreated.storage = undefined;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("runs the reinstall wipe once, and every caller shares it", async () => {
|
|
56
|
+
mockWipe.mockResolvedValue(false);
|
|
57
|
+
const { sessionReady } = load();
|
|
58
|
+
await Promise.all([sessionReady(), sessionReady(), sessionReady()]);
|
|
59
|
+
expect(mockWipe).toHaveBeenCalledTimes(1);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("forgets a failed wipe, so the next call (the fatal screen's Try again) runs it again", async () => {
|
|
63
|
+
mockWipe.mockRejectedValueOnce(new Error("keychain unavailable")).mockResolvedValue(true);
|
|
64
|
+
const { sessionReady } = load();
|
|
65
|
+
await expect(sessionReady()).rejects.toThrow("keychain unavailable");
|
|
66
|
+
await expect(sessionReady()).resolves.toBe(true);
|
|
67
|
+
expect(mockWipe).toHaveBeenCalledTimes(2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("reads no session from the Keychain until the wipe has finished", async () => {
|
|
71
|
+
let finish: (wiped: boolean) => void = () => {};
|
|
72
|
+
mockWipe.mockImplementation(() => new Promise<boolean>((resolve) => (finish = resolve)));
|
|
73
|
+
load();
|
|
74
|
+
const read = storage().getItem("genesis-rn-starter-auth-token");
|
|
75
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
76
|
+
expect(mockKeychain.getItem).not.toHaveBeenCalled();
|
|
77
|
+
finish(true);
|
|
78
|
+
await expect(read).resolves.toBe("stored-session");
|
|
79
|
+
expect(mockKeychain.getItem).toHaveBeenCalledWith("genesis-rn-starter-auth-token");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, jest } from "@jest/globals";
|
|
2
|
+
import { Alert, type AlertButton } from "react-native";
|
|
3
|
+
import { act, screen, userEvent, within } from "@testing-library/react-native";
|
|
4
|
+
import { copy } from "@/copy";
|
|
5
|
+
import { fakeSupabase, next, releaseDelete } from "./fake-supabase";
|
|
6
|
+
import { expectPathname, renderApp } from "./render-app";
|
|
7
|
+
|
|
8
|
+
const t = copy.settings;
|
|
9
|
+
|
|
10
|
+
/** Records every Alert instead of showing it; `press` taps one of the last alert's buttons. */
|
|
11
|
+
function captureAlerts() {
|
|
12
|
+
const alert = jest.spyOn(Alert, "alert").mockImplementation(() => {});
|
|
13
|
+
const last = () => {
|
|
14
|
+
const call = alert.mock.calls.at(-1);
|
|
15
|
+
if (!call) throw new Error("no Alert was shown");
|
|
16
|
+
const [title, message, buttons] = call;
|
|
17
|
+
return { title, message, buttons: buttons ?? [] };
|
|
18
|
+
};
|
|
19
|
+
const press = async (text: string) => {
|
|
20
|
+
const button = last().buttons.find((b: AlertButton) => b.text === text);
|
|
21
|
+
if (!button) throw new Error(`the last Alert has no "${text}" button: ${JSON.stringify(last().buttons.map((b) => b.text))}`);
|
|
22
|
+
await act(async () => {
|
|
23
|
+
button.onPress?.();
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return { alert, last, press };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const deleteCalls = () => fakeSupabase.rpc.mock.calls.filter(([fn]) => fn === "delete_my_account");
|
|
30
|
+
|
|
31
|
+
describe("settings screen", () => {
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
jest.restoreAllMocks();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("shows who is signed in, the Notifications row, the version and both account actions", async () => {
|
|
37
|
+
await renderApp("/settings", "person@example.com");
|
|
38
|
+
const account = await screen.findByTestId("settings-row-email");
|
|
39
|
+
expect(within(account).getByText(t.signedInAs)).toBeOnTheScreen();
|
|
40
|
+
expect(within(account).getByText("person@example.com")).toBeOnTheScreen();
|
|
41
|
+
// The push block's row, added through useBlockSettings into the untitled `general` section.
|
|
42
|
+
expect(within(screen.getByTestId("genesis-push-settings")).getByText(t.notifications)).toBeOnTheScreen();
|
|
43
|
+
expect(within(screen.getByTestId("settings-row-version")).getByText(t.version)).toBeOnTheScreen();
|
|
44
|
+
expect(within(screen.getByTestId("sign-out")).getByText(t.signOut)).toBeOnTheScreen();
|
|
45
|
+
expect(within(screen.getByTestId("delete-account")).getByText(t.deleteAccount)).toBeOnTheScreen();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("signs out, and the app goes back to sign-in", async () => {
|
|
49
|
+
const app = await renderApp("/settings", "person@example.com");
|
|
50
|
+
await userEvent.setup().press(await screen.findByTestId("sign-out"));
|
|
51
|
+
expect(fakeSupabase.auth.signOut).toHaveBeenCalledTimes(1);
|
|
52
|
+
// A full sign-out (the server revokes the refresh token), not just this device's copy.
|
|
53
|
+
expect(fakeSupabase.auth.signOut).toHaveBeenCalledWith();
|
|
54
|
+
expect(await screen.findByText(copy.signIn.headline)).toBeOnTheScreen();
|
|
55
|
+
await expectPathname(app, "/sign-in");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("asks before deleting the account, and Cancel deletes nothing", async () => {
|
|
59
|
+
const alerts = captureAlerts();
|
|
60
|
+
await renderApp("/settings", "person@example.com");
|
|
61
|
+
await userEvent.setup().press(await screen.findByTestId("delete-account"));
|
|
62
|
+
expect(alerts.last().title).toBe(t.deleteConfirmTitle);
|
|
63
|
+
expect(alerts.last().message).toBe(t.deleteConfirmBody);
|
|
64
|
+
expect(alerts.last().buttons.find((b) => b.text === t.deleteConfirm)?.style).toBe("destructive");
|
|
65
|
+
await alerts.press(t.cancel);
|
|
66
|
+
expect(deleteCalls()).toHaveLength(0);
|
|
67
|
+
expect(fakeSupabase.auth.signOut).not.toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("deletes the account once confirmed, revokes the Apple tokens, signs this device out and says so", async () => {
|
|
71
|
+
const alerts = captureAlerts();
|
|
72
|
+
const app = await renderApp("/settings", "person@example.com");
|
|
73
|
+
await userEvent.setup().press(await screen.findByTestId("delete-account"));
|
|
74
|
+
await alerts.press(t.deleteConfirm);
|
|
75
|
+
expect(deleteCalls()).toHaveLength(1);
|
|
76
|
+
// App Review requires Sign in with Apple tokens to be revoked when the account goes.
|
|
77
|
+
expect(fakeSupabase.functions.invoke).toHaveBeenCalledWith("genesis-apple-revoke", expect.objectContaining({ body: { action: "revoke" } }));
|
|
78
|
+
expect(fakeSupabase.auth.signOut).toHaveBeenCalledWith({ scope: "local" });
|
|
79
|
+
expect(alerts.last().title).toBe(t.deletedTitle);
|
|
80
|
+
await expectPathname(app, "/sign-in");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("ignores Delete account while a deletion is running", async () => {
|
|
84
|
+
const alerts = captureAlerts();
|
|
85
|
+
await renderApp("/settings", "person@example.com", () => {
|
|
86
|
+
next.holdDelete = true;
|
|
87
|
+
});
|
|
88
|
+
const user = userEvent.setup();
|
|
89
|
+
await user.press(await screen.findByTestId("delete-account"));
|
|
90
|
+
await alerts.press(t.deleteConfirm);
|
|
91
|
+
expect(deleteCalls()).toHaveLength(1);
|
|
92
|
+
const shown = alerts.alert.mock.calls.length;
|
|
93
|
+
await user.press(screen.getByTestId("delete-account"));
|
|
94
|
+
expect(alerts.alert.mock.calls.length).toBe(shown); // no second confirmation
|
|
95
|
+
await act(async () => releaseDelete());
|
|
96
|
+
expect(deleteCalls()).toHaveLength(1);
|
|
97
|
+
expect(alerts.last().title).toBe(t.deletedTitle);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// delete_my_account's error codes (src/lib/account.ts) → the copy, and whether to offer a fresh sign-in.
|
|
101
|
+
it.each([
|
|
102
|
+
["GA002", t.deleteErrors.recentSignIn, true],
|
|
103
|
+
["42501", t.deleteErrors.notAllowed, true],
|
|
104
|
+
["GA001", t.deleteErrors.refused, false],
|
|
105
|
+
["GA999", t.deleteErrors.refused, false],
|
|
106
|
+
["23503", t.deleteErrors.inUse, false],
|
|
107
|
+
["XX000", t.deleteErrors.unknown, false],
|
|
108
|
+
])("reports refusal %s as a refusal with its own message, and keeps the session", async (code, message, signInAgain) => {
|
|
109
|
+
const alerts = captureAlerts();
|
|
110
|
+
const app = await renderApp("/settings", "person@example.com", () => {
|
|
111
|
+
next.deleteError = code;
|
|
112
|
+
});
|
|
113
|
+
await userEvent.setup().press(await screen.findByTestId("delete-account"));
|
|
114
|
+
await alerts.press(t.deleteConfirm);
|
|
115
|
+
expect(deleteCalls()).toHaveLength(1);
|
|
116
|
+
expect(alerts.last().title).toBe(t.deleteFailedTitle);
|
|
117
|
+
expect(alerts.last().message).toBe(message);
|
|
118
|
+
expect(alerts.last().buttons.map((b) => b.text)).toEqual(signInAgain ? [t.cancel, t.signInAgain] : [t.ok]);
|
|
119
|
+
expect(fakeSupabase.auth.signOut).not.toHaveBeenCalled();
|
|
120
|
+
expect(app.getPathname()).toBe("/settings");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("offers a fresh sign-in after a refusal that needs one, and it signs out", async () => {
|
|
124
|
+
const alerts = captureAlerts();
|
|
125
|
+
const app = await renderApp("/settings", "person@example.com", () => {
|
|
126
|
+
next.deleteError = "GA002";
|
|
127
|
+
});
|
|
128
|
+
await userEvent.setup().press(await screen.findByTestId("delete-account"));
|
|
129
|
+
await alerts.press(t.deleteConfirm);
|
|
130
|
+
await alerts.press(t.signInAgain);
|
|
131
|
+
expect(fakeSupabase.auth.signOut).toHaveBeenCalledTimes(1);
|
|
132
|
+
await expectPathname(app, "/sign-in");
|
|
133
|
+
});
|
|
134
|
+
});
|