Skip to content

Commit

Permalink
chore: fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Dec 16, 2024
1 parent c914d50 commit a4dab0d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
23 changes: 22 additions & 1 deletion tests/__mocks__/valid-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
]
}
8 changes: 7 additions & 1 deletion tests/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
30 changes: 24 additions & 6 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<typeof createAdapters>,
Expand Down
6 changes: 0 additions & 6 deletions tests/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ afterEach(() => {

afterAll(() => server.close());

beforeEach(async () => {
jest.clearAllMocks();
jest.resetModules();
await setupTests();
});

async function setupTests() {
db.users.create({
id: 1,
Expand Down

0 comments on commit a4dab0d

Please sign in to comment.