From ee0e0eb5130754cb53b7cb4bd3d012ab6e3000ae Mon Sep 17 00:00:00 2001 From: Josh Dales Date: Sat, 7 Aug 2021 15:12:02 -0400 Subject: [PATCH] Add a new fixture and test for the branch checking --- __mocks__/@actions/github.ts | 1 + __tests__/fixtures/branches.yml | 5 +++++ __tests__/main.test.ts | 14 ++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 __tests__/fixtures/branches.yml diff --git a/__mocks__/@actions/github.ts b/__mocks__/@actions/github.ts index d423a29d..12afe422 100644 --- a/__mocks__/@actions/github.ts +++ b/__mocks__/@actions/github.ts @@ -8,6 +8,7 @@ export const context = { owner: "monalisa", repo: "helloworld", }, + ref: "test/testing-time", }; const mockApi = { diff --git a/__tests__/fixtures/branches.yml b/__tests__/fixtures/branches.yml new file mode 100644 index 00000000..cdf9551d --- /dev/null +++ b/__tests__/fixtures/branches.yml @@ -0,0 +1,5 @@ +test-branch: + - branch: "test/*" + +feature-branch: + - branch: "*/feature/*" diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index de145599..3e6529ab 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -15,6 +15,7 @@ const paginateMock = jest.spyOn(gh, "paginate"); const getPullMock = jest.spyOn(gh.rest.pulls, "get"); const yamlFixtures = { + "branches.yml": fs.readFileSync("__tests__/fixtures/branches.yml"), "only_pdfs.yml": fs.readFileSync("__tests__/fixtures/only_pdfs.yml"), }; @@ -102,6 +103,19 @@ describe("run", () => { expect(addLabelsMock).toHaveBeenCalledTimes(0); expect(removeLabelMock).toHaveBeenCalledTimes(0); }); + + it("adds labels based on the branch names that match the glob pattern", async () => { + usingLabelerConfigYaml("branches.yml"); + await run(); + + expect(addLabelsMock).toHaveBeenCalledTimes(1); + expect(addLabelsMock).toHaveBeenCalledWith({ + owner: "monalisa", + repo: "helloworld", + issue_number: 123, + labels: ["test-branch"], + }); + }); }); function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {