diff --git a/test/jest/acceptance/error-catalog.spec.ts b/test/jest/acceptance/error-catalog.spec.ts index a98d928be5..a0d3ff8933 100644 --- a/test/jest/acceptance/error-catalog.spec.ts +++ b/test/jest/acceptance/error-catalog.spec.ts @@ -5,47 +5,36 @@ import { getServerPort } from '../util/getServerPort'; interface Workflow { type: string; cmd: string; - env: { [key: string]: string | undefined }; } const integrationWorkflows: Workflow[] = [ { type: 'typescript', cmd: 'test', - env: { - INTERNAL_SNYK_CODE_IGNORES_ENABLED: 'false', - }, - }, - { - type: 'typescript', - cmd: 'test code', - env: { - INTERNAL_SNYK_CODE_IGNORES_ENABLED: 'false', - }, }, { type: 'golang/native', cmd: 'code test', - env: { - // internal GAF feature flag for consistent ignores - INTERNAL_SNYK_CODE_IGNORES_ENABLED: 'true', - }, }, ]; describe.each(integrationWorkflows)( 'outputs Error Catalog errors', - ({ cmd, type, env }) => { - env = { + ({ cmd, type }) => { + const snykOrg = '11111111-2222-3333-4444-555555555555'; + let env: any = { ...process.env, - ...env, }; describe('authentication errors', () => { describe(`${type} workflow`, () => { it(`snyk ${cmd}`, async () => { - await runSnykCLI('config clear'); - const { code, stdout } = await runSnykCLI(cmd, { env }); + const { code, stdout } = await runSnykCLI(cmd, { + env: { + ...env, + SNYK_TOKEN: '1234', + }, + }); expect(code).toBe(2); expect(stdout).toContain('Authentication error (SNYK-0005)'); @@ -65,6 +54,7 @@ describe.each(integrationWorkflows)( SNYK_HOST: 'http://' + ipAddr + ':' + port, SNYK_TOKEN: '123456789', SNYK_HTTP_PROTOCOL_UPGRADE: '0', + SNYK_CFG_ORG: snykOrg, }; server = fakeServer(baseApi, 'snykToken'); server.listen(port, () => { @@ -84,11 +74,19 @@ describe.each(integrationWorkflows)( describe(`${type} workflow`, () => { it(`snyk ${cmd}`, async () => { server.setStatusCode(500); - const { code, stdout } = await runSnykCLI(`${cmd}`, { env }); + const { code } = await runSnykCLI(`${cmd}`, { env }); expect(code).toBe(2); - expect(stdout).toContain( - 'Request not fulfilled due to server error (SNYK-9999)', - ); + const analyticsRequest = server + .getRequests() + .filter((value) => + (value.url as string).includes( + `/api/hidden/orgs/${snykOrg}/analytics`, + ), + ) + .pop(); + expect( + analyticsRequest?.body.data.attributes.interaction.errors[0].code, + ).toEqual('500'); }); }); }); @@ -97,11 +95,20 @@ describe.each(integrationWorkflows)( describe(`${type} workflow`, () => { it(`snyk ${cmd}`, async () => { server.setStatusCode(400); - const { code, stdout } = await runSnykCLI(`${cmd}`, { env }); + const { code } = await runSnykCLI(`${cmd}`, { env }); expect(code).toBe(2); - expect(stdout).toContain( - 'Client request cannot be processed (SNYK-0003)', - ); + + const analyticsRequest = server + .getRequests() + .filter((value) => + (value.url as string).includes( + `/api/hidden/orgs/${snykOrg}/analytics`, + ), + ) + .pop(); + expect( + analyticsRequest?.body.data.attributes.interaction.errors[0].code, + ).toEqual('400'); }); }); });