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
4
fork

Configure Feed

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

test(appview): improve DELETE /api/admin/boards/:id test coverage (ATB-45)

Malpercio a0601e3f f8340280

+49 -7
+49 -7
apps/appview/src/routes/__tests__/admin.test.ts
··· 1943 1943 expect(res.status).toBe(200); 1944 1944 const data = await res.json(); 1945 1945 expect(data.success).toBe(true); 1946 - expect(mockDeleteRecord).toHaveBeenCalledWith( 1947 - expect.objectContaining({ 1948 - repo: ctx.config.forumDid, 1949 - collection: "space.atbb.forum.board", 1950 - rkey: "tid-test-board", 1951 - }) 1952 - ); 1946 + expect(mockDeleteRecord).toHaveBeenCalledWith({ 1947 + repo: ctx.config.forumDid, 1948 + collection: "space.atbb.forum.board", 1949 + rkey: "tid-test-board", 1950 + }); 1953 1951 }); 1954 1952 1955 1953 it("returns 409 when board has posts → deleteRecord NOT called", async () => { ··· 1990 1988 }); 1991 1989 1992 1990 expect(res.status).toBe(400); 1991 + const data = await res.json(); 1992 + expect(data.error).toContain("Invalid board ID"); 1993 1993 expect(mockDeleteRecord).not.toHaveBeenCalled(); 1994 1994 }); 1995 1995 ··· 2002 2002 const data = await res.json(); 2003 2003 expect(data.error).toContain("Board not found"); 2004 2004 expect(mockDeleteRecord).not.toHaveBeenCalled(); 2005 + }); 2006 + 2007 + it("returns 503 when board lookup query fails", async () => { 2008 + const dbSelectSpy = vi.spyOn(ctx.db, "select").mockImplementationOnce(() => { 2009 + throw new Error("DB connection lost"); 2010 + }); 2011 + 2012 + const res = await app.request(`/api/admin/boards/${boardId}`, { 2013 + method: "DELETE", 2014 + }); 2015 + 2016 + expect(res.status).toBe(503); 2017 + const data = await res.json(); 2018 + expect(data.error).toContain("Please try again later"); 2019 + expect(mockDeleteRecord).not.toHaveBeenCalled(); 2020 + 2021 + dbSelectSpy.mockRestore(); 2022 + }); 2023 + 2024 + it("returns 503 when post count query fails", async () => { 2025 + const originalSelect = ctx.db.select.bind(ctx.db); 2026 + let callCount = 0; 2027 + const dbSelectSpy = vi.spyOn(ctx.db, "select").mockImplementation((...args: any[]) => { 2028 + callCount++; 2029 + if (callCount === 1) { 2030 + // First call: board lookup — pass through to real DB 2031 + return (originalSelect as any)(...args); 2032 + } 2033 + // Second call: post count preflight — throw DB error 2034 + throw new Error("DB connection lost"); 2035 + }); 2036 + 2037 + const res = await app.request(`/api/admin/boards/${boardId}`, { 2038 + method: "DELETE", 2039 + }); 2040 + 2041 + expect(res.status).toBe(503); 2042 + const data = await res.json(); 2043 + expect(data.error).toContain("Please try again later"); 2044 + expect(mockDeleteRecord).not.toHaveBeenCalled(); 2045 + 2046 + dbSelectSpy.mockRestore(); 2005 2047 }); 2006 2048 2007 2049 it("returns 401 when unauthenticated", async () => {