Add tests on Editable relation (#188)
This commit is contained in:
@ -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,
|
||||
),
|
||||
}),
|
||||
);
|
||||
}),
|
||||
];
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user