Added update test
This commit is contained in:
10
front/package-lock.json
generated
10
front/package-lock.json
generated
@ -55,6 +55,7 @@
|
|||||||
"eslint-plugin-promise": "^6.1.1",
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
"eslint-plugin-react": "^7.31.11",
|
"eslint-plugin-react": "^7.31.11",
|
||||||
"eslint-plugin-storybook": "^0.6.11",
|
"eslint-plugin-storybook": "^0.6.11",
|
||||||
|
"mock-apollo-client": "^1.2.1",
|
||||||
"prettier": "^2.8.0",
|
"prettier": "^2.8.0",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
@ -19710,6 +19711,15 @@
|
|||||||
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
|
"integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/mock-apollo-client": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/mock-apollo-client/-/mock-apollo-client-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-QYQ6Hxo+t7hard1bcHHbsHxlNQYTQsaMNsm2Psh/NbwLMi2R4tGzplJKt97MUWuARHMq3GHB4PTLj/gxej4Caw==",
|
||||||
|
"dev": true,
|
||||||
|
"peerDependencies": {
|
||||||
|
"@apollo/client": "^3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/mri": {
|
"node_modules/mri": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
|
||||||
|
|||||||
@ -105,6 +105,7 @@
|
|||||||
"eslint-plugin-promise": "^6.1.1",
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
"eslint-plugin-react": "^7.31.11",
|
"eslint-plugin-react": "^7.31.11",
|
||||||
"eslint-plugin-storybook": "^0.6.11",
|
"eslint-plugin-storybook": "^0.6.11",
|
||||||
|
"mock-apollo-client": "^1.2.1",
|
||||||
"prettier": "^2.8.0",
|
"prettier": "^2.8.0",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
|
|||||||
54
front/src/services/people/__tests__/update.test.ts
Normal file
54
front/src/services/people/__tests__/update.test.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { createMockClient, RequestHandlerResponse } from 'mock-apollo-client';
|
||||||
|
import { UPDATE_PERSON, updatePerson } from '../update';
|
||||||
|
import { GraphqlQueryPerson } from '../../../interfaces/person.interface';
|
||||||
|
|
||||||
|
const mockClient = createMockClient();
|
||||||
|
|
||||||
|
const PERSON_RESULT = {
|
||||||
|
city: 'San Francisco',
|
||||||
|
company: {
|
||||||
|
company_domain: 'example.com',
|
||||||
|
company_name: 'ACME',
|
||||||
|
id: 1,
|
||||||
|
__typename: 'Company',
|
||||||
|
},
|
||||||
|
email: 'john@example.com',
|
||||||
|
firstname: 'John',
|
||||||
|
id: 1,
|
||||||
|
lastname: 'Doe',
|
||||||
|
phone: '+1 (555) 123-4567',
|
||||||
|
__typename: 'Person',
|
||||||
|
created_at: 'today',
|
||||||
|
};
|
||||||
|
|
||||||
|
mockClient.setRequestHandler(UPDATE_PERSON, () => {
|
||||||
|
return new Promise<RequestHandlerResponse<GraphqlQueryPerson>>((resolve) =>
|
||||||
|
resolve({ data: PERSON_RESULT }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates a person', async () => {
|
||||||
|
const result = await updatePerson(
|
||||||
|
{
|
||||||
|
fullName: 'John Doe',
|
||||||
|
id: 1,
|
||||||
|
email: 'john@example.com',
|
||||||
|
company: {
|
||||||
|
id: 2,
|
||||||
|
name: 'ACME',
|
||||||
|
domain: 'example.com',
|
||||||
|
},
|
||||||
|
phone: '+1 (555) 123-4567',
|
||||||
|
pipe: {
|
||||||
|
id: 3,
|
||||||
|
name: 'Customer',
|
||||||
|
icon: '!',
|
||||||
|
},
|
||||||
|
creationDate: new Date(),
|
||||||
|
city: 'San Francisco',
|
||||||
|
countryCode: 'US',
|
||||||
|
},
|
||||||
|
mockClient,
|
||||||
|
);
|
||||||
|
expect(result.data.email).toBe('john@example.com');
|
||||||
|
});
|
||||||
@ -1,8 +1,8 @@
|
|||||||
import { gql } from '@apollo/client';
|
import { ApolloClient, NormalizedCacheObject, gql } from '@apollo/client';
|
||||||
import { Person, mapGqlPerson } from '../../interfaces/person.interface';
|
import { Person, mapGqlPerson } from '../../interfaces/person.interface';
|
||||||
import { apiClient } from '../../apollo';
|
import { apiClient } from '../../apollo';
|
||||||
|
|
||||||
const UPDATE_PERSON = gql`
|
export const UPDATE_PERSON = gql`
|
||||||
mutation UpdatePeople(
|
mutation UpdatePeople(
|
||||||
$id: Int
|
$id: Int
|
||||||
$firstname: String
|
$firstname: String
|
||||||
@ -41,8 +41,11 @@ const UPDATE_PERSON = gql`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export async function updatePerson(person: Person) {
|
export async function updatePerson(
|
||||||
const result = await apiClient.mutate({
|
person: Person,
|
||||||
|
client: ApolloClient<NormalizedCacheObject> = apiClient,
|
||||||
|
) {
|
||||||
|
const result = await client.mutate({
|
||||||
mutation: UPDATE_PERSON,
|
mutation: UPDATE_PERSON,
|
||||||
variables: mapGqlPerson(person),
|
variables: mapGqlPerson(person),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user