'use strict' const { test } = require('node:test') const sget = require('simple-get').concat const fastify = require('../../')() fastify.addHttpMethod('PROPPATCH', { hasBody: true }) const bodySample = ` Jim Whitehead Roy Fielding ` test('shorthand - proppatch', t => { t.plan(1) try { fastify.route({ method: 'PROPPATCH', url: '*', handler: function (req, reply) { reply .code(207) .send(` http://www.example.com/bar.html HTTP/1.1 424 Failed Dependency HTTP/1.1 409 Conflict Copyright Owner cannot be deleted or altered. ` ) } }) t.assert.ok(true) } catch (e) { t.assert.fail() } }) test('proppatch test', async t => { await fastify.listen({ port: 0 }) t.after(() => { fastify.close() }) // 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 - proppatch', (t, done) => { t.plan(3) sget({ url: `http://localhost:${fastify.server.address().port}/test/a.txt`, headers: { 'content-type': 'text/plain' }, body: bodySample, method: 'PROPPATCH' }, (err, response, body) => { t.assert.ifError(err) t.assert.strictEqual(response.statusCode, 207) t.assert.strictEqual(response.headers['content-length'], '' + body.length) done() }) }) await t.test('request with body and no content type (415 error) - proppatch', (t, done) => { t.plan(3) sget({ url: `http://localhost:${fastify.server.address().port}/test/a.txt`, body: bodySample, method: 'PROPPATCH' }, (err, response, body) => { t.assert.ifError(err) t.assert.strictEqual(response.statusCode, 415) t.assert.strictEqual(response.headers['content-length'], '' + body.length) done() }) }) await t.test('request without body - proppatch', (t, done) => { t.plan(3) sget({ url: `http://localhost:${fastify.server.address().port}/test/a.txt`, method: 'PROPPATCH' }, (err, response, body) => { t.assert.ifError(err) t.assert.strictEqual(response.statusCode, 207) t.assert.strictEqual(response.headers['content-length'], '' + body.length) done() }) }) })