From 2e5d22cc57bdaa90d4f88eefe77c35564a2509f4 Mon Sep 17 00:00:00 2001 From: Matthias Keckl <53833818+matthyk@users.noreply.github.com> Date: Fri, 26 Jan 2024 18:26:00 +0100 Subject: [PATCH] chore: add test cases for new http methods (#94) --- test/fixture/routes.03.json | 155 ++++++++++++++++++++++++++++++++++++ test/routes.test.js | 18 ++++- 2 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 test/fixture/routes.03.json diff --git a/test/fixture/routes.03.json b/test/fixture/routes.03.json new file mode 100644 index 0000000..510d627 --- /dev/null +++ b/test/fixture/routes.03.json @@ -0,0 +1,155 @@ +[ + { + "method": "PROPFIND", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + }, + { + "method": "PROPPATCH", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + }, + { + "method": "MKCOL", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + }, + { + "method": "COPY", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + }, + { + "method": "MOVE", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + }, + { + "method": "LOCK", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + }, + { + "method": "UNLOCK", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + }, + { + "method": "TRACE", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + }, + { + "method": "SEARCH", + "url": "/api/test", + "prefix": "/api", + "hooks": { + "onRequest": [], + "preParsing": [], + "preValidation": [], + "preHandler": [], + "preSerialization": [], + "onError": [], + "onSend": [], + "onResponse": [], + "onTimeout": [], + "onRequestAbort": [] + } + } +] diff --git a/test/routes.test.js b/test/routes.test.js index bab0ed4..325d44c 100644 --- a/test/routes.test.js +++ b/test/routes.test.js @@ -59,13 +59,25 @@ test('routes', async t => { app.register(function sibling (instance, opts, next) { next() }) + app.register(function routes (instance, opts, next) { + ['propfind', 'proppatch', 'mkcol', 'copy', 'move', 'lock', 'unlock', 'trace', 'search'].forEach(method => { + instance.route({ + method, + url: '/test', + handler () {} + }) + }) + + next() + }, { prefix: '/api' }) await app.ready() const root = app.overview() - t.equal(root.children.length, 2) + t.equal(root.children.length, 3) t.equal(root.children[0].name, 'register1') t.equal(root.children[1].name, 'sibling') + t.equal(root.children[2].name, 'routes') t.equal(root.routes.length, 8) t.same(root.routes, require('./fixture/routes.00.json')) @@ -76,4 +88,8 @@ test('routes', async t => { const reg2 = reg1.children[0] t.same(reg2.routes.length, 2) t.same(reg2.routes, require('./fixture/routes.02.json')) + + const reg3 = root.children[2] + t.same(reg3.routes.length, 9) + t.same(reg3.routes, require('./fixture/routes.03.json')) })