create-disposabl-app 0.17.6 → 0.18.1
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 +4 -0
- package/dist/disposabl.js +42 -9
- package/dist/index.js +64 -18
- package/dist/templates/default/apps/mobile/README.md +40 -0
- package/dist/templates/default/apps/mobile/app.config.js +46 -2
- package/dist/templates/default/apps/mobile/app.json +2 -1
- package/dist/templates/default/apps/mobile/package.json +7 -1
- package/dist/templates/default/apps/mobile/plugins/with-android-signing.js +23 -1
- package/dist/templates/default/apps/mobile/scripts/fresh-android.mjs +24 -0
- package/dist/templates/default/apps/mobile/scripts/play-aab.mjs +176 -0
- package/dist/templates/default/apps/mobile/scripts/verify-play-aab.mjs +77 -0
- package/dist/templates/default/bun.lock +12 -3
- package/dist/templates/default/bunfig.toml +1 -0
- package/dist/templates/default/package.json +6 -2
- package/dist/templates/default/packages/backend/convex/files/guard.ts +2 -0
- package/dist/templates/default/packages/backend/convex/http.ts +11 -1
- package/dist/templates/default/packages/backend/convex/schema.ts +10 -0
- package/dist/templates/default/packages/backend/convex/telemetry.ts +12 -16
- package/dist/templates/default/packages/cli/telemetry.ts +40 -3
- package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +2 -0
- package/dist/templates/default/packages/disposabl-kit/client/components/account-deletion.tsx +111 -0
- package/dist/templates/default/packages/disposabl-kit/client/components/consent-identity.tsx +50 -0
- package/dist/templates/default/packages/disposabl-kit/client/components/legal-page.tsx +12 -1
- package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry-lease.ts +200 -0
- package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry.ts +8 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/consent.tsx +23 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/legal/delete-account.tsx +6 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/legal/support.tsx +33 -0
- package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +13 -0
- package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +19 -2
- package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +1 -0
- package/dist/templates/default/packages/disposabl-kit/legal/README.md +1 -1
- package/dist/templates/default/packages/disposabl-kit/legal/config.ts +32 -4
- package/dist/templates/default/packages/disposabl-kit/legal/index.ts +2 -2
- package/dist/templates/default/packages/disposabl-kit/legal/publisher.ts +6 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +13 -9
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/paywall.ts +28 -4
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/policy.ts +31 -14
- package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +45 -34
- package/dist/templates/default/packages/disposabl-kit/mobile/components/settings-links.tsx +14 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/expo-plugin.cjs +3 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/index.ts +4 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +55 -8
- package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +147 -124
- package/dist/templates/default/packages/disposabl-kit/server/billing-handoff.ts +113 -95
- package/dist/templates/default/packages/disposabl-kit/server/files-functions.ts +70 -54
- package/dist/templates/default/packages/disposabl-kit/server/http.ts +49 -21
- package/dist/templates/default/packages/disposabl-kit/server/lib/platform-spec.ts +25 -1
- package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +375 -69
- package/dist/templates/default/packages/sdk/README.md +2 -0
- package/dist/templates/default/packages/sdk/src/analytics.ts +7 -2
- package/dist/templates/default/packages/skill/SKILL.md +4 -2
- package/dist/templates/default/packages/skill/references/store-submissions.md +25 -0
- package/dist/templates/default/packages/tests/README.md +28 -1
- package/dist/templates/default/packages/tests/account-deletion-ui.test.ts +21 -0
- package/dist/templates/default/packages/tests/auth-email-setup.test.ts +45 -0
- package/dist/templates/default/packages/tests/components/account-deletion.test.mjs +82 -0
- package/dist/templates/default/packages/tests/components/consent-identity.test.mjs +175 -0
- package/dist/templates/default/packages/tests/components/mobile-deletion-link.test.mjs +40 -0
- package/dist/templates/default/packages/tests/components/mobile-theme.test.mjs +56 -3
- package/dist/templates/default/packages/tests/components/pricing-identity.test.mjs +113 -0
- package/dist/templates/default/packages/tests/components/support-page.test.mjs +36 -0
- package/dist/templates/default/packages/tests/consent-identity.test.ts +13 -0
- package/dist/templates/default/packages/tests/desktop-macos-release.test.ts +153 -145
- package/dist/templates/default/packages/tests/flows/legal.e2e.ts +40 -3
- package/dist/templates/default/packages/tests/helpers/auth-email-setup/probe.test.mjs +44 -0
- package/dist/templates/default/packages/tests/helpers/mobile-simulator/preflight.py +80 -0
- package/dist/templates/default/packages/tests/helpers/mobile-simulator/test_preflight.py +57 -0
- package/dist/templates/default/packages/tests/mobile-android-e2e-network.test.ts +81 -1
- package/dist/templates/default/packages/tests/mobile-android-signing.test.ts +52 -0
- package/dist/templates/default/packages/tests/mobile-deletion-link.test.ts +21 -0
- package/dist/templates/default/packages/tests/mobile-ios-reachability-pin.test.ts +84 -0
- package/dist/templates/default/packages/tests/mobile-simulator-preflight.test.ts +16 -0
- package/dist/templates/default/packages/tests/native-billing.test.ts +288 -0
- package/dist/templates/default/packages/tests/pricing-identity.test.ts +13 -0
- package/dist/templates/default/packages/tests/sdk-analytics.test.ts +28 -2
- package/dist/templates/default/packages/tests/support-page.test.ts +13 -0
- package/dist/templates/default/packages/tests/telemetry.test.ts +389 -18
- package/dist/templates/default/packages/tests/ui-telemetry-lease.test.ts +346 -0
- package/dist/templates/default/patches/convex-mcp-account-erasure-alpha7.patch +466 -0
- package/dist/templates/default/vendor/README.md +61 -1
- package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.patch +890 -0
- package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.patch +1060 -0
- package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.4.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.5.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.6.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.7.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.8.tgz +0 -0
- package/dist/templates/default/vendor/convex-auth-core-erasure-disposabl.6.patch +115 -0
- package/dist/templates/default/vendor/convex-auth-identity-cutoff-disposabl.7.patch +442 -0
- package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.md +11 -0
- package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.patch +78 -0
- package/dist/templates/default/vendor/convex-auth-marker-disposabl.4.patch +169 -0
- package/dist/templates/default/vendor/convex-auth-marker-password-disposabl.5.patch +126 -0
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { afterEach, expect, mock, test } from "bun:test";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { act, create } from "react-test-renderer";
|
|
4
|
+
|
|
5
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
6
|
+
let authenticated = false;
|
|
7
|
+
const authEnabled = process.env.TEST_AUTH_DISABLED !== "true";
|
|
8
|
+
mock.module("../../disposabl-kit/features", () => ({
|
|
9
|
+
authenticationEnabled: authEnabled,
|
|
10
|
+
}));
|
|
11
|
+
mock.module("convex/react", () => ({
|
|
12
|
+
useConvexAuth: () => {
|
|
13
|
+
if (!authEnabled) throw new Error("Auth hook without provider");
|
|
14
|
+
return { isAuthenticated: authenticated, isLoading: false };
|
|
15
|
+
},
|
|
16
|
+
}));
|
|
17
|
+
const { AccountDeletion, DeletionPanel } =
|
|
18
|
+
await import("../../disposabl-kit/client/components/account-deletion");
|
|
19
|
+
let renderer;
|
|
20
|
+
async function render(element) {
|
|
21
|
+
await act(async () => {
|
|
22
|
+
renderer = create(element);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const text = () => JSON.stringify(renderer.toJSON());
|
|
26
|
+
afterEach(async () => {
|
|
27
|
+
await act(async () => renderer?.unmount());
|
|
28
|
+
authenticated = false;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("anonymous users get sign-in when authentication is enabled", async () => {
|
|
32
|
+
await render(createElement(AccountDeletion));
|
|
33
|
+
if (authEnabled) {
|
|
34
|
+
expect(text()).toContain("Sign in to manage your account deletion request");
|
|
35
|
+
expect(renderer.root.findByType("a").props.href).toBe(
|
|
36
|
+
"/login?returnTo=%2Flegal%2Fdelete-account",
|
|
37
|
+
);
|
|
38
|
+
} else expect(renderer.toJSON()).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("signed-in users see unavailable until the backend is wired", async () => {
|
|
42
|
+
if (!authEnabled) return;
|
|
43
|
+
authenticated = true;
|
|
44
|
+
await render(createElement(AccountDeletion));
|
|
45
|
+
expect(text()).toContain("Account deletion requests are not available yet");
|
|
46
|
+
expect(renderer.root.findAllByType("button")).toHaveLength(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("confirmation can be cancelled and only confirm invokes the request", async () => {
|
|
50
|
+
const request = mock();
|
|
51
|
+
await render(
|
|
52
|
+
createElement(DeletionPanel, { state: "idle", onRequest: request }),
|
|
53
|
+
);
|
|
54
|
+
await act(async () =>
|
|
55
|
+
renderer.root.findAllByType("button")[0].props.onClick(),
|
|
56
|
+
);
|
|
57
|
+
expect(text()).toContain("Confirm deletion request");
|
|
58
|
+
await act(async () =>
|
|
59
|
+
renderer.root.findAllByType("button")[1].props.onClick(),
|
|
60
|
+
);
|
|
61
|
+
expect(request).not.toHaveBeenCalled();
|
|
62
|
+
await act(async () =>
|
|
63
|
+
renderer.root.findAllByType("button")[0].props.onClick(),
|
|
64
|
+
);
|
|
65
|
+
await act(async () =>
|
|
66
|
+
renderer.root.findAllByType("button")[0].props.onClick(),
|
|
67
|
+
);
|
|
68
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("pending, failure and completed states do not conflate request and deletion", async () => {
|
|
72
|
+
await render(createElement(DeletionPanel, { state: "pending" }));
|
|
73
|
+
expect(text()).toContain("Your account has not yet been deleted");
|
|
74
|
+
await act(async () =>
|
|
75
|
+
renderer.update(createElement(DeletionPanel, { state: "failed" })),
|
|
76
|
+
);
|
|
77
|
+
expect(text()).toContain("could not confirm your deletion request");
|
|
78
|
+
await act(async () =>
|
|
79
|
+
renderer.update(createElement(DeletionPanel, { state: "completed" })),
|
|
80
|
+
);
|
|
81
|
+
expect(text()).toContain("Your account deletion has been completed");
|
|
82
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { afterEach, expect, mock, test } from "bun:test";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { act, create } from "react-test-renderer";
|
|
4
|
+
import { getFunctionName } from "convex/server";
|
|
5
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
6
|
+
let token = "alice",
|
|
7
|
+
authenticated = true,
|
|
8
|
+
loading = false;
|
|
9
|
+
let account = { username: "alice", email: null, profile: null },
|
|
10
|
+
user = { id: "user-a", username: "alice" };
|
|
11
|
+
let queue = null;
|
|
12
|
+
let calls = [];
|
|
13
|
+
const convex = { url: "http://127.0.0.1:3540" };
|
|
14
|
+
const request = {
|
|
15
|
+
kind: "redirect",
|
|
16
|
+
status: "pending",
|
|
17
|
+
clientName: "Client",
|
|
18
|
+
serverName: "Service",
|
|
19
|
+
scopes: [],
|
|
20
|
+
redirectUri: "http://localhost/callback",
|
|
21
|
+
};
|
|
22
|
+
mock.module("@convex-dev/auth/react", () => ({ useAuthToken: () => token }));
|
|
23
|
+
mock.module("convex/browser", () => ({
|
|
24
|
+
ConvexHttpClient: class {
|
|
25
|
+
setAuth(value) {
|
|
26
|
+
this.token = value;
|
|
27
|
+
}
|
|
28
|
+
query(reference) {
|
|
29
|
+
const name = getFunctionName(reference);
|
|
30
|
+
calls.push([this.token, name]);
|
|
31
|
+
if (queue) return queue[name];
|
|
32
|
+
return Promise.resolve(name === "auth:account" ? account : user);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
mock.module("convex/react", () => ({
|
|
37
|
+
useConvex: () => convex,
|
|
38
|
+
useConvexAuth: () => ({ isAuthenticated: authenticated, isLoading: loading }),
|
|
39
|
+
useQuery: () => request,
|
|
40
|
+
useAction: () => async () => ({}),
|
|
41
|
+
}));
|
|
42
|
+
mock.module("@tanstack/react-router", () => ({
|
|
43
|
+
createFileRoute: () => (config) => ({
|
|
44
|
+
...config,
|
|
45
|
+
useSearch: () => ({ request: "request" }),
|
|
46
|
+
}),
|
|
47
|
+
Navigate: () => null,
|
|
48
|
+
}));
|
|
49
|
+
mock.module("../../disposabl-kit/client/components/ui/button", () => ({
|
|
50
|
+
Button: ({ children, ...props }) => createElement("button", props, children),
|
|
51
|
+
}));
|
|
52
|
+
const { Route } = await import("../../disposabl-kit/client/routes/consent");
|
|
53
|
+
let renderer;
|
|
54
|
+
const render = async () =>
|
|
55
|
+
act(async () => {
|
|
56
|
+
renderer = create(createElement(Route.component));
|
|
57
|
+
});
|
|
58
|
+
const refresh = async () =>
|
|
59
|
+
act(async () => {
|
|
60
|
+
renderer.update(createElement(Route.component));
|
|
61
|
+
});
|
|
62
|
+
const text = () => JSON.stringify(renderer.toJSON());
|
|
63
|
+
const allow = () =>
|
|
64
|
+
renderer.root
|
|
65
|
+
.findAllByType("button")
|
|
66
|
+
.find((b) => b.props.children === "Allow");
|
|
67
|
+
afterEach(async () => {
|
|
68
|
+
await act(async () => renderer?.unmount());
|
|
69
|
+
token = "alice";
|
|
70
|
+
authenticated = true;
|
|
71
|
+
loading = false;
|
|
72
|
+
account = { username: "alice", email: null, profile: null };
|
|
73
|
+
user = { id: "user-a", username: "alice" };
|
|
74
|
+
queue = null;
|
|
75
|
+
calls = [];
|
|
76
|
+
});
|
|
77
|
+
test("username, verified email, profile and stable id are displayed", async () => {
|
|
78
|
+
await render();
|
|
79
|
+
expect(text()).toContain("alice");
|
|
80
|
+
expect(allow().props.disabled).toBe(false);
|
|
81
|
+
for (const [value, expected] of [
|
|
82
|
+
[
|
|
83
|
+
{ username: null, email: "verified@example.test", profile: null },
|
|
84
|
+
"verified@example.test",
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
{
|
|
88
|
+
username: null,
|
|
89
|
+
email: null,
|
|
90
|
+
profile: { email: "google@example.test" },
|
|
91
|
+
},
|
|
92
|
+
"google@example.test",
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
{ username: null, email: null, profile: { name: "Google Name" } },
|
|
96
|
+
"Google Name",
|
|
97
|
+
],
|
|
98
|
+
[{ username: null, email: null, profile: null }, "user-a"],
|
|
99
|
+
]) {
|
|
100
|
+
token += "x";
|
|
101
|
+
account = value;
|
|
102
|
+
await refresh();
|
|
103
|
+
expect(text()).toContain(expected);
|
|
104
|
+
expect(allow().props.disabled).toBe(false);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
test("loading and unavailable block approval; stale account never survives token change", async () => {
|
|
108
|
+
await render();
|
|
109
|
+
expect(allow().props.disabled).toBe(false);
|
|
110
|
+
let finishAccount, finishUser;
|
|
111
|
+
queue = {
|
|
112
|
+
"auth:account": new Promise((r) => {
|
|
113
|
+
finishAccount = r;
|
|
114
|
+
}),
|
|
115
|
+
"users/index:current": new Promise((r) => {
|
|
116
|
+
finishUser = r;
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
token = "bob";
|
|
120
|
+
await refresh();
|
|
121
|
+
expect(text()).toContain("Loading your account");
|
|
122
|
+
expect(text()).not.toContain("alice");
|
|
123
|
+
expect(allow().props.disabled).toBe(true);
|
|
124
|
+
await act(async () => {
|
|
125
|
+
finishAccount({ username: "bob", email: null, profile: null });
|
|
126
|
+
finishUser({ id: "user-b", username: "bob" });
|
|
127
|
+
});
|
|
128
|
+
expect(text()).toContain("bob");
|
|
129
|
+
expect(allow().props.disabled).toBe(false);
|
|
130
|
+
token = "charlie";
|
|
131
|
+
queue = null;
|
|
132
|
+
account = null;
|
|
133
|
+
await refresh();
|
|
134
|
+
expect(text()).toContain("could not be loaded");
|
|
135
|
+
expect(allow().props.disabled).toBe(true);
|
|
136
|
+
loading = true;
|
|
137
|
+
await refresh();
|
|
138
|
+
expect(allow()).toBeUndefined();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("late account response cannot overwrite a newer account", async () => {
|
|
142
|
+
let finishOldAccount, finishOldUser;
|
|
143
|
+
queue = {
|
|
144
|
+
"auth:account": new Promise((r) => {
|
|
145
|
+
finishOldAccount = r;
|
|
146
|
+
}),
|
|
147
|
+
"users/index:current": new Promise((r) => {
|
|
148
|
+
finishOldUser = r;
|
|
149
|
+
}),
|
|
150
|
+
};
|
|
151
|
+
await render();
|
|
152
|
+
expect(allow().props.disabled).toBe(true);
|
|
153
|
+
token = "bob";
|
|
154
|
+
queue = null;
|
|
155
|
+
account = { username: "bob", email: null, profile: null };
|
|
156
|
+
user = { id: "user-b", username: "bob" };
|
|
157
|
+
await refresh();
|
|
158
|
+
expect(text()).toContain("bob");
|
|
159
|
+
await act(async () => {
|
|
160
|
+
finishOldAccount({ username: "alice", email: null, profile: null });
|
|
161
|
+
finishOldUser({ id: "user-a", username: "alice" });
|
|
162
|
+
});
|
|
163
|
+
expect(text()).toContain("bob");
|
|
164
|
+
expect(text()).not.toContain("alice");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("failed account lookup leaves approval unavailable", async () => {
|
|
168
|
+
queue = {
|
|
169
|
+
"auth:account": Promise.reject(new Error("offline")),
|
|
170
|
+
"users/index:current": Promise.resolve(user),
|
|
171
|
+
};
|
|
172
|
+
await render();
|
|
173
|
+
expect(text()).toContain("could not be loaded");
|
|
174
|
+
expect(allow().props.disabled).toBe(true);
|
|
175
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { afterEach, expect, mock, test } from "bun:test";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { act, create } from "react-test-renderer";
|
|
4
|
+
|
|
5
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
6
|
+
const enabled = process.env.TEST_AUTH_DISABLED !== "true";
|
|
7
|
+
const open = mock(async () => {});
|
|
8
|
+
process.env.EXPO_PUBLIC_CONVEX_SITE_URL = "https://example.test";
|
|
9
|
+
mock.module("../../disposabl-kit/features", () => ({
|
|
10
|
+
authenticationEnabled: enabled,
|
|
11
|
+
}));
|
|
12
|
+
mock.module("react-native", () => ({ Alert: { alert: mock() } }));
|
|
13
|
+
mock.module("expo-web-browser", () => ({ openBrowserAsync: open }));
|
|
14
|
+
mock.module("../../disposabl-kit/mobile/design/preferences", () => ({
|
|
15
|
+
PreferenceRow: "Row",
|
|
16
|
+
PreferenceSection: "Section",
|
|
17
|
+
PreferenceSeparator: "Separator",
|
|
18
|
+
}));
|
|
19
|
+
const { SettingsLinks } =
|
|
20
|
+
await import("../../disposabl-kit/mobile/components/settings-links");
|
|
21
|
+
let renderer;
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
await act(async () => renderer?.unmount());
|
|
24
|
+
});
|
|
25
|
+
test("delete account is linked only when authentication is enabled", async () => {
|
|
26
|
+
await act(async () => {
|
|
27
|
+
renderer = create(createElement(SettingsLinks));
|
|
28
|
+
});
|
|
29
|
+
const rows = renderer.root.findAllByType("Row");
|
|
30
|
+
const deletion = rows.find((row) => row.props.label === "Delete account");
|
|
31
|
+
if (!enabled) {
|
|
32
|
+
expect(deletion).toBeUndefined();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
expect(deletion).toBeDefined();
|
|
36
|
+
await act(async () => deletion.props.onPress());
|
|
37
|
+
expect(open).toHaveBeenCalledWith(
|
|
38
|
+
"https://example.test/legal/delete-account",
|
|
39
|
+
);
|
|
40
|
+
});
|
|
@@ -17,6 +17,9 @@ const appearance = {
|
|
|
17
17
|
}),
|
|
18
18
|
};
|
|
19
19
|
const read = mock((key) => Promise.resolve(saved.get(key) ?? null));
|
|
20
|
+
const write = mock(async (key, value) => {
|
|
21
|
+
saved.set(key, value);
|
|
22
|
+
});
|
|
20
23
|
mock.module("react-native", () => ({
|
|
21
24
|
View: "View",
|
|
22
25
|
Appearance: appearance,
|
|
@@ -37,9 +40,7 @@ mock.module("expo-router", () => ({
|
|
|
37
40
|
mock.module("expo-status-bar", () => ({ StatusBar: "StatusBar" }));
|
|
38
41
|
mock.module("expo-secure-store", () => ({
|
|
39
42
|
getItemAsync: read,
|
|
40
|
-
setItemAsync:
|
|
41
|
-
saved.set(key, value);
|
|
42
|
-
},
|
|
43
|
+
setItemAsync: write,
|
|
43
44
|
}));
|
|
44
45
|
const {
|
|
45
46
|
ThemeProvider,
|
|
@@ -65,6 +66,8 @@ beforeEach(() => {
|
|
|
65
66
|
saved.clear();
|
|
66
67
|
appearance.setColorScheme.mockClear();
|
|
67
68
|
read.mockImplementation((key) => Promise.resolve(saved.get(key) ?? null));
|
|
69
|
+
write.mockImplementation(async (key, value) => saved.set(key, value));
|
|
70
|
+
write.mockClear();
|
|
68
71
|
});
|
|
69
72
|
afterEach(async () => {
|
|
70
73
|
await act(async () => renderer?.unmount());
|
|
@@ -120,3 +123,53 @@ test("a delayed stored preference cannot replace a user's new choice", async ()
|
|
|
120
123
|
await act(async () => finish("light"));
|
|
121
124
|
expect(selection.preference).toBe("dark");
|
|
122
125
|
});
|
|
126
|
+
|
|
127
|
+
test("failed persistence leaves the visible choice but cannot survive remount", async () => {
|
|
128
|
+
write.mockImplementation(async () => {
|
|
129
|
+
throw new Error("storage unavailable");
|
|
130
|
+
});
|
|
131
|
+
await mount();
|
|
132
|
+
await act(async () => selection.setPreference("dark"));
|
|
133
|
+
expect(selection.preference).toBe("dark");
|
|
134
|
+
expect(saved.has("app-theme")).toBe(false);
|
|
135
|
+
await act(async () => renderer.unmount());
|
|
136
|
+
await mount();
|
|
137
|
+
expect(selection.preference).toBe("system");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("queued choices save in selection order even when a write is delayed", async () => {
|
|
141
|
+
let finish;
|
|
142
|
+
write.mockImplementation((key, value) => {
|
|
143
|
+
if (value === "dark")
|
|
144
|
+
return new Promise((resolve) => {
|
|
145
|
+
finish = () => {
|
|
146
|
+
saved.set(key, value);
|
|
147
|
+
resolve();
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
saved.set(key, value);
|
|
151
|
+
return Promise.resolve();
|
|
152
|
+
});
|
|
153
|
+
await mount();
|
|
154
|
+
await act(async () => selection.setPreference("dark"));
|
|
155
|
+
await act(async () => selection.setPreference("light"));
|
|
156
|
+
expect(write).toHaveBeenCalledTimes(1);
|
|
157
|
+
await act(async () => finish());
|
|
158
|
+
expect(saved.get("app-theme")).toBe("light");
|
|
159
|
+
await act(async () => renderer.unmount());
|
|
160
|
+
await mount();
|
|
161
|
+
expect(selection.preference).toBe("light");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("a read failure falls back to system without writing a replacement", async () => {
|
|
165
|
+
saved.set("app-theme", "dark");
|
|
166
|
+
read.mockImplementation((key) =>
|
|
167
|
+
key === "app-theme"
|
|
168
|
+
? Promise.reject(new Error("storage unavailable"))
|
|
169
|
+
: Promise.resolve(null),
|
|
170
|
+
);
|
|
171
|
+
await mount();
|
|
172
|
+
expect(selection.preference).toBe("system");
|
|
173
|
+
expect(saved.get("app-theme")).toBe("dark");
|
|
174
|
+
expect(write).not.toHaveBeenCalled();
|
|
175
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { afterEach, expect, mock, test } from "bun:test";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { act, create } from "react-test-renderer";
|
|
4
|
+
import { getFunctionName } from "convex/server";
|
|
5
|
+
|
|
6
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
7
|
+
const jwt = (subject) =>
|
|
8
|
+
`header.${Buffer.from(JSON.stringify({ sub: subject })).toString("base64url")}.signature`;
|
|
9
|
+
let token = jwt("alice"),
|
|
10
|
+
authenticated = true,
|
|
11
|
+
loading = false;
|
|
12
|
+
let account = { username: "alice", email: null, profile: null };
|
|
13
|
+
let user = { id: "user-a", username: "alice" };
|
|
14
|
+
let pending = null;
|
|
15
|
+
const convex = { url: "http://127.0.0.1:3540" };
|
|
16
|
+
mock.module("@convex-dev/auth/react", () => ({ useAuthToken: () => token }));
|
|
17
|
+
mock.module("convex/browser", () => ({
|
|
18
|
+
ConvexHttpClient: class {
|
|
19
|
+
setAuth() {}
|
|
20
|
+
query(reference) {
|
|
21
|
+
const name = getFunctionName(reference);
|
|
22
|
+
return pending
|
|
23
|
+
? pending[name]
|
|
24
|
+
: Promise.resolve(name === "auth:account" ? account : user);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
mock.module("convex/react", () => ({
|
|
29
|
+
useConvex: () => convex,
|
|
30
|
+
useConvexAuth: () => ({ isAuthenticated: authenticated, isLoading: loading }),
|
|
31
|
+
useQuery: () => undefined,
|
|
32
|
+
useAction: () => async () => ({
|
|
33
|
+
balance: 42,
|
|
34
|
+
hasMonthlyPlan: false,
|
|
35
|
+
checkoutNeedsReview: false,
|
|
36
|
+
customerId: "user-a",
|
|
37
|
+
}),
|
|
38
|
+
}));
|
|
39
|
+
mock.module("@tanstack/react-router", () => ({
|
|
40
|
+
createFileRoute: () => (config) => config,
|
|
41
|
+
}));
|
|
42
|
+
mock.module("../../disposabl-kit/features", () => ({ paymentsEnabled: true }));
|
|
43
|
+
const { Pricing } = await import("../../disposabl-kit/client/routes/pricing");
|
|
44
|
+
let renderer;
|
|
45
|
+
const render = async () =>
|
|
46
|
+
act(async () => {
|
|
47
|
+
renderer = create(createElement(Pricing));
|
|
48
|
+
});
|
|
49
|
+
const refresh = async () =>
|
|
50
|
+
act(async () => {
|
|
51
|
+
renderer.update(createElement(Pricing));
|
|
52
|
+
});
|
|
53
|
+
const text = () => JSON.stringify(renderer.toJSON());
|
|
54
|
+
afterEach(async () => {
|
|
55
|
+
await act(async () => renderer?.unmount());
|
|
56
|
+
token = jwt("alice");
|
|
57
|
+
authenticated = true;
|
|
58
|
+
loading = false;
|
|
59
|
+
account = { username: "alice", email: null, profile: null };
|
|
60
|
+
user = { id: "user-a", username: "alice" };
|
|
61
|
+
pending = null;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("shows the authenticated account and retains anonymous pricing", async () => {
|
|
65
|
+
await render();
|
|
66
|
+
expect(text()).toContain("Signed in as");
|
|
67
|
+
expect(text()).toContain("alice");
|
|
68
|
+
authenticated = false;
|
|
69
|
+
token = null;
|
|
70
|
+
await refresh();
|
|
71
|
+
expect(text()).toContain("Sign in");
|
|
72
|
+
expect(text()).not.toContain("alice");
|
|
73
|
+
expect(text()).not.toContain("Signed in as");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("does not show a prior account while switching or after an old response", async () => {
|
|
77
|
+
await render();
|
|
78
|
+
let resolveAccount, resolveUser;
|
|
79
|
+
pending = {
|
|
80
|
+
"auth:account": new Promise((resolve) => {
|
|
81
|
+
resolveAccount = resolve;
|
|
82
|
+
}),
|
|
83
|
+
"users/index:current": new Promise((resolve) => {
|
|
84
|
+
resolveUser = resolve;
|
|
85
|
+
}),
|
|
86
|
+
};
|
|
87
|
+
token = jwt("bob");
|
|
88
|
+
await refresh();
|
|
89
|
+
expect(text()).toContain("Loading your account");
|
|
90
|
+
expect(text()).not.toContain("alice");
|
|
91
|
+
token = jwt("charlie");
|
|
92
|
+
pending = null;
|
|
93
|
+
account = { username: "charlie", email: null, profile: null };
|
|
94
|
+
user = { id: "user-c", username: "charlie" };
|
|
95
|
+
await refresh();
|
|
96
|
+
expect(text()).toContain("charlie");
|
|
97
|
+
await act(async () => {
|
|
98
|
+
resolveAccount({ username: "bob", email: null, profile: null });
|
|
99
|
+
resolveUser({ id: "user-b", username: "bob" });
|
|
100
|
+
});
|
|
101
|
+
expect(text()).toContain("charlie");
|
|
102
|
+
expect(text()).not.toContain("bob");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("reports identity lookup failure without inventing a label", async () => {
|
|
106
|
+
pending = {
|
|
107
|
+
"auth:account": Promise.reject(new Error("offline")),
|
|
108
|
+
"users/index:current": Promise.resolve(user),
|
|
109
|
+
};
|
|
110
|
+
await render();
|
|
111
|
+
expect(text()).toContain("Your account could not be loaded");
|
|
112
|
+
expect(text()).not.toContain("Signed in as");
|
|
113
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { afterEach, expect, mock, test } from "bun:test";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { act, create } from "react-test-renderer";
|
|
4
|
+
|
|
5
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
6
|
+
const legalConfig = { appName: "Example", privacyEmail: "" };
|
|
7
|
+
mock.module("../../disposabl-kit/legal", () => ({ legalConfig }));
|
|
8
|
+
mock.module("@tanstack/react-router", () => ({
|
|
9
|
+
createFileRoute: () => (options) => ({ options }),
|
|
10
|
+
}));
|
|
11
|
+
const { Route } =
|
|
12
|
+
await import("../../disposabl-kit/client/routes/legal/support");
|
|
13
|
+
let renderer;
|
|
14
|
+
afterEach(async () => {
|
|
15
|
+
await act(async () => renderer?.unmount());
|
|
16
|
+
legalConfig.privacyEmail = "";
|
|
17
|
+
});
|
|
18
|
+
test("support shows an honest unconfigured state", async () => {
|
|
19
|
+
await act(async () => {
|
|
20
|
+
renderer = create(createElement(Route.options.component));
|
|
21
|
+
});
|
|
22
|
+
expect(JSON.stringify(renderer.toJSON())).toContain(
|
|
23
|
+
"publisher has not provided a support contact yet",
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
test("support links to the configured contact", async () => {
|
|
27
|
+
legalConfig.privacyEmail = "publisher@example.test";
|
|
28
|
+
await act(async () => {
|
|
29
|
+
renderer = create(createElement(Route.options.component));
|
|
30
|
+
});
|
|
31
|
+
expect(
|
|
32
|
+
renderer.root
|
|
33
|
+
.findAllByType("a")
|
|
34
|
+
.some((a) => a.props.href === "mailto:publisher@example.test"),
|
|
35
|
+
).toBe(true);
|
|
36
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
test("consent displays only the current authenticated account", () => {
|
|
7
|
+
const result = spawnSync(
|
|
8
|
+
process.execPath,
|
|
9
|
+
["test", join(import.meta.dirname, "components/consent-identity.test.mjs")],
|
|
10
|
+
{ encoding: "utf8", env: process.env },
|
|
11
|
+
);
|
|
12
|
+
assert.equal(result.status, 0, result.stdout + result.stderr);
|
|
13
|
+
});
|