From bace2a1bc39d0d9e742e7e2b9b5828b2cfdd87eb Mon Sep 17 00:00:00 2001 From: Adam Schrader Date: Sat, 29 Apr 2017 21:52:54 -0400 Subject: [PATCH] Fix linting issues --- test/multipartUploads.spec.js | 2 +- test/options.spec.js | 48 ++++++++++++++++++----------------- test/server.js | 14 +++++----- 3 files changed, 33 insertions(+), 31 deletions(-) diff --git a/test/multipartUploads.spec.js b/test/multipartUploads.spec.js index 4e69f5b..f4be574 100644 --- a/test/multipartUploads.spec.js +++ b/test/multipartUploads.spec.js @@ -212,4 +212,4 @@ describe('Test Upload With Fields', function() { }); }); } -}); \ No newline at end of file +}); diff --git a/test/options.spec.js b/test/options.spec.js index d532c02..b1af76c 100644 --- a/test/options.spec.js +++ b/test/options.spec.js @@ -12,6 +12,31 @@ describe('File Upload Options Tests', function() { done(); }); + /** + * Upload the file for testing and verify the expected filename. + * @param {object} options The expressFileUpload options. + * @param {string} actualFileNameToUpload The name of the file to upload. + * @param {string} expectedFileNameOnFileSystem The name of the file after upload. + * @param {function} done The mocha continuation function. + */ + function executeFileUploadTestWalk(options, + actualFileNameToUpload, + expectedFileNameOnFileSystem, + done) { + request(server.setup(options)) + .post('/upload/single') + .attach('testFile', path.join(fileDir, actualFileNameToUpload)) + .expect(200) + .end(function(err) { + if (err) + return done(err); + + const uploadedFilePath = path.join(uploadDir, expectedFileNameOnFileSystem); + + fs.stat(uploadedFilePath, done); + }); + } + describe('Testing [safeFileNames] option to ensure:', function() { it('Does nothing to your filename when disabled.', function(done) { @@ -159,27 +184,4 @@ describe('File Upload Options Tests', function() { executeFileUploadTestWalk(fileUploadOptions, actualFileName, expectedFileName, done); }); }); - - function executeFileUploadTestWalk(options, - actualFileNameToUpload, - expectedFilNameOnFileSystem, - done) { - const argsUnderTest = options; - const app = server.setup(argsUnderTest); - const actualFileName = actualFileNameToUpload; - const expectedFileName = expectedFilNameOnFileSystem; - - request(app) - .post('/upload/single') - .attach('testFile', path.join(fileDir, actualFileName)) - .expect(200) - .end(function(err) { - if (err) - return done(err); - - const uploadedFilePath = path.join(uploadDir, expectedFileName); - - fs.stat(uploadedFilePath, done); - }); - } }); diff --git a/test/server.js b/test/server.js index 7d014fe..3f4bdeb 100644 --- a/test/server.js +++ b/test/server.js @@ -12,7 +12,7 @@ const clearUploadsDir = function() { } }; -var setup = function(fileUploadOptions) { +const setup = function(fileUploadOptions) { const express = require('express'); const expressFileupload = require('../lib/index'); @@ -28,7 +28,7 @@ var setup = function(fileUploadOptions) { let testFile = req.files.testFile; let uploadPath = path.join(uploadDir, testFile.name); - testFile.mv(uploadPath, function (err) { + testFile.mv(uploadPath, function(err) { if (err) return res.status(500).send(err); @@ -55,7 +55,7 @@ var setup = function(fileUploadOptions) { let testFile = req.files.testFile; let uploadPath = path.join(uploadDir, testFile.name); - testFile.mv(uploadPath, function (err) { + testFile.mv(uploadPath, function(err) { if (err) return res.status(500).send(err); @@ -87,15 +87,15 @@ var setup = function(fileUploadOptions) { if (!testFile3) return res.status(400).send('testFile3 was not uploaded'); - testFile1.mv(uploadPath1, function (err) { + testFile1.mv(uploadPath1, function(err) { if (err) return res.status(500).send(err); - testFile2.mv(uploadPath2, function (err) { + testFile2.mv(uploadPath2, function(err) { if (err) return res.status(500).send(err); - testFile3.mv(uploadPath3, function (err) { + testFile3.mv(uploadPath3, function(err) { if (err) return res.status(500).send(err); @@ -124,7 +124,7 @@ var setup = function(fileUploadOptions) { for (let i = 0; i < testFiles.length; i++) { let uploadPath = path.join(uploadDir, testFiles[i].name); - testFiles[i].mv(uploadPath, function (err) { + testFiles[i].mv(uploadPath, function(err) { if (err) return res.status(500).send(err);