Skip to content

Commit

Permalink
Merge pull request #1235 from snyk/fix/snyk-wizard
Browse files Browse the repository at this point in the history
fix: options passed to snyk wizard
  • Loading branch information
anthogez committed Jun 24, 2020
2 parents 14bbc0d + b7b9088 commit d2a5578
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/cli/commands/protect/wizard.ts
Expand Up @@ -595,7 +595,6 @@ function processAnswers(answers, policy, options) {
(inspectRes as MultiProjectResult).scannedProjects[0],
options,
inspectRes.plugin,
options,
);
})
// clear spinner in case of success or failure
Expand Down
46 changes: 28 additions & 18 deletions test/acceptance/cli-wizard/cli-monitor.acceptance.test.ts
@@ -1,5 +1,5 @@
import * as tap from 'tap';
import * as sinon from 'sinon';
import * as fs from 'fs';
import * as cli from '../../../src/cli/commands';
import { fakeServer } from '../fake-server';
import { getVersion } from '../../../src/lib/version';
Expand Down Expand Up @@ -55,6 +55,33 @@ before('prime config', async (t) => {
t.end();
});

test('`wizard` for supported package managers', async (t) => {
chdirWorkspaces('npm-package-no-vulns');
// TODO(boost): confirm that monitor is called with correct params
// this currently fails as fake-server is not called?
// const monitorSpy = sinon.stub(snykMonitor, 'monitor').callThrough();
const result = await cli.wizard({ file: 'package-lock.json' });
t.contains(
result,
'You can see a snapshot of your dependencies here',
'wizard saves snapshot',
);
// t.equal(monitorSpy.calledOnceWith(
// 'npm-package-no-vulns',
// {} as MonitorMeta,
// [] as ScannedProject,
// {} as Options,
// {} as PluginMetadata,
// ), true);
try {
fs.unlinkSync('./.snyk');
} catch (err) {
throw new Error(
'Failed to delete test/acceptance/workspaces/npm-package-no-vulns/.snyk',
);
}
});

test('`wizard` for unsupported package managers', async (t) => {
chdirWorkspaces();
async function testUnsupported(data) {
Expand Down Expand Up @@ -120,20 +147,3 @@ after('teardown', async (t) => {
t.end();
}
});

// fixture can be fixture path or object
function stubDockerPluginResponse(fixture: string | object, t) {
const plugin = {
async inspect() {
return typeof fixture === 'object' ? fixture : require(fixture);
},
};
const spyPlugin = sinon.spy(plugin, 'inspect');
const loadPlugin = sinon.stub(plugins, 'loadPlugin');
loadPlugin
.withArgs(sinon.match.any, sinon.match({ docker: true }))
.returns(plugin);
t.teardown(loadPlugin.restore);

return spyPlugin;
}
5 changes: 5 additions & 0 deletions test/acceptance/fake-server.ts
Expand Up @@ -144,6 +144,11 @@ export function fakeServer(root, apikey) {
},
);

server.get(root + '/authorization/:action', (req, res, next) => {
res.send({ result: { allowed: true } });
return next();
});

server.put(root + '/monitor/:registry/graph', (req, res, next) => {
res.send({
id: 'monitor',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d2a5578

Please sign in to comment.