summaryrefslogtreecommitdiffstats
path: root/fastify-busboy/test/get-limit.test.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--fastify-busboy/test/get-limit.test.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/fastify-busboy/test/get-limit.test.js b/fastify-busboy/test/get-limit.test.js
new file mode 100644
index 0000000..76a2997
--- /dev/null
+++ b/fastify-busboy/test/get-limit.test.js
@@ -0,0 +1,34 @@
+'use strict'
+
+const getLimit = require('../lib/utils/getLimit')
+const { test } = require('tap')
+
+test('Get limit', t => {
+ t.plan(2)
+
+ t.test('Correctly resolves limits', t => {
+ t.plan(8)
+ t.strictSame(getLimit(undefined, 'fieldSize', 1), 1)
+ t.strictSame(getLimit(undefined, 'fileSize', Infinity), Infinity)
+
+ t.strictSame(getLimit({}, 'fieldSize', 1), 1)
+ t.strictSame(getLimit({}, 'fileSize', Infinity), Infinity)
+ t.strictSame(getLimit({ fieldSize: null }, 'fieldSize', 1), 1)
+ t.strictSame(getLimit({ fileSize: null }, 'fileSize', Infinity), Infinity)
+
+ t.strictSame(getLimit({ fieldSize: 0 }, 'fieldSize', 1), 0)
+ t.strictSame(getLimit({ fileSize: 2 }, 'fileSize', 1), 2)
+ })
+
+ t.test('Throws an error on incorrect limits', t => {
+ t.plan(2)
+
+ t.throws(function () {
+ getLimit({ fieldSize: '1' }, 'fieldSize', 1)
+ }, new Error('Limit fieldSize is not a valid number'))
+
+ t.throws(function () {
+ getLimit({ fieldSize: NaN }, 'fieldSize', 1)
+ }, new Error('Limit fieldSize is not a valid number'))
+ })
+})