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

78 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-12-11 09:56:39 +01:00
const { describe, it, beforeEach } = require('mocha');
2019-12-11 09:32:40 +01:00
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', () => {
2019-12-11 09:56:39 +01:00
beforeEach(() => {
mock.registered = {};
});
2019-12-11 09:32:40 +01:00
it('should detect all requests on root', () => {
2019-12-11 12:19:02 +01:00
requestor(mock, './test/root');
2019-12-11 09:38:35 +01:00
expect(mock.registered).to.have.all.keys([
'post-/',
'get-/',
'put-/',
'delete-/',
'all-/'
]);
2019-12-11 09:32:40 +01:00
});
2019-12-11 09:56:39 +01:00
it('should detect requests on root.subfolder', () => {
2019-12-11 12:19:02 +01:00
requestor(mock, './test/root.sub');
2019-12-11 09:56:39 +01:00
expect(mock.registered).to.have.all.keys([
'post-/sub/',
'get-/sub/',
'put-/sub/',
'delete-/sub/',
'all-/sub/'
]);
});
it('should detect requests on subfolder', () => {
2019-12-11 12:19:02 +01:00
requestor(mock, './test/sub');
2019-12-11 09:56:39 +01:00
expect(mock.registered).to.have.all.keys([
'post-/sub/',
'get-/sub/',
'put-/sub/',
'delete-/sub/',
'all-/sub/',
2019-12-11 12:01:34 +01:00
'get-/sub/lv1/lv2/lv3/',
'all-/sub/root/'
2019-12-11 09:56:39 +01:00
]);
});
2019-12-11 12:19:02 +01:00
it('should build requests with subdirectory', () => {
requestor(mock, './test/sub', {}, 'test');
expect(mock.registered).to.have.all.keys([
'post-/test/sub/',
'get-/test/sub/',
'put-/test/sub/',
'delete-/test/sub/',
'all-/test/sub/',
'get-/test/sub/lv1/lv2/lv3/',
'all-/test/sub/root/'
]);
});
2019-12-11 09:32:40 +01:00
});