@pplethai/cli 0.21.0 → 0.23.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.
Files changed (117) hide show
  1. package/README.md +12 -14
  2. package/dist/bin.js +102 -102
  3. package/package.json +3 -6
  4. package/templates/golden-path/.dev.vars.example +0 -33
  5. package/templates/golden-path/.env.example +0 -10
  6. package/templates/golden-path/.github/workflows/ci.yml +0 -22
  7. package/templates/golden-path/AGENTS.md +0 -1
  8. package/templates/golden-path/CLAUDE.md +0 -187
  9. package/templates/golden-path/README.md +0 -118
  10. package/templates/golden-path/gitignore +0 -17
  11. package/templates/golden-path/index.html +0 -16
  12. package/templates/golden-path/migrations/0001_init.sql +0 -10
  13. package/templates/golden-path/overlay-mtime.mjs +0 -30
  14. package/templates/golden-path/package-lock.json +0 -4318
  15. package/templates/golden-path/package.json +0 -41
  16. package/templates/golden-path/scripts/assert-dev-compiled-out.mjs +0 -45
  17. package/templates/golden-path/shared/api.ts +0 -325
  18. package/templates/golden-path/src/auth.ts +0 -230
  19. package/templates/golden-path/src/call-service.ts +0 -147
  20. package/templates/golden-path/src/dataset-query.ts +0 -470
  21. package/templates/golden-path/src/dataset-schema.ts +0 -398
  22. package/templates/golden-path/src/db.ts +0 -32
  23. package/templates/golden-path/src/dev-call-service.ts +0 -392
  24. package/templates/golden-path/src/dev-personas.ts +0 -186
  25. package/templates/golden-path/src/dev-read-dataset.ts +0 -444
  26. package/templates/golden-path/src/dev-registry.ts +0 -294
  27. package/templates/golden-path/src/email.ts +0 -224
  28. package/templates/golden-path/src/entry-name.ts +0 -114
  29. package/templates/golden-path/src/env.ts +0 -38
  30. package/templates/golden-path/src/files.ts +0 -38
  31. package/templates/golden-path/src/identity-header.ts +0 -17
  32. package/templates/golden-path/src/index.ts +0 -276
  33. package/templates/golden-path/src/legal-identity.ts +0 -180
  34. package/templates/golden-path/src/levels.ts +0 -132
  35. package/templates/golden-path/src/notification-response.ts +0 -55
  36. package/templates/golden-path/src/notify.ts +0 -311
  37. package/templates/golden-path/src/payment.ts +0 -554
  38. package/templates/golden-path/src/read-dataset.ts +0 -490
  39. package/templates/golden-path/src/registry.ts +0 -128
  40. package/templates/golden-path/src/vite-env.d.ts +0 -27
  41. package/templates/golden-path/test/apply-migrations.ts +0 -4
  42. package/templates/golden-path/test/call-service.test.ts +0 -288
  43. package/templates/golden-path/test/dev-call-service.test.ts +0 -455
  44. package/templates/golden-path/test/dev-read-dataset.test.ts +0 -379
  45. package/templates/golden-path/test/dev-registry.test.ts +0 -404
  46. package/templates/golden-path/test/effective-sub.test.ts +0 -101
  47. package/templates/golden-path/test/email-offline.test.ts +0 -51
  48. package/templates/golden-path/test/email.test.ts +0 -117
  49. package/templates/golden-path/test/env.d.ts +0 -17
  50. package/templates/golden-path/test/fixtures/overlay/branch-list/entry.md +0 -85
  51. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/audience.json +0 -3
  52. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/named.json +0 -3
  53. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/offices.json +0 -6
  54. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/roster.json +0 -3
  55. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/summary.json +0 -1
  56. package/templates/golden-path/test/fixtures/overlay/catalog/entry.md +0 -8
  57. package/templates/golden-path/test/fixtures/overlay/catalog/mocks/responses.json +0 -7
  58. package/templates/golden-path/test/fixtures/overlay/election/2027/score/entry.md +0 -11
  59. package/templates/golden-path/test/fixtures/overlay/election/2027/score/mocks/responses.json +0 -7
  60. package/templates/golden-path/test/fixtures/overlay/election/results/entry.md +0 -24
  61. package/templates/golden-path/test/fixtures/overlay/election/results/mocks/turnout.json +0 -1
  62. package/templates/golden-path/test/fixtures/overlay/orders/entry.md +0 -12
  63. package/templates/golden-path/test/fixtures/overlay/orders/mocks/responses.json +0 -36
  64. package/templates/golden-path/test/fixtures/overlay/platform/email/entry.md +0 -12
  65. package/templates/golden-path/test/fixtures/overlay/platform/email/mocks/responses.json +0 -11
  66. package/templates/golden-path/test/fixtures/overlay/platform/legal-identity/entry.md +0 -8
  67. package/templates/golden-path/test/fixtures/overlay/platform/legal-identity/mocks/responses.json +0 -13
  68. package/templates/golden-path/test/fixtures/overlay/platform/payments/entry.md +0 -12
  69. package/templates/golden-path/test/fixtures/overlay/platform/payments/mocks/responses.json +0 -71
  70. package/templates/golden-path/test/fixtures/overlay/platform/sms/entry.md +0 -10
  71. package/templates/golden-path/test/fixtures/overlay/platform/sms/mocks/responses.json +0 -7
  72. package/templates/golden-path/test/fixtures/overlay/score/entry.md +0 -10
  73. package/templates/golden-path/test/fixtures/overlay/score/mocks/responses.json +0 -7
  74. package/templates/golden-path/test/harness.ts +0 -153
  75. package/templates/golden-path/test/interaction.test.ts +0 -230
  76. package/templates/golden-path/test/legal-identity.test.ts +0 -323
  77. package/templates/golden-path/test/membership.test.ts +0 -105
  78. package/templates/golden-path/test/notification-response.test.ts +0 -79
  79. package/templates/golden-path/test/payment-app.test.ts +0 -210
  80. package/templates/golden-path/test/payment-offline.test.ts +0 -91
  81. package/templates/golden-path/test/payment.test.ts +0 -427
  82. package/templates/golden-path/test/payments-offline.ts +0 -33
  83. package/templates/golden-path/test/read-dataset.test.ts +0 -387
  84. package/templates/golden-path/test/service-call.test.ts +0 -166
  85. package/templates/golden-path/test/smoke.test.ts +0 -464
  86. package/templates/golden-path/tsconfig.json +0 -20
  87. package/templates/golden-path/tsconfig.worker.json +0 -21
  88. package/templates/golden-path/vite.config.ts +0 -12
  89. package/templates/golden-path/vitest.config.ts +0 -28
  90. package/templates/golden-path/web/App.tsx +0 -478
  91. package/templates/golden-path/web/app.css +0 -83
  92. package/templates/golden-path/web/main.tsx +0 -51
  93. package/templates/golden-path/web/pple.ts +0 -124
  94. package/templates/golden-path/web/vite-env.d.ts +0 -10
  95. package/templates/golden-path/wrangler.jsonc +0 -89
  96. package/templates/payment-bridge/.github/workflows/ci.yml +0 -21
  97. package/templates/payment-bridge/CLAUDE.md +0 -9
  98. package/templates/payment-bridge/README.md +0 -57
  99. package/templates/payment-bridge/docs/verify-webhook.md +0 -80
  100. package/templates/payment-bridge/docs/verify-webhook.ts +0 -29
  101. package/templates/payment-bridge/gitignore +0 -5
  102. package/templates/payment-bridge/package-lock.json +0 -4198
  103. package/templates/payment-bridge/package.json +0 -21
  104. package/templates/payment-bridge/src/bridge-key.ts +0 -18
  105. package/templates/payment-bridge/src/env.ts +0 -14
  106. package/templates/payment-bridge/src/index.ts +0 -39
  107. package/templates/payment-bridge/src/platform.ts +0 -49
  108. package/templates/payment-bridge/src/webhook.ts +0 -86
  109. package/templates/payment-bridge/test/docs.test.ts +0 -9
  110. package/templates/payment-bridge/test/fixtures/payments-responses.json +0 -71
  111. package/templates/payment-bridge/test/harness.ts +0 -78
  112. package/templates/payment-bridge/test/inbound.test.ts +0 -138
  113. package/templates/payment-bridge/test/webhook.test.ts +0 -174
  114. package/templates/payment-bridge/tsconfig.json +0 -22
  115. package/templates/payment-bridge/vitest.config.ts +0 -8
  116. package/templates/payment-bridge/wrangler.jsonc +0 -15
  117. package/templates/payment-bridge.version +0 -1
@@ -1,79 +0,0 @@
1
- // How to test a Notification Response handler (docs/adr/0035). The platform
2
- // wrapper hands your handler the parsed event and your env, so a test calls
3
- // `notificationResponse` on the default export directly with a sample event.
4
- // There is no request to build and no secret to send. The wrapper's own work
5
- // (the status mapping, 404 for no handler) is the platform's, not yours to test.
6
-
7
- import { afterEach, describe, expect, it } from "vitest";
8
- import worker from "../src/index";
9
- import type { NotificationResponseEvent } from "../src/notification-response";
10
- import { makeHarness, testExecutionContext } from "./harness";
11
-
12
- const sample = (overrides: Partial<NotificationResponseEvent> = {}): NotificationResponseEvent => ({
13
- type: "notification.response",
14
- id: "clx1",
15
- notificationId: "clw1",
16
- ref: "leave:123",
17
- app: { slug: "leave-request" },
18
- responder: { sub: "sub-1" },
19
- action: "reject",
20
- values: { note: "ไม่ว่าง" },
21
- respondedAt: "2026-11-10T07:03:00.000Z",
22
- attempt: 1,
23
- ...overrides,
24
- });
25
-
26
- afterEach(() => {
27
- delete worker.notificationResponse;
28
- });
29
-
30
- describe("a Notification Response handler", () => {
31
- it("is not defined until you add one, which the platform answers with 404 so answers keep coming", () => {
32
- expect(worker.notificationResponse).toBeUndefined();
33
- });
34
-
35
- it("is called with the event, and counts an answer once however often it is delivered", async () => {
36
- const decisions = new Map<string, string>();
37
- worker.notificationResponse = async (event) => {
38
- // At-least-once delivery: the same id may come again, so key on it.
39
- if (decisions.has(event.id)) return;
40
- decisions.set(event.id, `${event.ref}:${event.action}`);
41
- };
42
- const h = makeHarness();
43
- const ctx = testExecutionContext();
44
-
45
- // Returning nothing is a 204: delivered.
46
- expect(await worker.notificationResponse(sample(), h.testEnv, ctx)).toBeUndefined();
47
- await worker.notificationResponse(sample({ attempt: 2 }), h.testEnv, ctx);
48
-
49
- expect([...decisions]).toEqual([["clx1", "leave:123:reject"]]);
50
- });
51
-
52
- it("can opt out of answers by returning a 410", async () => {
53
- worker.notificationResponse = () => new Response(null, { status: 410 });
54
- const h = makeHarness();
55
-
56
- const result = await worker.notificationResponse(sample(), h.testEnv, testExecutionContext());
57
-
58
- expect((result as Response).status).toBe(410);
59
- });
60
-
61
- it("can leave slow work to waitUntil, after the answer is acknowledged", async () => {
62
- const background: Promise<unknown>[] = [];
63
- const ctx = { ...testExecutionContext(), waitUntil: (p: Promise<unknown>) => void background.push(p) };
64
- let notified = false;
65
- worker.notificationResponse = (_event, _env, handlerCtx) => {
66
- handlerCtx.waitUntil(
67
- (async () => {
68
- notified = true;
69
- })(),
70
- );
71
- };
72
- const h = makeHarness();
73
-
74
- await worker.notificationResponse(sample(), h.testEnv, ctx as unknown as ExecutionContext);
75
- await Promise.all(background);
76
-
77
- expect(notified).toBe(true);
78
- });
79
- });
@@ -1,210 +0,0 @@
1
- // A fresh template app takes a fake payment end to end, offline (ADR-0037,
2
- // ADR-0026): the Payer asks the app for a Payment, is sent to the Checkout
3
- // address, and the platform calls `payment()` when it is paid, which verifies
4
- // the event and stops there: issuing a legal Receipt is the Builder's decision,
5
- // never a default (see "the two patterns" below). The platform is the registry's own mocks,
6
- // as the signed-in Persona. Offline there is no Checkout Page and no platform
7
- // callback, so this stands in for both: it hands the handler the event the
8
- // platform would send. A real checkout is a deployed Beta app's.
9
-
10
- import { describe, expect, it } from "vitest";
11
- import { createPaymentHandler } from "../src/index";
12
- import { issueReceipt, paymentHandler, rejectPayment, verifyPaymentEvent, type PaymentPaidEvent, type PaymentReceiptIssuedEvent } from "../src/payment";
13
- import { makeHarness, testExecutionContext } from "./harness";
14
- import { offlinePayments } from "./payments-offline";
15
-
16
- const SERVICES = { PPLE_SERVICES_URL: "https://services.test", PPLE_APP_KEY: "app-key" };
17
-
18
- const post = (body: unknown) => ({
19
- method: "POST",
20
- headers: { "content-type": "application/json" },
21
- body: JSON.stringify(body),
22
- });
23
-
24
- /** What the platform sends when `pay_offline-mock` is paid. */
25
- const PAID_EVENT: PaymentPaidEvent = {
26
- type: "payment.paid",
27
- id: "evt_1",
28
- payment: {
29
- id: "pay_offline-mock",
30
- kind: "donation",
31
- amountSatang: 50_000,
32
- description: "รายการทดสอบ",
33
- reference: "offline-mock",
34
- mode: "test",
35
- },
36
- payer: { name: "บุคคลทดสอบ หนึ่ง", maskedCitizenId: "x-xxxx-xxxxx-xx-0" },
37
- voucher: { number: "TEST-PV-000001", nameTh: "…", isReceipt: false },
38
- paidAt: "2026-01-01T00:00:00.000Z",
39
- };
40
-
41
- describe("a fresh template app, offline", () => {
42
- it.each(["hq-staff", "member", "kyc-verified-nonmember", "delegate"])(
43
- "takes a donation as %s: create, pay, verified, and no Receipt issued until the app decides",
44
- async (persona) => {
45
- const h = makeHarness({ services: offlinePayments(persona) }, { ...SERVICES, DEV_PERSONA: persona });
46
-
47
- // 1. The Payer asks for a Payment and gets the address to pay at.
48
- const created = await h.request("/api/payments", post({ amountSatang: 50_000 }));
49
- expect(created.status).toBe(201);
50
- const { id, checkoutUrl } = (await created.json()) as { id: string; checkoutUrl: string };
51
- expect(id).toBe("pay_offline-mock");
52
- expect(checkoutUrl).toMatch(/^https:\/\//);
53
-
54
- // 2. Paid: the platform calls `payment()`. The handler verifies and does not issue:
55
- // a legal Receipt is the Builder's decision, so a fresh app never issues one by default (P4).
56
- const handler = createPaymentHandler({ fetchImpl: h.fetchImpl });
57
- expect(await handler(PAID_EVENT, h.testEnv, testExecutionContext())).toBeUndefined();
58
- expect(h.calls.services.map((c) => `${c.method} ${c.path}`)).toEqual([
59
- "POST /platform/payments",
60
- "GET /platform/payments/pay_offline-mock",
61
- ]);
62
-
63
- // 3. The app can read the Payment back for its page.
64
- const read = await h.request(`/api/payments/${id}`);
65
- expect(read.status).toBe(200);
66
- expect(await read.json()).toMatchObject({ payment: { state: "paid", mode: "test" } });
67
- },
68
- );
69
-
70
- it.each(["hq-staff", "member", "kyc-verified-nonmember", "delegate"])(
71
- "sends %s to checkout with a Checkout Pass when they tap to pay (ADR-0043)",
72
- async (persona) => {
73
- const h = makeHarness({ services: offlinePayments(persona) }, { ...SERVICES, DEV_PERSONA: persona });
74
-
75
- // The Payer taps to pay: the app mints a pass now, not at create time.
76
- const res = await h.request("/api/payments/pay_offline-mock/checkout", { method: "POST" });
77
-
78
- expect(res.status).toBe(201);
79
- expect(await res.json()).toEqual({ checkoutUrl: "https://pay.example.invalid/pay_offline-mock", pass: "offline-mock-pass" });
80
- expect(h.calls.services.map((c) => `${c.method} ${c.path}`)).toEqual([
81
- "POST /platform/payments/pay_offline-mock/checkout-pass",
82
- ]);
83
- },
84
- );
85
-
86
- it("sends the Payer's own token with the pass call, and no other call carries it", async () => {
87
- const tokens: Record<string, string | null> = {};
88
- const h = makeHarness(
89
- {
90
- services: (req) => {
91
- tokens[new URL(req.url).pathname] = req.headers.get("x-pple-user-token");
92
- return Response.json({ checkoutUrl: "https://pay.example.test/pay_1", pass: "p" }, { status: 201 });
93
- },
94
- },
95
- { ...SERVICES, DEV_PERSONA: "member" },
96
- );
97
- const res = await h.request("/api/payments/pay_1/checkout", { method: "POST" }, "payer-token");
98
-
99
- expect(res.status).toBe(201);
100
- expect(tokens).toEqual({ "/platform/payments/pay_1/checkout-pass": "payer-token" });
101
- });
102
-
103
- it("tells the Payer when the Payment belongs to someone else (409)", async () => {
104
- const h = makeHarness(
105
- { services: () => Response.json({ error: "payment_tied_to_another_payer" }, { status: 409 }) },
106
- { ...SERVICES, DEV_PERSONA: "member" },
107
- );
108
-
109
- const res = await h.request("/api/payments/pay_1/checkout", { method: "POST" });
110
-
111
- expect(res.status).toBe(409);
112
- expect(await res.json()).toEqual({ error: "not_your_payment" });
113
- });
114
-
115
- // The Checkout Page turns an unverified Payer away, so the app says so first.
116
- // The mocks cannot: the Service never sees who is signed in.
117
- it.each(["unverified", "kyc-pending"])("does not start a payment for %s: they must verify first", async (persona) => {
118
- const h = makeHarness({ services: offlinePayments(persona) }, { ...SERVICES, DEV_PERSONA: persona });
119
-
120
- const res = await h.request("/api/payments", post({ amountSatang: 50_000 }));
121
-
122
- expect(res.status).toBe(403);
123
- expect(await res.json()).toEqual({ error: "kyc_required" });
124
- expect(h.calls.services).toEqual([]);
125
- });
126
-
127
- it("refuses an amount that is not a positive whole number of satang", async () => {
128
- const h = makeHarness({ services: offlinePayments("hq-staff") }, SERVICES);
129
-
130
- for (const amountSatang of [0, -5, 10.5, "100", null]) {
131
- const res = await h.request("/api/payments", post({ amountSatang }));
132
- expect(res.status).toBe(400);
133
- }
134
- expect(h.calls.services).toEqual([]);
135
- });
136
-
137
- describe("the two patterns, which a Builder writes into their own `payment` handler", () => {
138
- // The same helpers, wired the way payments.md shows. The template's default
139
- // handler is neither: it only verifies.
140
- it("issue at payment: verify the event, then issue the Receipt", async () => {
141
- const h = makeHarness({ services: offlinePayments("hq-staff") }, SERVICES);
142
- const handler = paymentHandler({
143
- "payment.paid": async (event, env) => {
144
- const verified = await verifyPaymentEvent(env, event, h.fetchImpl);
145
- if (!verified.ok) return verified.reason === "mismatch" ? undefined : new Response(null, { status: 503 });
146
- const issued = await issueReceipt(env, event.payment.id, h.fetchImpl);
147
- if (!issued.ok && issued.reason !== "not_paid") return new Response(null, { status: 503 });
148
- },
149
- });
150
-
151
- expect(await handler(PAID_EVENT, h.testEnv, testExecutionContext())).toBeUndefined();
152
- expect(h.calls.services.map((c) => `${c.method} ${c.path}`)).toEqual([
153
- "GET /platform/payments/pay_offline-mock",
154
- "POST /platform/payments/pay_offline-mock/receipt",
155
- ]);
156
- });
157
-
158
- it("verify first: the app's own check decides between issuing and rejecting", async () => {
159
- const h = makeHarness({ services: offlinePayments("hq-staff") }, SERVICES);
160
- const outcome = (stockOk: boolean) =>
161
- paymentHandler({
162
- "payment.paid": async (event, env) => {
163
- const verified = await verifyPaymentEvent(env, event, h.fetchImpl);
164
- if (!verified.ok) return verified.reason === "mismatch" ? undefined : new Response(null, { status: 503 });
165
- if (stockOk) await issueReceipt(env, event.payment.id, h.fetchImpl);
166
- else await rejectPayment(env, event.payment.id, h.fetchImpl);
167
- },
168
- });
169
-
170
- await outcome(true)(PAID_EVENT, h.testEnv, testExecutionContext());
171
- await outcome(false)(PAID_EVENT, h.testEnv, testExecutionContext());
172
- expect(h.calls.services.map((c) => c.path.split("/").pop())).toEqual(["pay_offline-mock", "receipt", "pay_offline-mock", "reject"]);
173
- });
174
- });
175
-
176
- it("does not issue a Receipt for an event the platform does not agree with", async () => {
177
- const h = makeHarness({ services: offlinePayments("hq-staff") }, SERVICES);
178
- const forged = { ...PAID_EVENT, payment: { ...PAID_EVENT.payment, amountSatang: 99_999_900 } };
179
-
180
- const handler = createPaymentHandler({ fetchImpl: h.fetchImpl });
181
-
182
- // Answered 2xx so it is not retried, and nothing was issued.
183
- expect(await handler(forged, h.testEnv, testExecutionContext())).toBeUndefined();
184
- expect(h.calls.services.map((c) => c.method)).toEqual(["GET"]);
185
- });
186
-
187
- it("is told to try again when the platform cannot be reached, so the Receipt is not lost", async () => {
188
- const h = makeHarness({ services: () => new Response(null, { status: 502 }) }, SERVICES);
189
-
190
- const handler = createPaymentHandler({ fetchImpl: h.fetchImpl });
191
-
192
- const answer = await handler(PAID_EVENT, h.testEnv, testExecutionContext());
193
- expect((answer as Response).status).toBe(503);
194
- });
195
-
196
- it("ignores the other outcomes, and the next time the handler hears of a Receipt it only acknowledges", async () => {
197
- const h = makeHarness({ services: offlinePayments("hq-staff") }, SERVICES);
198
- const handler = createPaymentHandler({ fetchImpl: h.fetchImpl });
199
- const issued = {
200
- type: "payment.receipt_issued",
201
- id: "evt_receipt_issued_rcp_1",
202
- payment: PAID_EVENT.payment,
203
- payer: PAID_EVENT.payer!,
204
- receipt: { id: "rcp_1", number: "TEST-2569-000001", isTest: true, issuedAt: "2026-01-01T00:00:00.000Z", replaces: null },
205
- } satisfies PaymentReceiptIssuedEvent;
206
-
207
- expect(await handler(issued, h.testEnv, testExecutionContext())).toBeUndefined();
208
- expect(h.calls.services).toEqual([]);
209
- });
210
- });
@@ -1,91 +0,0 @@
1
- // Offline payments (ADR-0026, docs/adr/0037). The registry's own mocks for
2
- // `platform/payments` (registry/payments/mocks/responses.json) are the
3
- // answers `npm run dev` gives, as the signed-in Persona. This drives the real
4
- // files through the same matcher a Builder's `callService` uses offline, with
5
- // the helpers on top, so what the Skill promises is what runs.
6
- //
7
- // There is no Checkout Page or Gateway offline: the Payment is simply paid.
8
-
9
- import { describe, expect, it } from "vitest";
10
- import { DEV_PERSONAS } from "../src/dev-personas";
11
- import { createCheckoutPass, createPayment, getPayment, issueReceipt, rejectPayment } from "../src/payment";
12
- import { offlinePayments } from "./payments-offline";
13
-
14
- /** `callService` as `npm run dev` runs it for this Persona. */
15
- const offlineAs =
16
- (persona: string): typeof fetch =>
17
- async (input, init) =>
18
- offlinePayments(persona)(new Request(input as RequestInfo, init));
19
-
20
- const env = { PPLE_SERVICES_URL: "https://services.test", PPLE_APP_KEY: "k", DEV_PERSONA: "none" };
21
- const INPUT = {
22
- kind: "donation" as const,
23
- amountSatang: 50_000,
24
- description: "บริจาค",
25
- reference: "order-1",
26
- returnUrl: "http://localhost:5173/thanks",
27
- };
28
-
29
- // The entry is `userToken: none`, so the Service never sees who is signed in
30
- // and the registry refuses a Persona on its mocks. Every Persona gets the same
31
- // answers: the Payer got through checkout. Whether a Persona may start a
32
- // payment at all is the app's own gate on `actor.kyc.verified`
33
- // (test/payment-app.test.ts), which is where the platform's KYC rule is
34
- // visible to a Builder offline.
35
- const personas = Object.keys(DEV_PERSONAS);
36
-
37
- describe("offline payments", () => {
38
- it("covers Personas that are and are not KYC-verified", () => {
39
- const kyc = personas.map((name) => DEV_PERSONAS[name]!.actor.kyc.verified);
40
- expect(kyc).toContain(true);
41
- expect(kyc).toContain(false);
42
- });
43
-
44
- it.each([...personas, "intern"])("%s: a Payment is created, paid, receipted and can be rejected", async (persona) => {
45
- const fetchImpl = offlineAs(persona);
46
-
47
- const created = await createPayment(env, INPUT, fetchImpl);
48
- expect(created).toMatchObject({ ok: true, id: "pay_offline-mock", state: "created" });
49
-
50
- const read = await getPayment(env, "pay_offline-mock", fetchImpl);
51
- expect(read).toMatchObject({ ok: true, payment: { state: "paid", mode: "test", receipt: null } });
52
- if (!read.ok) throw new Error("unreachable");
53
- // The Voucher says it is not a receipt, and the Payer is masked.
54
- expect(read.payment.voucher).toMatchObject({ isReceipt: false });
55
- expect(read.payment.payer?.maskedCitizenId).toMatch(/x/);
56
-
57
- expect(await issueReceipt(env, "pay_offline-mock", fetchImpl)).toMatchObject({
58
- ok: true,
59
- issuedNow: true,
60
- receipt: { isTest: true, number: expect.stringMatching(/^TEST-/) },
61
- });
62
- expect(await rejectPayment(env, "pay_offline-mock", fetchImpl)).toMatchObject({
63
- ok: true,
64
- payment: { state: "refunded", refund: { status: "refunded" } },
65
- });
66
- });
67
-
68
- // A signed-in Payer's app mints a pass the Checkout Page would redeem
69
- // (ADR-0043). Offline there is no Checkout Page: the mock answers the address.
70
- it.each([...personas, "intern"])("%s: a Checkout Pass is minted and answers an address to go to", async (persona) => {
71
- const fetchImpl = offlineAs(persona);
72
-
73
- const pass = await createCheckoutPass(env, "pay_offline-mock", "payer-token", fetchImpl);
74
-
75
- expect(pass).toEqual({ ok: true, checkoutUrl: expect.stringMatching(/^https:\/\/.+\/pay_offline-mock$/), pass: "offline-mock-pass" });
76
- });
77
-
78
- it("mints a pass with no token while a Persona is signed in, as `npm run dev` does", async () => {
79
- // `npm run dev` signs the Payer in as the Persona and sends no PPLE ID token,
80
- // so a blank token is fine offline and refused against the real platform.
81
- const fetchImpl = offlineAs("member");
82
-
83
- expect(await createCheckoutPass({ ...env, DEV_PERSONA: "member" }, "pay_offline-mock", "", fetchImpl)).toMatchObject({
84
- ok: true,
85
- });
86
- expect(await createCheckoutPass(env, "pay_offline-mock", "", fetchImpl)).toEqual({
87
- ok: false,
88
- reason: "user_token_invalid",
89
- });
90
- });
91
- });