1
0
Fork 0
mirror of https://code.forgejo.org/actions/git-backporting synced 2025-03-17 23:54:06 +01:00
git-backporting/test/service/git/github/github-service.test.ts
2023-06-22 17:57:49 +02:00

40 lines
No EOL
1.3 KiB
TypeScript

import GitServiceFactory from "@bp/service/git/git-service-factory";
import { GitPullRequest, GitServiceType } from "@bp/service/git/git.types";
import GitHubService from "@bp/service/git/github/github-service";
import { mergedPullRequestFixture, repo, targetOwner } from "../../../support/moctokit/moctokit-data";
import { setupMoctokit } from "../../../support/moctokit/moctokit-support";
describe("github service", () => {
let gitService: GitHubService;
beforeAll(() => {
// init git service
GitServiceFactory.getOrCreate(GitServiceType.GITHUB, "whatever");
});
beforeEach(() => {
// mock github api calls
setupMoctokit();
gitService = GitServiceFactory.getService() as GitHubService;
});
test("get pull request: success", async () => {
const res: GitPullRequest = await gitService.getPullRequest(targetOwner, repo, mergedPullRequestFixture.number);
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");
expect(res.commits!.length).toBe(1);
expect(res.commits).toEqual(["28f63db774185f4ec4b57cd9aaeb12dbfb4c9ecc"]);
});
});