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

85 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-01-30 10:51:05 +01:00
'use strict';
2020-02-24 12:34:07 +01:00
const { test } = require ('ava');
2020-01-03 19:13:21 +01:00
const requestor = require ('../index');
const mock = {
registered: {},
post (path, handler) {
this.registered[`post-${path}`] = handler;
},
get (path, handler) {
this.registered[`get-${path}`] = handler;
},
put (path, handler) {
this.registered[`put-${path}`] = handler;
},
delete (path, handler) {
this.registered[`delete-${path}`] = handler;
},
all (path, handler) {
this.registered[`all-${path}`] = handler;
}
};
2020-02-24 12:34:07 +01:00
test.test.beforeEach (() => {
mock.registered = {};
});
test ('detect requests on root', (t) => {
requestor (mock, '/test/root');
const keys = [
'post-/',
'get-/',
'put-/',
'delete-/',
'all-/'
];
t.deepEqual (Object.keys (mock.registered), keys);
});
2020-01-03 19:13:21 +01:00
2020-02-24 12:34:07 +01:00
test ('detect requests on root.subfolder', (t) => {
requestor (mock, './test/root.sub');
const keys = [
'post-/sub/',
'get-/sub/',
'put-/sub/',
'delete-/sub/',
'all-/sub/'
];
2020-01-03 19:13:21 +01:00
2020-02-24 12:34:07 +01:00
t.deepEqual (Object.keys (mock.registered), keys);
});
test ('detect requests on subfolder', (t) => {
requestor (mock, './test/sub');
const keys = [
'post-/sub/',
'get-/sub/',
'put-/sub/',
'delete-/sub/',
'all-/sub/',
'get-/sub/lv1/lv2/lv3/',
'all-/sub/root/'
];
t.deepEqual (Object.keys (mock.registered), keys);
});
2020-01-03 19:13:21 +01:00
2020-02-24 12:34:07 +01:00
test ('build requests with subdirectory', (t) => {
requestor (mock, './test/sub', { subdir: 'test' });
const 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/'
];
2020-01-03 19:13:21 +01:00
2020-02-24 12:34:07 +01:00
t.deepEqual (Object.keys (mock.registered), keys);
2020-01-03 19:13:21 +01:00
});