describe('LU instance', function() { const response = require('./../../fixtures/translation/serviceresponses/intentsAndutterances.json') before(function(){ nock('https://api.cognitive.microsofttranslator.com') .post(/.*/) .reply(200, response) }) it('Transalte LU instance content', async () => { let luContent = await fs.readFile(path.join(__dirname, './../../fixtures/translation/files/intentsAndUtterances.lu')) let result = await fs.readFile(path.join(__dirname, './../../fixtures/translation/translatedfiles/intentsAndUtterances.lu')) const luInstance = new LU(luContent.toString()) await luInstance.translate('xxxxxxx', 'fr', true, false) compareLuFiles(luInstance.content, result) }); });
.post(uri => uri.includes('createasync')) .reply(202, { operationId: 'f8c64e2a-aaaa-3a09-8f78-39d7adc76ec5'
.post(uri => uri.includes('createasync')) .reply(202, { operationId: 'f8c64e2a-aaaa-3a09-8f78-39d7adc76ec5'
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(); }); });
// test test('Should deploy without path', done => { // spy on console const consoleSpy = sinon.spy(console, 'log'); // handle correct request const deployServer = nock('http://localhost:8080') .post('/deploy') .reply(() => replyWithStream([{message: 'Deployment success!', deployments, level: 'info'}])); // execute login deploy().then(() => { // make sure log in was successful // check that server was called expect(deployServer.isDone()).toBeTruthy(); // first check console output expect(consoleSpy.args).toMatchSnapshot(); // restore console console.log.restore(); // tear down nock deployServer.done(); done(); }); });
.post(uri => uri.includes('createasync')) .reply(202, { operationId: 'f8c64e2a-aaaa-3a09-8f78-39d7adc76ec5'
.post(uri => uri.includes('createasync')) .reply(202, { operationId: 'f8c64e2a-aaaa-3a09-8f78-39d7adc76ec5'
// 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(); }); });
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(); }); });
// test removal test('Should remove', done => { // handle correct request const rmServer = nock('http://localhost:8080').post(`/remove/${id}`).reply(204); // 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(); }); });
// test removal error test('Should show remove error', done => { // handle correct request const rmServer = nock('http://localhost:8080').post(`/remove/${id}`).reply(500); // 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(); }); });
// test removal error test('Should show not found error', done => { // handle correct request const rmServer = nock('http://localhost:8080').post(`/remove/${id}`).reply(404); // 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(); }); });
// test update test('Should update server', done => { // handle correct request const updateServer = nock('http://localhost:8080').post('/update/server').reply(200, {updated: true}); // spy on console const consoleSpy = sinon.spy(console, 'log'); // execute login update({target: 'server'}).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(); }); });
// test update error test('Should display update error', done => { // handle correct request const response = {updated: false, error: 'Test error', log: 'log'}; const updateServer = nock('http://localhost:8080').post('/update/traefik').reply(500, response); // 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(); }); });