From 960a7bf30266cf8268556424e9124ea079e5db0d Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:57:27 +0100 Subject: [PATCH] chore: add default config tests --- src/types/plugin-inputs.ts | 2 +- tests/main.test.ts | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/types/plugin-inputs.ts b/src/types/plugin-inputs.ts index c3cdb5a..77bb358 100644 --- a/src/types/plugin-inputs.ts +++ b/src/types/plugin-inputs.ts @@ -60,7 +60,7 @@ export const userActivityWatcherSettingsSchema = T.Object( /** * List of events to consider as valid activity on a task */ - eventWhitelist: T.Array(T.String({ default: Object.values(eventWhitelist) })), + eventWhitelist: T.Array(T.String(), { default: Object.values(eventWhitelist) }), }, { default: {} } ); diff --git a/tests/main.test.ts b/tests/main.test.ts index 24e7ddd..00a8ff1 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -1,7 +1,7 @@ import { drop } from "@mswjs/data"; import { TransformDecodeError, Value } from "@sinclair/typebox/value"; import { runPlugin } from "../src/run"; -import { userActivityWatcherSettingsSchema } from "../src/types/plugin-inputs"; +import { UserActivityWatcherSettings, userActivityWatcherSettingsSchema } from "../src/types/plugin-inputs"; import { db } from "./__mocks__/db"; import { server } from "./__mocks__/node"; import cfg from "./__mocks__/results/valid-configuration.json"; @@ -13,6 +13,7 @@ import mockUsers from "./__mocks__/mock-users"; import { botAssignmentComment, getIssueHtmlUrl, STRINGS } from "./__mocks__/strings"; import { createComment, createEvent, createIssue, createRepo, ONE_DAY } from "./__mocks__/helpers"; import { collectLinkedPullRequests } from "../src/handlers/collect-linked-pulls"; +import ms from "ms"; dotenv.config(); const octokit = jest.requireActual("@octokit/rest"); @@ -51,6 +52,29 @@ describe("User start/stop", () => { ) ).toThrow(TransformDecodeError); }); + it("Should define eventWhitelist defaults if omitted", () => { + const settings = Value.Default(userActivityWatcherSettingsSchema, { + warning: "12 days", + disqualification: "2 days", + watch: { optOut: [STRINGS.PRIVATE_REPO_NAME] }, + }); + const decodedSettings = Value.Decode(userActivityWatcherSettingsSchema, settings); + expect(decodedSettings.eventWhitelist).toEqual(["review_requested", "ready_for_review", "commented", "committed"]); + }); + it("Should define all defaults if omitted", () => { + const settings = Value.Default(userActivityWatcherSettingsSchema, { + watch: { optOut: [STRINGS.PRIVATE_REPO_NAME] }, // has no default + }) as UserActivityWatcherSettings; + + const decodedSettings = Value.Decode(userActivityWatcherSettingsSchema, settings); + + expect(decodedSettings).toEqual({ + warning: ms("3.5 days"), + disqualification: ms("7 days"), + watch: { optOut: [STRINGS.PRIVATE_REPO_NAME] }, + eventWhitelist: ["review_requested", "ready_for_review", "commented", "committed"], + }); + }); it("Should run", async () => { const context = createContext(1, 1); const result = await runPlugin(context);