e8f79d43f9
closes #517 add index test for Application add app.toJSON test add test for app.inspect() add tests for app.use() add tests for app.onerror() add tests for app.respond() add tests for app.context() add tests for app.request() add tests for app.response refactor for non-existence of test/app...js no need for *.js use helpers/ dir for non-tests
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
|
|
'use strict';
|
|
|
|
const context = require('../helpers/context');
|
|
|
|
describe('ctx.fresh', function(){
|
|
describe('the request method is not GET and HEAD', function (){
|
|
it('should return false', function (){
|
|
const ctx = context();
|
|
ctx.req.method = 'POST';
|
|
ctx.fresh.should.be.false;
|
|
})
|
|
})
|
|
|
|
describe('the response is non-2xx', function(){
|
|
it('should return false', function(){
|
|
const ctx = context();
|
|
ctx.status = 404;
|
|
ctx.req.method = 'GET';
|
|
ctx.req.headers['if-none-match'] = '123';
|
|
ctx.set('ETag', '123');
|
|
ctx.fresh.should.be.false;
|
|
})
|
|
});
|
|
|
|
describe('the response is 2xx', function(){
|
|
describe('and etag matches', function(){
|
|
it('should return true', function(){
|
|
const ctx = context();
|
|
ctx.status = 200;
|
|
ctx.req.method = 'GET';
|
|
ctx.req.headers['if-none-match'] = '123';
|
|
ctx.set('ETag', '123');
|
|
ctx.fresh.should.be.true;
|
|
})
|
|
})
|
|
|
|
describe('and etag do not match', function(){
|
|
it('should return false', function(){
|
|
const ctx = context();
|
|
ctx.status = 200;
|
|
ctx.req.method = 'GET';
|
|
ctx.req.headers['if-none-match'] = '123';
|
|
ctx.set('ETag', 'hey');
|
|
ctx.fresh.should.be.false;
|
|
})
|
|
})
|
|
})
|
|
})
|