Skip to content

Commit

Permalink
Merge pull request #750 from hms-dbmi-cellenics/1902-clean-up-v1-samp…
Browse files Browse the repository at this point in the history
…les-redux

1902 clean up v1 samples, projects redux
  • Loading branch information
cosa65 authored Jun 28, 2022
2 parents def7de6 + 1331f8a commit 2ebf8c9
Show file tree
Hide file tree
Showing 56 changed files with 392 additions and 2,192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ Object {
"organism": null,
"type": "10x",
},
"name": undefined,
"name": "project-1",
"notifyByEmail": true,
"projectUuid": "project-1",
"projectUuid": "b3f6c0ca86ec045c84f380cd5016972e",
"sampleIds": Array [],
},
}
`;

exports[`createExperiment Works correctly 2`] = `"{\\"id\\":\\"b3f6c0ca86ec045c84f380cd5016972e\\",\\"description\\":\\"Analysis description\\"}"`;
exports[`createExperiment Works correctly 2`] = `"{\\"id\\":\\"b3f6c0ca86ec045c84f380cd5016972e\\",\\"name\\":\\"project-1\\",\\"description\\":\\"Analysis description\\"}"`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`createProject action Works corectly project when there are no errors 1`] = `
exports[`createProject action Creates a project when there are no errors 1`] = `
Object {
"project": Object {
"createdDate": "2020-01-01T00:00:00.000Z",
Expand All @@ -13,7 +13,7 @@ Object {
"metadataKeys": Array [],
"name": "test project",
"samples": Array [],
"uuid": "random-project-uuid",
"uuid": "random-experiment-uuid",
},
}
`;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`updateMetadataTrack action Works correctly in api v2 1`] = `
exports[`updateMetadataTrack action Works correctly 1`] = `
Array [
Object {
"newKey": "New_track",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ import initialSamplesState, { sampleTemplate } from 'redux/reducers/samples/init
import {
PROJECTS_METADATA_CREATE,
} from 'redux/actionTypes/projects';
import { saveProject } from 'redux/actions/projects';
import { saveSamples } from 'redux/actions/samples';

import '__test__/test-utils/setupTests';

import { SAMPLES_UPDATE } from 'redux/actionTypes/samples';

const mockStore = configureStore([thunk]);

jest.mock('redux/actions/projects/saveProject');
saveProject.mockImplementation(() => async () => { });

jest.mock('redux/actions/samples/saveSamples');
saveSamples.mockImplementation(() => async () => { });

describe('createMetadataTrack action', () => {
const project1uuid = 'project1';
const sample1uuid = 'sample1';
Expand Down
28 changes: 7 additions & 21 deletions src/__test__/redux/actions/projects/createProject.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import { v4 as uuidv4 } from 'uuid';

import handleError from 'utils/http/handleError';
import createProject from 'redux/actions/projects/createProject';
import initialProjectsState from 'redux/reducers/projects';
import { saveProject } from 'redux/actions/projects';

import { createExperiment } from 'redux/actions/experiments';
import {
PROJECTS_CREATE, PROJECTS_SAVING, PROJECTS_ERROR,
} from 'redux/actionTypes/projects';
import '__test__/test-utils/setupTests';

import config from 'config';
import { api } from 'utils/constants';

jest.mock('config');
jest.mock('utils/http/handleError');

const mockStore = configureStore([thunk]);

jest.mock('uuid');
const projectUuid = 'random-project-uuid';
uuidv4.mockImplementation(() => projectUuid);

jest.mock('redux/actions/projects/saveProject');
saveProject.mockImplementation(() => async () => { });

const experimentId = 'random-experiment-uuid';
jest.mock('redux/actions/experiments/createExperiment');
createExperiment.mockImplementation((uuid, name) => async () => ({
Expand Down Expand Up @@ -56,16 +45,14 @@ describe('createProject action', () => {
const projectDescription = 'test project description';
const experimentName = 'mockExperimentName';

it('Works corectly project when there are no errors', async () => {
config.currentApiVersion = api.V1;

it('Creates a project when there are no errors', async () => {
fetchMock.mockResponse(JSON.stringify({}));

await store.dispatch(
createProject(projectName, projectDescription, experimentName),
);

expect(createExperiment).toHaveBeenCalledWith(projectUuid, experimentName);
expect(createExperiment).toHaveBeenCalledWith(experimentName);

// Sends correct actions
const actions = store.getActions();
Expand All @@ -78,17 +65,16 @@ describe('createProject action', () => {
expect(actions[1].payload).toMatchSnapshot();
});

it('Shows error when there was a fetch error', async () => {
config.currentApiVersion = api.V1;
it('Shows error when there was an experiment error', async () => {
const fetchErrorMessage = 'some error';

fetchMock.mockResponse(JSON.stringify({ message: fetchErrorMessage }), { url: 'mockedUrl', status: 400 });
createExperiment.mockImplementationOnce(() => { throw new Error(fetchErrorMessage); });

await store.dispatch(
createProject(projectName, projectDescription, experimentName),
);

expect(createExperiment).toHaveBeenCalledWith(projectUuid, experimentName);
expect(createExperiment).toHaveBeenCalledWith(experimentName);

// Sends correct actions
const actions = store.getActions();
Expand Down
10 changes: 0 additions & 10 deletions src/__test__/redux/actions/projects/deleteMetadataTrack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import deleteMetadataTrack from 'redux/actions/projects/deleteMetadataTrack';
import initialProjectState from 'redux/reducers/projects';
import initialSampleState from 'redux/reducers/samples';

import { saveProject } from 'redux/actions/projects';
import { saveSamples } from 'redux/actions/samples';
import '__test__/test-utils/setupTests';

import { PROJECTS_METADATA_DELETE } from 'redux/actionTypes/projects';
Expand All @@ -24,12 +22,6 @@ jest.mock('config');

const mockStore = configureStore([thunk]);

jest.mock('redux/actions/projects/saveProject');
saveProject.mockImplementation(() => async () => { });

jest.mock('redux/actions/samples/saveSamples');
saveSamples.mockImplementation(() => async () => { });

const mockProjectUuid = 'project-1234';
const mockSampleUuid = 'sample-1234';
const metadataTrack = 'Test';
Expand Down Expand Up @@ -96,8 +88,6 @@ describe('deleteMetadataTrack action', () => {
});

it('Does not update metadata if save fails', async () => {
saveProject.mockImplementation(() => async () => { throw new Error('some weird error'); });

const store = mockStore(initialState);
await store.dispatch(deleteMetadataTrack(metadataTrack, mockProject.uuid));

Expand Down
83 changes: 14 additions & 69 deletions src/__test__/redux/actions/projects/deleteProject.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
Expand All @@ -6,19 +8,14 @@ import deleteProject from 'redux/actions/projects/deleteProject';
import initialSampleState, { sampleTemplate } from 'redux/reducers/samples/initialState';
import initialProjectState, { projectTemplate } from 'redux/reducers/projects/initialState';

import { SAMPLES_DELETE_API_V1 } from 'redux/actionTypes/samples';
import {
PROJECTS_DELETE, PROJECTS_SAVED, PROJECTS_SAVING, PROJECTS_SET_ACTIVE,
} from 'redux/actionTypes/projects';
import { EXPERIMENTS_DELETED } from 'redux/actionTypes/experiments';

import config from 'config';
import { api } from 'utils/constants';
import { SAMPLES_DELETE } from 'redux/actionTypes/samples';

jest.mock('config');

jest.mock('redux/actions/projects/saveProject', () => { });

enableFetchMocks();

const mockStore = configureStore([thunk]);
Expand Down Expand Up @@ -104,19 +101,9 @@ describe('deleteProject action', () => {

// Sets up loading state for saving project
const actions = store.getActions();
expect(actions[0].type).toEqual(PROJECTS_SAVING);

// Delete experiments
expect(actions[1].type).toEqual(EXPERIMENTS_DELETED);

// Delete sample
expect(actions[2].type).toEqual(SAMPLES_DELETE_API_V1);

// Delete project
expect(actions[3].type).toEqual(PROJECTS_DELETE);

// Resolve loading state
expect(actions[4].type).toEqual(PROJECTS_SAVED);
expect(_.map(actions, 'type')).toEqual([
PROJECTS_SAVING, SAMPLES_DELETE, EXPERIMENTS_DELETED, PROJECTS_DELETE, PROJECTS_SAVED,
]);
});

it('Dispatches event correctly for multiple samples', async () => {
Expand All @@ -125,19 +112,9 @@ describe('deleteProject action', () => {

// Sets up loading state for saving project
const actions = store.getActions();
expect(actions[0].type).toEqual(PROJECTS_SAVING);

// Delete experiments
expect(actions[1].type).toEqual(EXPERIMENTS_DELETED);

// Delete sample
expect(actions[2].type).toEqual(SAMPLES_DELETE_API_V1);

// Delete project
expect(actions[3].type).toEqual(PROJECTS_DELETE);

// Resolve loading state
expect(actions[4].type).toEqual(PROJECTS_SAVED);
expect(_.map(actions, 'type')).toEqual([
PROJECTS_SAVING, SAMPLES_DELETE, EXPERIMENTS_DELETED, PROJECTS_DELETE, PROJECTS_SAVED,
]);
});

it('Switches to activeProjectUuid to another project if multiple project exists', async () => {
Expand All @@ -146,45 +123,13 @@ describe('deleteProject action', () => {

// Sets up loading state for saving project
const actions = store.getActions();
expect(actions[0].type).toEqual(PROJECTS_SAVING);

// Switch active proejct
expect(actions[1].type).toEqual(PROJECTS_SET_ACTIVE);

// Delete experiments
expect(actions[2].type).toEqual(EXPERIMENTS_DELETED);

// Delete sample
expect(actions[3].type).toEqual(SAMPLES_DELETE_API_V1);

// Delete project
expect(actions[4].type).toEqual(PROJECTS_DELETE);

// Resolve loading state
expect(actions[5].type).toEqual(PROJECTS_SAVED);
});

it('Dispatches fetch correctly.', async () => {
const response = new Response(JSON.stringify({}));
fetchMock.mockResolvedValueOnce(response);

const store = mockStore(initialStateUniSample);
await store.dispatch(deleteProject(mockProjectUuid1));

expect(fetchMock).toHaveBeenCalledWith(
`http://localhost:3000/v2/experiments/${mockProject.uuid}`,
{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
},
);
expect(_.map(actions, 'type')).toEqual([
PROJECTS_SAVING, PROJECTS_SET_ACTIVE, SAMPLES_DELETE,
EXPERIMENTS_DELETED, PROJECTS_DELETE, PROJECTS_SAVED,
]);
});

it('Dispatches fetch correctly in api v2', async () => {
config.currentApiVersion = api.V2;

it('Dispatches fetch correctly', async () => {
const response = new Response(JSON.stringify({}));
fetchMock.mockResolvedValueOnce(response);

Expand Down
Loading

0 comments on commit 2ebf8c9

Please sign in to comment.