This repository has been archived on 2020-08-13. You can view files and clone it, but cannot push or open issues or pull requests.
requestor/test/main.js
2019-12-11 12:01:34 +01:00

65 lines
1.5 KiB
JavaScript

const { describe, it, beforeEach } = require('mocha');
const expect = require('chai').expect;
const requestor = require('../index');
const mock = {
registered: {},
post: function (path, handler) {
this.registered['post-' + path] = handler;
},
get: function (path, handler) {
this.registered['get-' + path] = handler;
},
put: function (path, handler) {
this.registered['put-' + path] = handler;
},
delete: function (path, handler) {
this.registered['delete-' + path] = handler;
},
all: function (path, handler) {
this.registered['all-' + path] = handler;
}
};
describe('requestor', () => {
beforeEach(() => {
mock.registered = {};
});
it('should detect all requests on root', () => {
requestor(mock, './test/root', {});
expect(mock.registered).to.have.all.keys([
'post-/',
'get-/',
'put-/',
'delete-/',
'all-/'
]);
});
it('should detect requests on root.subfolder', () => {
requestor(mock, './test/root.sub', {});
expect(mock.registered).to.have.all.keys([
'post-/sub/',
'get-/sub/',
'put-/sub/',
'delete-/sub/',
'all-/sub/'
]);
});
it('should detect requests on subfolder', () => {
requestor(mock, './test/sub', {});
expect(mock.registered).to.have.all.keys([
'post-/sub/',
'get-/sub/',
'put-/sub/',
'delete-/sub/',
'all-/sub/',
'get-/sub/lv1/lv2/lv3/',
'all-/sub/root/'
]);
});
});