koa-lite/test/request/idempotent.js

27 lines
689 B
JavaScript
Raw Permalink Normal View History

2014-07-06 08:43:14 +00:00
'use strict';
2017-05-11 03:30:32 +00:00
const assert = require('assert');
const request = require('../helpers/context').request;
2014-07-06 08:43:14 +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){
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
describe('when the request method is not idempotent', () => {
it('should return false', () => {
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
});
});
});