hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { api, contractBaseUrl, expectPage, isLive, json, loginAdmin, SKIP_MESSAGE } from "./helpers/live-client"; |
| 2 | |
| 3 | if (!isLive) console.warn(SKIP_MESSAGE); |
| 4 | |
| 5 | // The insights and podcast doors stand in front of an AI service the scratch |
| 6 | // backend does not have to be running. So every assertion here is written to |
| 7 | // hold in both worlds: the reads answer their DTO either way (they only serve |
| 8 | // stored rows), and the detached writes are allowed to answer 503 — what they |
| 9 | // may never do is 500, or invent a receipt they did not queue. |
| 10 | describe.skipIf(!isLive)(`ai contract @ ${contractBaseUrl}`, () => { |
| 11 | beforeAll(loginAdmin); |
| 12 | |
| 13 | it("answers the caller's own insight with every section present", async () => { |
| 14 | const insight = await json<Record<string, unknown>>("/insights/me"); |
| 15 | expect(typeof insight.user_id).toBe("string"); |
| 16 | // Arrays, never null: an absent section and an empty one are different |
| 17 | // claims, and the client renders them differently. |
| 18 | expect(Array.isArray(insight.attention)).toBe(true); |
| 19 | expect(Array.isArray(insight.cards)).toBe(true); |
| 20 | expect(Array.isArray(insight.segments)).toBe(true); |
| 21 | // `summary` is null until ZEKA has computed this caller at least once. |
| 22 | expect(insight.summary === null || typeof insight.summary === "object").toBe(true); |
| 23 | }); |
| 24 | |
| 25 | it("pages the run ledger for a manager+ caller", async () => { |
| 26 | expectPage(await json("/insights/runs?limit=1")); |
| 27 | }); |
| 28 | |
| 29 | it("keeps a run row's counters and pending list on the documented shape", async () => { |
| 30 | const page = await json<{ items: Record<string, unknown>[] }>("/insights/runs?limit=1"); |
| 31 | const run = page.items[0]; |
| 32 | if (!run) return; // A backend that has never swept has no row to check. |
| 33 | expect(typeof run.run_day).toBe("string"); |
| 34 | expect(["running", "ok", "partial", "failed", "skipped"]).toContain(run.status); |
| 35 | expect(typeof run.students_total).toBe("number"); |
| 36 | expect(typeof run.budget_exceeded).toBe("boolean"); |
| 37 | expect(Array.isArray(run.pending_students)).toBe(true); |
| 38 | expect(Array.isArray(run.failed_modules)).toBe(true); |
| 39 | }); |
| 40 | |
| 41 | it("either queues a school-wide recompute or refuses it for want of a service", async () => { |
| 42 | const response = await api("/insights/refresh", { method: "POST", body: {} }); |
| 43 | expect([202, 503]).toContain(response.status); |
| 44 | if (response.status === 202) { |
| 45 | // Documented receipt is `{status: "accepted"}` only: the work's own |
| 46 | // record is ZEKA's (zeka_run), so no message row id is minted here. |
| 47 | const receipt = (await response.json()) as Record<string, unknown>; |
| 48 | expect(receipt.status).toBe("accepted"); |
| 49 | } |
| 50 | }); |
| 51 | |
| 52 | it("refuses a podcast job for an unknown source without pretending to queue it", async () => { |
| 53 | const response = await api("/podcast/jobs", { |
| 54 | method: "POST", |
| 55 | body: { source_id: "00000000-0000-0000-0000-000000000000" }, |
| 56 | }); |
| 57 | // 503 with no service, 400/404 for a malformed or unresolvable id, and the |
| 58 | // backend's documented 409 `source_missing` when the note has no narratable |
| 59 | // PDF on this host (a nonexistent note lands there too, by design). A 202 |
| 60 | // here would mean the backend minted a job for nothing. |
| 61 | expect([400, 404, 409, 503]).toContain(response.status); |
| 62 | }); |
| 63 | |
| 64 | it("answers nothing for an audio job id that is not the caller's", async () => { |
| 65 | // The stream is addressed by job id and resolved from the caller's own job |
| 66 | // row, so a caller cannot name a file at all — an unknown id is a 404, and |
| 67 | // never bytes. (The old `?path=` door, which took a client-supplied path |
| 68 | // and answered 400 on escape, is gone.) |
| 69 | const response = await api(`/podcast/jobs/${encodeURIComponent("00000000-0000-0000-0000-000000000000")}/audio`); |
| 70 | expect([404, 503]).toContain(response.status); |
| 71 | }); |
| 72 | }); |