Fix front unit test on main (#20233)
Jest mocks runs before the const is defined
This commit is contained in:
+7
-6
@@ -9,13 +9,14 @@ import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
||||
import { useRefetchAggregateQueries } from '@/object-record/hooks/useRefetchAggregateQueries';
|
||||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper';
|
||||
|
||||
const personId = 'a7286b9a-c039-4a89-9567-2dfa7953cda9';
|
||||
const input = { name: { firstName: 'John', lastName: 'Doe' } };
|
||||
const PERSON_ID = 'a7286b9a-c039-4a89-9567-2dfa7953cda9';
|
||||
|
||||
jest.mock('uuid', () => ({
|
||||
v4: jest.fn(() => personId),
|
||||
v4: jest.fn(() => 'a7286b9a-c039-4a89-9567-2dfa7953cda9'),
|
||||
}));
|
||||
|
||||
const input = { name: { firstName: 'John', lastName: 'Doe' } };
|
||||
|
||||
jest.mock('@/object-record/hooks/useRefetchAggregateQueries');
|
||||
const mockRefetchAggregateQueries = jest.fn();
|
||||
(useRefetchAggregateQueries as jest.Mock).mockReturnValue({
|
||||
@@ -26,11 +27,11 @@ const mocks = [
|
||||
{
|
||||
request: {
|
||||
query,
|
||||
variables: { input: { ...input, id: personId } },
|
||||
variables: { input: { ...input, id: PERSON_ID } },
|
||||
},
|
||||
result: jest.fn(() => ({
|
||||
data: {
|
||||
createPerson: { ...responseData, ...input, id: personId },
|
||||
createPerson: { ...responseData, ...input, id: PERSON_ID },
|
||||
},
|
||||
})),
|
||||
},
|
||||
@@ -58,7 +59,7 @@ describe('useCreateOneRecord', () => {
|
||||
await act(async () => {
|
||||
const res = await result.current.createOneRecord(input);
|
||||
expect(res).toBeDefined();
|
||||
expect(res).toHaveProperty('id', personId);
|
||||
expect(res).toHaveProperty('id', PERSON_ID);
|
||||
});
|
||||
|
||||
expect(mocks[0].result).toHaveBeenCalled();
|
||||
|
||||
+10
-12
@@ -1,15 +1,19 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { act } from 'react';
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
import { CoreObjectNameSingular } from 'twenty-shared/types';
|
||||
import { spreadsheetImportDialogState } from '@/spreadsheet-import/states/spreadsheetImportDialogState';
|
||||
|
||||
import { useOpenObjectRecordsSpreadsheetImportDialog } from '@/object-record/spreadsheet-import/hooks/useOpenObjectRecordsSpreadsheetImportDialog';
|
||||
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
|
||||
|
||||
import gql from 'graphql-tag';
|
||||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper';
|
||||
|
||||
const COMPANY_ID = 'cb2e9f4b-20c3-4759-9315-4ffeecfaf71a';
|
||||
|
||||
jest.mock('uuid', () => ({
|
||||
v4: jest.fn(() => 'cb2e9f4b-20c3-4759-9315-4ffeecfaf71a'),
|
||||
}));
|
||||
|
||||
const mockBatchCreateManyRecords = jest.fn().mockResolvedValue([]);
|
||||
|
||||
jest.mock('@/object-record/hooks/useBatchCreateManyRecords', () => ({
|
||||
@@ -18,17 +22,11 @@ jest.mock('@/object-record/hooks/useBatchCreateManyRecords', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
const companyId = 'cb2e9f4b-20c3-4759-9315-4ffeecfaf71a';
|
||||
|
||||
jest.mock('uuid', () => ({
|
||||
v4: jest.fn(() => companyId),
|
||||
}));
|
||||
|
||||
const mockResult = jest.fn(() => ({
|
||||
data: {
|
||||
createCompanies: [
|
||||
{
|
||||
id: companyId,
|
||||
id: COMPANY_ID,
|
||||
name: 'Example Company',
|
||||
employees: 0,
|
||||
idealCustomerProfile: true,
|
||||
@@ -137,7 +135,7 @@ describe('useOpenObjectRecordsSpreadsheetImportDialog', () => {
|
||||
const submitData = {
|
||||
validStructuredRows: [
|
||||
{
|
||||
id: companyId,
|
||||
id: COMPANY_ID,
|
||||
name: 'Example Company',
|
||||
idealCustomerProfile: true,
|
||||
employees: '0',
|
||||
@@ -146,7 +144,7 @@ describe('useOpenObjectRecordsSpreadsheetImportDialog', () => {
|
||||
invalidStructuredRows: [],
|
||||
allStructuredRows: [
|
||||
{
|
||||
id: companyId,
|
||||
id: COMPANY_ID,
|
||||
name: 'Example Company',
|
||||
__index: 'cbc3985f-dde9-46d1-bae2-c124141700ac',
|
||||
idealCustomerProfile: true,
|
||||
|
||||
Reference in New Issue
Block a user