2013-11-13 17:01:15 +00:00
|
|
|
|
|
|
|
var context = require('../context');
|
|
|
|
|
|
|
|
describe('ctx.fresh', function(){
|
2014-07-06 08:43:14 +00:00
|
|
|
describe('the request method is not GET and HEAD', function (){
|
|
|
|
it('should return false', function (){
|
|
|
|
var ctx = context();
|
|
|
|
ctx.req.method = 'POST';
|
|
|
|
ctx.fresh.should.be.false;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2013-11-13 17:01:15 +00:00
|
|
|
describe('the response is non-2xx', function(){
|
|
|
|
it('should return false', function(){
|
|
|
|
var 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(){
|
|
|
|
var 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(){
|
|
|
|
var 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;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-07-06 08:43:14 +00:00
|
|
|
})
|