|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const Lab = require('lab') |
| 4 | +const Code = require('code') |
| 5 | +const pkg = require('../package.json') |
| 6 | +const lab = exports.lab = Lab.script() |
| 7 | +const Plugin = require('../lib/index') |
| 8 | + |
| 9 | +let mockServer = { |
| 10 | + log: console.log |
| 11 | +} |
| 12 | + |
| 13 | +lab.experiment('Plugin - init', () => { |
| 14 | + lab.test('Correct attributes', (done) => { |
| 15 | + let attributes = Plugin.attributes |
| 16 | + Code.expect(attributes.name).to.be.equal(pkg.name) |
| 17 | + Code.expect(attributes.version).to.be.equal(pkg.version) |
| 18 | + Code.expect(attributes.multiple).to.be.true() |
| 19 | + done() |
| 20 | + }) |
| 21 | + |
| 22 | + lab.test('No upload path', (done) => { |
| 23 | + Plugin(mockServer, {}, (err) => { |
| 24 | + Code.expect(err).to.be.instanceof(Error) |
| 25 | + Code.expect(err.message).to.be.equal('Must define a path to upload files') |
| 26 | + done() |
| 27 | + }) |
| 28 | + }) |
| 29 | + |
| 30 | + lab.test('Invalid upload path', (done) => { |
| 31 | + Plugin(mockServer, {upload: {path: './invalid/path'}}, (err) => { |
| 32 | + Code.expect(err).to.be.instanceof(Error) |
| 33 | + Code.expect(err.message).to.be.startWith( |
| 34 | + 'Must define a valid accessible path to upload files - ' |
| 35 | + ) |
| 36 | + done() |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + lab.test('Invalid upload path', (done) => { |
| 41 | + Plugin(mockServer, {upload: {path: './invalid/path'}}, (err) => { |
| 42 | + Code.expect(err).to.be.instanceof(Error) |
| 43 | + Code.expect(err.message).to.be.startWith( |
| 44 | + 'Must define a valid accessible path to upload files - ' |
| 45 | + ) |
| 46 | + done() |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + lab.test('Define route with default options', (done) => { |
| 51 | + mockServer.route = function (route) { |
| 52 | + const config = route.config |
| 53 | + const payload = config.payload |
| 54 | + Code.expect(route.method).to.be.equal('POST') |
| 55 | + Code.expect(route.path).to.be.equal('/files') |
| 56 | + Code.expect(config.tags).to.not.exist() |
| 57 | + Code.expect(config.auth).to.be.false() |
| 58 | + Code.expect(payload.output).to.be.equal('stream') |
| 59 | + Code.expect(payload.parse).to.be.true() |
| 60 | + Code.expect(payload.allow).to.be.equal('multipart/form-data') |
| 61 | + Code.expect(payload.maxBytes).to.not.exist() |
| 62 | + Code.expect(config.pre).to.be.instanceof(Array) |
| 63 | + Code.expect(config.pre).to.have.length(1) |
| 64 | + Code.expect(config.pre[0].assign).to.be.equal('file') |
| 65 | + Code.expect(config.validate.query).to.not.exist() |
| 66 | + Code.expect(config.validate.params).to.not.exist() |
| 67 | + Code.expect(config.validate.headers).to.not.exist() |
| 68 | + Code.expect(config.validate.auth).to.not.exist() |
| 69 | + Code.expect(config.validate.payload).to.exist() |
| 70 | + Code.expect(config.validate.payload.isJoi).to.be.true() |
| 71 | + Code.expect(config.description).to.be.equal('Uploads a file') |
| 72 | + } |
| 73 | + Plugin(mockServer, {upload: {path: './'}}, (err) => { |
| 74 | + Code.expect(err).to.not.exist() |
| 75 | + done() |
| 76 | + }) |
| 77 | + }) |
| 78 | +}) |
0 commit comments