diff --git a/clients/render/fileUploads.js b/clients/render/fileUploads.js index adfbff162..517171c68 100644 --- a/clients/render/fileUploads.js +++ b/clients/render/fileUploads.js @@ -53,7 +53,7 @@ export const handleFileUploadError = (error, file) => { * * @param {File} file File blob * @param {object} processData object of data to process files {verify, field, fieldId, cf2, $form, CF_API_DATA, messages} - * @param {object} processFunctions object of function that will be called within processFiles then test the cases they are called {hashAndUpload, hashFile, createMediaFromFile, handleFileUploadResponse, handleFileUploadError} + * @param {object} processFunctions object of functions that will be called within processFiles then test the cases they are called {hashAndUpload, hashFile, createMediaFromFile, handleFileUploadResponse, handleFileUploadError} */ export const hashAndUpload = (file, processData, processFunctions ) => { @@ -80,9 +80,7 @@ export const hashAndUpload = (file, processData, processFunctions ) => { response => response.json() ) .then( - response => { - handleFileUploadResponse(response,cf2,$form,messages,field); - } + response => handleFileUploadResponse(response,cf2,$form,messages,field) ) .catch( error => { @@ -101,7 +99,7 @@ export const hashAndUpload = (file, processData, processFunctions ) => { * * @param {array} files array of Files * @param {object} processData object of data to process files {verify, field, fieldId, cf2, $form, CF_API_DATA, messages} - * @param {object} processFunctions object of function that will be called within processFiles then test the cases they are called {hashAndUpload, hashFile, createMediaFromFile, handleFileUploadResponse, handleFileUploadError} + * @param {object} processFunctions object of functions that will be called within processFiles then test the cases they are called {hashAndUpload, hashFile, createMediaFromFile, handleFileUploadResponse, handleFileUploadError} */ export const processFiles = (files, processData, processFunctions) => { diff --git a/clients/tests/unit/render/fileUploads.test.js b/clients/tests/unit/render/fileUploads.test.js index a7f2fa067..6426b5544 100644 --- a/clients/tests/unit/render/fileUploads.test.js +++ b/clients/tests/unit/render/fileUploads.test.js @@ -161,7 +161,7 @@ describe( 'hashAndUpload', () => { }); -describe( 'processFiles', () => { +describe( 'Calls to hashAndUpload based on number of files passed to processFiles', () => { let processFunctions = {hashAndUpload, hashFile, createMediaFromFile, handleFileUploadResponse, handleFileUploadError}; const processData = { @@ -169,15 +169,23 @@ describe( 'processFiles', () => { field: data.cf2.fields.fld_9226671_1, fieldId: data.cf2.fields.fld_9226671_1.fieldId, cf2: cf2, - $form: obj.$form, - CF_API_DATA: CF_API_DATA, + $form: data.obj.$form, + CF_API_DATA: data.CF_API_DATA, messages: messages } - it( 'Call to hashAndUpload' , () => { + it( 'Call to hashAndUpload three times because three files' , () => { + processFunctions.hashAndUpload = jest.fn(); + processFiles(data.threeFiles, processData, processFunctions); + expect(processFunctions.hashAndUpload).toBeCalled(); + expect(processFunctions.hashAndUpload.mock.calls.length).toBe(3); + }); + + it( 'Call to hashAndUpload once because one file' , () => { processFunctions.hashAndUpload = jest.fn(); - processFiles(data.threeFiles, processData, processFunctions ); - expect( processFunctions.hashAndUpload ).toBeCalled(); + processFiles([data.file], processData, processFunctions); + expect(processFunctions.hashAndUpload).toBeCalled(); + expect(processFunctions.hashAndUpload.mock.calls.length).toBe(1); }); }); \ No newline at end of file