describe('Unit | Adapter', function() { it('should exist', function() { expect(Adapter).to.be.a('function'); }); });
it('should update the recording id when the name changes', async function() { const polly = new Polly('squawk'); expect(polly.recordingName).to.equal('squawk'); expect(polly.recordingId).to.contain('squawk'); polly.recordingName = 'chirp'; expect(polly.recordingName).to.equal('chirp'); expect(polly.recordingId).to.contain('chirp'); await polly.stop(); });
it('registers a known event via .on() with .times() and override with { times }', function() { const handler = new Handler(); const { _eventEmitter: eventEmitter } = handler; handler.times(2).on('request', () => {}, { times: 1 }); expect(eventEmitter.hasListeners('request')).to.be.true; eventEmitter.emitSync('request'); expect(eventEmitter.hasListeners('request')).to.be.false; });
it('should be chainable', function() { expect(base.setHeader('one', '1')).to.equal(base); expect(base.setHeaders({ one: '1' })).to.equal(base); expect(base.type('text/plain')).to.equal(base); expect(base.send('body')).to.equal(base); expect(base.json({ foo: 'bar' })).to.equal(base); expect(base.end()).to.equal(base); });
it('should concat handlers for same paths with different star segment names', async function() { addHandlers('/ping/*path'); expect(server.lookup('GET', '/ping/*path').handlers).to.have.lengthOf(3); addHandlers('/ping/*rest'); expect(server.lookup('GET', '/ping/*path').handlers).to.have.lengthOf(6); expect(server.lookup('GET', '/ping/*rest').handlers).to.have.lengthOf(6); });
it('should not be configurable once requests are handled', async function() { this.polly._requests.push({}); expect(() => this.polly.configure()).to.throw( PollyError, 'Cannot call `configure` once requests have been handled.' ); });
it('.passthrough()', function() { const interceptor = new Interceptor(); expect(interceptor.shouldPassthrough).to.be.false; expect(interceptor.shouldIntercept).to.be.true; interceptor.passthrough(); expect(interceptor.shouldPassthrough).to.be.true; expect(interceptor.shouldIntercept).to.be.false; });
it('registers a known event via .on() with { times }', function() { const handler = new Handler(); const { _eventEmitter: eventEmitter } = handler; handler.on('request', () => {}, { times: 2 }); expect(eventEmitter.hasListeners('request')).to.be.true; eventEmitter.emitSync('request'); expect(eventEmitter.hasListeners('request')).to.be.true; eventEmitter.emitSync('request'); expect(eventEmitter.hasListeners('request')).to.be.false; });
it('should handle multiple routes on all HTTP methods', function() { HTTP_METHODS.forEach(method => { server[method.toLowerCase()]([ `/${method}`, `/${method}/*path` ]).intercept(() => 200); expect(request(method, `/${method}`)).to.equal(200); expect(request(method, `/${method}/foo/bar`)).to.equal(200); }); });
it('should handle all HTTP methods', function() { HTTP_METHODS.forEach(method => { server[method.toLowerCase()]('/foo').intercept(() => 200); expect(request(method, '/foo')).to.equal(200); }); });