Skip to content
Snippets Groups Projects
Commit c67476a3 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

reactionSchema removed (it has been taken from old API)

parent 6ba67e87
No related branches found
No related tags found
1 merge request!311Resolve "remove usage of old reaction endpoint"
Showing
with 17 additions and 293 deletions
......@@ -9,7 +9,7 @@ import { twMerge } from 'tailwind-merge';
import { FIRST_ARRAY_ELEMENT, SECOND_ARRAY_ELEMENT, ZERO } from '@/constants/common';
import { PluginsContextMenu } from '@/services/pluginsManager/pluginContextMenu/pluginsContextMenu';
import { BioEntity, Reaction } from '@/types/models';
import { BioEntity, NewReaction } from '@/types/models';
import { ClickCoordinates } from '@/services/pluginsManager/pluginContextMenu/pluginsContextMenu.types';
import { currentModelSelector } from '@/redux/models/models.selectors';
import { mapDataLastPositionSelector } from '@/redux/map/map.selectors';
......@@ -44,7 +44,7 @@ export const ContextMenu = (): React.ReactNode => {
const modelId = model ? model.idObject : ZERO;
const handleCallback = (
callback: (coordinates: ClickCoordinates, element: BioEntity | Reaction | undefined) => void,
callback: (coordinates: ClickCoordinates, element: BioEntity | NewReaction | undefined) => void,
) => {
return () => {
dispatch(closeContextMenu());
......
......@@ -2,7 +2,6 @@
import { openReactionDrawerById, selectTab } from '@/redux/drawer/drawer.slice';
import { PluginsEventBus } from '@/services/pluginsManager/pluginsEventBus';
import { searchFitBounds } from '@/services/pluginsManager/map/triggerSearch/searchFitBounds';
import { reactionsFixture } from '@/models/fixtures/reactionFixture';
import { mockNetworkNewAPIResponse } from '@/utils/mockNetworkResponse';
import { apiPath } from '@/redux/apiPath';
import { HttpStatusCode } from 'axios';
......@@ -30,26 +29,24 @@ describe('clickHandleReaction', () => {
return {
unwrap: jest.fn().mockResolvedValue([]),
payload: {
data: [reactionsFixture[0]],
data: [newReactionFixture],
},
};
});
reactionId = reactionsFixture[0].id;
modelId = reactionsFixture[0].modelId;
reactionId = newReactionFixture.id;
modelId = newReactionFixture.model;
mockedAxiosClient
.onGet(apiPath.getReactionByIdInNewApi(reactionId, modelId))
.reply(HttpStatusCode.Ok, bioEntityFixture);
[
...reactionsFixture[0].products,
...reactionsFixture[0].reactants,
...reactionsFixture[0].modifiers,
...newReactionFixture.products,
...newReactionFixture.reactants,
...newReactionFixture.modifiers,
].forEach(element => {
mockedAxiosClient
.onGet(
apiPath.getElementById('aliasId' in element ? element.aliasId : element.element, modelId),
)
.onGet(apiPath.getElementById(element.element, modelId))
.reply(HttpStatusCode.Ok, bioEntityFixture);
});
clickHandleReaction(dispatch, hasFitBounds)(
......
/* eslint-disable no-magic-numbers */
import { SIZE_OF_EMPTY_ARRAY } from '@/constants/common';
import { bioEntityResponseFixture } from '@/models/fixtures/bioEntityContentsFixture';
import { reactionsFixture } from '@/models/fixtures/reactionFixture';
import {
ELEMENT_SEARCH_RESULT_MOCK_ALIAS,
ELEMENT_SEARCH_RESULT_MOCK_REACTION,
......@@ -186,7 +185,7 @@ describe('handleReactionResults - util', () => {
products: [],
modifiers: [
{
...reactionsFixture[0].modifiers[0],
...newReactionFixture.modifiers[0],
aliasId: ELEMENT_SEARCH_RESULT_MOCK_ALIAS.id,
},
],
......
import { ZOD_SEED } from '@/constants';
import { z } from 'zod';
// eslint-disable-next-line import/no-extraneous-dependencies
import { createFixture } from 'zod-fixture';
import { reactionSchema } from '../reaction';
export const reactionsFixture = createFixture(z.array(reactionSchema), {
seed: ZOD_SEED,
array: { min: 2, max: 2 },
});
import { z } from 'zod';
import { positionSchema } from './positionSchema';
import { productsSchema } from './products';
import { reactionLineSchema } from './reactionLineSchema';
import { referenceSchema } from './referenceSchema';
export const reactionSchema = z.object({
centerPoint: positionSchema,
hierarchyVisibilityLevel: z.string().nullable(),
id: z.number(),
kineticLaw: z.null(),
lines: z.array(reactionLineSchema),
modelId: z.number(),
modifiers: z.array(productsSchema),
name: z.string(),
notes: z.string(),
products: z.array(productsSchema),
reactants: z.array(productsSchema),
reactionId: z.string(),
references: z.array(referenceSchema),
type: z.string(),
});
......@@ -2,12 +2,12 @@ import {
REFERENCES_MOCK_ALL_INVALID,
REFERENCES_MOCK_ALL_VALID,
} from '@/models/mocks/referencesMock';
import { Reaction } from '@/types/models';
import { ReferenceFiltered } from '@/types/reference';
import { NewReaction } from '@/types/models';
import { getReferencesWithoutEmptyLink } from './getFilteredReferences';
describe('getFilteredReferences - subUtil', () => {
const cases: [Pick<Reaction, 'references'>, ReferenceFiltered[]][] = [
const cases: [Pick<NewReaction, 'references'>, ReferenceFiltered[]][] = [
[
{
references: REFERENCES_MOCK_ALL_VALID,
......
import { Reaction } from '@/types/models';
import { NewReaction } from '@/types/models';
import { ReferenceFiltered } from '@/types/reference';
type InputReaction = Pick<Reaction, 'references'>;
type InputReaction = Pick<NewReaction, 'references'>;
export const getReferencesWithoutEmptyLink = (
reaction: InputReaction | undefined,
......
import { BioEntity, Reaction } from '@/types/models';
import { BioEntity, NewReaction } from '@/types/models';
export type ClickCoordinates = {
modelId: number;
......@@ -13,7 +13,7 @@ export type PluginContextMenuItemType = {
name: string;
style: string;
enabled: boolean;
callback: (coordinates: ClickCoordinates, element: BioEntity | Reaction | undefined) => void;
callback: (coordinates: ClickCoordinates, element: BioEntity | NewReaction | undefined) => void;
};
export type PluginsContextMenuType = {
......@@ -23,7 +23,7 @@ export type PluginsContextMenuType = {
name: string,
style: string,
enabled: boolean,
callback: (coordinates: ClickCoordinates, element: BioEntity | Reaction | undefined) => void,
callback: (coordinates: ClickCoordinates, element: BioEntity | NewReaction | undefined) => void,
) => string;
removeMenu: (hash: string, id: string) => void;
updateMenu: (hash: string, id: string, name: string, style: string, enabled: boolean) => void;
......
......@@ -50,7 +50,6 @@ import { pluginSchema } from '@/models/pluginSchema';
import { projectSchema } from '@/models/projectSchema';
import { publicationsResponseSchema } from '@/models/publicationsResponseSchema';
import { publicationSchema } from '@/models/publicationsSchema';
import { reactionSchema } from '@/models/reaction';
import { reactionLineSchema } from '@/models/reactionLineSchema';
import { referenceSchema } from '@/models/referenceSchema';
import { sessionSchemaValid } from '@/models/sessionValidSchema';
......@@ -120,7 +119,6 @@ export type BioEntity = z.infer<typeof bioEntitySchema>;
export type BioEntityContent = z.infer<typeof bioEntityContentSchema>;
export type BioEntityResponse = z.infer<typeof bioEntityResponseSchema>;
export type Chemical = z.infer<typeof chemicalSchema>;
export type Reaction = z.infer<typeof reactionSchema>;
export type NewReaction = z.infer<typeof newReactionSchema>;
const newReactionsSchema = pageableSchema(newReactionSchema);
export type NewReactions = z.infer<typeof newReactionsSchema>;
......
/* eslint-disable no-magic-numbers */
import mapNewReactionToReaction from '@/utils/reaction/mapNewReactionToReaction';
describe('mapNewReactionToReaction', () => {
const newReaction = {
id: 31141,
notes: '',
idReaction: 're22',
name: '',
reversible: false,
symbol: null,
abbreviation: null,
formula: null,
mechanicalConfidenceScore: null,
lowerBound: null,
upperBound: null,
subsystem: null,
geneProteinReaction: null,
visibilityLevel: '',
z: 45,
synonyms: [],
model: 137,
kinetics: null,
line: {
id: 109668,
width: 1,
color: {
alpha: 255,
rgb: -16777216,
},
z: 0,
segments: [
{
x1: 149.31765717927775,
y1: 319.13724818355684,
x2: 142.5553586937381,
y2: 314.86275181644316,
},
],
startArrow: {
arrowType: 'NONE',
angle: 2.748893571891069,
lineType: 'SOLID',
length: 15,
},
endArrow: {
arrowType: 'NONE',
angle: 2.748893571891069,
lineType: 'SOLID',
length: 15,
},
lineType: 'SOLID',
},
processCoordinates: null,
modifiers: [],
products: [
{
id: 85169,
line: {
id: 109670,
width: 1,
color: {
alpha: 255,
rgb: -16777216,
},
z: 0,
segments: [
{
x1: 142.5553586937381,
y1: 314.86275181644316,
x2: 122.2063492063492,
y2: 302,
},
],
startArrow: {
arrowType: 'NONE',
angle: 2.748893571891069,
lineType: 'SOLID',
length: 15,
},
endArrow: {
arrowType: 'OPEN',
angle: 2.748893571891069,
lineType: 'SOLID',
length: 15,
},
lineType: 'SOLID',
},
stoichiometry: null,
element: 58886,
},
],
reactants: [
{
id: 85168,
line: {
id: 109669,
width: 1,
color: {
alpha: 255,
rgb: -16777216,
},
z: 0,
segments: [
{
x1: 169.66666666666666,
y1: 332,
x2: 149.31765717927775,
y2: 319.13724818355684,
},
],
startArrow: {
arrowType: 'NONE',
angle: 2.748893571891069,
lineType: 'SOLID',
length: 15,
},
endArrow: {
arrowType: 'NONE',
angle: 2.748893571891069,
lineType: 'SOLID',
length: 15,
},
lineType: 'SOLID',
},
stoichiometry: null,
element: 58872,
},
],
operators: [],
elementId: 're22',
references: [],
sboTerm: 'SBO:0000171',
};
const expectedReaction = {
centerPoint: {
x: 0,
y: 0,
},
hierarchyVisibilityLevel: '',
id: 31141,
kineticLaw: null,
lines: [
{
start: {
x: 149.31765717927775,
y: 319.13724818355684,
},
end: {
x: 142.5553586937381,
y: 314.86275181644316,
},
type: '',
},
{
start: {
x: 142.5553586937381,
y: 314.86275181644316,
},
end: {
x: 122.2063492063492,
y: 302,
},
type: '',
},
{
start: {
x: 169.66666666666666,
y: 332,
},
end: {
x: 149.31765717927775,
y: 319.13724818355684,
},
type: '',
},
],
modelId: 137,
modifiers: [],
name: '',
notes: '',
products: [],
reactants: [],
reactionId: 're22',
references: [],
type: 'Positive influence',
};
it('should return correct reaction object from new reaction object', () => {
const result = mapNewReactionToReaction(newReaction);
expect(result).toEqual(expectedReaction);
});
});
/* eslint-disable no-magic-numbers */
import { NewReaction, Reaction, ReactionLine } from '@/types/models';
import ReactionTypeEnum from '@/utils/reaction/ReactionTypeEnum';
type ReactionTypeKey = keyof typeof ReactionTypeEnum;
export default function mapNewReactionToReaction(newReaction: NewReaction): Reaction {
const lines: Array<ReactionLine> = [];
let start;
let end;
newReaction.line.segments.forEach(segment => {
start = { x: segment.x1, y: segment.y1 };
end = { x: segment.x2, y: segment.y2 };
lines.push({ start, end, type: '' });
});
[
...newReaction.products,
...newReaction.reactants,
...newReaction.modifiers,
...newReaction.operators,
].forEach(element => {
element.line.segments.forEach(segment => {
start = { x: segment.x1, y: segment.y1 };
end = { x: segment.x2, y: segment.y2 };
lines.push({ start, end, type: '' });
});
});
return {
centerPoint: { x: 0, y: 0 },
hierarchyVisibilityLevel: '',
id: newReaction.id,
kineticLaw: null,
lines,
modelId: newReaction.model,
modifiers: [],
name: '',
notes: newReaction.notes,
products: [],
reactants: [],
reactionId: newReaction.idReaction,
references: newReaction.references,
type: ReactionTypeEnum[newReaction.sboTerm as ReactionTypeKey],
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment