From a4dab0da1e32c9b62a10727d5c870fbe40a7c2d0 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Mon, 16 Dec 2024 09:54:42 +0900 Subject: [PATCH] chore: fixing tests --- tests/__mocks__/valid-configuration.json | 23 +++++++++++++++++- tests/configuration.test.ts | 8 ++++++- tests/main.test.ts | 30 +++++++++++++++++++----- tests/start.test.ts | 6 ----- 4 files changed, 53 insertions(+), 14 deletions(-) diff --git a/tests/__mocks__/valid-configuration.json b/tests/__mocks__/valid-configuration.json index a3e8bc1d..39807ebd 100644 --- a/tests/__mocks__/valid-configuration.json +++ b/tests/__mocks__/valid-configuration.json @@ -10,5 +10,26 @@ "assignedIssueScope": "org", "emptyWalletText": "Please set your wallet address with the /wallet command first and try again.", "rolesWithReviewAuthority": ["OWNER", "ADMIN", "MEMBER"], - "requiredLabelsToStart": ["Priority: 1 (Normal)", "Priority: 2 (Medium)", "Priority: 3 (High)", "Priority: 4 (Urgent)", "Priority: 5 (Emergency)"] + "requiredLabelsToStart": [ + { + "name": "Priority: 1 (Normal)", + "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + }, + { + "name": "Priority: 2 (Medium)", + "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + }, + { + "name": "Priority: 3 (High)", + "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + }, + { + "name": "Priority: 4 (Urgent)", + "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + }, + { + "name": "Priority: 5 (Emergency)", + "roles": ["admin", "member", "contributor", "owner", "billing_manager"] + } + ] } diff --git a/tests/configuration.test.ts b/tests/configuration.test.ts index 0b17148c..5364bc88 100644 --- a/tests/configuration.test.ts +++ b/tests/configuration.test.ts @@ -2,7 +2,13 @@ import { Value } from "@sinclair/typebox/value"; import { AssignedIssueScope, PluginSettings, pluginSettingsSchema, Role } from "../src/types"; import cfg from "./__mocks__/valid-configuration.json"; -const PRIORITY_LABELS = ["Priority: 1 (Normal)", "Priority: 2 (Medium)", "Priority: 3 (High)", "Priority: 4 (Urgent)", "Priority: 5 (Emergency)"]; +const PRIORITY_LABELS = [ + { name: "Priority: 1 (Normal)" }, + { name: "Priority: 2 (Medium)" }, + { name: "Priority: 3 (High)" }, + { name: "Priority: 4 (Urgent)" }, + { name: "Priority: 5 (Emergency)" }, +]; describe("Configuration tests", () => { it("Should decode the configuration", () => { diff --git a/tests/main.test.ts b/tests/main.test.ts index b49c61a3..4f7bccf5 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -20,8 +20,26 @@ type PayloadSender = Context["payload"]["sender"]; const octokit = jest.requireActual("@octokit/rest"); const TEST_REPO = "ubiquity/test-repo"; -const PRIORITY_ONE = "Priority: 1 (Normal)"; -const PRIORITY_LABELS = [PRIORITY_ONE, "Priority: 2 (Medium)", "Priority: 3 (High)", "Priority: 4 (Urgent)", "Priority: 5 (Emergency)"]; +const PRIORITY_ONE = { name: "Priority: 1 (Normal)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }; +const PRIORITY_LABELS = [ + PRIORITY_ONE, + { + name: "Priority: 2 (Medium)", + roles: ["admin", "member", "contributor", "owner", "billing_manager"], + }, + { + name: "Priority: 3 (High)", + roles: ["admin", "member", "contributor", "owner", "billing_manager"], + }, + { + name: "Priority: 4 (Urgent)", + roles: ["admin", "member", "contributor", "owner", "billing_manager"], + }, + { + name: "Priority: 5 (Emergency)", + roles: ["admin", "member", "contributor", "owner", "billing_manager"], + }, +]; beforeAll(() => { server.listen(); @@ -288,9 +306,9 @@ describe("User start/stop", () => { const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender; const context = createContext(issue, sender, "/start", "1", false, [ - "Priority: 3 (High)", - "Priority: 4 (Urgent)", - "Priority: 5 (Emergency)", + { name: "Priority: 3 (High)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }, + { name: "Priority: 4 (Urgent)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }, + { name: "Priority: 5 (Emergency)", roles: ["admin", "member", "contributor", "owner", "billing_manager"] }, ]) as Context<"issue_comment.created">; context.adapters = createAdapters(getSupabase(), context); @@ -664,7 +682,7 @@ export function createContext( body = "/start", appId: string | null = "1", startRequiresWallet = false, - requiredLabelsToStart: string[] = PRIORITY_LABELS + requiredLabelsToStart = PRIORITY_LABELS ): Context { return { adapters: {} as ReturnType, diff --git a/tests/start.test.ts b/tests/start.test.ts index 6012d77b..3d08a9b8 100644 --- a/tests/start.test.ts +++ b/tests/start.test.ts @@ -24,12 +24,6 @@ afterEach(() => { afterAll(() => server.close()); -beforeEach(async () => { - jest.clearAllMocks(); - jest.resetModules(); - await setupTests(); -}); - async function setupTests() { db.users.create({ id: 1,