'use strict'; const { test } = require ('ava'); 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; } }; 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); }); test ('detect requests on root.subfolder', (t) => { requestor (mock, './test/root.sub'); const keys = [ 'post-/sub/', 'get-/sub/', 'put-/sub/', 'delete-/sub/', 'all-/sub/' ]; 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); }); 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/' ]; t.deepEqual (Object.keys (mock.registered), keys); });