Skip to content

Commit

Permalink
chore: add default config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 19, 2024
1 parent 863ea9a commit 960a7bf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/types/plugin-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} }
);
Expand Down
26 changes: 25 additions & 1 deletion tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 960a7bf

Please sign in to comment.