2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-12 04:59:30 +00:00
|
|
|
const context = require('../helpers/context');
|
2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('ctx.fresh', () => {
|
|
|
|
describe('the request method is not GET and HEAD', () => {
|
|
|
|
it('should return false', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2014-07-06 08:43:14 +00:00
|
|
|
ctx.req.method = 'POST';
|
|
|
|
ctx.fresh.should.be.false;
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2014-07-06 08:43:14 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('the response is non-2xx', () => {
|
|
|
|
it('should return false', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-13 17:01:15 +00:00
|
|
|
ctx.status = 404;
|
|
|
|
ctx.req.method = 'GET';
|
|
|
|
ctx.req.headers['if-none-match'] = '123';
|
|
|
|
ctx.set('ETag', '123');
|
|
|
|
ctx.fresh.should.be.false;
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
2013-11-13 17:01:15 +00:00
|
|
|
});
|
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('the response is 2xx', () => {
|
|
|
|
describe('and etag matches', () => {
|
|
|
|
it('should return true', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-13 17:01:15 +00:00
|
|
|
ctx.status = 200;
|
|
|
|
ctx.req.method = 'GET';
|
|
|
|
ctx.req.headers['if-none-match'] = '123';
|
|
|
|
ctx.set('ETag', '123');
|
|
|
|
ctx.fresh.should.be.true;
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('and etag do not match', () => {
|
|
|
|
it('should return false', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2013-11-13 17:01:15 +00:00
|
|
|
ctx.status = 200;
|
|
|
|
ctx.req.method = 'GET';
|
|
|
|
ctx.req.headers['if-none-match'] = '123';
|
|
|
|
ctx.set('ETag', 'hey');
|
|
|
|
ctx.fresh.should.be.false;
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|