Skip to content

Commit

Permalink
chore: fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Sep 2, 2024
1 parent 5437e76 commit 10650d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/handlers/shared/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function start(context: Context, issue: Context["payload"]["issue"]
}

// get labels
const labels = issue.labels;
const labels = issue.labels ?? [];
const priceLabel = labels.find((label: Label) => label.name.startsWith("Price: "));

if (!priceLabel) {
Expand Down
50 changes: 25 additions & 25 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 1 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender);
const context = createContext(issue, sender) as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);

const { output } = await userStartStop(context);
const { content } = await userStartStop(context);

expect(output).toEqual("Task assigned successfully");
expect(content).toEqual("Task assigned successfully");
});

test("User can start an issue with teammates", async () => {
const issue = db.issue.findFirst({ where: { id: { equals: 1 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as Sender;

const context = createContext(issue, sender, "/start @user3");
const context = createContext(issue, sender, "/start @user3") as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context as unknown as Context);
context.adapters = createAdapters(getSupabase(), context);

const { output } = await userStartStop(context as unknown as Context);
const { content } = await userStartStop(context);

expect(output).toEqual("Task assigned successfully");
expect(content).toEqual("Task assigned successfully");

const issue2 = db.issue.findFirst({ where: { id: { equals: 1 } } }) as unknown as Issue;
expect(issue2.assignees).toHaveLength(2);
Expand All @@ -68,26 +68,26 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 2 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 2 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/stop");
const context = createContext(issue, sender, "/stop") as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);

const { output } = await userStartStop(context);
const { content } = await userStartStop(context);

expect(output).toEqual("Task unassigned successfully");
expect(content).toEqual("Task unassigned successfully");
});

test("Stopping an issue should close the author's linked PR", async () => {
const infoSpy = jest.spyOn(console, "info").mockImplementation(() => {});
const issue = db.issue.findFirst({ where: { id: { equals: 2 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 2 } } }) as unknown as PayloadSender;
const context = createContext(issue, sender, "/stop");
const context = createContext(issue, sender, "/stop") as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);

const { output } = await userStartStop(context);
const { content } = await userStartStop(context);

expect(output).toEqual("Task unassigned successfully");
expect(content).toEqual("Task unassigned successfully");
const logs = infoSpy.mock.calls.flat();
expect(logs[0]).toMatch(/Opened prs/);
expect(cleanLogString(logs[3])).toMatch(
Expand All @@ -101,28 +101,28 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 2 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/stop");
const context = createContext(issue, sender, "/stop") as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);

await expect(userStartStop(context as unknown as Context)).rejects.toThrow("```diff\n! You are not assigned to this task\n```");
await expect(userStartStop(context)).rejects.toThrow("```diff\n! You are not assigned to this task\n```");
});

test("User can't stop an issue without assignees", async () => {
const issue = db.issue.findFirst({ where: { id: { equals: 6 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/stop");
const context = createContext(issue, sender, "/stop") as Context<"issue_comment.created">;
context.adapters = createAdapters(getSupabase(), context as unknown as Context);

await expect(userStartStop(context as unknown as Context)).rejects.toThrow("```diff\n! You are not assigned to this task\n```");
await expect(userStartStop(context)).rejects.toThrow("```diff\n! You are not assigned to this task\n```");
});

test("User can't start an issue that's already assigned", async () => {
const issue = db.issue.findFirst({ where: { id: { equals: 2 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/start");
const context = createContext(issue, sender, "/start") as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);

Expand All @@ -133,7 +133,7 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 3 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender);
const context = createContext(issue, sender) as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);

Expand All @@ -144,7 +144,7 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 1 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/start", "2", true);
const context = createContext(issue, sender, "/start", "2", true) as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(false), context);
await expect(userStartStop(context)).rejects.toThrow("No wallet address found");
Expand All @@ -154,18 +154,18 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 4 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender);
const context = createContext(issue, sender) as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context as unknown as Context);

await expect(userStartStop(context as unknown as Context)).rejects.toThrow("This issue is closed, please choose another.");
await expect(userStartStop(context)).rejects.toThrow("This issue is closed, please choose another.");
});

test("User can't start an issue that's a parent issue", async () => {
const issue = db.issue.findFirst({ where: { id: { equals: 5 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 1 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/start");
const context = createContext(issue, sender, "/start") as Context<"issue_comment.created">;

context.adapters = createAdapters(getSupabase(), context);

Expand All @@ -176,7 +176,7 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 1 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 2 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender);
const context = createContext(issue, sender) as Context<"issue_comment.created">;
context.config.maxConcurrentTasks = 1;

context.adapters = createAdapters(getSupabase(), context);
Expand All @@ -188,7 +188,7 @@ describe("User start/stop", () => {
const issue = db.issue.findFirst({ where: { id: { equals: 6 } } }) as unknown as Issue;
const sender = db.users.findFirst({ where: { id: { equals: 2 } } }) as unknown as PayloadSender;

const context = createContext(issue, sender, "/start");
const context = createContext(issue, sender, "/start") as Context<"issue_comment.created">;
context.adapters = createAdapters(getSupabase(), context);

await expect(userStartStop(context)).rejects.toThrow("user2 you were previously unassigned from this task. You cannot be reassigned.");
Expand Down

0 comments on commit 10650d8

Please sign in to comment.