Skip to content

Commit

Permalink
feat: delete vuln paths option once transformed
Browse files Browse the repository at this point in the history
Add tests for the setDefaultTestOptions()
  • Loading branch information
lili2311 committed Mar 12, 2021
1 parent 15dce36 commit 442e37f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/cli/commands/test/set-default-test-options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as config from '../../../lib/config';
import { Options, ShowVulnPaths, TestOptions } from '../../../lib/types';

export function setDefaultTestOptions(
options: Options & TestOptions,
): Options & TestOptions {
const svpSupplied = (options['show-vulnerable-paths'] || '').toLowerCase();
export function setDefaultTestOptions(options: Options): Options & TestOptions {
const svpSupplied = (options['show-vulnerable-paths'] || '')
.toString()
.toLowerCase();

delete options['show-vulnerable-paths'];
return {
...options,
// org fallback to config unless specified
Expand Down
3 changes: 0 additions & 3 deletions test/run-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('CLI runTest - propagate correct user error', () => {
const options: Options & TestOptions = {
path: '',
traverseNodeModules: false,
interactive: false,
showVulnPaths: 'none',
};

Expand All @@ -37,7 +36,6 @@ describe('CLI runTest - propagate correct user error', () => {
const options: Options & TestOptions = {
path: '',
traverseNodeModules: false,
interactive: false,
showVulnPaths: 'none',
};

Expand All @@ -59,7 +57,6 @@ describe('CLI runTest - propagate correct user error', () => {
const options: Options & TestOptions = {
path: '',
traverseNodeModules: false,
interactive: false,
showVulnPaths: 'none',
};

Expand Down
99 changes: 99 additions & 0 deletions test/set-default-test-options.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { setDefaultTestOptions } from '../src/cli/commands/test/set-default-test-options';

describe('setDefaultTestOptions', () => {
it('defaults to show-vulnerable-paths:some & org from config when no options passed in', () => {
const updated = setDefaultTestOptions({ path: '/' });
expect(updated).toEqual({
org: undefined,
path: '/',
showVulnPaths: 'some',
});
});

it('with show-vulnerable-paths set to `false` => `none`', () => {
const options = {
path: '/',
'show-vulnerable-paths': 'false',
};
const updated = setDefaultTestOptions(options);
expect(updated).toEqual({
org: undefined,
path: '/',
showVulnPaths: 'none',
});
});

it('with show-vulnerable-paths as boolean => `some`', () => {
const options = {
path: '/',
'show-vulnerable-paths': true,
};
const updated = setDefaultTestOptions(options as any);
expect(updated).toEqual({
org: undefined,
path: '/',
showVulnPaths: 'some',
});
});

it('with show-vulnerable-paths set to `none` => `none`', () => {
const options = {
path: '/',
'show-vulnerable-paths': 'none',
};
const updated = setDefaultTestOptions(options);
expect(updated).toEqual({
org: undefined,
path: '/',
showVulnPaths: 'none',
});
});

it('with show-vulnerable-paths set to `true` => `some`', () => {
const options = {
path: '/',
'show-vulnerable-paths': 'true',
};
const updated = setDefaultTestOptions(options);
expect(updated).toEqual({
org: undefined,
path: '/',
showVulnPaths: 'some',
});
});

it('with show-vulnerable-paths set to `some` => `some`', () => {
const options = {
path: '/',
'show-vulnerable-paths': 'some',
};
const updated = setDefaultTestOptions(options);
expect(updated).toEqual({
org: undefined,
path: '/',
showVulnPaths: 'some',
});
});

it('with show-vulnerable-paths set to `all` => `all`', () => {
const options = {
path: '/',
'show-vulnerable-paths': 'all',
};
const updated = setDefaultTestOptions(options);
expect(updated).toEqual({
org: undefined,
path: '/',
showVulnPaths: 'all',
});
});

it('with org set', () => {
const updated = setDefaultTestOptions({ path: '/', org: 'my-org' });
expect(updated).toEqual({
org: 'my-org',
path: '/',
showVulnPaths: 'some',
});
});
});
2 changes: 0 additions & 2 deletions test/snyk-code-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('Test snyk code', () => {
const options: Options & TestOptions = {
path: '',
traverseNodeModules: false,
interactive: false,
showVulnPaths: 'none',
};
isFeatureFlagSupportedForOrgSpy.mockResolvedValueOnce({ code: 401 });
Expand All @@ -82,7 +81,6 @@ describe('Test snyk code', () => {
const options: Options & TestOptions = {
path: '',
traverseNodeModules: false,
interactive: false,
showVulnPaths: 'none',
code: true,
};
Expand Down

0 comments on commit 442e37f

Please sign in to comment.