mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 08:20:58 -05:00
Added tests for github-context
This commit is contained in:
parent
18961aec12
commit
ed2fbd8914
1 changed files with 104 additions and 0 deletions
104
tests/unit/platforms/github/github-context.spec.ts
Normal file
104
tests/unit/platforms/github/github-context.spec.ts
Normal file
|
@ -0,0 +1,104 @@
|
|||
import mockFs from "mock-fs";
|
||||
import { GitHubContext } from "@/platforms/github/github-context";
|
||||
|
||||
describe("GitHubContext", () => {
|
||||
describe("ref", () => {
|
||||
test("returns ref when GITHUB_REF is set", () => {
|
||||
const context = new GitHubContext({ GITHUB_REF: "refs/tags/v1.0.0" });
|
||||
|
||||
expect(context.ref).toBe("refs/tags/v1.0.0");
|
||||
});
|
||||
|
||||
test("returns undefined when GITHUB_REF is not set", () => {
|
||||
const context = new GitHubContext({});
|
||||
|
||||
expect(context.ref).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("tag", () => {
|
||||
test("returns tag when GITHUB_REF is set", () => {
|
||||
const context = new GitHubContext({ GITHUB_REF: "refs/tags/v1.0.0" });
|
||||
|
||||
expect(context.tag).toBe("v1.0.0");
|
||||
});
|
||||
|
||||
test("returns undefined when GITHUB_REF is not set", () => {
|
||||
const context = new GitHubContext({});
|
||||
|
||||
expect(context.tag).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("version", () => {
|
||||
test("returns version when GITHUB_REF is set", () => {
|
||||
const context = new GitHubContext({ GITHUB_REF: "refs/tags/v1.0.0" });
|
||||
|
||||
expect(context.version).toBe("1.0.0");
|
||||
});
|
||||
|
||||
test("returns undefined when GITHUB_REF is not set", () => {
|
||||
const context = new GitHubContext({});
|
||||
|
||||
expect(context.version).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("repo", () => {
|
||||
test("returns repository when GITHUB_REPOSITORY is set", () => {
|
||||
const context = new GitHubContext({ GITHUB_REPOSITORY: "owner/repo" });
|
||||
|
||||
expect(context.repo).toEqual({ owner: "owner", repo: "repo" });
|
||||
});
|
||||
|
||||
test("returns undefined when GITHUB_REPOSITORY is not set", () => {
|
||||
const context = new GitHubContext({});
|
||||
|
||||
expect(context.repo).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("apiUrl", () => {
|
||||
test("returns API URL when GITHUB_API_URL is set", () => {
|
||||
const context = new GitHubContext({ GITHUB_API_URL: "https://api.foo.com" });
|
||||
|
||||
expect(context.apiUrl).toBe("https://api.foo.com");
|
||||
});
|
||||
|
||||
test("returns default API URL when GITHUB_API_URL is not set", () => {
|
||||
const context = new GitHubContext({});
|
||||
|
||||
expect(context.apiUrl).toBe("https://api.github.com");
|
||||
});
|
||||
});
|
||||
|
||||
describe("payload", () => {
|
||||
beforeAll(() => {
|
||||
mockFs({
|
||||
"payload.json": JSON.stringify({ release: { id: 42 } }),
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mockFs.restore();
|
||||
});
|
||||
|
||||
test("returns payload when GITHUB_EVENT_PATH is set and file exists", () => {
|
||||
const context = new GitHubContext({ GITHUB_EVENT_PATH: "payload.json" });
|
||||
|
||||
expect(context.payload).toEqual({ release: { id: 42 } });
|
||||
});
|
||||
|
||||
test("returns empty object when GITHUB_EVENT_PATH is set but file does not exist", () => {
|
||||
const context = new GitHubContext({ GITHUB_EVENT_PATH: "foo.json" });
|
||||
|
||||
expect(context.payload).toEqual({});
|
||||
});
|
||||
|
||||
test("returns empty object when GITHUB_EVENT_PATH is not set", () => {
|
||||
const context = new GitHubContext({});
|
||||
|
||||
expect(context.payload).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue