/* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of Requestor which is released under BSD-3-Clause. * See file 'LICENSE' for full license details. * Created by Timo Hocker , March 2020 */ '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 ('detect requests on root', (t) => { mock.registered = {}; requestor (mock, './test_files/root'); const keys = [ 'all-/', 'delete-/', 'get-/', 'post-/', 'put-/' ]; t.deepEqual (Object.keys (mock.registered), keys); }); test ('detect requests on root.subfolder', (t) => { mock.registered = {}; requestor (mock, './test_files/root.sub'); const keys = [ 'all-/sub/', 'delete-/sub/', 'get-/sub/', 'post-/sub/', 'put-/sub/' ]; t.deepEqual (Object.keys (mock.registered), keys); }); test ('detect requests on subfolder', (t) => { mock.registered = {}; requestor (mock, './test_files/sub'); const keys = [ 'all-/sub/', 'all-/sub/root/', 'delete-/sub/', 'get-/sub/', 'get-/sub/lv1/lv2/lv3/', 'post-/sub/', 'put-/sub/' ]; t.deepEqual (Object.keys (mock.registered), keys); }); test ('build requests with subdirectory', (t) => { mock.registered = {}; requestor (mock, './test_files/sub', { subdir: 'test' }); const keys = [ 'all-/test/sub/', 'all-/test/sub/root/', 'delete-/test/sub/', 'get-/test/sub/', 'get-/test/sub/lv1/lv2/lv3/', 'post-/test/sub/', 'put-/test/sub/' ]; t.deepEqual (Object.keys (mock.registered), keys); });