From 4b2cf01947881fd862c91b16424d75626367aa7c Mon Sep 17 00:00:00 2001 From: Chad Bentz <1760475+felickz@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:22:27 +0000 Subject: [PATCH] integration test to ensure RequestError catch --- __tests__/dependency-graph.int.test.ts | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 __tests__/dependency-graph.int.test.ts diff --git a/__tests__/dependency-graph.int.test.ts b/__tests__/dependency-graph.int.test.ts new file mode 100644 index 0000000..c2c4628 --- /dev/null +++ b/__tests__/dependency-graph.int.test.ts @@ -0,0 +1,29 @@ +import {RequestError} from '@octokit/request-error' +import * as dependencyGraph from '../src/dependency-graph' +import * as core from '@actions/core' + +// mock call to core.getInput('repo-token'.. to avoid environment setup - Input required and not supplied: repo-token +jest.mock('@actions/core', () => ({ + getInput: (input: string) => { + if (input === 'repo-token') { + return 'gh_testtoken' + } + } +})) + +test('it properly catches RequestError type', async () => { + const token = core.getInput('repo-token', {required: true}) + expect(token).toBe('gh_testtoken') + + //Integration test to make an API request using current dependencies and ensure response can parse into RequestError + try { + await dependencyGraph.compare({ + owner: 'actions', + repo: 'dependency-review-action', + baseRef: 'refs/heads/master', + headRef: 'refs/heads/master' + }) + } catch (error) { + expect(error).toBeInstanceOf(RequestError) + } +})