2014-07-06 08:43:14 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-05-11 03:30:32 +00:00
|
|
|
const assert = require('assert');
|
2015-10-12 04:59:30 +00:00
|
|
|
const request = require('../helpers/context').request;
|
2014-07-06 08:43:14 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('ctx.idempotent', () => {
|
|
|
|
describe('when the request method is idempotent', () => {
|
|
|
|
it('should return true', () => {
|
2014-07-06 08:43:14 +00:00
|
|
|
['GET', 'HEAD', 'PUT', 'DELETE', 'OPTIONS', 'TRACE'].forEach(check);
|
2015-10-12 20:36:41 +00:00
|
|
|
function check(method){
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2014-07-06 08:43:14 +00:00
|
|
|
req.method = method;
|
2017-05-11 03:30:32 +00:00
|
|
|
assert.equal(req.idempotent, true);
|
2014-07-06 08:43:14 +00:00
|
|
|
}
|
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('when the request method is not idempotent', () => {
|
|
|
|
it('should return false', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2014-07-06 08:43:14 +00:00
|
|
|
req.method = 'POST';
|
2017-05-11 03:30:32 +00:00
|
|
|
assert.equal(req.idempotent, false);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|