Skip to content

Commit

Permalink
Merge pull request #702 from hms-dbmi-cellenics/cellsets-endpoint-v2
Browse files Browse the repository at this point in the history
[BIOMAGE-1878] - Add v2 cellsets endpoints
  • Loading branch information
aerlaut authored May 9, 2022
2 parents 15be5fe + 14afd6d commit 5513e45
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ Object {
"method": "PATCH",
}
`;
exports[`createCellSet action Uses V2 URL when using API version V2 1`] = `
Object {
"body": "[{\\"$match\\":{\\"query\\":\\"$[?(@.key == \\\\\\"scratchpad\\\\\\")]\\",\\"value\\":{\\"children\\":[{\\"$insert\\":{\\"index\\":\\"-\\",\\"value\\":{\\"key\\":\\"some-uuid\\",\\"name\\":\\"one\\",\\"color\\":\\"#ff0000\\",\\"type\\":\\"cellSets\\",\\"cellIds\\":[1,2,3]}}}]}}}]",
"headers": Object {
"Content-Type": "application/boschni-json-merger+json",
},
"method": "PATCH",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ Object {
"method": "PATCH",
}
`;
exports[`deleteCellSet action Uses V2 URL when using API version V2 1`] = `
Object {
"body": "[{\\"$match\\":{\\"query\\":\\"$[?(@.key == \\\\\\"scratchpad\\\\\\")]\\",\\"value\\":{\\"children\\":[{\\"$match\\":{\\"query\\":\\"$[?(@.key == \\\\\\"my-key\\\\\\")]\\",\\"value\\":{\\"$remove\\":true}}}]}}}]",
"headers": Object {
"Content-Type": "application/boschni-json-merger+json",
},
"method": "PATCH",
}
`;
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`loadCellSets action Dispatches a loaded action when run with the initial state. 1`] = `undefined`;
exports[`loadCellSets action Dispatches a loaded action when run with the initial state. 1`] = `
Object {
"payload": Object {
"data": Object {
"cellIds": Object {},
"color": "#ff0000",
"name": "one",
},
"experimentId": "1234",
},
"type": "cellSets/loaded",
}
`;

exports[`loadCellSets action Dispatches a loading action when run after an error condition. 1`] = `
Object {
"type": "cellSets/loading",
}
`;

exports[`loadCellSets action Dispatches an error condition if fetch fails 1`] = `undefined`;
exports[`loadCellSets action Dispatches an error condition if fetch fails 1`] = `
Object {
"payload": Object {
"error": "We couldn't get the list of cell sets.",
},
"type": "cellSets/error",
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`reorderCellSet action Uses V2 URL when using API version V2 1`] = `
Object {
"body": "[{\\"$match\\":{\\"query\\":\\"$[?(@.key == \\\\\\"root\\\\\\")]\\",\\"value\\":{\\"children\\":[{\\"$match\\":{\\"query\\":\\"$[?(@.key == \\\\\\"child\\\\\\")]\\",\\"value\\":{\\"$move\\":5}}}]}}}]",
"headers": Object {
"Content-Type": "application/boschni-json-merger+json",
},
"method": "PATCH",
}
`;
exports[`reorderCellSet action Works correctly 1`] = `
Object {
"payload": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ Object {
"method": "PATCH",
}
`;
exports[`updateCellSetProperty action Uses V2 URL when using API version V2 1`] = `
Object {
"body": "[{\\"$match\\":{\\"query\\":\\"$[?(@.key == \\\\\\"root\\\\\\")]\\",\\"value\\":{\\"children\\":[{\\"$match\\":{\\"query\\":\\"$[?(@.key == \\\\\\"child\\\\\\")]\\",\\"value\\":{\\"name\\":\\"Some node!\\"}}}]}}}]",
"headers": Object {
"Content-Type": "application/boschni-json-merger+json",
},
"method": "PATCH",
}
`;
23 changes: 22 additions & 1 deletion src/__test__/redux/actions/cellSets/createCellSet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import createCellSet from 'redux/actions/cellSets/createCellSet';
import initialState from 'redux/reducers/cellSets/initialState';

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

import uuid from 'uuid';

import '__test__/test-utils/setupTests';

enableFetchMocks();

jest.mock('config');

jest.mock('uuid', () => jest.fn());
uuid.v4 = jest.fn(() => 'some-uuid');

Expand All @@ -25,6 +30,8 @@ describe('createCellSet action', () => {
beforeEach(() => {
const response = new Response(JSON.stringify({}));

config.currentApiVersion = api.V1;

fetchMock.resetMocks();
fetchMock.doMock();
fetchMock.mockResolvedValueOnce(response);
Expand Down Expand Up @@ -55,11 +62,25 @@ describe('createCellSet action', () => {
const store = mockStore({ cellSets: { ...initialState, loading: false } });
await store.dispatch(createCellSet(experimentId, cellSet.name, cellSet.color, cellSet.cellIds));

expect(fetch).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledTimes(1);

const [url, body] = fetch.mock.calls[0];

expect(url).toEqual('http://localhost:3000/v1/experiments/1234/cellSets');
expect(body).toMatchSnapshot();
});

it('Uses V2 URL when using API version V2', async () => {
config.currentApiVersion = api.V2;

const store = mockStore({ cellSets: { ...initialState, loading: false } });
await store.dispatch(createCellSet(experimentId, cellSet.name, cellSet.color, cellSet.cellIds));

expect(fetchMock).toHaveBeenCalledTimes(1);

const [url, body] = fetch.mock.calls[0];

expect(url).toEqual('http://localhost:3000/v2/experiments/1234/cellSets');
expect(body).toMatchSnapshot();
});
});
22 changes: 22 additions & 0 deletions src/__test__/redux/actions/cellSets/deleteCellSet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';

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

import waitForActions from 'redux-mock-store-await-actions';

import { CELL_SETS_DELETE } from 'redux/actionTypes/cellSets';
Expand All @@ -11,6 +14,9 @@ import deleteCellSet from 'redux/actions/cellSets/deleteCellSet';
import '__test__/test-utils/setupTests';

enableFetchMocks();

jest.mock('config');

const mockStore = configureStore([thunk]);

describe('deleteCellSet action', () => {
Expand All @@ -20,6 +26,8 @@ describe('deleteCellSet action', () => {
beforeEach(() => {
const response = new Response(JSON.stringify({}));

config.currentApiVersion = api.V1;

fetchMock.resetMocks();
fetchMock.doMock();
fetchMock.mockResolvedValueOnce(response);
Expand Down Expand Up @@ -59,4 +67,18 @@ describe('deleteCellSet action', () => {
expect(url).toEqual('http://localhost:3000/v1/experiments/1234/cellSets');
expect(body).toMatchSnapshot();
});

it('Uses V2 URL when using API version V2', async () => {
config.currentApiVersion = api.V2;

const store = mockStore({ cellSets: { ...initialState, loading: false } });
await store.dispatch(deleteCellSet(experimentId, key));

expect(fetchMock).toHaveBeenCalledTimes(1);

const [url, body] = fetch.mock.calls[0];

expect(url).toEqual('http://localhost:3000/v2/experiments/1234/cellSets');
expect(body).toMatchSnapshot();
});
});
38 changes: 28 additions & 10 deletions src/__test__/redux/actions/cellSets/loadCellSets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import loadCellSets from 'redux/actions/cellSets/loadCellSets';
import initialState from 'redux/reducers/cellSets/initialState';

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

import '__test__/test-utils/setupTests';

jest.mock('config');

enableFetchMocks();
const mockStore = configureStore([thunk]);

describe('loadCellSets action', () => {
const experimentId = '1234';

const cellSet = {
const cellSets = {
name: 'one', color: '#ff0000', cellIds: new Set([1, 2, 3]),
};

Expand All @@ -23,7 +28,9 @@ describe('loadCellSets action', () => {
};

beforeEach(() => {
const response = new Response(JSON.stringify({}));
const response = new Response(JSON.stringify({ cellSets }));

config.currentApiVersion = api.V1;

fetchMock.resetMocks();
fetchMock.doMock();
Expand All @@ -32,14 +39,14 @@ describe('loadCellSets action', () => {

it('Does not dispatch on normal operation', async () => {
const store = mockStore({ cellSets: { loading: false, error: false }, experimentSettings });
store.dispatch(loadCellSets(experimentId, cellSet.name, cellSet.color, cellSet.cellIds));
await store.dispatch(loadCellSets(experimentId));
expect(store.getActions().length).toEqual(0);
});

it('Dispatches on loading state', async () => {
const store = mockStore({ cellSets: { loading: true, error: false }, experimentSettings });
await store.dispatch(loadCellSets(experimentId));
expect(store.getActions().length).toBeGreaterThan(0);
it('Dispatches on force reload ', async () => {
const store = mockStore({ cellSets: { loading: false, error: false }, experimentSettings });
await store.dispatch(loadCellSets(experimentId, true));
expect(store.getActions().length).toEqual(1);
});

it('Dispatches on loading and error state', async () => {
Expand All @@ -50,7 +57,7 @@ describe('loadCellSets action', () => {

it('Dispatches a loading action when run after an error condition.', async () => {
const store = mockStore({ cellSets: { loading: false, error: true }, experimentSettings });
store.dispatch(loadCellSets(experimentId));
await store.dispatch(loadCellSets(experimentId));

const firstAction = store.getActions()[0];

Expand All @@ -59,7 +66,7 @@ describe('loadCellSets action', () => {

it('Dispatches a loaded action when run with the initial state.', async () => {
const store = mockStore({ cellSets: initialState, experimentSettings });
store.dispatch(loadCellSets(experimentId));
await store.dispatch(loadCellSets(experimentId));

const firstAction = store.getActions()[0];

Expand All @@ -72,9 +79,20 @@ describe('loadCellSets action', () => {
fetchMock.resetMocks();
fetchMock.mockReject(new Error('some weird error that happened'));

store.dispatch(loadCellSets(experimentId));
await store.dispatch(loadCellSets(experimentId));

const firstAction = store.getActions()[0];
expect(firstAction).toMatchSnapshot();
});

it('Uses V2 URL when using API version V2', async () => {
config.currentApiVersion = api.V2;

const store = mockStore({ cellSets: initialState, experimentSettings });
await store.dispatch(loadCellSets(experimentId));

const fetchUrl = fetchMock.mock.calls[0][0];

expect(fetchUrl).toEqual('http://localhost:3000/v2/experiments/1234/cellSets');
});
});
26 changes: 24 additions & 2 deletions src/__test__/redux/actions/cellSets/reorderCellSet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import waitForActions from 'redux-mock-store-await-actions';
import { waitFor } from '@testing-library/react';

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

import reorderCellSet from 'redux/actions/cellSets/reorderCellSet';
import { CELL_SETS_REORDER } from 'redux/actionTypes/cellSets';
import pushNotificationMessage from 'utils/pushNotificationMessage';

import initialState from 'redux/reducers/cellSets/initialState';

enableFetchMocks();

jest.mock('config');

const mockStore = configureStore([thunk]);

describe('reorderCellSet action', () => {
Expand All @@ -36,6 +42,8 @@ describe('reorderCellSet action', () => {
beforeEach(() => {
jest.resetAllMocks();

config.currentApiVersion = api.V1;

fetchMock.resetMocks();
fetchMock.doMock();
});
Expand All @@ -51,9 +59,9 @@ describe('reorderCellSet action', () => {
expect(store.getActions()[0]).toMatchSnapshot();

// Fetch was called correctly
expect(fetch).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledTimes(1);

const [url, body] = fetch.mock.calls[0];
const [url, body] = fetchMock.mock.calls[0];
expect(url).toEqual('http://localhost:3000/v1/experiments/1234/cellSets');
expect(body).toMatchSnapshot();
});
Expand All @@ -72,4 +80,18 @@ describe('reorderCellSet action', () => {

expect(store.getActions()).toHaveLength(0);
});

it('Uses V2 URL when using API version V2', async () => {
config.currentApiVersion = api.V2;

const store = mockStore({ cellSets: { ...cellSetsNodeState, loading: false } });
await store.dispatch(reorderCellSet(experimentId, cellSetKey, 5));

expect(fetchMock).toHaveBeenCalledTimes(1);

const [url, body] = fetch.mock.calls[0];

expect(url).toEqual('http://localhost:3000/v2/experiments/1234/cellSets');
expect(body).toMatchSnapshot();
});
});
Loading

0 comments on commit 5513e45

Please sign in to comment.