Public: anyone can read this; the crew can change it.
A test pins app-note moderation: a banned visitor's notes leave the app's list, and unbanning brings them back #6809
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6792-a-test-pins-app-note-moderation-a-banned → main 1 commit fork
1 file
changed +84
−0
test/app-notes-moderation.test.ts added +84
| @@ -0,0 +1,84 @@ | ||
| 1 | /** | |
| 2 | * Moderation of the notes visitors leave in an app (`core/app_notes.ts`): | |
| 3 | * hide one note, ban a sender (their notes leave the owner's list, only for | |
| 4 | * that app), unban (the ban lifts; notes hidden with it stay hidden, as the | |
| 5 | * module documents), and the limits that cap each list. | |
| 6 | */ | |
| 7 | import { beforeEach, describe, expect, test } from "bun:test"; | |
| 8 | import { Database } from "bun:sqlite"; | |
| 9 | import migration from "../src/core/migrations/20261022130000-app-notes.ts"; | |
| 10 | import { | |
| 11 | banVisitor, | |
| 12 | bannedNotes, | |
| 13 | hideNote, | |
| 14 | insertNote, | |
| 15 | isBanned, | |
| 16 | notesOf, | |
| 17 | notesOfApp, | |
| 18 | unbanVisitor, | |
| 19 | } from "../src/core/app_notes.ts"; | |
| 20 | ||
| 21 | let db: Database; | |
| 22 | const add = (appId: string, visitor: string, n: number) => | |
| 23 | insertNote(db, { appId, repoId: "r", issueNumber: n, visitor, name: `n${n}` }); | |
| 24 | ||
| 25 | beforeEach(() => { | |
| 26 | db = new Database(":memory:"); | |
| 27 | db.exec(migration); | |
| 28 | }); | |
| 29 | ||
| 30 | describe("app note moderation", () => { | |
| 31 | test("notesOfApp lists the app's notes and none of another app's", () => { | |
| 32 | add("a", "v1", 1); | |
| 33 | add("a", "v2", 2); | |
| 34 | add("b", "v1", 3); | |
| 35 | expect(notesOfApp(db, "a").map((n) => n.issueNumber).sort()).toEqual([1, 2]); | |
| 36 | expect(notesOfApp(db, "b").map((n) => n.issueNumber)).toEqual([3]); | |
| 37 | }); | |
| 38 | ||
| 39 | test("hideNote removes one note from the app list and the visitor's own list", () => { | |
| 40 | const first = add("a", "v1", 1); | |
| 41 | add("a", "v1", 2); | |
| 42 | add("a", "v2", 3); | |
| 43 | hideNote(db, first.id); | |
| 44 | expect(notesOfApp(db, "a").map((n) => n.issueNumber).sort()).toEqual([2, 3]); | |
| 45 | expect(notesOf(db, "a", "v1").map((n) => n.issueNumber)).toEqual([2]); | |
| 46 | }); | |
| 47 | ||
| 48 | test("banVisitor hides that visitor's notes on that app only; unbanVisitor lifts the ban", () => { | |
| 49 | add("a", "v1", 1); | |
| 50 | const latest = add("a", "v1", 2); | |
| 51 | add("a", "v2", 3); | |
| 52 | add("b", "v1", 4); | |
| 53 | banVisitor(db, "a", "v1"); | |
| 54 | expect(isBanned(db, "a", "v1")).toBe(true); | |
| 55 | expect(isBanned(db, "b", "v1")).toBe(false); | |
| 56 | expect(notesOfApp(db, "a").map((n) => n.issueNumber)).toEqual([3]); | |
| 57 | expect(notesOf(db, "a", "v1")).toEqual([]); | |
| 58 | expect(notesOfApp(db, "b").map((n) => n.issueNumber)).toEqual([4]); | |
| 59 | // each banned sender once, as their latest note; other apps list none | |
| 60 | expect(bannedNotes(db, "a").map((n) => n.id)).toEqual([latest.id]); | |
| 61 | expect(bannedNotes(db, "b")).toEqual([]); | |
| 62 | ||
| 63 | unbanVisitor(db, "a", "v1"); | |
| 64 | expect(isBanned(db, "a", "v1")).toBe(false); | |
| 65 | expect(bannedNotes(db, "a")).toEqual([]); | |
| 66 | // the notes hidden with the ban stay hidden; new ones show | |
| 67 | expect(notesOfApp(db, "a").map((n) => n.issueNumber)).toEqual([3]); | |
| 68 | add("a", "v1", 5); | |
| 69 | expect(notesOfApp(db, "a").map((n) => n.issueNumber).sort()).toEqual([3, 5]); | |
| 70 | }); | |
| 71 | ||
| 72 | test("the limit arguments cap each list", () => { | |
| 73 | for (let i = 1; i <= 4; i++) add("a", "v1", i); | |
| 74 | add("a", "v2", 5); | |
| 75 | add("a", "v3", 6); | |
| 76 | banVisitor(db, "a", "v2"); | |
| 77 | banVisitor(db, "a", "v3"); | |
| 78 | add("a", "v1", 7); | |
| 79 | expect(notesOfApp(db, "a", 2)).toHaveLength(2); | |
| 80 | expect(notesOf(db, "a", "v1", 3)).toHaveLength(3); | |
| 81 | expect(bannedNotes(db, "a", 1)).toHaveLength(1); | |
| 82 | expect(bannedNotes(db, "a")).toHaveLength(2); | |
| 83 | }); | |
| 84 | }); |
new above
offline