|
| 1 | +import { ActionRequestMessage, handle } from './handler'; |
| 2 | + |
| 3 | +import { createAppAuth } from '@octokit/auth-app'; |
| 4 | +import { Octokit } from '@octokit/rest'; |
| 5 | + |
| 6 | +jest.mock('@octokit/auth-app', () => ({ |
| 7 | + createAppAuth: jest.fn().mockImplementation(() => jest.fn().mockImplementation(() => ({ token: 'Blaat' }))), |
| 8 | +})); |
| 9 | +const mockOctokit = { checks: { get: jest.fn() }, actions: { listRepoWorkflowRuns: jest.fn() } }; |
| 10 | +jest.mock('@octokit/rest', () => ({ |
| 11 | + Octokit: jest.fn().mockImplementation(() => mockOctokit), |
| 12 | +})); |
| 13 | + |
| 14 | +const TEST_DATA: ActionRequestMessage = { |
| 15 | + id: 1, |
| 16 | + eventType: 'check_run', |
| 17 | + repositoryName: 'hello-world', |
| 18 | + repositoryOwner: 'Codertocat', |
| 19 | + installationId: 2, |
| 20 | +}; |
| 21 | + |
| 22 | +describe('handler', () => { |
| 23 | + beforeEach(() => { |
| 24 | + process.env.GITHUB_APP_KEY = 'TEST_CERTIFICATE_DATA'; |
| 25 | + process.env.GITHUB_APP_ID = '1337'; |
| 26 | + process.env.GITHUB_APP_CLIENT_ID = 'TEST_CLIENT_ID'; |
| 27 | + process.env.GITHUB_APP_CLIENT_SECRET = 'TEST_CLIENT_SECRET'; |
| 28 | + jest.clearAllMocks(); |
| 29 | + mockOctokit.actions.listRepoWorkflowRuns.mockImplementation(() => ({ |
| 30 | + total_count: 1, |
| 31 | + })); |
| 32 | + }); |
| 33 | + |
| 34 | + it('ignores non-sqs events', async () => { |
| 35 | + expect.assertions(1); |
| 36 | + expect(handle('aws:s3', TEST_DATA)).rejects.toEqual(Error('Cannot handle non-SQS events!')); |
| 37 | + }); |
| 38 | + |
| 39 | + it('checks queued workflows', async () => { |
| 40 | + await handle('aws:sqs', TEST_DATA); |
| 41 | + expect(mockOctokit.actions.listRepoWorkflowRuns).toBeCalledWith({ |
| 42 | + owner: TEST_DATA.repositoryOwner, |
| 43 | + repo: TEST_DATA.repositoryName, |
| 44 | + status: 'queued', |
| 45 | + }); |
| 46 | + }); |
| 47 | +}); |
0 commit comments