beforeEach(() => { app = nock('https://api.classy.org') .persist() .post('/oauth2/auth') .reply(200, { expires_in: 10 }); });
function nockConfig (yamlConfig) { const encoding = 'base64' nock('https://api.github.com') .persist() .get('/repos/AlQaholic007/test/contents/.github/hydrabot.yml') .reply(200, { content: Buffer.from(yamlConfig).toString(encoding), encoding: encoding }) }
function nockEmptyConfig () { nock('https://api.github.com') .persist() .get('/repos/AlQaholic007/test/contents/.github/hydrabot.yml') .reply(404) .get('/repos/AlQaholic007/.github/contents/.github/hydrabot.yml') .reply(404) }
test('Handles HTTP errors from POST request', (t) => { t.plan(3) t.on('end', async () => { nock.cleanAll() }) const logger = new Logger(apiKey, createOptions({ retryTimes: 2 , retryTimeout: 100 })) nock(logger._url) .post('/', () => { return true }) .query(() => { return true }) .reply(500, 'NOPE') .persist() const expectedErr = 'An error occured while making the request. ' + 'Response status code: 500 null' let count = 0 logger.log('This will not work', (err) => { t.equal(err, expectedErr, `Error ${++count} received as expected`) }) })
it('should end the stream when max retry attempts reached for non executed builds', done => { const scope = mockServer .persist() .get(path) .reply(200, { status: STATUS_TYPES.notExecuted }); const stream = new StreamBuildStages(buildStagesOptions); let counter = 0; stream.on('data', () => { counter++; }); stream.on('end', status => { expect(status).toBe(STATUS_TYPES.notExecuted); expect(counter).toBe(0); scope.persist(false); done(); }); });
.persist() .get('/') .reply(200, html);
it('should handle non-200 responses as errors', () => { nock('https://api.classy.org') .persist() .post('/oauth2/auth') .reply(200, { expires_in: 10 }); const method = resource.createMethod({ method: 'GET', path: '/test' }); nock('https://api.classy.org') .get('/2.0/test/test') .reply(404); return method({ token: 'app' }) .then((response) => false, (error) => true) .then((val) => expect(val).to.be.true); });
.query(() => { return true }) .reply(200, 'Ingester response') .persist()