'use strict'
const { test } = require('node:test')
const fastify = require('../../')()
fastify.addHttpMethod('PROPFIND', { hasBody: true })
const bodySample = `
`
test('can be created - propfind', t => {
t.plan(1)
try {
fastify.route({
method: 'PROPFIND',
url: '*',
handler: function (req, reply) {
return reply.code(207)
.send(`
/
2022-04-13T12:35:30Z
Wed, 13 Apr 2022 12:35:30 GMT
"e0-5dc8869b53ef1"
httpd/unix-directory
HTTP/1.1 200 OK
`
)
}
})
t.assert.ok(true)
} catch (e) {
t.assert.fail()
}
})
test('propfind test', async t => {
await fastify.listen({ port: 0 })
t.after(() => {
fastify.close()
})
await t.test('request - propfind', async t => {
t.plan(3)
const result = await fetch(`http://localhost:${fastify.server.address().port}/`, {
method: 'PROPFIND'
})
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 207)
const body = await result.text()
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
})
await t.test('request with other path - propfind', async t => {
t.plan(3)
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
method: 'PROPFIND'
})
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 207)
const body = await result.text()
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
})
// the body test uses a text/plain content type instead of application/xml because it requires
// a specific content type parser
await t.test('request with body - propfind', async t => {
t.plan(3)
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
method: 'PROPFIND',
headers: { 'content-type': 'text/plain' },
body: bodySample
})
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 207)
const body = await result.text()
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
})
await t.test('request with body and no content type (415 error) - propfind', async t => {
t.plan(3)
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
method: 'PROPFIND',
body: bodySample,
headers: { 'content-type': '' }
})
t.assert.ok(!result.ok)
t.assert.strictEqual(result.status, 415)
const body = await result.text()
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
})
await t.test('request without body - propfind', async t => {
t.plan(3)
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
method: 'PROPFIND'
})
t.assert.ok(result.ok)
t.assert.strictEqual(result.status, 207)
const body = await result.text()
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
})
})