Skip to content

Commit

Permalink
fix: removed /allow command
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Dec 17, 2024
1 parent c4c22d0 commit 7591c53
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 244 deletions.
78 changes: 0 additions & 78 deletions src/handlers/command-parser.ts

This file was deleted.

78 changes: 0 additions & 78 deletions src/handlers/comment.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { commandHandlers, handleComment } from "./handlers/comment";
import { globalLabelUpdate } from "./handlers/global-config-update";
import { watchLabelChange } from "./handlers/label-change";
import { onLabelChangeSetPricing } from "./handlers/pricing-label";
Expand All @@ -9,15 +8,6 @@ import { isIssueLabelEvent } from "./types/typeguards";
export async function run(context: Context) {
const { eventName, logger } = context;

if (context.command) {
await commandHandlers[context.command.name](context, {
username: context.command.parameters.username,
labels: context.command.parameters.labelTypes,
command: context.command.name,
});
return;
}

switch (eventName) {
case "issues.opened":
case "repository.created":
Expand All @@ -33,9 +23,6 @@ export async function run(context: Context) {
case "label.edited":
await watchLabelChange(context);
break;
case "issue_comment.created":
await handleComment(context);
break;
case "push":
await globalLabelUpdate(context);
break;
Expand Down
80 changes: 5 additions & 75 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { drop } from "@mswjs/data";
import commandParser, { CommandArguments } from "../src/handlers/command-parser";
import { Env } from "../src/types/env";
import { Value } from "@sinclair/typebox/value";
import * as crypto from "node:crypto";
import { calculateLabelValue, calculateTaskPrice } from "../src/shared/pricing";
import { Context } from "../src/types/context";
import { Env } from "../src/types/env";
import { AssistivePricingSettings, pluginSettingsSchema } from "../src/types/plugin-input";
import workerFetch from "../src/worker";
import { db } from "./__mocks__/db";
import { server } from "./__mocks__/node";
import issueCommented from "./__mocks__/requests/issue-comment-post.json";
import usersGet from "./__mocks__/users-get.json";
import * as crypto from "node:crypto";
import { AssistivePricingSettings, pluginSettingsSchema } from "../src/types/plugin-input";
import { calculateLabelValue, calculateTaskPrice } from "../src/shared/pricing";
import { Value } from "@sinclair/typebox/value";

const { privateKey, publicKey } = crypto.generateKeyPairSync("rsa", {
modulusLength: 2048,
Expand Down Expand Up @@ -51,44 +50,6 @@ describe("User tests", () => {
expect(decodedSettings.globalConfigUpdate).toBeUndefined();
});

it("Should parse the /allow command", () => {
const command = "/allow @user time priority".split(/\s+/);
const invalidCommand = "allow user time priority".split(/\s+/);
const unknownCommand = "/foo user time priority".split(/\s+/);
const commandForRemoval = "/allow @user".split(/\s+/);
const result: CommandArguments = {
command: "allow",
labels: [],
username: "",
};
commandParser
.action((command, username, labels) => {
result.command = command;
result.username = username;
result.labels = labels;
})
.parse(command, { from: "user" });
expect(result).toEqual({
command: "allow",
labels: ["time", "priority"],
username: "user",
});
expect(() => commandParser.exitOverride().parse(invalidCommand, { from: "user" })).toThrow();
expect(() => commandParser.exitOverride().parse(unknownCommand, { from: "user" })).toThrow();
commandParser
.action((command, username, labels) => {
result.command = command;
result.username = username;
result.labels = labels;
})
.parse(commandForRemoval, { from: "user" });
expect(result).toEqual({
command: "allow",
labels: [],
username: "user",
});
});

it("Should accurately calculates prices", () => {
const context = {
config: {
Expand Down Expand Up @@ -136,37 +97,6 @@ describe("User tests", () => {
}
});

it("Should handle the comment", async () => {
const data = issueCommented;
const sign = crypto.createSign("SHA256");
sign.update(JSON.stringify(data));
sign.end();
const signature = sign.sign(privateKey, "base64");

process.env = {
SUPABASE_URL: "http://localhost:65432",
SUPABASE_KEY: "key",
};

const result = await workerFetch.fetch(
{
headers: {
get: () => "application/json",
},
json: () => ({
...data,
signature,
}),
method: "POST",
url,
} as unknown as Request,
{
KERNEL_PUBLIC_KEY: publicKey,
} as Env
);
expect(result.ok).toEqual(true);
});

it("Should deny non POST request", async () => {
const result = await workerFetch.fetch(
{
Expand Down

0 comments on commit 7591c53

Please sign in to comment.