Skip to content

Commit

Permalink
chore: add test cases for new http methods (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthyk authored Jan 26, 2024
1 parent caab0a1 commit 2e5d22c
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 1 deletion.
155 changes: 155 additions & 0 deletions test/fixture/routes.03.json
Original file line number Diff line number Diff line change
@@ -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": []
}
}
]
18 changes: 17 additions & 1 deletion test/routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand All @@ -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'))
})

0 comments on commit 2e5d22c

Please sign in to comment.