-
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 #43 from ubiquity-os-marketplace/development
Merge development into main
- Loading branch information
Showing
5 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { beforeEach, describe, expect, it, jest } from "@jest/globals"; | ||
import { RestEndpointMethodTypes } from "@octokit/rest"; | ||
import { Logs } from "@ubiquity-os/ubiquity-os-logger"; | ||
import { ListIssueForRepo } from "../src/types/github-types"; | ||
import { ContextPlugin } from "../src/types/plugin-input"; | ||
|
||
jest.unstable_mockModule("../src/helpers/collect-linked-pulls", () => []); | ||
jest.unstable_mockModule("../src/helpers/github-url", () => ({ | ||
parseIssueUrl: jest.fn(() => ({ | ||
repo: "repo", | ||
owner: "owner", | ||
issue_number: 1, | ||
})), | ||
})); | ||
jest.unstable_mockModule("../src/helpers/structured-metadata", () => ({ | ||
createStructuredMetadata: jest.fn(() => ""), | ||
})); | ||
|
||
describe("remindAssigneesForIssue", () => { | ||
let context: ContextPlugin; | ||
let issue: ListIssueForRepo; | ||
|
||
beforeEach(() => { | ||
context = { | ||
logger: new Logs("debug"), | ||
octokit: { | ||
rest: { | ||
issues: { | ||
createComment: jest.fn(), | ||
removeAssignees: jest.fn(), | ||
}, | ||
}, | ||
}, | ||
config: { | ||
warning: 1, | ||
disqualification: 1, | ||
pullRequestRequired: false, | ||
}, | ||
} as unknown as ContextPlugin; | ||
|
||
issue = { | ||
html_url: "https://github.com/owner/repo/issues/1", | ||
assignees: [{ login: "ubiquity-os", id: 1 }], | ||
} as unknown as ListIssueForRepo; | ||
}); | ||
|
||
it("should post a comment to the parent issue if posting to the pull request fails", async () => { | ||
context.config.pullRequestRequired = true; | ||
jest.unstable_mockModule("../src/helpers/collect-linked-pulls", () => { | ||
return { | ||
collectLinkedPullRequests: jest.fn(() => [ | ||
{ | ||
url: "https://github.com/owner/repo/pull/1", | ||
body: "", | ||
id: "1", | ||
login: "ubiquity-os", | ||
number: 1, | ||
state: "OPEN", | ||
title: "title", | ||
}, | ||
]), | ||
}; | ||
}); | ||
|
||
const mockedError = new Error("Failed to post comment"); | ||
|
||
(context.octokit.rest.issues.createComment as jest.MockedFunction<typeof context.octokit.rest.issues.createComment>) | ||
.mockRejectedValueOnce(mockedError) | ||
.mockResolvedValueOnce({} as unknown as RestEndpointMethodTypes["issues"]["createComment"]["response"]); | ||
|
||
const { remindAssigneesForIssue } = await import("../src/helpers/remind-and-remove"); | ||
await remindAssigneesForIssue(context, issue); | ||
|
||
expect(context.octokit.rest.issues.createComment).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
owner: "owner", | ||
repo: "repo", | ||
issue_number: 1, | ||
}) | ||
); | ||
|
||
expect(context.octokit.rest.issues.createComment).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
owner: "owner", | ||
repo: "repo", | ||
issue_number: 1, | ||
body: expect.stringContaining("this task has been idle for a while"), | ||
}) | ||
); | ||
}); | ||
}); |