From b2b72bc6a8c8e57ca70bb86823a58054977f435c Mon Sep 17 00:00:00 2001 From: Harish V Date: Fri, 20 Dec 2024 23:33:03 +0800 Subject: [PATCH] add tests for list site --- .../site/__tests__/site.router.test.ts | 26 +++++++++++++++++++ .../tests/integration/helpers/seed/index.ts | 3 +++ 2 files changed, 29 insertions(+) diff --git a/apps/studio/src/server/modules/site/__tests__/site.router.test.ts b/apps/studio/src/server/modules/site/__tests__/site.router.test.ts index 31ee44b986..249809a182 100644 --- a/apps/studio/src/server/modules/site/__tests__/site.router.test.ts +++ b/apps/studio/src/server/modules/site/__tests__/site.router.test.ts @@ -128,6 +128,32 @@ describe("site.router", async () => { }, ]) }) + + it("should only return sites if the permissions are not deleted for the site", async () => { + const { site: site1 } = await setupSite() + const { site: site2 } = await setupSite() + await setupAdminPermissions({ + userId: session.userId, + siteId: site1.id, + isDeleted: true, + }) + await setupAdminPermissions({ + userId: session.userId, + siteId: site2.id, + }) + + // Act + const result = await caller.list() + + // Assert + expect(result).toEqual([ + { + id: site2.id, + name: site2.name, + config: site2.config, + }, + ]) + }) }) describe("getSiteName", () => { diff --git a/apps/studio/tests/integration/helpers/seed/index.ts b/apps/studio/tests/integration/helpers/seed/index.ts index eeb70c3dc8..eaa3b028ab 100644 --- a/apps/studio/tests/integration/helpers/seed/index.ts +++ b/apps/studio/tests/integration/helpers/seed/index.ts @@ -9,9 +9,11 @@ import { nanoid } from "nanoid" export const setupAdminPermissions = async ({ userId, siteId, + isDeleted = false, }: { userId?: string siteId: number + isDeleted?: boolean }) => { if (!userId) throw new Error("userId is a required field") @@ -22,6 +24,7 @@ export const setupAdminPermissions = async ({ siteId, role: RoleType.Admin, resourceId: null, + deletedAt: isDeleted ? new Date() : null, }) .execute() }