'use strict' const t = require('tap') const test = t.test const sget = require('simple-get').concat const fastify = require('..')() 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.pass() } catch (e) { t.fail() } }) fastify.listen({ port: 0 }, err => { t.error(err) t.teardown(() => { fastify.close() }) test('request - propfind', t => { t.plan(3) sget({ url: `http://localhost:${fastify.server.address().port}/`, method: 'PROPFIND' }, (err, response, body) => { t.error(err) t.equal(response.statusCode, 207) t.equal(response.headers['content-length'], '' + body.length) }) }) test('request with other path - propfind', t => { t.plan(3) sget({ url: `http://localhost:${fastify.server.address().port}/test`, method: 'PROPFIND' }, (err, response, body) => { t.error(err) t.equal(response.statusCode, 207) t.equal(response.headers['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 test('request with body - propfind', t => { t.plan(3) sget({ url: `http://localhost:${fastify.server.address().port}/test`, headers: { 'content-type': 'text/plain' }, body: bodySample, method: 'PROPFIND' }, (err, response, body) => { t.error(err) t.equal(response.statusCode, 207) t.equal(response.headers['content-length'], '' + body.length) }) }) test('request with body and no content type (415 error) - propfind', t => { t.plan(3) sget({ url: `http://localhost:${fastify.server.address().port}/test`, body: bodySample, method: 'PROPFIND' }, (err, response, body) => { t.error(err) t.equal(response.statusCode, 415) t.equal(response.headers['content-length'], '' + body.length) }) }) test('request without body - propfind', t => { t.plan(3) sget({ url: `http://localhost:${fastify.server.address().port}/test`, method: 'PROPFIND' }, (err, response, body) => { t.error(err) t.equal(response.statusCode, 207) t.equal(response.headers['content-length'], '' + body.length) }) }) })