I have defined the following simple function and I want to test this using nock. function checkJobAndUpload(ycgResponse, targetJob, integrationId, jobBoardId, callback) { const options = { uri: 'https://multiposting.stepstone.com/status/1', method: 'GET', resolveWithFullResponse: true }; const payload = JSON.stringify({ message: 'success' }) const put_options = { uri: 'https://multiposting.stepstone.com/listings/1', method: 'PUT', body: payload, resolveWithFullResponse: true }; rp(options).then(response => { console.log('Status call succeeded') return rp(put_options) }).then(response => { console.log('Update call succeeded') callback(null, { statusCode: 200 }); }).catch(error => { callback({ statusCode: 500 }); }); }
Below is my nock setup.
it('Should succeed in check, update and upload job status functions', () => { nock.cleanAll(); var statusAPI = nock('https://multiposting.stepstone.com').get(`/status/1`).reply(200, statusResponse) var putAPI = nock('https://multiposting.stepstone.com/').filteringRequestBody(function (body) { console.log(body); return 'ABC'; }).put('/listings/1', 'ABC').reply(201) console.log(nock.pendingMocks()) sut.checkAndUpload(ycgResponse, targetJob, integrationId, jobBoard, function (err, response) { console.log(err) console.log('----') console.log(response) console.log(nock.activeMocks()) console.log(putAPI.isDone()) console.log(statusAPI.isDone()) should.equal(200, response.statusCode) }); });
The issue here is that the callback
is not being called back. Always the first GET
request passes but the PUT
request neither passes nor fails. I do not see any errors as well.
Here is my console.logs
uploader #check and upload [ 'GET https://multiposting.stepstone.com:443/status/1', 'PUT https://multiposting.stepstone.com:443/listings/1' ] ✓ Should succeed in check, update and upload job status functions Status call succeeded {"message":"success"} 1 passing (32ms)
via madan
No comments:
Post a Comment