Add tests on Editable relation (#188)

This commit is contained in:
Charles Bochet
2023-06-02 16:48:44 +02:00
committed by GitHub
parent 97274db8b4
commit a618636180
9 changed files with 133 additions and 69 deletions

View File

@ -1,5 +1,5 @@
import { graphql } from 'msw';
import { filterAndSortData } from './mock-data';
import { filterAndSortData, updateOneFromData } from './mock-data';
import { GraphqlQueryCompany } from '../interfaces/entities/company.interface';
import { mockedCompaniesData } from './mock-data/companies';
import { GraphqlQueryUser } from '../interfaces/entities/user.interface';
@ -61,7 +61,6 @@ export const graphqlMocks = [
req.variables.orderBy,
req.variables.limit,
);
console.log({ returnedMockedData });
return res(
ctx.data({
users: returnedMockedData,
@ -81,4 +80,15 @@ export const graphqlMocks = [
}),
);
}),
graphql.mutation('UpdatePeople', (req, res, ctx) => {
return res(
ctx.data({
updateOnePerson: updateOneFromData(
mockedPeopleData,
req.variables.id,
req.variables,
),
}),
);
}),
];

View File

@ -1,3 +1,4 @@
import { GraphQLVariables } from 'msw';
import {
CompanyOrderByWithRelationInput,
PersonOrderByWithRelationInput,
@ -112,3 +113,21 @@ export function filterAndSortData<DataT>(
return filteredData;
}
export function fetchOneFromData<DataT extends { id: string }>(
data: Array<DataT>,
id: string,
): DataT | undefined {
return data.filter((item) => item.id === id)[0];
}
export function updateOneFromData<DataT extends { id: string }>(
data: Array<DataT>,
id: string,
payload: GraphQLVariables,
): DataT | undefined {
const object = data.filter((item) => item.id === id)[0];
const newObject = Object.assign(object, payload);
return newObject;
}

View File

@ -3,14 +3,4 @@ import { ApolloClient, InMemoryCache } from '@apollo/client';
export const mockedClient = new ApolloClient({
uri: process.env.REACT_APP_API_URL,
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
query: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
},
});