Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
shayanaijaz committed Aug 18, 2023
1 parent ff8f83a commit ff86ec2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const systemsFixture = {
icon: null,
hidden: true,
homeDir: '/home/username',
default: true,
keyservice: true,
},
{
name: 'My Data (Frontera)',
Expand Down
85 changes: 57 additions & 28 deletions client/src/redux/sagas/datafiles.sagas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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: [
{
Expand All @@ -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',
Expand Down Expand Up @@ -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'],
Expand All @@ -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' },
Expand All @@ -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'],
Expand All @@ -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',
Expand All @@ -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', () => {
Expand Down

0 comments on commit ff86ec2

Please sign in to comment.