From 442e37f22fd9a477e0f7066cefff2ca367145e0d Mon Sep 17 00:00:00 2001 From: ghe Date: Thu, 11 Mar 2021 18:03:51 +0000 Subject: [PATCH] feat: delete vuln paths option once transformed Add tests for the setDefaultTestOptions() --- .../commands/test/set-default-test-options.ts | 9 +- test/run-test.spec.ts | 3 - test/set-default-test-options.spec.ts | 99 +++++++++++++++++++ test/snyk-code-test.spec.ts | 2 - 4 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 test/set-default-test-options.spec.ts diff --git a/src/cli/commands/test/set-default-test-options.ts b/src/cli/commands/test/set-default-test-options.ts index 8ddf3ae519..a6106fe7fd 100644 --- a/src/cli/commands/test/set-default-test-options.ts +++ b/src/cli/commands/test/set-default-test-options.ts @@ -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 diff --git a/test/run-test.spec.ts b/test/run-test.spec.ts index dd70a2fcf3..942d55fc62 100644 --- a/test/run-test.spec.ts +++ b/test/run-test.spec.ts @@ -15,7 +15,6 @@ describe('CLI runTest - propagate correct user error', () => { const options: Options & TestOptions = { path: '', traverseNodeModules: false, - interactive: false, showVulnPaths: 'none', }; @@ -37,7 +36,6 @@ describe('CLI runTest - propagate correct user error', () => { const options: Options & TestOptions = { path: '', traverseNodeModules: false, - interactive: false, showVulnPaths: 'none', }; @@ -59,7 +57,6 @@ describe('CLI runTest - propagate correct user error', () => { const options: Options & TestOptions = { path: '', traverseNodeModules: false, - interactive: false, showVulnPaths: 'none', }; diff --git a/test/set-default-test-options.spec.ts b/test/set-default-test-options.spec.ts new file mode 100644 index 0000000000..895f405d5e --- /dev/null +++ b/test/set-default-test-options.spec.ts @@ -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', + }); + }); +}); diff --git a/test/snyk-code-test.spec.ts b/test/snyk-code-test.spec.ts index 786542530b..55c15cdae3 100644 --- a/test/snyk-code-test.spec.ts +++ b/test/snyk-code-test.spec.ts @@ -63,7 +63,6 @@ describe('Test snyk code', () => { const options: Options & TestOptions = { path: '', traverseNodeModules: false, - interactive: false, showVulnPaths: 'none', }; isFeatureFlagSupportedForOrgSpy.mockResolvedValueOnce({ code: 401 }); @@ -82,7 +81,6 @@ describe('Test snyk code', () => { const options: Options & TestOptions = { path: '', traverseNodeModules: false, - interactive: false, showVulnPaths: 'none', code: true, };