From ccd11007730f5c78b3610c1f165a5cec35943a66 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Tue, 30 Apr 2024 17:54:07 +0200 Subject: [PATCH] Fix tests (#5228) Fixing typecheck + storybook:modules! --- .../__tests__/useCalendarEvents.test.tsx | 4 ++++ .../comment/__stories__/mock-comment.ts | 18 ++++++++++++++-- .../useMapToObjectRecordIdentifier.test.tsx | 1 + .../hooks/__tests__/useIsFieldEmpty.test.tsx | 1 + .../__stories__/ChipFieldDisplay.stories.tsx | 1 + .../__stories__/BooleanFieldInput.stories.tsx | 2 +- .../utils/isMatchingCurrencyFilter.spec.ts | 2 +- .../utils/isRecordMatchingFilter.spec.ts | 12 +++++------ .../SingleEntitySelect.stories.tsx | 2 +- ...attedAsObjectRecordForSelectArray.test.tsx | 4 ++++ .../utils/sortObjectRecordByDateField.test.ts | 16 ++++++++++---- ...gsAccountsEmailsBlocklistInput.stories.tsx | 1 + .../components/__stories__/mockedBlocklist.ts | 8 ++++++- .../getFieldPreviewValueFromRecord.test.ts | 21 +++++++++++++++---- 14 files changed, 73 insertions(+), 20 deletions(-) diff --git a/packages/twenty-front/src/modules/activities/calendar/hooks/__tests__/useCalendarEvents.test.tsx b/packages/twenty-front/src/modules/activities/calendar/hooks/__tests__/useCalendarEvents.test.tsx index 498cc5ff75..8abad356b6 100644 --- a/packages/twenty-front/src/modules/activities/calendar/hooks/__tests__/useCalendarEvents.test.tsx +++ b/packages/twenty-front/src/modules/activities/calendar/hooks/__tests__/useCalendarEvents.test.tsx @@ -10,6 +10,7 @@ const calendarEvents: CalendarEvent[] = [ isFullDay: false, startsAt: '2024-02-17T21:45:27.822Z', visibility: 'METADATA', + __typename: 'CalendarEvent', }, { id: '5678', @@ -17,6 +18,7 @@ const calendarEvents: CalendarEvent[] = [ isFullDay: false, startsAt: '2024-02-18T21:43:27.754Z', visibility: 'SHARE_EVERYTHING', + __typename: 'CalendarEvent', }, { id: '91011', @@ -24,6 +26,7 @@ const calendarEvents: CalendarEvent[] = [ isFullDay: true, startsAt: '2024-02-19T22:05:27.653Z', visibility: 'METADATA', + __typename: 'CalendarEvent', }, { id: '121314', @@ -31,6 +34,7 @@ const calendarEvents: CalendarEvent[] = [ isFullDay: true, startsAt: '2024-02-20T23:15:23.150Z', visibility: 'SHARE_EVERYTHING', + __typename: 'CalendarEvent', }, ]; diff --git a/packages/twenty-front/src/modules/activities/comment/__stories__/mock-comment.ts b/packages/twenty-front/src/modules/activities/comment/__stories__/mock-comment.ts index bc672c491c..b95cf72505 100644 --- a/packages/twenty-front/src/modules/activities/comment/__stories__/mock-comment.ts +++ b/packages/twenty-front/src/modules/activities/comment/__stories__/mock-comment.ts @@ -4,7 +4,13 @@ import { Comment } from '@/activities/types/Comment'; export const mockComment: Pick< Comment, - 'id' | 'author' | 'createdAt' | 'body' | 'updatedAt' | 'activityId' + | 'id' + | 'author' + | 'createdAt' + | 'body' + | 'updatedAt' + | 'activityId' + | '__typename' > = { id: 'fake_comment_1_uuid', body: 'Hello, this is a comment.', @@ -19,11 +25,18 @@ export const mockComment: Pick< createdAt: DateTime.fromFormat('2021-03-12', 'yyyy-MM-dd').toISO() ?? '', updatedAt: DateTime.fromFormat('2021-03-13', 'yyyy-MM-dd').toISO() ?? '', activityId: 'fake_activity_1_uuid', + __typename: 'Comment', }; export const mockCommentWithLongValues: Pick< Comment, - 'id' | 'author' | 'createdAt' | 'body' | 'updatedAt' | 'activityId' + | 'id' + | 'author' + | 'createdAt' + | 'body' + | 'updatedAt' + | 'activityId' + | '__typename' > = { id: 'fake_comment_2_uuid', body: 'Hello, this is a comment. Hello, this is a comment. Hello, this is a comment. Hello, this is a comment. Hello, this is a comment. Hello, this is a comment.', @@ -38,4 +51,5 @@ export const mockCommentWithLongValues: Pick< createdAt: DateTime.fromFormat('2021-03-12', 'yyyy-MM-dd').toISO() ?? '', updatedAt: DateTime.fromFormat('2021-03-13', 'yyyy-MM-dd').toISO() ?? '', activityId: 'fake_activity_1_uuid', + __typename: 'Comment', }; diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useMapToObjectRecordIdentifier.test.tsx b/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useMapToObjectRecordIdentifier.test.tsx index 17337fd905..d0157678c0 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useMapToObjectRecordIdentifier.test.tsx +++ b/packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useMapToObjectRecordIdentifier.test.tsx @@ -14,6 +14,7 @@ describe('useMapToObjectRecordIdentifier', () => { return mapToObjectRecordIdentifier({ id: 'id', name: { firstName: 'Sheldon', lastName: 'Cooper' }, + __typename: 'Person', }); }, { diff --git a/packages/twenty-front/src/modules/object-record/record-field/hooks/__tests__/useIsFieldEmpty.test.tsx b/packages/twenty-front/src/modules/object-record/record-field/hooks/__tests__/useIsFieldEmpty.test.tsx index 821891c843..1f0570f3e9 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/hooks/__tests__/useIsFieldEmpty.test.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/hooks/__tests__/useIsFieldEmpty.test.tsx @@ -45,6 +45,7 @@ describe('useIsFieldEmpty', () => { result.current.setFieldState({ id: 'id', phone: '+1 233223', + __typename: 'Person', }); }); diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx index 5a1d417bd0..f574700482 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/__stories__/ChipFieldDisplay.stories.tsx @@ -19,6 +19,7 @@ const ChipFieldValueSetterEffect = () => { firstName: 'Henry', lastName: 'Cavill', }, + __typename: 'Person', }); }, [setEntityFields]); diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/BooleanFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/BooleanFieldInput.stories.tsx index 87afe95c46..3edc386741 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/BooleanFieldInput.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/__stories__/BooleanFieldInput.stories.tsx @@ -22,7 +22,7 @@ const BooleanFieldValueSetterEffect = ({ const setField = useSetRecoilState(recordStoreFamilyState(entityId)); useEffect(() => { - setField({ id: entityId, Boolean: value }); + setField({ id: entityId, Boolean: value, __typename: 'Person' }); }, [entityId, setField, value]); return <>; diff --git a/packages/twenty-front/src/modules/object-record/record-filter/utils/isMatchingCurrencyFilter.spec.ts b/packages/twenty-front/src/modules/object-record/record-filter/utils/isMatchingCurrencyFilter.spec.ts index a4563f1e88..bee7fd8c08 100644 --- a/packages/twenty-front/src/modules/object-record/record-filter/utils/isMatchingCurrencyFilter.spec.ts +++ b/packages/twenty-front/src/modules/object-record/record-filter/utils/isMatchingCurrencyFilter.spec.ts @@ -1,4 +1,4 @@ -import { CurrencyFilter } from '@/object-record/record-filter/types/ObjectRecordQueryFilter'; +import { CurrencyFilter } from '@/object-record/graphql/types/RecordGqlOperationFilter'; import { isMatchingCurrencyFilter } from '@/object-record/record-filter/utils/isMatchingCurrencyFilter'; describe('isMatchingCurrencyFilter', () => { diff --git a/packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.spec.ts b/packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.spec.ts index bdfe17707d..c745fec8fe 100644 --- a/packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.spec.ts +++ b/packages/twenty-front/src/modules/object-record/record-filter/utils/isRecordMatchingFilter.spec.ts @@ -1,4 +1,4 @@ -import { ObjectRecordQueryFilter } from '@/object-record/record-filter/types/ObjectRecordQueryFilter'; +import { RecordGqlOperationFilter } from '@/object-record/graphql/types/RecordGqlOperationFilter'; import { mockedCompaniesData } from '~/testing/mock-data/companies'; import { mockObjectMetadataItem } from '~/testing/mock-data/objectMetadataItems'; @@ -161,7 +161,7 @@ describe('isRecordMatchingFilter', () => { describe('Complex And/Or/Not Nesting', () => { it('matches record with a combination of and + or filters', () => { - const filter: ObjectRecordQueryFilter = { + const filter: RecordGqlOperationFilter = { and: [ { domainName: { eq: 'airbnb.com' } }, { @@ -191,7 +191,7 @@ describe('isRecordMatchingFilter', () => { }); it('matches record with nested not filter', () => { - const filter: ObjectRecordQueryFilter = { + const filter: RecordGqlOperationFilter = { not: { and: [ { name: { eq: 'Airbnb' } }, @@ -218,7 +218,7 @@ describe('isRecordMatchingFilter', () => { }); it('matches record with deep nesting of and, or, and not filters', () => { - const filter: ObjectRecordQueryFilter = { + const filter: RecordGqlOperationFilter = { and: [ { domainName: { eq: 'apple.com' } }, { @@ -245,7 +245,7 @@ describe('isRecordMatchingFilter', () => { }); it('matches record with and filter at root level', () => { - const filter: ObjectRecordQueryFilter = { + const filter: RecordGqlOperationFilter = { and: [ { name: { eq: 'Facebook' } }, { idealCustomerProfile: { eq: true } }, @@ -270,7 +270,7 @@ describe('isRecordMatchingFilter', () => { }); it('matches record with or filter at root level including a not condition', () => { - const filter: ObjectRecordQueryFilter = { + const filter: RecordGqlOperationFilter = { or: [{ name: { eq: 'Sequoia' } }, { not: { employees: { eq: 1 } } }], }; diff --git a/packages/twenty-front/src/modules/object-record/relation-picker/components/__stories__/SingleEntitySelect.stories.tsx b/packages/twenty-front/src/modules/object-record/relation-picker/components/__stories__/SingleEntitySelect.stories.tsx index 24a9ca725c..0bb2497fbf 100644 --- a/packages/twenty-front/src/modules/object-record/relation-picker/components/__stories__/SingleEntitySelect.stories.tsx +++ b/packages/twenty-front/src/modules/object-record/relation-picker/components/__stories__/SingleEntitySelect.stories.tsx @@ -19,7 +19,7 @@ const entities = mockedPeopleData.map((person) => ({ name: person.name.firstName + ' ' + person.name.lastName, avatarUrl: person.avatarUrl, avatarType: 'rounded', - record: person, + record: { ...person, __typename: 'Person' }, })); const meta: Meta = { diff --git a/packages/twenty-front/src/modules/object-record/relation-picker/hooks/__tests__/useMultiObjectRecordsQueryResultFormattedAsObjectRecordForSelectArray.test.tsx b/packages/twenty-front/src/modules/object-record/relation-picker/hooks/__tests__/useMultiObjectRecordsQueryResultFormattedAsObjectRecordForSelectArray.test.tsx index decadcd2e5..9bd679cc47 100644 --- a/packages/twenty-front/src/modules/object-record/relation-picker/hooks/__tests__/useMultiObjectRecordsQueryResultFormattedAsObjectRecordForSelectArray.test.tsx +++ b/packages/twenty-front/src/modules/object-record/relation-picker/hooks/__tests__/useMultiObjectRecordsQueryResultFormattedAsObjectRecordForSelectArray.test.tsx @@ -36,8 +36,10 @@ describe('useMultiObjectRecordsQueryResultFormattedAsObjectRecordForSelectArray' 'e992bda7-d797-4e12-af04-9b427f42244c', updatedAt: '2023-11-30T11:13:15.308Z', createdAt: '2023-11-30T11:13:15.308Z', + __typename: 'Opportunity', }, cursor: 'cursor', + __typename: 'OpportunityEdge', }, ], pageInfo: {}, @@ -49,8 +51,10 @@ describe('useMultiObjectRecordsQueryResultFormattedAsObjectRecordForSelectArray' id: personId, updatedAt: '2023-11-30T11:13:15.308Z', createdAt: '2023-11-30T11:13:15.308Z', + __typename: 'Person', }, cursor: 'cursor', + __typename: 'PersonEdge', }, ], pageInfo: {}, diff --git a/packages/twenty-front/src/modules/object-record/utils/sortObjectRecordByDateField.test.ts b/packages/twenty-front/src/modules/object-record/utils/sortObjectRecordByDateField.test.ts index 46a03aae83..ac2999508a 100644 --- a/packages/twenty-front/src/modules/object-record/utils/sortObjectRecordByDateField.test.ts +++ b/packages/twenty-front/src/modules/object-record/utils/sortObjectRecordByDateField.test.ts @@ -3,10 +3,18 @@ import { OrderBy } from '@/object-metadata/types/OrderBy'; import { sortObjectRecordByDateField } from './sortObjectRecordByDateField'; describe('sortByObjectRecordByCreatedAt', () => { - const recordOldest = { id: '', createdAt: '2022-01-01T00:00:00.000Z' }; - const recordNewest = { id: '', createdAt: '2022-01-02T00:00:00.000Z' }; - const recordNull1 = { id: '', createdAt: null }; - const recordNull2 = { id: '', createdAt: null }; + const recordOldest = { + id: '', + createdAt: '2022-01-01T00:00:00.000Z', + __typename: 'RecordType', + }; + const recordNewest = { + id: '', + createdAt: '2022-01-02T00:00:00.000Z', + __typename: 'RecordType', + }; + const recordNull1 = { id: '', createdAt: null, __typename: 'RecordType' }; + const recordNull2 = { id: '', createdAt: null, __typename: 'RecordType' }; it('should sort in ascending order with null values first', () => { const sortDirection = 'AscNullsFirst' satisfies OrderBy; diff --git a/packages/twenty-front/src/modules/settings/accounts/components/__stories__/SettingsAccountsEmailsBlocklistInput.stories.tsx b/packages/twenty-front/src/modules/settings/accounts/components/__stories__/SettingsAccountsEmailsBlocklistInput.stories.tsx index b7feb02d16..3ceef7405d 100644 --- a/packages/twenty-front/src/modules/settings/accounts/components/__stories__/SettingsAccountsEmailsBlocklistInput.stories.tsx +++ b/packages/twenty-front/src/modules/settings/accounts/components/__stories__/SettingsAccountsEmailsBlocklistInput.stories.tsx @@ -20,6 +20,7 @@ const meta: Meta = { decorators: [ComponentDecorator, ClearMocksDecorator], args: { updateBlockedEmailList: updateBlockedEmailListJestFn, + blockedEmailOrDomainList: [], }, argTypes: { updateBlockedEmailList: { control: false }, diff --git a/packages/twenty-front/src/modules/settings/accounts/components/__stories__/mockedBlocklist.ts b/packages/twenty-front/src/modules/settings/accounts/components/__stories__/mockedBlocklist.ts index b6aef1c487..a03fa5207c 100644 --- a/packages/twenty-front/src/modules/settings/accounts/components/__stories__/mockedBlocklist.ts +++ b/packages/twenty-front/src/modules/settings/accounts/components/__stories__/mockedBlocklist.ts @@ -1,28 +1,34 @@ import { DateTime } from 'luxon'; -export const mockedBlocklist = [ +import { BlocklistItem } from '@/accounts/types/BlocklistItem'; + +export const mockedBlocklist: BlocklistItem[] = [ { id: '1', handle: 'test1@twenty.com', workspaceMemberId: '1', createdAt: DateTime.now().minus({ hours: 2 }).toISO() ?? '', + __typename: 'BlocklistItem', }, { id: '2', handle: 'test2@twenty.com', workspaceMemberId: '1', createdAt: DateTime.now().minus({ days: 2 }).toISO() ?? '', + __typename: 'BlocklistItem', }, { id: '3', handle: 'test3@twenty.com', workspaceMemberId: '1', createdAt: DateTime.now().minus({ days: 3 }).toISO() ?? '', + __typename: 'BlocklistItem', }, { id: '4', handle: '@twenty.com', workspaceMemberId: '1', createdAt: DateTime.now().minus({ days: 4 }).toISO() ?? '', + __typename: 'BlocklistItem', }, ]; diff --git a/packages/twenty-front/src/modules/settings/data-model/utils/__tests__/getFieldPreviewValueFromRecord.test.ts b/packages/twenty-front/src/modules/settings/data-model/utils/__tests__/getFieldPreviewValueFromRecord.test.ts index 7411d1bd87..ace5906578 100644 --- a/packages/twenty-front/src/modules/settings/data-model/utils/__tests__/getFieldPreviewValueFromRecord.test.ts +++ b/packages/twenty-front/src/modules/settings/data-model/utils/__tests__/getFieldPreviewValueFromRecord.test.ts @@ -12,7 +12,11 @@ describe('getFieldPreviewValueFromRecord', () => { describe('SELECT field', () => { it('returns the select option corresponding to the record field value', () => { // Given - const record: ObjectRecord = { id: '', stage: 'MEETING' }; + const record: ObjectRecord = { + id: '', + stage: 'MEETING', + __typename: 'Opportunity', + }; const fieldMetadataItem = mockedOpportunityObjectMetadataItem.fields.find( ({ name }) => name === 'stage', )!; @@ -32,7 +36,11 @@ describe('getFieldPreviewValueFromRecord', () => { it('returns undefined if the select option was not found', () => { // Given - const record: ObjectRecord = { id: '', industry: 'DOES_NOT_EXIST' }; + const record: ObjectRecord = { + id: '', + industry: 'DOES_NOT_EXIST', + __typename: 'Opportunity', + }; const fieldMetadataItem = mockedOpportunityObjectMetadataItem.fields.find( ({ name }) => name === 'stage', )!; @@ -63,6 +71,7 @@ describe('getFieldPreviewValueFromRecord', () => { people: { edges: [{ node: firstRelationRecord }, { node: { id: '2' } }], }, + __typename: 'Opportunity', }; const fieldMetadataItem = mockedCompanyObjectMetadataItem.fields.find( ({ name }) => name === 'people', @@ -81,7 +90,11 @@ describe('getFieldPreviewValueFromRecord', () => { it('returns the record field value ("to one" relation)', () => { // Given const relationRecord = { id: '20', name: 'Twenty' }; - const record = { id: '', company: relationRecord }; + const record = { + id: '', + company: relationRecord, + __typename: 'Opportunity', + }; const fieldMetadataItem = mockedPersonObjectMetadataItem.fields.find( ({ name }) => name === 'company', )!; @@ -100,7 +113,7 @@ describe('getFieldPreviewValueFromRecord', () => { describe('Other fields', () => { it('returns the record field value', () => { // Given - const record = { id: '', name: 'Twenty' }; + const record = { id: '', name: 'Twenty', __typename: 'Opportunity' }; const fieldMetadataItem = mockedCompanyObjectMetadataItem.fields.find( ({ name }) => name === 'name', )!;