Skip to content

Commit

Permalink
#2818 Test number of calls to hashAndUpload based on number of files …
Browse files Browse the repository at this point in the history
…passed to processFiles
  • Loading branch information
New0 committed Jan 7, 2019
1 parent 3c6d195 commit 43356a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
8 changes: 3 additions & 5 deletions clients/render/fileUploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => {

Expand All @@ -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 => {
Expand All @@ -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) => {

Expand Down
20 changes: 14 additions & 6 deletions clients/tests/unit/render/fileUploads.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,31 @@ 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 = {
verify: 'f42ea553cb',
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);
});

});

0 comments on commit 43356a2

Please sign in to comment.