it('throws correct error with request error', async function () { nock(this.baseUrl) .get('/Basic/1') .replyWithError('cannot connect'); return this.fhirClient.read({ resourceType: 'Basic', id: '1', }).then(() => { throw new Error('should not have succeeded'); }) .catch((error) => { expect(error).to.have.property('message').and.match(/cannot connect/); }); });
it('should use the provided debugging function and errorLogger on error', function() { const method = resource.createMethod({ method: 'GET', path: '/test' }); nock('https://api.classy.org') .get('/2.0/test/test') .replyWithError({ test: 'oh no, an error!' }); return method({ token: 'app' }).catch(() => { expect(onRequestDebugStub).to.have.been.called; expect(errorLoggerStub).to.have.been.called; }); });
it('Check get by id 404 does not exist', (done) => { const content = fs.readFileSync('./test/mockedresponses/users-404.json') const parsedContent = JSON.parse(content) nock(`http://127.0.0.1:${process.env.PORT}/`) .get('/users/0000000000000001') .replyWithError({ status: 404, body: parsedContent }) apilocal.get('/users/0000000000000001') .then(res => { //non action needed }).catch((response) => { expect(response.status).equal(404) expect(response.body).to.have.property('errors') expect(response.body.errors).to.be.an('array') expect(response.body.errors[0]).to.have.property('msg') expect(response.body.errors[0].msg).equal('Not found') done() }) })
it('should end the stream when max network failure attempts reached', done => { mockServer .get(path) .reply(200, { status: STATUS_TYPES.inProgress, stages: [stageOneStub], }) .get(path) .replyWithError('boom!') .get(path) .replyWithError('boom!') .get(path) .replyWithError('boom!') .get(path) .replyWithError('boom!'); const stream = new StreamBuildStages(buildStagesOptions); const data = []; stream.on('data', build => { data.push(build); }); stream.on('error', error => { expect(error.message).toBe('boom!'); expect(data).toHaveLength(1); done(); }); });
it('Check users return error 500', (done) => { const content = fs.readFileSync('./test/mockedresponses/users-500.json') const parsedContent = JSON.parse(content) nock(`http://127.0.0.1:${process.env.PORT}/`) .get('/users') .replyWithError({ status: 500, body: parsedContent }) apilocal.get('/users') .then(response => { console.log('should not print it') // done() }).catch((response) => { expect(response.status).equal(500) expect(response.body).to.have.property('errors') expect(response.body.errors).to.be.an('array') expect(response.body.errors[0]).to.have.property('msg') expect(response.body.errors[0].msg).equal('Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.') done() }) })
it('set_control_info Net-Error', function (done) { var vals = { 'power': false, 'mode': 3, 'stemp': 24, 'shum': 0 }; var req = nock('http://127.0.0.1') .post('/aircon/set_control_info', /pow=0&mode=3&stemp=24.0&shum=0/) .replyWithError({code: 'ETIMEDOUT'}); var daikin = new DaikinACRequest('127.0.0.1'); var res = daikin.setACControlInfo(vals, function(err, ret, daikinResponse) { //console.log(JSON.stringify(daikinResponse)); //console.log(JSON.stringify(err)); expect(req.isDone()).to.be.true; expect(daikinResponse).to.be.null; expect(ret).to.be.null; expect(err.toString()).to.be.equal('Error: Error while communicating with Daikin device: ETIMEDOUT'); done(); }); });
.get(path) .query(true) .replyWithError('boom!');
nock('https://api.telegram.org') .post('/botfoo/sendMessage') .replyWithError('something awful happened') const transport = new Transport({ token: 'foo',
it('should handle response errors', () => { const method = resource.createMethod({ method: 'GET', path: '/test' }); nock('https://api.classy.org') .get('/2.0/test/test') .replyWithError({ test: 'oh no!' }); return method({ token: 'app' }) .catch((error) => { expect(error.message).to.equal('{"test":"oh no!"}'); expect(errorLoggerStub).to.have.been.called; }); });
}) .get(path) .replyWithError('boom!') .get(path) .reply(200, {