Skip to content
Snippets Groups Projects
Commit 28fa3983 authored by Mateusz Mikołajczak's avatar Mateusz Mikołajczak
Browse files

fix(mirna): improvement store management mirna

parent acc96f78
No related branches found
No related tags found
1 merge request!22[BLOCKED]Resolve MIN-60 "Feature/ connect search mirna query"
Pipeline #79170 passed
import { PROJECT_ID } from '@/constants/mapId';
import { getMirnasStringWithQuery } from './getMirnasStringWithQuery';
describe('getMirnasStringWithQuery', () => {
it('should return url string', () => {
expect(getMirnasStringWithQuery('hsa-miR-302b-3p')).toBe(
`projects/${PROJECT_ID}/miRnas:search?query=hsa-miR-302b-3p`,
);
});
});
import { PROJECT_ID } from '@/constants/mapId';
export const getMirnasStringWithQuery = (searchQuery: string): string =>
`projects/${PROJECT_ID}/miRnas:search?query=${searchQuery}`;
import { PROJECT_ID } from '@/constants/mapId';
import { mirnasFixture } from '@/models/fixtures/mirnasFixture';
import { HTTP_NOT_FOUND, HTTP_OK } from '@/constants/httpResponses';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import {
ToolkitStoreWithSingleSlice,
createStoreInstanceUsingSliceReducer,
} from '@/utils/createStoreInstanceUsingSliceReducer';
import { getMirnasStringWithQuery } from '@/queries/getMirnasStringWithQuery';
import { HttpStatusCode } from 'axios';
import { getMirnas } from './mirnas.thunks';
import mirnasReducer from './mirnas.slice';
import { MirnasState } from './mirnas.types';
......@@ -32,8 +32,8 @@ describe('mirnas reducer', () => {
});
it('should update store after succesfull getMirnas query', async () => {
mockedAxiosClient
.onGet(`projects/${PROJECT_ID}/miRnas:search?query=${SEARCH_QUERY}`)
.reply(HTTP_OK, mirnasFixture);
.onGet(getMirnasStringWithQuery(SEARCH_QUERY))
.reply(HttpStatusCode.Ok, mirnasFixture);
const { type } = await store.dispatch(getMirnas(SEARCH_QUERY));
const { data, loading, error } = store.getState().mirnas;
......@@ -46,8 +46,8 @@ describe('mirnas reducer', () => {
it('should update store after failed getMirnas query', async () => {
mockedAxiosClient
.onGet(`projects/${PROJECT_ID}/miRnas:search?query=${SEARCH_QUERY}`)
.reply(HTTP_NOT_FOUND, []);
.onGet(getMirnasStringWithQuery(SEARCH_QUERY))
.reply(HttpStatusCode.NotFound, []);
const { type } = await store.dispatch(getMirnas(SEARCH_QUERY));
const { data, loading, error } = store.getState().mirnas;
......@@ -60,8 +60,8 @@ describe('mirnas reducer', () => {
it('should update store on loading getMirnas query', async () => {
mockedAxiosClient
.onGet(`projects/${PROJECT_ID}/miRnas:search?query=${SEARCH_QUERY}`)
.reply(HTTP_OK, mirnasFixture);
.onGet(getMirnasStringWithQuery(SEARCH_QUERY))
.reply(HttpStatusCode.Ok, mirnasFixture);
const mirnasPromise = store.dispatch(getMirnas(SEARCH_QUERY));
......
import { PROJECT_ID } from '@/constants/mapId';
import { mirnasFixture } from '@/models/fixtures/mirnasFixture';
import { HTTP_OK } from '@/constants/httpResponses';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import {
ToolkitStoreWithSingleSlice,
createStoreInstanceUsingSliceReducer,
} from '@/utils/createStoreInstanceUsingSliceReducer';
import { getMirnasStringWithQuery } from '@/queries/getMirnasStringWithQuery';
import { HttpStatusCode } from 'axios';
import { getMirnas } from './mirnas.thunks';
import mirnasReducer from './mirnas.slice';
import { MirnasState } from './mirnas.types';
......@@ -21,16 +21,16 @@ describe('mirnas thunks', () => {
describe('getMirnas', () => {
it('should return data when data response from API is valid', async () => {
mockedAxiosClient
.onGet(`projects/${PROJECT_ID}/miRnas:search?query=${SEARCH_QUERY}`)
.reply(HTTP_OK, mirnasFixture);
.onGet(getMirnasStringWithQuery(SEARCH_QUERY))
.reply(HttpStatusCode.Ok, mirnasFixture);
const { payload } = await store.dispatch(getMirnas(SEARCH_QUERY));
expect(payload).toEqual(mirnasFixture);
});
it('should return undefined when data response from API is not valid ', async () => {
mockedAxiosClient
.onGet(`projects/${PROJECT_ID}/miRnas:search?query=${SEARCH_QUERY}`)
.reply(HTTP_OK, { randomProperty: 'randomValue' });
.onGet(getMirnasStringWithQuery(SEARCH_QUERY))
.reply(HttpStatusCode.Ok, { randomProperty: 'randomValue' });
const { payload } = await store.dispatch(getMirnas(SEARCH_QUERY));
expect(payload).toEqual(undefined);
......
import { z } from 'zod';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { axiosInstance } from '@/services/api/utils/axiosInstance';
import { PROJECT_ID } from '@/constants/mapId';
import { Mirna } from '@/types/models';
import { mirnaSchema } from '@/models/mirnaSchema';
import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema';
import { getMirnasStringWithQuery } from '@/queries/getMirnasStringWithQuery';
export const getMirnas = createAsyncThunk(
'project/getMirnas',
async (searchQuery: string): Promise<Mirna[] | undefined> => {
const response = await axiosInstance.get<Mirna[]>(
`projects/${PROJECT_ID}/miRnas:search?query=${searchQuery}`,
);
const response = await axiosInstance.get<Mirna[]>(getMirnasStringWithQuery(searchQuery));
const isDataValid = validateDataUsingZodSchema(response.data, z.array(mirnaSchema));
......
import { Loading } from '@/types/loadingState';
import { FetchDataState } from '@/types/fetchDataState';
import { Mirna } from '@/types/models';
export type MirnasState = {
data: Mirna[] | undefined;
loading: Loading;
error: Error;
};
export type MirnasState = FetchDataState<Mirna[]>;
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