this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(firehose): added transactions between tests

ansxor e0f0bde3 8da03676

+23 -8
+23 -8
apps/firehose/tests/firehose.test.ts
··· 1 - import { test, expect, beforeAll, afterAll } from "bun:test"; 1 + import { test, expect, beforeAll, afterAll, beforeEach, afterEach } from "bun:test"; 2 2 import { setupTestDb, teardownTestDb } from "db/test-utils"; 3 3 import type { InferOutput } from "@atcute/lexicons/validations"; 4 4 import { loop } from "../index"; ··· 6 6 import type { CaAnsxorCatnipTrack } from "lexicon/atcute-lexicon"; 7 7 8 8 let db: Awaited<ReturnType<typeof setupTestDb>>; 9 + let txDb: typeof db; 10 + let rollback: () => void; 9 11 10 12 beforeAll(async () => { 11 13 db = await setupTestDb(); ··· 13 15 14 16 afterAll(async () => { 15 17 await teardownTestDb(); 18 + }); 19 + 20 + beforeEach(async () => { 21 + await new Promise<void>((resolveSetup) => { 22 + let rejectTx: (err: Error) => void; 23 + db.transaction(async (tx) => { 24 + txDb = tx as unknown as typeof db; 25 + resolveSetup(); 26 + await new Promise<void>((_, reject) => { 27 + rejectTx = reject; 28 + }); 29 + }).catch(() => {}); 30 + rollback = () => rejectTx(new Error("rollback")); 31 + }); 32 + }); 33 + 34 + afterEach(() => { 35 + rollback(); 16 36 }); 17 37 18 38 function mockSubscription( ··· 59 79 }, 60 80 }; 61 81 62 - test("can query tracks", async () => { 63 - const tracks = await db.query.tracks.findMany(); 64 - expect(tracks).toEqual([]); 65 - }); 66 - 67 82 test("inserts track from create commit event", async () => { 68 83 const subscription = mockSubscription([createTrackEvent]); 69 - await loop(subscription, db); 84 + await loop(subscription, txDb); 70 85 71 - const tracks = await db.query.tracks.findMany(); 86 + const tracks = await txDb.query.tracks.findMany(); 72 87 expect(tracks).toHaveLength(1); 73 88 const track = tracks[0]; 74 89 expect(track).not.toBeUndefined();