|
| 1 | +/* @todo clean up and configure test suite */ |
| 2 | + |
| 3 | +import run from '../src/main'; |
| 4 | + |
| 5 | +import * as github from '../__mocks__/@actions/github'; |
| 6 | +import * as core from '../__mocks__/@actions/core'; |
| 7 | + |
| 8 | +const fs = jest.requireActual('fs'); |
| 9 | + |
| 10 | +jest.mock('@actions/core'); |
| 11 | +jest.mock('@actions/github'); |
| 12 | + |
| 13 | +const setFailedMock = jest.spyOn(core, "setFailed") |
| 14 | +const getOctokitMock = jest.spyOn(github, "getOctokit") |
| 15 | + |
| 16 | +const gh = github.getOctokit('_'); |
| 17 | + |
| 18 | +const listPullsMock = jest.spyOn(gh.rest.pulls, 'list'); |
| 19 | +const updateBranchMock = jest.spyOn(gh.rest.pulls, 'updateBranch'); |
| 20 | + |
| 21 | +afterAll(() => jest.restoreAllMocks()); |
| 22 | + |
| 23 | +// Good reference: https://github.com/simple-icons/release-action/blob/master/test/main.test.js |
| 24 | +describe('run', () => { |
| 25 | + it('updates open pull requests with default settings', async () => { |
| 26 | + |
| 27 | + await run(core as any, github as any); |
| 28 | + |
| 29 | + // We expect the action to authenticate with GitHub |
| 30 | + expect(getOctokitMock).toHaveBeenCalledTimes(1); |
| 31 | + |
| 32 | + // Default limit is 100 so we expect only 1 call to listPulls |
| 33 | + expect(listPullsMock).toHaveBeenCalledTimes(1); |
| 34 | + |
| 35 | + expect(updateBranchMock).toHaveBeenCalledWith({ |
| 36 | + pull_number: 123, |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + // it('updates open', async () => { |
| 41 | + // mockGitHubResponseChangedFiles('foo.txt'); |
| 42 | + |
| 43 | + // await run(core, github); |
| 44 | + |
| 45 | + // // expect(removeLabelMock).toHaveBeenCalledTimes(0); |
| 46 | + // // expect(addLabelsMock).toHaveBeenCalledTimes(0); |
| 47 | + // }); |
| 48 | + |
| 49 | + // it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => { |
| 50 | + // const mockInput = { |
| 51 | + // 'repo-token': 'foo', |
| 52 | + // 'configuration-path': 'bar', |
| 53 | + // 'sync-labels': true, |
| 54 | + // }; |
| 55 | + |
| 56 | + // jest |
| 57 | + // .spyOn(core, 'getInput') |
| 58 | + // .mockImplementation((name: string, ...opts) => mockInput[name]); |
| 59 | + |
| 60 | + // usingLabelerConfigYaml('only_pdfs.yml'); |
| 61 | + // mockGitHubResponseChangedFiles('foo.txt'); |
| 62 | + // getPullMock.mockResolvedValue(<any>{ |
| 63 | + // data: { |
| 64 | + // labels: [{ name: 'touched-a-pdf-file' }], |
| 65 | + // }, |
| 66 | + // }); |
| 67 | + |
| 68 | + // await run(core, github); |
| 69 | + |
| 70 | + // expect(addLabelsMock).toHaveBeenCalledTimes(0); |
| 71 | + // expect(removeLabelMock).toHaveBeenCalledTimes(1); |
| 72 | + // expect(removeLabelMock).toHaveBeenCalledWith({ |
| 73 | + // owner: 'monalisa', |
| 74 | + // repo: 'helloworld', |
| 75 | + // issue_number: 123, |
| 76 | + // name: 'touched-a-pdf-file', |
| 77 | + // }); |
| 78 | + // }); |
| 79 | + |
| 80 | + // it('(with sync-labels: false) it issues no delete calls even when there are preexisting PR labels that no longer match the glob pattern', async () => { |
| 81 | + // const mockInput = { |
| 82 | + // 'repo-token': 'foo', |
| 83 | + // 'configuration-path': 'bar', |
| 84 | + // 'sync-labels': false, |
| 85 | + // }; |
| 86 | + |
| 87 | + // jest |
| 88 | + // .spyOn(core, 'getInput') |
| 89 | + // .mockImplementation((name: string, ...opts) => mockInput[name]); |
| 90 | + |
| 91 | + // usingLabelerConfigYaml('only_pdfs.yml'); |
| 92 | + // mockGitHubResponseChangedFiles('foo.txt'); |
| 93 | + // getPullMock.mockResolvedValue(<any>{ |
| 94 | + // data: { |
| 95 | + // labels: [{ name: 'touched-a-pdf-file' }], |
| 96 | + // }, |
| 97 | + // }); |
| 98 | + |
| 99 | + // await run(core, github); |
| 100 | + |
| 101 | + // expect(addLabelsMock).toHaveBeenCalledTimes(0); |
| 102 | + // expect(removeLabelMock).toHaveBeenCalledTimes(0); |
| 103 | + // }); |
| 104 | +}); |
0 commit comments