Skip to content

Commit 3d872fb

Browse files
committedMar 30, 2021
test: assert exact errors for unsupported
1 parent 77e6665 commit 3d872fb

4 files changed

+18
-35
lines changed
 

‎src/cli/modes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface ModeData {
88

99
const modes: Record<string, ModeData> = {
1010
source: {
11-
allowedCommands: ['test', 'monitor', 'fix'],
11+
allowedCommands: ['test', 'monitor'],
1212
config: (args): [] => {
1313
args['source'] = true;
1414
return args;

‎test/cli-fix.functional.spec.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import * as fs from 'fs';
33

44
import cli = require('../src/cli/commands');
55
import * as snyk from '../src/lib';
6-
7-
import * as validateFixSupported from '../src/cli/commands/fix/validate-fix-command-is-supported';
6+
import * as featureFlags from '../src/lib/feature-flags';
87

98
import stripAnsi from 'strip-ansi';
109

@@ -49,8 +48,8 @@ const pipWithRemediation = JSON.parse(
4948
describe('snyk fix (functional tests)', () => {
5049
beforeAll(async () => {
5150
jest
52-
.spyOn(validateFixSupported, 'validateFixCommandIsSupported')
53-
.mockResolvedValue(true);
51+
.spyOn(featureFlags, 'isFeatureFlagSupportedForOrg')
52+
.mockResolvedValue({ ok: true });
5453
});
5554

5655
afterAll(async () => {

‎test/cli-fix.system.spec.ts

-26
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,6 @@ describe('snyk fix (system tests)', () => {
143143
testTimeout,
144144
);
145145

146-
/* this command is different
147-
* it shows help text not an error when command is not supported
148-
*/
149-
it.skip(
150-
'`shows error when called with container`',
151-
(done) => {
152-
exec(
153-
`node ${main} container fix`,
154-
{
155-
env: {
156-
PATH: process.env.PATH,
157-
SNYK_TOKEN: apiKey,
158-
SNYK_API,
159-
SNYK_HOST,
160-
},
161-
},
162-
(err, stdout, stderr) => {
163-
expect(stderr).toBe('');
164-
expect(stdout).toMatch('COMMANDS');
165-
expect(err).toBe(null);
166-
done();
167-
},
168-
);
169-
},
170-
testTimeout,
171-
);
172146
it(
173147
'`shows error when called with --code`',
174148
(done) => {

‎test/validate-fix-command-is-supported.spec.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { validateFixCommandIsSupported } from '../src/cli/commands/fix/validate-fix-command-is-supported';
2+
import { CommandNotSupportedError } from '../src/lib/errors/command-not-supported';
3+
import { FeatureNotSupportedByEcosystemError } from '../src/lib/errors/not-supported-by-ecosystem';
24
import * as featureFlags from '../src/lib/feature-flags';
35
import { ShowVulnPaths } from '../src/lib/types';
46
describe('setDefaultTestOptions', () => {
@@ -19,7 +21,9 @@ describe('setDefaultTestOptions', () => {
1921
.spyOn(featureFlags, 'isFeatureFlagSupportedForOrg')
2022
.mockResolvedValue({ ok: false });
2123
const options = { path: '/', showVulnPaths: 'all' as ShowVulnPaths };
22-
expect(validateFixCommandIsSupported(options)).rejects.toThrowError('');
24+
expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
25+
new CommandNotSupportedError('snyk fix', undefined),
26+
);
2327
});
2428

2529
it('fix is NOT supported for --source + enabled FF', () => {
@@ -31,7 +35,9 @@ describe('setDefaultTestOptions', () => {
3135
showVulnPaths: 'all' as ShowVulnPaths,
3236
source: true,
3337
};
34-
expect(validateFixCommandIsSupported(options)).rejects.toThrowError('');
38+
expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
39+
new FeatureNotSupportedByEcosystemError('snyk fix', 'cpp'),
40+
);
3541
});
3642

3743
it('fix is NOT supported for --docker + enabled FF', () => {
@@ -43,7 +49,9 @@ describe('setDefaultTestOptions', () => {
4349
showVulnPaths: 'all' as ShowVulnPaths,
4450
docker: true,
4551
};
46-
expect(validateFixCommandIsSupported(options)).rejects.toThrowError('');
52+
expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
53+
new FeatureNotSupportedByEcosystemError('snyk fix', 'docker'),
54+
);
4755
});
4856

4957
it('fix is NOT supported for --code + enabled FF', () => {
@@ -55,6 +63,8 @@ describe('setDefaultTestOptions', () => {
5563
showVulnPaths: 'all' as ShowVulnPaths,
5664
code: true,
5765
};
58-
expect(validateFixCommandIsSupported(options)).rejects.toThrowError('');
66+
expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
67+
new FeatureNotSupportedByEcosystemError('snyk fix', 'code'),
68+
);
5969
});
6070
});

0 commit comments

Comments
 (0)
Please sign in to comment.