@pplethai/cli 0.8.0 → 0.10.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/dist/bin.js +126 -124
- package/package.json +1 -1
- package/templates/golden-path/.dev.vars.example +4 -3
- package/templates/golden-path/CLAUDE.md +10 -5
- package/templates/golden-path/README.md +5 -4
- package/templates/golden-path/package-lock.json +24 -8
- package/templates/golden-path/package.json +1 -1
- package/templates/golden-path/src/call-service.ts +17 -10
- package/templates/golden-path/src/dev-call-service.ts +21 -20
- package/templates/golden-path/src/dev-read-dataset.ts +23 -34
- package/templates/golden-path/src/dev-registry.ts +25 -7
- package/templates/golden-path/src/entry-name.ts +114 -0
- package/templates/golden-path/src/env.ts +2 -2
- package/templates/golden-path/src/read-dataset.ts +6 -4
- package/templates/golden-path/src/registry.ts +1 -1
- package/templates/golden-path/test/call-service.test.ts +118 -8
- package/templates/golden-path/test/dev-call-service.test.ts +201 -25
- package/templates/golden-path/test/dev-read-dataset.test.ts +52 -13
- package/templates/golden-path/test/dev-registry.test.ts +35 -6
- package/templates/golden-path/test/fixtures/overlay/catalog/entry.md +8 -0
- package/templates/golden-path/test/fixtures/overlay/election/2027/score/entry.md +11 -0
- package/templates/golden-path/test/fixtures/overlay/election/2027/score/mocks/responses.json +7 -0
- package/templates/golden-path/test/fixtures/overlay/election/results/entry.md +24 -0
- package/templates/golden-path/test/fixtures/overlay/election/results/mocks/turnout.json +1 -0
- package/templates/golden-path/test/fixtures/overlay/platform/sms/entry.md +10 -0
- package/templates/golden-path/test/fixtures/overlay/platform/sms/mocks/responses.json +7 -0
- package/templates/golden-path/test/fixtures/overlay/score/entry.md +10 -0
- package/templates/golden-path/test/fixtures/overlay/score/mocks/responses.json +7 -0
- package/templates/golden-path/test/harness.ts +1 -1
- package/templates/golden-path/test/read-dataset.test.ts +45 -12
- package/templates/golden-path/vite.config.ts +0 -18
- package/templates/golden-path/test/fixtures/overlay/shop/catalog/entry.md +0 -8
- /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/entry.md +0 -0
- /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/audience.json +0 -0
- /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/named.json +0 -0
- /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/offices.json +0 -0
- /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/roster.json +0 -0
- /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/summary.json +0 -0
- /package/templates/golden-path/test/fixtures/overlay/{shop/catalog → catalog}/mocks/responses.json +0 -0
- /package/templates/golden-path/test/fixtures/overlay/{shop/orders → orders}/entry.md +0 -0
- /package/templates/golden-path/test/fixtures/overlay/{shop/orders → orders}/mocks/responses.json +0 -0
|
@@ -20,9 +20,10 @@ const writtenAt: Record<string, unknown> = import.meta.glob("./fixtures/overlay/
|
|
|
20
20
|
|
|
21
21
|
beforeAll(() => {
|
|
22
22
|
const keys = Object.keys(overlay).join("\n");
|
|
23
|
-
expect(keys).toContain("
|
|
24
|
-
expect(keys).toContain("
|
|
25
|
-
expect(keys).toContain("
|
|
23
|
+
expect(keys).toContain("branch-list/entry.md");
|
|
24
|
+
expect(keys).toContain("branch-list/mocks/offices.json");
|
|
25
|
+
expect(keys).toContain("branch-list/mocks/summary.json");
|
|
26
|
+
expect(keys).toContain("election/results/mocks/turnout.json");
|
|
26
27
|
const offices = timeFor("mocks/offices.json");
|
|
27
28
|
expect(offices).toMatch(/^\d{4}-\d{2}-\d{2}T/);
|
|
28
29
|
});
|
|
@@ -37,7 +38,7 @@ describe("offline readDataset", () => {
|
|
|
37
38
|
],
|
|
38
39
|
});
|
|
39
40
|
expect(filtered.status).toBe(200);
|
|
40
|
-
expect(filtered.headers.get("x-pple-mock")).toBe("
|
|
41
|
+
expect(filtered.headers.get("x-pple-mock")).toBe("branch-list");
|
|
41
42
|
expect(filtered.headers.get("x-pple-error")).toBeNull();
|
|
42
43
|
expect(platformError(filtered)).toBeNull();
|
|
43
44
|
const filteredBody = await filtered.json<{ objects: { id: string }[]; next: null; sweptAt: string; snapshot: number }>();
|
|
@@ -75,8 +76,8 @@ describe("offline readDataset", () => {
|
|
|
75
76
|
const res = await read(
|
|
76
77
|
{ objectType: "offices" },
|
|
77
78
|
{
|
|
78
|
-
"/
|
|
79
|
-
"/
|
|
79
|
+
"/fixtures/overlay/branch-list/mocks/offices.json": "2024-05-01T00:00:00.000Z",
|
|
80
|
+
"/fixtures/overlay/branch-list/entry.md": "2020-01-01T00:00:00.000Z",
|
|
80
81
|
},
|
|
81
82
|
);
|
|
82
83
|
const body = await res.json<{ sweptAt: string }>();
|
|
@@ -104,7 +105,7 @@ describe("offline readDataset", () => {
|
|
|
104
105
|
|
|
105
106
|
const summary = await read({ objectType: "summary", persona: "member", userToken: undefined });
|
|
106
107
|
expect(summary.status).toBe(200);
|
|
107
|
-
expect(summary.headers.get("x-pple-mock")).toBe("
|
|
108
|
+
expect(summary.headers.get("x-pple-mock")).toBe("branch-list");
|
|
108
109
|
expect(await summary.json()).toMatchObject({ object: { title: "สรุปสาขา" } });
|
|
109
110
|
|
|
110
111
|
const summaryQuery = await read({ objectType: "summary", search: [["limit", "1"]] });
|
|
@@ -171,7 +172,7 @@ describe("offline readDataset", () => {
|
|
|
171
172
|
});
|
|
172
173
|
|
|
173
174
|
it("says no_mock for a missing entry or mock, and not_found for an unknown type", async () => {
|
|
174
|
-
const missing = await read({ entry: "
|
|
175
|
+
const missing = await read({ entry: "missing", objectType: "offices" });
|
|
175
176
|
expect(missing.status).toBe(404);
|
|
176
177
|
expect(missing.headers.get("x-pple-error")).toBe("no_mock");
|
|
177
178
|
expect(missing.headers.get("x-pple-mock")).toBeNull();
|
|
@@ -197,7 +198,44 @@ describe("offline readDataset", () => {
|
|
|
197
198
|
});
|
|
198
199
|
});
|
|
199
200
|
|
|
201
|
+
describe("offline readDataset from nested overlay folders", () => {
|
|
202
|
+
it("reads election/results from .pple/registry/election/results/", async () => {
|
|
203
|
+
const res = await read({ entry: "election/results", objectType: "turnout" });
|
|
204
|
+
expect(res.status).toBe(200);
|
|
205
|
+
expect(res.headers.get("x-pple-mock")).toBe("election/results");
|
|
206
|
+
const body = (await res.json()) as { objects: { id: string }[]; sweptAt: string };
|
|
207
|
+
expect(body.objects.map((o) => o.id)).toEqual(["a", "b"]);
|
|
208
|
+
expect(body.sweptAt).toBe(timeFor("election/results/mocks/turnout.json"));
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("does not answer a name that is only the tail of a nested path", async () => {
|
|
212
|
+
for (const entry of ["results", "election/branch-list"]) {
|
|
213
|
+
const res = await read({ entry, objectType: "turnout" });
|
|
214
|
+
expect(res.status).toBe(404);
|
|
215
|
+
expect(res.headers.get("x-pple-error")).toBe("no_mock");
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("fails only the entry a full-name DEV_REGISTRY_ERROR names", async () => {
|
|
220
|
+
const spec = "election/results=provider_unavailable";
|
|
221
|
+
const hit = await read({ entry: "election/results", objectType: "turnout", devRegistryError: spec });
|
|
222
|
+
expect(hit.status).toBe(502);
|
|
223
|
+
const other = await read({ objectType: "summary", devRegistryError: spec });
|
|
224
|
+
expect(other.status).toBe(200);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
200
228
|
describe("DEV_REGISTRY_ERROR", () => {
|
|
229
|
+
it("answers `renamed` as 410 for the full name it names, and only that one", async () => {
|
|
230
|
+
const spec = "election/results=renamed";
|
|
231
|
+
const hit = await read({ entry: "election/results", objectType: "turnout", devRegistryError: spec });
|
|
232
|
+
expect(hit.status).toBe(410);
|
|
233
|
+
expect(hit.headers.get("x-pple-error")).toBe("renamed");
|
|
234
|
+
expect(platformError(hit)).toBe("renamed");
|
|
235
|
+
const other = await read({ objectType: "summary", devRegistryError: spec });
|
|
236
|
+
expect(other.status).toBe(200);
|
|
237
|
+
});
|
|
238
|
+
|
|
201
239
|
it("returns the platform refusal before the token and the level", async () => {
|
|
202
240
|
const res = await read({
|
|
203
241
|
objectType: "roster",
|
|
@@ -214,15 +252,15 @@ describe("DEV_REGISTRY_ERROR", () => {
|
|
|
214
252
|
it("lets a per-entry code win, and accepts a dataset refusal code", async () => {
|
|
215
253
|
const specific = await read({
|
|
216
254
|
objectType: "offices",
|
|
217
|
-
devRegistryError: "not_granted,
|
|
255
|
+
devRegistryError: "not_granted, branch-list=needs_beta",
|
|
218
256
|
});
|
|
219
257
|
expect(specific.status).toBe(403);
|
|
220
258
|
expect(specific.headers.get("x-pple-error")).toBe("needs_beta");
|
|
221
259
|
|
|
222
260
|
const other = await read({
|
|
223
|
-
entry: "
|
|
261
|
+
entry: "orders",
|
|
224
262
|
objectType: "offices",
|
|
225
|
-
devRegistryError: "not_granted,
|
|
263
|
+
devRegistryError: "not_granted, branch-list=needs_beta",
|
|
226
264
|
});
|
|
227
265
|
expect(other.headers.get("x-pple-error")).toBe("not_granted");
|
|
228
266
|
|
|
@@ -234,7 +272,7 @@ describe("DEV_REGISTRY_ERROR", () => {
|
|
|
234
272
|
try {
|
|
235
273
|
const ignored = await read({
|
|
236
274
|
objectType: "summary",
|
|
237
|
-
devRegistryError: "
|
|
275
|
+
devRegistryError: "branch-list=not_a_code, not_listed",
|
|
238
276
|
});
|
|
239
277
|
expect(ignored.status).toBe(404);
|
|
240
278
|
expect(ignored.headers.get("x-pple-error")).toBe("not_listed");
|
|
@@ -262,7 +300,8 @@ function read(
|
|
|
262
300
|
times: Record<string, unknown> = writtenAt,
|
|
263
301
|
): Promise<Response> {
|
|
264
302
|
return Promise.resolve(answerOfflineDataset(overlay, times, {
|
|
265
|
-
|
|
303
|
+
overlayRoot: "fixtures/overlay/",
|
|
304
|
+
entry: "branch-list",
|
|
266
305
|
persona: "hq-staff",
|
|
267
306
|
userToken: "t",
|
|
268
307
|
...input,
|
|
@@ -49,7 +49,7 @@ describe("the emulated registry path", () => {
|
|
|
49
49
|
expect(await res.json()).toEqual({
|
|
50
50
|
call: {
|
|
51
51
|
consumer: "dev-consumer",
|
|
52
|
-
entry: "
|
|
52
|
+
entry: "branch-list",
|
|
53
53
|
identity: DEV_PERSONAS["hq-staff"],
|
|
54
54
|
},
|
|
55
55
|
path: "/offices",
|
|
@@ -81,7 +81,7 @@ describe("the emulated registry path", () => {
|
|
|
81
81
|
expect(await res.json()).toMatchObject({
|
|
82
82
|
call: {
|
|
83
83
|
consumer: "brave-purple-lion",
|
|
84
|
-
entry: "
|
|
84
|
+
entry: "branch-list",
|
|
85
85
|
identity: DEV_PERSONAS["province-coordinator"],
|
|
86
86
|
},
|
|
87
87
|
path: "/",
|
|
@@ -101,7 +101,7 @@ describe("the emulated registry path", () => {
|
|
|
101
101
|
);
|
|
102
102
|
|
|
103
103
|
expect(await res.json()).toMatchObject({
|
|
104
|
-
call: { consumer: "dev-consumer", entry: "
|
|
104
|
+
call: { consumer: "dev-consumer", entry: "branch-list", identity: null },
|
|
105
105
|
path: "/offices",
|
|
106
106
|
});
|
|
107
107
|
});
|
|
@@ -205,6 +205,35 @@ describe("the emulated registry path", () => {
|
|
|
205
205
|
expect(await res.json()).toEqual({ self: "hono", path: "/offices" });
|
|
206
206
|
});
|
|
207
207
|
|
|
208
|
+
it("routes a nested local path to a namespaced entry's handler", async () => {
|
|
209
|
+
install("2027/score");
|
|
210
|
+
install("score");
|
|
211
|
+
const h = makeHarness();
|
|
212
|
+
|
|
213
|
+
const res = await worker.fetch(
|
|
214
|
+
new Request("https://localhost/.pple/registry/2027/score/district/7?round=2"),
|
|
215
|
+
h.testEnv,
|
|
216
|
+
ctx,
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
expect(res.status).toBe(200);
|
|
220
|
+
const body = (await res.json()) as { call: { entry: string }; path: string; search: string };
|
|
221
|
+
expect(body.call.entry).toBe("2027/score");
|
|
222
|
+
expect(body.path).toBe("/district/7");
|
|
223
|
+
expect(body.search).toBe("?round=2");
|
|
224
|
+
|
|
225
|
+
const bare = await worker.fetch(new Request("https://localhost/.pple/registry/score/x"), h.testEnv, ctx);
|
|
226
|
+
expect(((await bare.json()) as { path: string }).path).toBe("/x");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("does not take a key that only shares leading text with the path", async () => {
|
|
230
|
+
install("2027/score");
|
|
231
|
+
const h = makeHarness();
|
|
232
|
+
await expect(
|
|
233
|
+
worker.fetch(new Request("https://localhost/.pple/registry/2027/scores/x"), h.testEnv, ctx),
|
|
234
|
+
).rejects.toThrow("registry handler missing");
|
|
235
|
+
});
|
|
236
|
+
|
|
208
237
|
it("answers 404 when the registry path names no entry", async () => {
|
|
209
238
|
const h = makeHarness();
|
|
210
239
|
const res = await worker.fetch(new Request("https://localhost/.pple/registry/"), h.testEnv, ctx);
|
|
@@ -291,7 +320,7 @@ describe("callRegistry", () => {
|
|
|
291
320
|
expect(res.status).toBe(200);
|
|
292
321
|
expect(await res.json()).toEqual({
|
|
293
322
|
consumer: "brave-purple-lion",
|
|
294
|
-
entry: "
|
|
323
|
+
entry: "branch-list",
|
|
295
324
|
identity: DEV_PERSONAS["province-coordinator"],
|
|
296
325
|
});
|
|
297
326
|
if (!seen.request) throw new Error("handler did not run");
|
|
@@ -329,7 +358,7 @@ describe("callRegistry", () => {
|
|
|
329
358
|
expect(await res.json()).toEqual({
|
|
330
359
|
call: {
|
|
331
360
|
consumer: "brave-purple-lion",
|
|
332
|
-
entry: "
|
|
361
|
+
entry: "branch-list",
|
|
333
362
|
identity: null,
|
|
334
363
|
},
|
|
335
364
|
method: "POST",
|
|
@@ -352,7 +381,7 @@ describe("callRegistry", () => {
|
|
|
352
381
|
|
|
353
382
|
expect(await res.json()).toEqual({
|
|
354
383
|
consumer: "from-env",
|
|
355
|
-
entry: "
|
|
384
|
+
entry: "branch-list",
|
|
356
385
|
identity: DEV_PERSONAS.delegate,
|
|
357
386
|
});
|
|
358
387
|
expect(path).toBe("/items");
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: dataset
|
|
3
|
+
visibility: private
|
|
4
|
+
namespace: election
|
|
5
|
+
description: ผลเลือกตั้งสำหรับทดสอบ
|
|
6
|
+
level: public
|
|
7
|
+
objectTypes:
|
|
8
|
+
turnout:
|
|
9
|
+
shape: collection
|
|
10
|
+
cadence: 1d
|
|
11
|
+
id: id
|
|
12
|
+
index: []
|
|
13
|
+
schema:
|
|
14
|
+
type: object
|
|
15
|
+
properties:
|
|
16
|
+
id:
|
|
17
|
+
type: string
|
|
18
|
+
votes:
|
|
19
|
+
type: integer
|
|
20
|
+
required:
|
|
21
|
+
- id
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
ผลเลือกตั้งสำหรับทดสอบออฟไลน์
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[{ "id": "a", "votes": 10 }, { "id": "b", "votes": 20 }]
|
|
@@ -36,7 +36,7 @@ export interface Fakes {
|
|
|
36
36
|
/** Handles POST {NOTIFY_API_BASE}/notifications */
|
|
37
37
|
notify?: (req: Request) => Response | Promise<Response>;
|
|
38
38
|
/**
|
|
39
|
-
* Handles `{PPLE_SERVICES_URL}/<
|
|
39
|
+
* Handles `{PPLE_SERVICES_URL}/<name>/…` for `callService` and
|
|
40
40
|
* `readDataset`. Answer as the platform, or refuse with `serviceRefusal`
|
|
41
41
|
* and any `x-pple-error` code.
|
|
42
42
|
*/
|
|
@@ -38,7 +38,7 @@ describe("readDataset", () => {
|
|
|
38
38
|
env,
|
|
39
39
|
);
|
|
40
40
|
|
|
41
|
-
const result = await readDataset(h.testEnv, "
|
|
41
|
+
const result = await readDataset(h.testEnv, "branch-list", "offices", {
|
|
42
42
|
userToken: "user-token",
|
|
43
43
|
filter: { province: "เชียงใหม่", seats: { gte: 4, lt: 9 }, status: ["open", "closed"] },
|
|
44
44
|
sort: "-seats",
|
|
@@ -59,7 +59,7 @@ describe("readDataset", () => {
|
|
|
59
59
|
});
|
|
60
60
|
expect(seen).toEqual({ authorization: "Bearer app-key", userToken: "user-token" });
|
|
61
61
|
const url = new URL(`https://services.test${h.calls.services[0]?.path ?? ""}`);
|
|
62
|
-
expect(url.pathname).toBe("/
|
|
62
|
+
expect(url.pathname).toBe("/branch-list/offices");
|
|
63
63
|
expect(url.searchParams.get("province")).toBe("เชียงใหม่");
|
|
64
64
|
expect(url.searchParams.get("seats[gte]")).toBe("4");
|
|
65
65
|
expect(url.searchParams.get("seats[lt]")).toBe("9");
|
|
@@ -87,7 +87,7 @@ describe("readDataset", () => {
|
|
|
87
87
|
env,
|
|
88
88
|
);
|
|
89
89
|
|
|
90
|
-
const result = await readDataset(h.testEnv, "
|
|
90
|
+
const result = await readDataset(h.testEnv, "branch-list", "offices", {
|
|
91
91
|
id: "branch-b",
|
|
92
92
|
fetchImpl: h.fetchImpl,
|
|
93
93
|
});
|
|
@@ -100,7 +100,7 @@ describe("readDataset", () => {
|
|
|
100
100
|
sweptAt: SWEPT,
|
|
101
101
|
snapshot: 3,
|
|
102
102
|
});
|
|
103
|
-
expect(h.calls.services[0]?.path).toBe("/
|
|
103
|
+
expect(h.calls.services[0]?.path).toBe("/branch-list/offices/branch-b");
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
it("reads a singleton", async () => {
|
|
@@ -110,7 +110,7 @@ describe("readDataset", () => {
|
|
|
110
110
|
},
|
|
111
111
|
env,
|
|
112
112
|
);
|
|
113
|
-
const result = await readDataset(h.testEnv, "
|
|
113
|
+
const result = await readDataset(h.testEnv, "branch-list", "summary", {
|
|
114
114
|
shape: "singleton",
|
|
115
115
|
fetchImpl: h.fetchImpl,
|
|
116
116
|
});
|
|
@@ -118,7 +118,7 @@ describe("readDataset", () => {
|
|
|
118
118
|
ok: true,
|
|
119
119
|
data: { object: { title: "สรุปสาขา" }, sweptAt: SWEPT, snapshot: 1 },
|
|
120
120
|
});
|
|
121
|
-
expect(h.calls.services[0]?.path).toBe("/
|
|
121
|
+
expect(h.calls.services[0]?.path).toBe("/branch-list/summary");
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
it("reads platform refusals from x-pple-error", async () => {
|
|
@@ -128,6 +128,7 @@ describe("readDataset", () => {
|
|
|
128
128
|
["level_not_met", 403],
|
|
129
129
|
["not_granted", 403],
|
|
130
130
|
["user_token_invalid", 401],
|
|
131
|
+
["renamed", 410],
|
|
131
132
|
["no_mock", 404],
|
|
132
133
|
] as const;
|
|
133
134
|
let next = serviceRefusal("not_found", 404);
|
|
@@ -135,7 +136,7 @@ describe("readDataset", () => {
|
|
|
135
136
|
|
|
136
137
|
for (const [code, status] of codes) {
|
|
137
138
|
next = serviceRefusal(code, status);
|
|
138
|
-
const result = await readDataset(h.testEnv, "
|
|
139
|
+
const result = await readDataset(h.testEnv, "branch-list", "offices", {
|
|
139
140
|
userToken: "t",
|
|
140
141
|
fetchImpl: h.fetchImpl,
|
|
141
142
|
});
|
|
@@ -169,7 +170,7 @@ describe("readDataset", () => {
|
|
|
169
170
|
env,
|
|
170
171
|
);
|
|
171
172
|
|
|
172
|
-
const result = await readDataset(h.testEnv, "
|
|
173
|
+
const result = await readDataset(h.testEnv, "branch-list", "offices", {
|
|
173
174
|
limit: 1,
|
|
174
175
|
follow: true,
|
|
175
176
|
fetchImpl: h.fetchImpl,
|
|
@@ -192,23 +193,55 @@ describe("readDataset", () => {
|
|
|
192
193
|
]);
|
|
193
194
|
});
|
|
194
195
|
|
|
196
|
+
it("reads a bare name and a full name, building services.<domain>/<full name>/…", async () => {
|
|
197
|
+
const fetchImpl = vi.fn<typeof fetch>(async () =>
|
|
198
|
+
Response.json({ objects: [], next: null, sweptAt: null, snapshot: null }),
|
|
199
|
+
);
|
|
200
|
+
await readDataset(env, "branch-list", "offices", { id: "b-1", fetchImpl });
|
|
201
|
+
await readDataset(env, "election/score", "turnout", { fetchImpl });
|
|
202
|
+
await readDataset(env, "election/2027/score", "turnout", { id: "u-1", fetchImpl });
|
|
203
|
+
expect(fetchImpl.mock.calls.map((call) => String(call[0]))).toEqual([
|
|
204
|
+
"https://services.test/branch-list/offices/b-1",
|
|
205
|
+
"https://services.test/election/score/turnout",
|
|
206
|
+
"https://services.test/election/2027/score/turnout/u-1",
|
|
207
|
+
]);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("takes platform/<x> as a full name, and rejects any name the validator refuses", async () => {
|
|
211
|
+
const fetchImpl = vi.fn<typeof fetch>(async () =>
|
|
212
|
+
Response.json({ objects: [], next: null, sweptAt: null, snapshot: null }),
|
|
213
|
+
);
|
|
214
|
+
await readDataset(env, "platform/turnout", "districts", { fetchImpl });
|
|
215
|
+
expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/platform/turnout/districts");
|
|
216
|
+
|
|
217
|
+
fetchImpl.mockClear();
|
|
218
|
+
await expect(readDataset(env, "Election/score", "offices", { fetchImpl })).rejects.toThrow(
|
|
219
|
+
/is not an entry name/,
|
|
220
|
+
);
|
|
221
|
+
await expect(readDataset(env, "health", "offices", { fetchImpl })).rejects.toThrow(/reserved/);
|
|
222
|
+
await expect(readDataset(env, "platform", "offices", { fetchImpl })).rejects.toThrow(
|
|
223
|
+
/"platform" belongs to the platform/,
|
|
224
|
+
);
|
|
225
|
+
expect(fetchImpl).not.toHaveBeenCalled();
|
|
226
|
+
});
|
|
227
|
+
|
|
195
228
|
it("uses the injected fetch under vitest, including when a persona is set", async () => {
|
|
196
229
|
const fetchImpl = vi.fn<typeof fetch>(async () =>
|
|
197
230
|
Response.json({ objects: [], next: null, sweptAt: null, snapshot: null }),
|
|
198
231
|
);
|
|
199
232
|
const result = await readDataset(
|
|
200
233
|
{ ...env, DEV_PERSONA: "hq-staff", DEV_REGISTRY_ERROR: "not_granted" },
|
|
201
|
-
"
|
|
234
|
+
"branch-list",
|
|
202
235
|
"offices",
|
|
203
236
|
{ fetchImpl },
|
|
204
237
|
);
|
|
205
238
|
expect(result).toMatchObject({ ok: true, data: { objects: [], next: null, sweptAt: null } });
|
|
206
239
|
expect(fetchImpl).toHaveBeenCalledOnce();
|
|
207
|
-
expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/
|
|
240
|
+
expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/branch-list/offices");
|
|
208
241
|
|
|
209
|
-
await expect(readDataset(env, "
|
|
242
|
+
await expect(readDataset(env, "branch-list", "offices")).rejects.toThrow(/injected fetch/);
|
|
210
243
|
await expect(
|
|
211
|
-
readDataset({ DEV_PERSONA: "none" }, "
|
|
244
|
+
readDataset({ DEV_PERSONA: "none" }, "branch-list", "offices", { fetchImpl }),
|
|
212
245
|
).rejects.toThrow(/PPLE_SERVICES_URL/);
|
|
213
246
|
});
|
|
214
247
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
1
|
import { cloudflare } from "@cloudflare/vite-plugin";
|
|
3
2
|
import react from "@vitejs/plugin-react";
|
|
4
3
|
import { defineConfig } from "vite";
|
|
@@ -10,21 +9,4 @@ import { overlayMtimePlugin } from "./overlay-mtime.mjs";
|
|
|
10
9
|
// single origin, so no CORS or proxy config is needed.
|
|
11
10
|
export default defineConfig({
|
|
12
11
|
plugins: [overlayMtimePlugin(), react(), cloudflare()],
|
|
13
|
-
resolve: {
|
|
14
|
-
alias: [
|
|
15
|
-
// @pplethai/components ships a "development" export condition pointing at
|
|
16
|
-
// its (unpublished) source, which Vite would otherwise pick during dev
|
|
17
|
-
// and fail to resolve. Pin the bare import to the built entry; the
|
|
18
|
-
// /styles.css and /form subpaths still resolve normally.
|
|
19
|
-
{
|
|
20
|
-
find: /^@pplethai\/components$/,
|
|
21
|
-
replacement: fileURLToPath(
|
|
22
|
-
new URL(
|
|
23
|
-
"./node_modules/@pplethai/components/dist/index.js",
|
|
24
|
-
import.meta.url,
|
|
25
|
-
),
|
|
26
|
-
),
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
12
|
});
|
/package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/entry.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/templates/golden-path/test/fixtures/overlay/{shop/catalog → catalog}/mocks/responses.json
RENAMED
|
File without changes
|
|
File without changes
|
/package/templates/golden-path/test/fixtures/overlay/{shop/orders → orders}/mocks/responses.json
RENAMED
|
File without changes
|