From ff86ec240e05c682251c79329173584ab1c7dd01 Mon Sep 17 00:00:00 2001 From: shayanaijaz Date: Fri, 18 Aug 2023 13:58:55 -0500 Subject: [PATCH] Added test --- .../fixtures/DataFiles.systems.fixture.js | 2 + .../src/redux/sagas/datafiles.sagas.test.js | 85 +++++++++++++------ 2 files changed, 59 insertions(+), 28 deletions(-) diff --git a/client/src/components/DataFiles/fixtures/DataFiles.systems.fixture.js b/client/src/components/DataFiles/fixtures/DataFiles.systems.fixture.js index a8e138a3c..d1a019d07 100644 --- a/client/src/components/DataFiles/fixtures/DataFiles.systems.fixture.js +++ b/client/src/components/DataFiles/fixtures/DataFiles.systems.fixture.js @@ -11,6 +11,8 @@ const systemsFixture = { icon: null, hidden: true, homeDir: '/home/username', + default: true, + keyservice: true, }, { name: 'My Data (Frontera)', diff --git a/client/src/redux/sagas/datafiles.sagas.test.js b/client/src/redux/sagas/datafiles.sagas.test.js index 73a4d2349..743642250 100644 --- a/client/src/redux/sagas/datafiles.sagas.test.js +++ b/client/src/redux/sagas/datafiles.sagas.test.js @@ -27,6 +27,7 @@ import * as matchers from 'redux-saga-test-plan/matchers'; import { fetchAppDefinitionUtil } from './apps.sagas'; import compressApp from './fixtures/compress.fixture'; import extractApp from './fixtures/extract.fixture'; +import systemsFixture from 'components/DataFiles/fixtures/DataFiles.systems.fixture'; jest.mock('cross-fetch'); @@ -407,29 +408,31 @@ describe('extractFiles', () => { }); describe('compressFiles', () => { - const action = { - type: 'DATA_FILES_COMPRESS', - payload: { - filename: 'test', - files: [ - { - system: 'test.system', - path: 'test1.txt', - name: 'test1.txt', - }, - { - system: 'test.system', - path: 'test2.txt', - name: 'test2.txt', - }, - ], - compressionType: 'zip', - scheme: 'private', - }, + const createAction = (scheme) => { + return { + type: 'DATA_FILES_COMPRESS', + payload: { + filename: 'test', + files: [ + { + system: 'test.system', + path: 'test1.txt', + name: 'test1.txt', + }, + { + system: 'test.system', + path: 'test2.txt', + name: 'test2.txt', + }, + ], + compressionType: 'zip', + scheme: scheme, + }, + }; }; - const jobHelperExpected = () => - JSON.stringify({ + const createJobHelperExpected = (archiveSystemId, archiveSystemDir) => { + return JSON.stringify({ job: { fileInputs: [ { @@ -440,8 +443,8 @@ describe('compressFiles', () => { }, ], name: `compress-0.0.1_${new Date().toISOString().split('.')[0]}`, - archiveSystemId: 'test.system', - archiveSystemDir: '', + archiveSystemId: archiveSystemId, + archiveSystemDir: archiveSystemDir, archiveOnAppError: false, appId: 'compress', appVersion: '0.0.1', @@ -469,9 +472,10 @@ describe('compressFiles', () => { execSystemId: 'frontera', }, }); + }; it('runs compressFiles saga with success', () => { - return expectSaga(compressFiles, action) + return expectSaga(compressFiles, createAction('private')) .provide([ [select(compressAppSelector), 'compress'], [select(defaultAllocationSelector), 'TACC-ACI'], @@ -484,7 +488,7 @@ describe('compressFiles', () => { type: 'DATA_FILES_SET_OPERATION_STATUS', payload: { status: { type: 'RUNNING' }, operation: 'compress' }, }) - .call(jobHelper, jobHelperExpected()) + .call(jobHelper, createJobHelperExpected('test.system', '')) .put({ type: 'DATA_FILES_SET_OPERATION_STATUS', payload: { status: { type: 'SUCCESS' }, operation: 'compress' }, @@ -493,7 +497,7 @@ describe('compressFiles', () => { }); it('runs compressFiles saga with push keys modal', () => { - return expectSaga(compressFiles, action) + return expectSaga(compressFiles, createAction('private')) .provide([ [select(compressAppSelector), 'compress'], [select(defaultAllocationSelector), 'TACC-ACI'], @@ -506,13 +510,13 @@ describe('compressFiles', () => { type: 'DATA_FILES_SET_OPERATION_STATUS', payload: { status: { type: 'RUNNING' }, operation: 'compress' }, }) - .call(jobHelper, jobHelperExpected()) + .call(jobHelper, createJobHelperExpected('test.system', '')) .put({ type: 'SYSTEMS_TOGGLE_MODAL', payload: { operation: 'pushKeys', props: { - onSuccess: action, + onSuccess: createAction('private'), system: 'test.cli.system', onCancel: { type: 'DATA_FILES_SET_OPERATION_STATUS', @@ -526,6 +530,31 @@ describe('compressFiles', () => { }) .run(); }); + + it('runs compressFiles saga with success for file in a public system', () => { + return expectSaga(compressFiles, createAction('public')) + .provide([ + [select(compressAppSelector), 'compress'], + [select(defaultAllocationSelector), 'TACC-ACI'], + [select(systemsSelector), systemsFixture.storage.configuration], + [matchers.call.fn(fetchAppDefinitionUtil), compressApp], + [matchers.call.fn(jobHelper), { status: 'PENDING' }], + ]) + .call(fetchAppDefinitionUtil, 'compress') + .put({ + type: 'DATA_FILES_SET_OPERATION_STATUS', + payload: { status: { type: 'RUNNING' }, operation: 'compress' }, + }) + .call( + jobHelper, + createJobHelperExpected('corral.home.username', '/home/username') + ) + .put({ + type: 'DATA_FILES_SET_OPERATION_STATUS', + payload: { status: { type: 'SUCCESS' }, operation: 'compress' }, + }) + .run(); + }); }); describe('copyFiles', () => {