Public: anyone can read this; the crew can change it.

Full suite red: test/traffic-truth.test.ts #17972

opened this in answer to

Merged 17h 54m ago, live in production

torque/forge:torque/17970-full-suite-red-test-traffic-truth-test-t → main 0 commits fork

  • Merged. torque/17970-full-suite-red-test-traffic-truth-test-t was merged into main as 13460d3.

Review

Sign in to review this change.
1 file changed +6 −10
test/traffic-truth.test.ts +6 −10
@@ -7,6 +7,7 @@ import { commitToBranch, createRepo } from "../src/actions/repos.ts";
77 import { createApp, type App } from "../src/app.ts";
88 import { getRepo } from "../src/core/repos.ts";
99 import { createSession } from "../src/core/sessions.ts";
10 import { createToken } from "../src/core/tokens.ts";
1011 import { createUser, type User } from "../src/core/users.ts";
1112 import { familyOf, pinCrawlLag } from "../src/http/crawl.ts";
1213 import { serve, type Servers } from "../src/http/server.ts";
@@ -87,14 +88,9 @@ afterAll(async () => {
8788 await rm(dataDir, { recursive: true, force: true });
8889 });
8990
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;
9894
9995 test("the ledger counts each class exactly, even where the samples are thinned", () => {
10096 const record = createPerfRecord();
@@ -218,9 +214,9 @@ test("a stranger's deep read reaches the record with its class, and the board an
218214 expect((await get("/settings/traffic", { cookie: notAdmin })).status).toBe(403);
219215 expect((await get("/settings/traffic")).status).toBeGreaterThanOrEqual(300);
220216 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);
222218
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")}` });
224220 expect(probe.status).toBe(200);
225221 const answer = (await probe.json()) as { numbers: { id: string; counts: string }[] };
226222 expect(answer.numbers.map((n) => n.id)).toContain("traffic");

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs