2023-07-02 00:05:17 +02:00
|
|
|
import GitClientFactory from "@bp/service/git/git-client-factory";
|
|
|
|
import { GitPullRequest, GitClientType } from "@bp/service/git/git.types";
|
|
|
|
import GitHubClient from "@bp/service/git/github/github-client";
|
|
|
|
import { mergedPullRequestFixture, repo, targetOwner } from "../../../support/mock/github-data";
|
|
|
|
import { mockGitHubClient } from "../../../support/mock/git-client-mock-support";
|
2023-01-05 11:41:14 +01:00
|
|
|
|
|
|
|
describe("github service", () => {
|
|
|
|
|
2023-07-02 00:05:17 +02:00
|
|
|
let gitClient: GitHubClient;
|
2023-01-05 11:41:14 +01:00
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
// init git service
|
2023-07-02 00:05:17 +02:00
|
|
|
GitClientFactory.reset();
|
|
|
|
GitClientFactory.getOrCreate(GitClientType.GITHUB, "whatever", "http://localhost/api/v3");
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
// mock github api calls
|
2023-07-02 00:05:17 +02:00
|
|
|
mockGitHubClient("http://localhost/api/v3");
|
2023-01-05 11:41:14 +01:00
|
|
|
|
2023-07-02 00:05:17 +02:00
|
|
|
gitClient = GitClientFactory.getClient() as GitHubClient;
|
2023-01-05 11:41:14 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test("get pull request: success", async () => {
|
2023-07-02 00:05:17 +02:00
|
|
|
const res: GitPullRequest = await gitClient.getPullRequest(targetOwner, repo, mergedPullRequestFixture.number);
|
2023-01-05 11:41:14 +01:00
|
|
|
expect(res.sourceRepo).toEqual({
|
|
|
|
owner: "fork",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/fork/reponame.git"
|
|
|
|
});
|
|
|
|
expect(res.targetRepo).toEqual({
|
|
|
|
owner: "owner",
|
|
|
|
project: "reponame",
|
|
|
|
cloneUrl: "https://github.com/owner/reponame.git"
|
|
|
|
});
|
|
|
|
expect(res.title).toBe("PR Title");
|
2023-06-22 17:57:49 +02:00
|
|
|
expect(res.commits!.length).toBe(1);
|
2023-01-05 11:41:14 +01:00
|
|
|
expect(res.commits).toEqual(["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|