feat: enhance testing capabilities and introduce new components for question management. Add testing section in AGENTS.md with instructions for running tests and configuring the test environment. Update package.json files to include test scripts and integrate @electric-sql/pglite for in-memory database testing. Introduce CalloutCard and update FilterBar and SoalBrowser components to support visibility filters for private and public questions. Implement new test cases for various functionalities across the application.
92a1d83 | import { describe, expect, it } from "bun:test"; | |
| import { TRPCError } from "@trpc/server"; | |
| import { assertOwnership } from "../ownership"; | |
| describe("assertOwnership", () => { | |
| const userId = "user-123"; | |
| it("throws NOT_FOUND when row is null", () => { | |
| try { | |
| assertOwnership(null, userId); | |
| expect.unreachable("Should have thrown"); | |
| } catch (err) { | |
| expect(err).toBeInstanceOf(TRPCError); | |
| expect((err as TRPCError).code).toBe("NOT_FOUND"); | |
| expect((err as TRPCError).message).toBe("Resource not found"); | |
| } | |
| }); | |
| it("throws NOT_FOUND when row is undefined", () => { | |
| try { | |
| assertOwnership(undefined, userId); | |
| expect.unreachable("Should have thrown"); | |
| } catch (err) { | |
| expect(err).toBeInstanceOf(TRPCError); | |
| expect((err as TRPCError).code).toBe("NOT_FOUND"); | |
| } | |
| }); | |
| it("throws NOT_FOUND with custom resource name", () => { | |
| try { | |
| assertOwnership(null, userId, "Question"); | |
| expect.unreachable("Should have thrown"); | |
| } catch (err) { | |
| expect(err).toBeInstanceOf(TRPCError); | |
| expect((err as TRPCError).code).toBe("NOT_FOUND"); | |
| expect((err as TRPCError).message).toBe("Question not found"); | |
| } | |
| }); | |
| it("throws FORBIDDEN when creatorUserId does not match", () => { | |
| try { | |
| assertOwnership({ creatorUserId: "other-user" }, userId); | |
| expect.unreachable("Should have thrown"); | |
| } catch (err) { | |
| expect(err).toBeInstanceOf(TRPCError); | |
| expect((err as TRPCError).code).toBe("FORBIDDEN"); | |
| } | |
| }); | |
| it("throws FORBIDDEN when creatorUserId is null and userId is provided", () => { | |
| try { | |
| assertOwnership({ creatorUserId: null }, userId); | |
| expect.unreachable("Should have thrown"); | |
| } catch (err) { | |
| expect(err).toBeInstanceOf(TRPCError); | |
| expect((err as TRPCError).code).toBe("FORBIDDEN"); | |
| } | |
| }); | |
| it("does not throw when creatorUserId matches userId", () => { | |
| expect(() => assertOwnership({ creatorUserId: userId }, userId)).not.toThrow(); | |
| }); | |
| }); | |