Public: anyone can read this; the crew can change it.
Full suite red: test/traffic-truth.test.ts #17972
Merged 17h 54m ago, live in production
torque/forge:torque/17970-full-suite-red-test-traffic-truth-test-t → main 0 commits fork
1 file
changed +6
−10
test/traffic-truth.test.ts +6 −10
| @@ -7,6 +7,7 @@ import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | ||
| 7 | 7 | import { createApp, type App } from "../src/app.ts"; |
| 8 | 8 | import { getRepo } from "../src/core/repos.ts"; |
| 9 | 9 | import { createSession } from "../src/core/sessions.ts"; |
| 10 | import { createToken } from "../src/core/tokens.ts"; | |
| 10 | 11 | import { createUser, type User } from "../src/core/users.ts"; |
| 11 | 12 | import { familyOf, pinCrawlLag } from "../src/http/crawl.ts"; |
| 12 | 13 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -87,14 +88,9 @@ afterAll(async () => { | ||
| 87 | 88 | await rm(dataDir, { recursive: true, force: true }); |
| 88 | 89 | }); |
| 89 | 90 | |
| 90 | const mintToken = async (username: string, scope: string): Promise<string> => { | |
| 91 | const res = await fetch(`${servers.url}/api/v1/tokens`, { | |
| 92 | method: "POST", | |
| 93 | headers: { "content-type": "application/json" }, | |
| 94 | body: JSON.stringify({ adminConfirm: scope === "admin", username, password: PASSWORD, name: "t", scope }), | |
| 95 | }); | |
| 96 | return ((await res.json()) as { token: string }).token; | |
| 97 | }; | |
| 91 | // A token straight from the core: the HTTP route hashes a password per mint, which is the cost this | |
| 92 | // test is not about. | |
| 93 | const mintToken = (user: User, scope: "ro" | "admin"): string => createToken(app.db, user.id, "t", scope).token; | |
| 98 | 94 | |
| 99 | 95 | test("the ledger counts each class exactly, even where the samples are thinned", () => { |
| 100 | 96 | const record = createPerfRecord(); |
| @@ -218,9 +214,9 @@ test("a stranger's deep read reaches the record with its class, and the board an | ||
| 218 | 214 | expect((await get("/settings/traffic", { cookie: notAdmin })).status).toBe(403); |
| 219 | 215 | expect((await get("/settings/traffic")).status).toBeGreaterThanOrEqual(300); |
| 220 | 216 | expect((await get("/api/v1/admin/kpis/probe")).status).toBe(404); |
| 221 | expect((await get("/api/v1/admin/kpis/probe", { authorization: `Bearer ${await mintToken("bob", "read")}` })).status).toBe(404); | |
| 217 | expect((await get("/api/v1/admin/kpis/probe", { authorization: `Bearer ${mintToken(bob, "ro")}` })).status).toBe(403); | |
| 222 | 218 | |
| 223 | const probe = await get("/api/v1/admin/kpis/probe", { authorization: `Bearer ${await mintToken("alice", "admin")}` }); | |
| 219 | const probe = await get("/api/v1/admin/kpis/probe", { authorization: `Bearer ${mintToken(alice, "admin")}` }); | |
| 224 | 220 | expect(probe.status).toBe(200); |
| 225 | 221 | const answer = (await probe.json()) as { numbers: { id: string; counts: string }[] }; |
| 226 | 222 | expect(answer.numbers.map((n) => n.id)).toContain("traffic"); |
new above
offline