Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CatalinSnyk committed Dec 10, 2024
1 parent b87d221 commit accb84a
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions test/jest/acceptance/error-catalog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
Expand All @@ -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, () => {
Expand All @@ -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');
});
});
});
Expand All @@ -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');
});
});
});
Expand Down

0 comments on commit accb84a

Please sign in to comment.