-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from gentlementlegen/fix/reminders
fix: avoid comments on closed / merged pull-requests
- Loading branch information
Showing
6 changed files
with
101 additions
and
10 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { beforeEach, describe, jest } from "@jest/globals"; | ||
import { Logs } from "@ubiquity-os/ubiquity-os-logger"; | ||
import { FOLLOWUP_HEADER } from "../src/types/constants"; | ||
import { ListForOrg, ListIssueForRepo } from "../src/types/github-types"; | ||
import { ContextPlugin } from "../src/types/plugin-input"; | ||
|
||
describe("Reminder tests", () => { | ||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("Should post reminders only on opened linked pull-requests", async () => { | ||
jest.unstable_mockModule("../src/helpers/task-metadata", () => { | ||
return { | ||
getTaskAssignmentDetails: jest.fn(() => ({ startPlusLabelDuration: "1", taskAssignees: [1] })), | ||
parsePriorityLabel: jest.fn(), | ||
}; | ||
}); | ||
jest.unstable_mockModule("../src/helpers/get-assignee-activity", () => { | ||
return { | ||
getAssigneesActivityForIssue: jest.fn(() => []), | ||
}; | ||
}); | ||
jest.unstable_mockModule("../src/helpers/collect-linked-pulls", () => { | ||
return { | ||
collectLinkedPullRequests: jest.fn(() => [ | ||
{ | ||
id: 2, | ||
state: "MERGED", | ||
url: "https://github.com/ubiquity-os/daemon-disqualifier/pull/2", | ||
}, | ||
{ | ||
id: 3, | ||
state: "CLOSE", | ||
url: "https://github.com/ubiquity-os/daemon-disqualifier/pull/3", | ||
}, | ||
{ | ||
id: 4, | ||
state: "OPEN", | ||
url: "https://github.com/ubiquity-os/daemon-disqualifier/pull/4", | ||
}, | ||
]), | ||
}; | ||
}); | ||
const f = jest.fn(() => []); | ||
jest.unstable_mockModule("../src/helpers/structured-metadata", () => { | ||
return { | ||
getCommentsFromMetadata: f, | ||
createStructuredMetadata: jest.fn(() => ""), | ||
}; | ||
}); | ||
const { updateTaskReminder } = await import("../src/helpers/task-update"); | ||
await updateTaskReminder( | ||
{ | ||
logger: new Logs("debug"), | ||
octokit: { | ||
rest: { | ||
issues: { | ||
listEvents: jest.fn(() => [ | ||
{ | ||
event: "assigned", | ||
actor: { | ||
id: 1, | ||
}, | ||
}, | ||
]), | ||
}, | ||
}, | ||
paginate: jest.fn((func: Function, args: unknown) => func(args)), | ||
}, | ||
config: {}, | ||
} as unknown as ContextPlugin, | ||
{ | ||
owner: { | ||
login: "ubiquity-os", | ||
}, | ||
name: "daemon-disqualifier", | ||
} as unknown as ListForOrg["data"][0], | ||
{ number: 1, html_url: "https://github.com/ubiquity-os/daemon-disqualifier/issue/1" } as unknown as ListIssueForRepo | ||
); | ||
// We expect it to be called 2 times because one pull-request is merged and one is closed | ||
expect(f).toHaveBeenCalledTimes(2); | ||
expect(f).toHaveBeenCalledWith(expect.anything(), 1, "ubiquity-os", "daemon-disqualifier", FOLLOWUP_HEADER); | ||
expect(f).toHaveBeenCalledWith(expect.anything(), 4, "ubiquity-os", "daemon-disqualifier", FOLLOWUP_HEADER); | ||
}); | ||
}); |