forked from ubiquity-os-marketplace/command-start-stop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for
getAllPullRequestsWithRetry
Introduce mock context and data to validate pull request retrieval.
- Loading branch information
1 parent
3d760e3
commit f6232c0
Showing
2 changed files
with
51 additions
and
2 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
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,49 @@ | ||
import { RestEndpointMethodTypes } from "@octokit/rest"; | ||
import { Logs } from "@ubiquity-os/ubiquity-os-logger"; | ||
import { Context } from "../src/types/context"; | ||
import { getAllPullRequestsWithRetry } from "../src/utils/issue"; | ||
|
||
const username = "private-user"; | ||
|
||
const mockPullRequestData = [ | ||
{ id: 1, number: 123, state: "open", user: { login: username } }, | ||
{ id: 2, number: 124, state: "open", user: { login: "public-user" } }, | ||
] as unknown as RestEndpointMethodTypes["pulls"]["list"]["response"]["data"]; | ||
|
||
const mockOctokit = { | ||
paginate: jest.fn().mockResolvedValue(mockPullRequestData), | ||
rest: { | ||
pulls: { | ||
list: jest.fn().mockResolvedValue(mockPullRequestData), | ||
}, | ||
repos: { | ||
listForOrg: jest.fn().mockResolvedValue(mockPullRequestData), | ||
}, | ||
}, | ||
}; | ||
|
||
// Mock context | ||
const context: Context = { | ||
eventName: "pull_request", | ||
payload: { | ||
repository: { | ||
name: "test-repo", | ||
owner: { | ||
login: "test-owner", | ||
}, | ||
}, | ||
}, | ||
octokit: mockOctokit as unknown as Context["octokit"], | ||
logger: new Logs("debug"), | ||
adapters: {}, | ||
} as unknown as Context; | ||
|
||
describe("getAllPullRequestsWithRetry", () => { | ||
it("should return pull requests even if user information is private", async () => { | ||
const pullRequests = await getAllPullRequestsWithRetry(context, "all", username); | ||
expect(pullRequests).toHaveLength(2); | ||
expect(pullRequests[0].user?.login).toBe(username); | ||
expect(pullRequests[1].user?.login).toBe(username); | ||
console.log(pullRequests); | ||
}); | ||
}); |