summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/test/busboy-constructor.test.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:56:19 +0000
commit0b6210cd37b68b94252cb798598b12974a20e1c1 (patch)
treee371686554a877842d95aa94f100bee552ff2a8e /fastify-busboy/test/busboy-constructor.test.js
parentInitial commit. (diff)
downloadnode-undici-upstream.tar.xz
node-undici-upstream.zip
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fastify-busboy/test/busboy-constructor.test.js')
-rw-r--r--fastify-busboy/test/busboy-constructor.test.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/fastify-busboy/test/busboy-constructor.test.js b/fastify-busboy/test/busboy-constructor.test.js
new file mode 100644
index 0000000..8607789
--- /dev/null
+++ b/fastify-busboy/test/busboy-constructor.test.js
@@ -0,0 +1,75 @@
+'use strict'
+
+const Busboy = require('../lib/main')
+const { test } = require('tap')
+
+test('busboy-constructor - should throw an Error if no options are provided', t => {
+ t.plan(1)
+
+ t.throws(() => new Busboy(), new Error('Busboy expected an options-Object.'))
+})
+
+test('busboy-constructor - should throw an Error if options does not contain headers', t => {
+ t.plan(1)
+
+ t.throws(() => new Busboy({}), new Error('Busboy expected an options-Object with headers-attribute.'))
+})
+
+test('busboy-constructor - if busboy is called without new-operator, still creates a busboy instance', t => {
+ t.plan(1)
+
+ const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
+ t.type(busboyInstance, Busboy)
+})
+
+test('busboy-constructor - should throw an Error if content-type is not set', t => {
+ t.plan(1)
+
+ t.throws(() => new Busboy({ headers: {} }), new Error('Missing Content-Type-header.'))
+})
+
+test('busboy-constructor - should throw an Error if content-type is unsupported', t => {
+ t.plan(1)
+
+ t.throws(() => new Busboy({ headers: { 'content-type': 'unsupported' } }), new Error('Unsupported Content-Type.'))
+})
+
+test('busboy-constructor - should not throw an Error if content-type is urlencoded', t => {
+ t.plan(1)
+
+ t.doesNotThrow(() => new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } }))
+})
+
+test('busboy-constructor - if busboy is called without stream options autoDestroy is set to false', t => {
+ t.plan(1)
+
+ const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
+ t.equal(busboyInstance._writableState.autoDestroy, false)
+})
+
+test('busboy-constructor - if busboy is called with invalid value for stream option highWaterMark we should throw', t => {
+ t.plan(1)
+
+ t.throws(() => Busboy({ highWaterMark: 'not_allowed_value_for_highWaterMark', headers: { 'content-type': 'application/x-www-form-urlencoded' } }), new Error('not_allowed_value_for_highWaterMark'))
+})
+
+test('busboy-constructor - if busboy is called with stream options and autoDestroy:true, autoDestroy should be set to true', t => {
+ t.plan(1)
+
+ const busboyInstance = Busboy({ autoDestroy: true, headers: { 'content-type': 'application/x-www-form-urlencoded' } })
+ t.equal(busboyInstance._writableState.autoDestroy, true)
+})
+
+test('busboy-constructor - busboy should be initialized with private attribute _done set as false', t => {
+ t.plan(1)
+
+ const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
+ t.equal(busboyInstance._done, false)
+})
+
+test('busboy-constructor - busboy should be initialized with private attribute _finished set as false', t => {
+ t.plan(1)
+
+ const busboyInstance = Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } })
+ t.equal(busboyInstance._finished, false)
+})