complete tests

This commit is contained in:
Timo Hocker 2019-12-11 09:56:39 +01:00
parent 3c5bf74581
commit e9cd5d8068
21 changed files with 70 additions and 8 deletions

View File

@ -11,12 +11,11 @@ module.exports = function (app, modulefolder, opts) {
for (const f of fs.readdirSync(modulefolder)) {
const regex = /(.*?)-(.*?)\.js/;
let [, method, url] = regex.exec(f);
url =
'/' +
url
.replace(/^root/i, '')
.replace(/\./g, '/')
.replace(/\/+/g, '/');
url = '/' + url + '/';
url = url
.replace(/^\/root/i, '/')
.replace(/\./g, '/')
.replace(/\/+/g, '/');
const handler = require(('./' + modulefolder + '/' + f)
.replace(/\/\.\//g, '/')

View File

@ -1,4 +1,4 @@
const { describe, it } = require('mocha');
const { describe, it, beforeEach } = require('mocha');
const expect = require('chai').expect;
const requestor = require('../index');
@ -23,8 +23,12 @@ const mock = {
};
describe('requestor', () => {
beforeEach(() => {
mock.registered = {};
});
it('should detect all requests on root', () => {
requestor(mock, './test/onroot', {});
requestor(mock, './test/root', {});
expect(mock.registered).to.have.all.keys([
'post-/',
'get-/',
@ -33,4 +37,27 @@ describe('requestor', () => {
'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/'
]);
});
});

3
test/root/all-root.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/root/delete-root.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/root/get-root.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/root/not-root.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/root/post-root.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/root/put-root.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/sub/all-sub.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/sub/delete-sub.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/sub/get-sub.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

View File

3
test/sub/not-sub.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/sub/post-sub.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};

3
test/sub/put-sub.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = (req, res, next, opts) => {
// dummy endpoint: do nothing
};