WIP! A BB-style forum, on the ATmosphere!
We're still working... we'll be back soon when we have something to show off!
node
typescript
hono
htmx
atproto
1import { describe, it, expect, beforeEach, afterEach } from "vitest";
2import { Indexer } from "../indexer.js";
3import { createTestContext, type TestContext } from "./test-context.js";
4import { boards, categories, forums } from "@atbb/db";
5import { eq } from "drizzle-orm";
6
7describe("Indexer - Board Helpers", () => {
8 let ctx: TestContext;
9 let indexer: Indexer;
10
11 beforeEach(async () => {
12 ctx = await createTestContext();
13 indexer = new Indexer(ctx.db, ctx.logger);
14 });
15
16 afterEach(async () => {
17 // Clean up in correct FK order: boards -> categories -> forums
18 await ctx.db.delete(boards).where(eq(boards.did, "did:plc:test-forum"));
19 await ctx.cleanup();
20 });
21
22 it("getBoardIdByUri returns board ID for valid URI", async () => {
23 // Get the forum ID created by createTestContext
24 const [forum] = await ctx.db
25 .select({ id: forums.id })
26 .from(forums)
27 .where(eq(forums.did, "did:plc:test-forum"))
28 .limit(1);
29
30 // Insert test category
31 const [category] = await ctx.db.insert(categories).values({
32 did: "did:plc:test-forum",
33 rkey: "cat1",
34 cid: "bafycat",
35 name: "Test Category",
36 forumId: forum.id,
37 createdAt: new Date(),
38 indexedAt: new Date(),
39 }).returning();
40
41 // Insert test board
42 const [board] = await ctx.db.insert(boards).values({
43 did: "did:plc:test-forum",
44 rkey: "board1",
45 cid: "bafyboard",
46 name: "Test Board",
47 categoryId: category.id,
48 categoryUri: `at://did:plc:test-forum/space.atbb.forum.category/cat1`,
49 createdAt: new Date(),
50 indexedAt: new Date(),
51 }).returning();
52
53 const uri = "at://did:plc:test-forum/space.atbb.forum.board/board1";
54 const boardId = await (indexer as any).getBoardIdByUri(uri, ctx.db);
55 expect(boardId).toBe(board.id);
56 });
57
58 it("getBoardIdByUri returns null for non-existent board", async () => {
59 const uri = "at://did:plc:test-forum/space.atbb.forum.board/nonexistent";
60 const boardId = await (indexer as any).getBoardIdByUri(uri, ctx.db);
61 expect(boardId).toBeNull();
62 });
63
64 it("getCategoryIdByUri returns category ID for valid URI", async () => {
65 // Get the forum ID created by createTestContext
66 const [forum] = await ctx.db
67 .select({ id: forums.id })
68 .from(forums)
69 .where(eq(forums.did, "did:plc:test-forum"))
70 .limit(1);
71
72 // Insert test category
73 const [category] = await ctx.db.insert(categories).values({
74 did: "did:plc:test-forum",
75 rkey: "cat2",
76 cid: "bafycat2",
77 name: "Test Category 2",
78 forumId: forum.id,
79 createdAt: new Date(),
80 indexedAt: new Date(),
81 }).returning();
82
83 const uri = "at://did:plc:test-forum/space.atbb.forum.category/cat2";
84 const categoryId = await (indexer as any).getCategoryIdByUri(uri, ctx.db);
85 expect(categoryId).toBe(category.id);
86 });
87
88 it("getCategoryIdByUri returns null for non-existent category", async () => {
89 const uri = "at://did:plc:test-forum/space.atbb.forum.category/nonexistent";
90 const categoryId = await (indexer as any).getCategoryIdByUri(uri, ctx.db);
91 expect(categoryId).toBeNull();
92 });
93});