afterEach(() => { CloudFormation.prototype.getSubscribersPoolID.restore() CloudFormation.prototype.getStatusPageCloudFrontURL.restore() SettingsProxy.prototype.getEmailNotification.restore() SettingsProxy.prototype.getServiceName.restore() SES.prototype.sendEmailWithRetry.restore() IncidentsStore.prototype.get.restore() IncidentUpdatesStore.prototype.query.restore() Cognito.prototype.listUsers.restore() console.log.restore() })
console.log.restore(); }); });
console.warn.restore(); done(); });
test('Should remove by url', done => { const rmServer = nock('http://localhost:8080').post(`/remove/${url}`).reply(204); const consoleSpy = sinon.spy(console, 'log'); remove({id: url}).then(() => { // make sure log in was successful // check that server was called expect(rmServer.isDone()).toBeTruthy(); // first check console output expect(consoleSpy.args).toMatchSnapshot(); // restore console console.log.restore(); rmServer.done(); done(); }); });
describe('tasks', () => { beforeEach(() => { sinon.stub(console, 'log') }) afterEach(() => { console.log.restore() }) it('loads config and outputs tasks to the console', () => { utils.tasks() expect(console.log.firstCall.args[0]).to.include('Tasks') }) })
// test test('Should not deploy with broken config', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); // corrupt config with string fs.writeFileSync(path.join(__dirname, '..', 'exoframe.json'), 'I am broken json now'); // execute deploy deploy().then(() => { // check console output expect(consoleSpy.args).toMatchSnapshot(); // restore console console.log.restore(); done(); }); });
// test test('Should not deploy with non-existent path', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); // execute deploy deploy({_: ['i-do-not-exist']}).then(() => { // check console output const pathLine = consoleSpy.args.splice(1, 1).pop(); expect(consoleSpy.args).toMatchSnapshot(); expect(pathLine[0].includes('Error! Path')).toBeTruthy(); expect(pathLine[0].includes(path.join(__dirname, '..', 'i-do-not-exist'))).toBeTruthy(); expect(pathLine[0].includes('do not exists')).toBeTruthy(); // restore console console.log.restore(); done(); }); });
// 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(); }); });
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 test('Should not deploy with config without project name', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); // corrupt config with string const exoConfig = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'exoframe.json'))); exoConfig.name = ''; fs.writeFileSync(path.join(__dirname, '..', 'exoframe.json'), JSON.stringify(exoConfig)); // execute deploy deploy().then(() => { // check console output expect(consoleSpy.args).toMatchSnapshot(); // restore console console.log.restore(); done(); }); });
// test update test('Should update traefik', done => { // handle correct request const updateServer = nock('http://localhost:8080').post('/update/traefik').reply(200, {updated: true}); // spy on console const consoleSpy = sinon.spy(console, 'log'); // execute login update({target: 'traefik'}).then(() => { // make sure log in was successful // check that server was called expect(updateServer.isDone()).toBeTruthy(); // first check console output expect(consoleSpy.args).toMatchSnapshot(); // restore console console.log.restore(); updateServer.done(); done(); }); });
afterEach(() => { CloudFormation.prototype.getSubscribersPoolID.restore() CloudFormation.prototype.getStatusPageCloudFrontURL.restore() SettingsProxy.prototype.getEmailNotification.restore() SettingsProxy.prototype.getServiceName.restore() SES.prototype.sendEmailWithRetry.restore() IncidentsStore.prototype.get.restore() IncidentUpdatesStore.prototype.query.restore() Cognito.prototype.listUsers.restore() console.log.restore() })
test('Should remove by token instead of default auth', done => { const rmServer = nock('http://localhost:8080').post(`/remove/${id}`).reply(204); const consoleSpy = sinon.spy(console, 'log'); remove({id: id, token: 'test-token'}).then(() => { // make sure log in was successful // check that server was called expect(rmServer.isDone()).toBeTruthy(); // first check console output expect(consoleSpy.args).toMatchSnapshot(); // restore console console.log.restore(); rmServer.done(); done(); }); });
// test removal error on incorrect success code test('Should show not found error', done => { // handle correct request const rmServer = nock('http://localhost:8080').post(`/remove/${id}`).reply(200); // spy on console const consoleSpy = sinon.spy(console, 'log'); // execute login remove({id}).then(() => { // make sure log in was successful // check that server was called expect(rmServer.isDone()).toBeTruthy(); // first check console output expect(consoleSpy.args).toMatchSnapshot(); // restore console console.log.restore(); rmServer.done(); done(); }); });