Added update test
This commit is contained in:
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 { apiClient } from '../../apollo';
|
||||
|
||||
const UPDATE_PERSON = gql`
|
||||
export const UPDATE_PERSON = gql`
|
||||
mutation UpdatePeople(
|
||||
$id: Int
|
||||
$firstname: String
|
||||
@ -41,8 +41,11 @@ const UPDATE_PERSON = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export async function updatePerson(person: Person) {
|
||||
const result = await apiClient.mutate({
|
||||
export async function updatePerson(
|
||||
person: Person,
|
||||
client: ApolloClient<NormalizedCacheObject> = apiClient,
|
||||
) {
|
||||
const result = await client.mutate({
|
||||
mutation: UPDATE_PERSON,
|
||||
variables: mapGqlPerson(person),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user