beforeEach(() => { sandbox = sinon.createSandbox(); mockStart = 10000000; mockNow = mockStart; sandbox.stub(Date, "now").callsFake(() => mockNow); fill = function (count, interval) { const mockData = []; for (let i = 0; i < count; ++i) { mockNow += interval; const mockMetric = createMockMetric(); metricsProvider._onMetrics(mockMetric); mockData.push(mockMetric); } return mockData; }; testContainer = utils.getTestContainer(sandbox); metricsProvider = new MetricsProvider(testContainer.screen); });
let seed1 = Math.random(); let seed2 = Math.random(); let stub = sinon.stub(mathRandom, 'onBeforeRun').callsFake((kernel) => { kernel.setUniform1f('randomSeed1', seed1); kernel.setUniform1f('randomSeed2', seed2); assert.ok(stub.called); stub.restore(); stub.callsFake((kernel) => { kernel.setUniform1f('randomSeed1', seed1); kernel.setUniform1f('randomSeed2', seed2);
}, ]}; const stub = sinon.stub(updates.githubApi.repos, 'getReleases').callsFake(() => Promise.resolve(mockReleaseData)); return updates.refresh('beta.2') .then(data => {
const reportable = _.size(_.filter(endpoints, endpoint => endpoint.report)); const metrics = new Metrics({id, endpoints, data: {prisoner: 'valjean'}}); sinon.stub(axios, 'create').callsFake(({baseURL = 'localhost'} = {}) => ({ post: (path, data) => { baseURL.should.equal(endpoints[counter].url); const reportable = _.size(_.filter(endpoints, endpoint => endpoint.report)); const metrics = new Metrics({endpoints, log: {debug: sinon.spy(), verbose: sinon.spy()}}); sinon.stub(axios, 'create').callsFake(() => ({ post: () => Promise.reject(), })); const endpoints = [{url: 'https://place.for.the.things/metrics', report: true}]; const metrics = new Metrics({endpoints, data: {inspector: 'javier'}}); sinon.stub(axios, 'create').callsFake(() => ({ post: (path, data) => { if (data.action === 'escape') data.should.have.property('freedman', 'valjean');
beforeEach(() => { let counter = {}; sinon.stub(axios, 'create').callsFake(() => ({ get: url => { counter[url] = counter[url] + 1 || 0;
describe('#sh', () => { it('should use shelljs.exec when mode is exec and detached is false', () => { const shell = new Shell(); sinon.stub(_shell, 'exec').callsFake(fakeExec); return shell.sh(['slip', 'sliding', 'away']) .then(result => { sinon.stub(child, 'spawn').callsFake(fakeSpawn); _.forEach([{mode: 'collect'}, {detached: true}], opts => { return shell.sh(['tupelo', 'honey', 'baby'], opts) sinon.stub(child, 'spawn').callsFake(fakeSpawn); return shell.sh(['set', 'us', 'up', 'the', 'bomb'], {mode: 'attach'}).should.be.rejected .then(child.spawn.restore()); sinon.stub(child, 'spawn').callsFake(fakeSpawn); return shell.sh(['van', 'the', 'man'], {detached: true}).should.be.fulfilled .then(child.spawn.restore()); const shell = new Shell(); process.lando = 'browser'; sinon.stub(child, 'spawn').callsFake((cmd, args, opts) => { opts.stdio[0].should.equal('ignore'); opts.stdio[1].should.equal('pipe'); const shell = new Shell(); process.lando = 'node'; sinon.stub(child, 'spawn').callsFake((cmd, args, opts) => { opts.stdio.should.equal('inherit'); return {
describe('storage:s3', function() { var createClientStub, uploadFileStub, onSpy beforeEach(function(){ onSpy = sinon.stub().callsFake(function(type, func) { if (type === 'end') { func({})
beforeAll(() => { try { fs.statSync(configPath); fs.unlinkSync(configPath); } catch (e) { // no config, just exit } sinon .stub(inquirer, 'prompt') .onFirstCall() .callsFake(() => Promise.resolve(configData)) .onSecondCall() .callsFake(() => Promise.resolve(users[0])) .onThirdCall() .callsFake(() => Promise.resolve(users[1])); });
// test failure test('Should not login with wrong certificate', done => { // stup inquirer answers sinon.stub(inquirer, 'prompt').callsFake(() => Promise.resolve(failedLogin.user)); // spy on console const consoleSpy = sinon.spy(console, 'log'); // execute login login({key: privateKeyNameBroken}).then(() => { // make sure log in was successful // check that server was called expect(failedLoginSrv.isDone()).toBeTruthy(); // first check console output expect(consoleSpy.args).toMatchSnapshot(); // restore inquirer inquirer.prompt.restore(); // restore console console.log.restore(); done(); }); });
it('should update password and send confirmation email when email and reset token are valid', async () => { await PasswordResetToken.create(resetToken); sandbox .stub(emailProvider, 'sendPasswordChangeEmail') .callsFake(() => Promise.resolve('email sent')); return request(app) .post('/v1/auth/reset-password') .send({ email: dbUser.email, password: 'updatedPassword2', resetToken: resetToken.resetToken, }) .expect(httpStatus.OK) .then((res) => { expect(res.body).to.be.equal('Password Updated'); }); });
// test wrong credentials test('Should fail to login with broken private key', done => { // stup inquirer answers sinon.stub(inquirer, 'prompt').callsFake(() => Promise.resolve(wrongUser)); // spy on console const consoleSpy = sinon.spy(console, 'log'); // execute login login({key: 'asd'}).then(() => { // first check console output expect(consoleSpy.args).toMatchSnapshot(); // then check the config (should not change) expect(cfg.userConfig.token).toEqual(token); expect(cfg.userConfig.user.username).toEqual(correctLogin.user.username); // restore inquirer inquirer.prompt.restore(); // restore console console.log.restore(); done(); }); });
test('Should not remove only endpoint', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); // stup inquirer answers sinon.stub(inquirer, 'prompt').callsFake(() => Promise.resolve({delEndpoint: origCfg.endpoint})); // execute login removeEndpoint({}).then(() => { // first check console output expect(consoleSpy.args).toMatchSnapshot(); // then check config changes expect(cfg.userConfig.endpoint).toEqual(origCfg.endpoint); expect(cfg.userConfig.user.username).toEqual(origCfg.user.username); expect(cfg.userConfig.token).toEqual(origCfg.token); expect(cfg.userConfig.endpoints.length).toEqual(0); // restore console console.log.restore(); // restore inquirer inquirer.prompt.restore(); done(); }); });
test('Should remove current endpoint using inquirer', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); // stup inquirer answers sinon.stub(inquirer, 'prompt').callsFake(() => Promise.resolve({delEndpoint: mockEndpoint})); // execute login removeEndpoint({}).then(() => { // first check console output expect(consoleSpy.args).toMatchSnapshot(); // then check config changes expect(cfg.userConfig.endpoint).toEqual(mockEndpoint2); expect(cfg.userConfig.user).toBeNull(); expect(cfg.userConfig.token).toBeNull(); expect(cfg.userConfig.endpoints.length).toEqual(1); expect(cfg.userConfig.endpoints[0].endpoint).toEqual(origCfg.endpoint); expect(cfg.userConfig.endpoints[0].user.username).toEqual(origCfg.user.username); expect(cfg.userConfig.endpoints[0].token).toEqual(origCfg.token); // restore console console.log.restore(); // restore inquirer inquirer.prompt.restore(); done(); }); });
test('Should show error on remove of non-existent endpoint', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); // stup inquirer answers sinon.stub(inquirer, 'prompt').callsFake(() => Promise.resolve({delEndpoint: 'do-not-exist'})); // execute login removeEndpoint({}).then(() => { // first check console output expect(consoleSpy.args).toMatchSnapshot(); // restore console console.log.restore(); // restore inquirer inquirer.prompt.restore(); done(); }); });
// test login test('Should login', done => { // stup inquirer answers sinon.stub(inquirer, 'prompt').callsFake(() => Promise.resolve(correctLogin.user)); // spy on console const consoleSpy = sinon.spy(console, 'log'); // execute login login({key: privateKeyName}).then(() => { // make sure log in was successful // check that server was called expect(correctLoginSrv.isDone()).toBeTruthy(); // first check console output expect(consoleSpy.args).toMatchSnapshot(); // then check config changes expect(cfg.userConfig.token).toEqual(token); expect(cfg.userConfig.user.username).toEqual(correctLogin.user.username); // restore inquirer inquirer.prompt.restore(); // restore console console.log.restore(); done(); }); });