Fix more tests 2 (#18293)
## Summary - Migrate more hand-written test mocks to auto-generated data from a real Twenty instance - Add generators for views, billing plans, API keys; extend record generator for workspace members, favorites, connected accounts, calendar events - Remove 9 hand-written mock files replaced by generated equivalents - Update 16 test/story files to use generated data - Fix WorkflowEditActionEmailBase story assertion to match configured recipient email ## Test plan - [x] Lint, typecheck, unit tests pass - [ ] Storybook tests pass in CI
This commit is contained in:
+186
-57
@@ -101,23 +101,31 @@ exports[`useDeleteOneRecord B. Starting from filled cache 1. Should handle succe
|
||||
exports[`useDeleteOneRecord B. Starting from filled cache 1. Should handle successfull record deletion 2`] = `
|
||||
{
|
||||
"__typename": "Company",
|
||||
"accountOwner": null,
|
||||
"accountOwner": {},
|
||||
"accountOwnerId": "20202020-1553-45c6-a028-5a9064cce07f",
|
||||
"address": {
|
||||
"__typename": "Address",
|
||||
"addressCity": "Dublin",
|
||||
"addressCountry": "Ireland",
|
||||
"addressCity": "Denver",
|
||||
"addressCountry": "",
|
||||
"addressLat": null,
|
||||
"addressLng": null,
|
||||
"addressPostcode": null,
|
||||
"addressState": null,
|
||||
"addressStreet1": "Eutaw Street",
|
||||
"addressStreet2": null,
|
||||
"addressPostcode": "",
|
||||
"addressState": "",
|
||||
"addressStreet1": "",
|
||||
"addressStreet2": "",
|
||||
},
|
||||
"createdAt": "2025-02-16T08:21:51.715Z",
|
||||
"annualRecurringRevenue": {
|
||||
"__typename": "Currency",
|
||||
"amountMicros": null,
|
||||
"currencyCode": null,
|
||||
},
|
||||
"attachments": [],
|
||||
"caredForPets": [],
|
||||
"createdAt": "2026-02-27T01:17:29.464Z",
|
||||
"createdBy": {
|
||||
"__typename": "Actor",
|
||||
"context": {},
|
||||
"name": "Tim Apple",
|
||||
"context": null,
|
||||
"name": "Tim A",
|
||||
"source": "MANUAL",
|
||||
"workspaceMemberId": "20202020-0687-4c41-b707-ed1bfca972a7",
|
||||
},
|
||||
@@ -125,28 +133,63 @@ exports[`useDeleteOneRecord B. Starting from filled cache 1. Should handle succe
|
||||
"domainName": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "https://linkedin.com",
|
||||
"primaryLinkUrl": "housecallpro.com",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"employees": null,
|
||||
"id": "20202020-3ec3-4fe3-8997-b76aa0bfa408",
|
||||
"linkedinLink": {
|
||||
"employees": 894,
|
||||
"favorites": [],
|
||||
"id": "20202020-a000-4485-94de-70c2a98daef2",
|
||||
"idealCustomerProfile": false,
|
||||
"introVideo": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"name": "Linkedin",
|
||||
"noteTargets": [],
|
||||
"opportunities": [
|
||||
"linkedinLink": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "https://linkedin.com/company/housecallpro",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"name": "Housecall Pro",
|
||||
"noteTargets": [
|
||||
{},
|
||||
],
|
||||
"opportunities": [],
|
||||
"people": [
|
||||
{},
|
||||
{},
|
||||
],
|
||||
"position": 1,
|
||||
"taskTargets": [],
|
||||
"position": 442,
|
||||
"previousEmployees": [],
|
||||
"tagline": "",
|
||||
"taskTargets": [
|
||||
{},
|
||||
],
|
||||
"timelineActivities": [
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
],
|
||||
"updatedAt": "2026-02-27T01:17:29.464Z",
|
||||
"updatedBy": {
|
||||
"__typename": "Actor",
|
||||
"context": null,
|
||||
"name": "Tim A",
|
||||
"source": "MANUAL",
|
||||
"workspaceMemberId": "20202020-0687-4c41-b707-ed1bfca972a7",
|
||||
},
|
||||
"visaSponsorship": false,
|
||||
"workPolicy": [],
|
||||
"xLink": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -243,23 +286,31 @@ exports[`useDeleteOneRecord B. Starting from filled cache 2. Should handle optim
|
||||
exports[`useDeleteOneRecord B. Starting from filled cache 2. Should handle optimistic cache on record deletion 2`] = `
|
||||
{
|
||||
"__typename": "Company",
|
||||
"accountOwner": null,
|
||||
"accountOwner": {},
|
||||
"accountOwnerId": "20202020-1553-45c6-a028-5a9064cce07f",
|
||||
"address": {
|
||||
"__typename": "Address",
|
||||
"addressCity": "Dublin",
|
||||
"addressCountry": "Ireland",
|
||||
"addressCity": "Denver",
|
||||
"addressCountry": "",
|
||||
"addressLat": null,
|
||||
"addressLng": null,
|
||||
"addressPostcode": null,
|
||||
"addressState": null,
|
||||
"addressStreet1": "Eutaw Street",
|
||||
"addressStreet2": null,
|
||||
"addressPostcode": "",
|
||||
"addressState": "",
|
||||
"addressStreet1": "",
|
||||
"addressStreet2": "",
|
||||
},
|
||||
"createdAt": "2025-02-16T08:21:51.715Z",
|
||||
"annualRecurringRevenue": {
|
||||
"__typename": "Currency",
|
||||
"amountMicros": null,
|
||||
"currencyCode": null,
|
||||
},
|
||||
"attachments": [],
|
||||
"caredForPets": [],
|
||||
"createdAt": "2026-02-27T01:17:29.464Z",
|
||||
"createdBy": {
|
||||
"__typename": "Actor",
|
||||
"context": {},
|
||||
"name": "Tim Apple",
|
||||
"context": null,
|
||||
"name": "Tim A",
|
||||
"source": "MANUAL",
|
||||
"workspaceMemberId": "20202020-0687-4c41-b707-ed1bfca972a7",
|
||||
},
|
||||
@@ -267,28 +318,63 @@ exports[`useDeleteOneRecord B. Starting from filled cache 2. Should handle optim
|
||||
"domainName": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "https://linkedin.com",
|
||||
"primaryLinkUrl": "housecallpro.com",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"employees": null,
|
||||
"id": "20202020-3ec3-4fe3-8997-b76aa0bfa408",
|
||||
"linkedinLink": {
|
||||
"employees": 894,
|
||||
"favorites": [],
|
||||
"id": "20202020-a000-4485-94de-70c2a98daef2",
|
||||
"idealCustomerProfile": false,
|
||||
"introVideo": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"name": "Linkedin",
|
||||
"noteTargets": [],
|
||||
"opportunities": [
|
||||
"linkedinLink": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "https://linkedin.com/company/housecallpro",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"name": "Housecall Pro",
|
||||
"noteTargets": [
|
||||
{},
|
||||
],
|
||||
"opportunities": [],
|
||||
"people": [
|
||||
{},
|
||||
{},
|
||||
],
|
||||
"position": 1,
|
||||
"taskTargets": [],
|
||||
"position": 442,
|
||||
"previousEmployees": [],
|
||||
"tagline": "",
|
||||
"taskTargets": [
|
||||
{},
|
||||
],
|
||||
"timelineActivities": [
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
],
|
||||
"updatedAt": "2026-02-27T01:17:29.464Z",
|
||||
"updatedBy": {
|
||||
"__typename": "Actor",
|
||||
"context": null,
|
||||
"name": "Tim A",
|
||||
"source": "MANUAL",
|
||||
"workspaceMemberId": "20202020-0687-4c41-b707-ed1bfca972a7",
|
||||
},
|
||||
"visaSponsorship": false,
|
||||
"workPolicy": [],
|
||||
"xLink": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -385,23 +471,31 @@ exports[`useDeleteOneRecord B. Starting from filled cache 3. Should handle optim
|
||||
exports[`useDeleteOneRecord B. Starting from filled cache 3. Should handle optimistic cache rollback on record deletion failure 2`] = `
|
||||
{
|
||||
"__typename": "Company",
|
||||
"accountOwner": null,
|
||||
"accountOwner": {},
|
||||
"accountOwnerId": "20202020-1553-45c6-a028-5a9064cce07f",
|
||||
"address": {
|
||||
"__typename": "Address",
|
||||
"addressCity": "Dublin",
|
||||
"addressCountry": "Ireland",
|
||||
"addressCity": "Denver",
|
||||
"addressCountry": "",
|
||||
"addressLat": null,
|
||||
"addressLng": null,
|
||||
"addressPostcode": null,
|
||||
"addressState": null,
|
||||
"addressStreet1": "Eutaw Street",
|
||||
"addressStreet2": null,
|
||||
"addressPostcode": "",
|
||||
"addressState": "",
|
||||
"addressStreet1": "",
|
||||
"addressStreet2": "",
|
||||
},
|
||||
"createdAt": "2025-02-16T08:21:51.715Z",
|
||||
"annualRecurringRevenue": {
|
||||
"__typename": "Currency",
|
||||
"amountMicros": null,
|
||||
"currencyCode": null,
|
||||
},
|
||||
"attachments": [],
|
||||
"caredForPets": [],
|
||||
"createdAt": "2026-02-27T01:17:29.464Z",
|
||||
"createdBy": {
|
||||
"__typename": "Actor",
|
||||
"context": {},
|
||||
"name": "Tim Apple",
|
||||
"context": null,
|
||||
"name": "Tim A",
|
||||
"source": "MANUAL",
|
||||
"workspaceMemberId": "20202020-0687-4c41-b707-ed1bfca972a7",
|
||||
},
|
||||
@@ -409,27 +503,62 @@ exports[`useDeleteOneRecord B. Starting from filled cache 3. Should handle optim
|
||||
"domainName": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "https://linkedin.com",
|
||||
"primaryLinkUrl": "housecallpro.com",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"employees": null,
|
||||
"id": "20202020-3ec3-4fe3-8997-b76aa0bfa408",
|
||||
"linkedinLink": {
|
||||
"employees": 894,
|
||||
"favorites": [],
|
||||
"id": "20202020-a000-4485-94de-70c2a98daef2",
|
||||
"idealCustomerProfile": false,
|
||||
"introVideo": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"name": "Linkedin",
|
||||
"noteTargets": [],
|
||||
"opportunities": [
|
||||
"linkedinLink": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "https://linkedin.com/company/housecallpro",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
"name": "Housecall Pro",
|
||||
"noteTargets": [
|
||||
{},
|
||||
],
|
||||
"opportunities": [],
|
||||
"people": [
|
||||
{},
|
||||
{},
|
||||
],
|
||||
"position": 1,
|
||||
"taskTargets": [],
|
||||
"position": 442,
|
||||
"previousEmployees": [],
|
||||
"tagline": "",
|
||||
"taskTargets": [
|
||||
{},
|
||||
],
|
||||
"timelineActivities": [
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
],
|
||||
"updatedAt": "2026-02-27T01:17:29.464Z",
|
||||
"updatedBy": {
|
||||
"__typename": "Actor",
|
||||
"context": null,
|
||||
"name": "Tim A",
|
||||
"source": "MANUAL",
|
||||
"workspaceMemberId": "20202020-0687-4c41-b707-ed1bfca972a7",
|
||||
},
|
||||
"visaSponsorship": false,
|
||||
"workPolicy": [],
|
||||
"xLink": {
|
||||
"__typename": "Links",
|
||||
"primaryLinkLabel": "",
|
||||
"primaryLinkUrl": "",
|
||||
"secondaryLinks": [],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
+9
-5
@@ -9,7 +9,7 @@ import { type MockedResponse } from '@apollo/client/testing';
|
||||
import { InMemoryTestingCacheInstance } from '~/testing/cache/inMemoryTestingCacheInstance';
|
||||
import { getJestMetadataAndApolloMocksWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksWrapper';
|
||||
import { getRecordFromRecordNode } from '@/object-record/cache/utils/getRecordFromRecordNode';
|
||||
import { allMockCompanyRecordsWithRelation } from '~/testing/mock-data/companiesWithRelations';
|
||||
import { mockedCompanyRecords } from '~/testing/mock-data/generated/data/companies/mock-companies-data';
|
||||
import { mockedPersonRecords } from '~/testing/mock-data/generated/data/people/mock-people-data';
|
||||
import { generatedMockObjectMetadataItems } from '~/testing/utils/generatedMockObjectMetadataItems';
|
||||
import { getMockObjectMetadataItemOrThrow } from '~/testing/utils/getMockObjectMetadataItemOrThrow';
|
||||
@@ -24,15 +24,19 @@ const flatPersonRecords = mockedPersonRecords.map((record) =>
|
||||
getRecordFromRecordNode({ recordNode: record }),
|
||||
);
|
||||
|
||||
const flatCompanyRecords = mockedCompanyRecords.map((record) =>
|
||||
getRecordFromRecordNode({ recordNode: record }),
|
||||
);
|
||||
|
||||
describe('useDeleteOneRecord', () => {
|
||||
const matchingCompanyId = allMockCompanyRecordsWithRelation[0].id;
|
||||
const matchingCompanyId = flatCompanyRecords[0].id;
|
||||
const personRecord = {
|
||||
...flatPersonRecords[0],
|
||||
deletedAt: null,
|
||||
companyId: matchingCompanyId,
|
||||
company: { ...allMockCompanyRecordsWithRelation[0] },
|
||||
company: { ...flatCompanyRecords[0] },
|
||||
};
|
||||
const relatedCompanyRecord = allMockCompanyRecordsWithRelation[0];
|
||||
const relatedCompanyRecord = flatCompanyRecords[0];
|
||||
const personObjectMetadataItem = getMockObjectMetadataItemOrThrow('person');
|
||||
const companyObjectMetadataItem = getMockObjectMetadataItemOrThrow('company');
|
||||
const objectMetadataItems = generatedMockObjectMetadataItems;
|
||||
@@ -199,7 +203,7 @@ describe('useDeleteOneRecord', () => {
|
||||
initialRecordsInCache: [
|
||||
{
|
||||
objectMetadataItem: companyObjectMetadataItem,
|
||||
records: allMockCompanyRecordsWithRelation,
|
||||
records: flatCompanyRecords,
|
||||
},
|
||||
{
|
||||
objectMetadataItem: personObjectMetadataItem,
|
||||
|
||||
+4
-2
@@ -26,7 +26,7 @@ import { ContextStoreDecorator } from '~/testing/decorators/ContextStoreDecorato
|
||||
import { IconsProviderDecorator } from '~/testing/decorators/IconsProviderDecorator';
|
||||
import { ObjectMetadataItemsDecorator } from '~/testing/decorators/ObjectMetadataItemsDecorator';
|
||||
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
|
||||
import { mockedCoreViewsData } from '~/testing/mock-data/views';
|
||||
import { mockedCoreViews } from '~/testing/mock-data/generated/metadata/views/mock-views-data';
|
||||
import { generatedMockObjectMetadataItems } from '~/testing/utils/generatedMockObjectMetadataItems';
|
||||
|
||||
const meta: Meta<typeof RecordCalendarMonth> = {
|
||||
@@ -46,7 +46,9 @@ const meta: Meta<typeof RecordCalendarMonth> = {
|
||||
|
||||
const setCoreViews = useSetAtomState(coreViewsState);
|
||||
|
||||
const mockCoreView = mockedCoreViewsData[0];
|
||||
const mockCoreView = mockedCoreViews.find(
|
||||
(v) => v.name === 'All Companies',
|
||||
)!;
|
||||
|
||||
const setContextStoreCurrentViewId = useSetAtomComponentState(
|
||||
contextStoreCurrentViewIdComponentState,
|
||||
|
||||
+4
-2
@@ -12,9 +12,11 @@ import { RecordTableDecorator } from '~/testing/decorators/RecordTableDecorator'
|
||||
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
|
||||
import { graphqlMocks } from '~/testing/graphqlMocks';
|
||||
import { mockedCompanyRecords } from '~/testing/mock-data/generated/data/companies/mock-companies-data';
|
||||
import { mockedViewsData } from '~/testing/mock-data/views';
|
||||
import { mockedCoreViews } from '~/testing/mock-data/generated/metadata/views/mock-views-data';
|
||||
import { sleep } from '~/utils/sleep';
|
||||
|
||||
const companyView = mockedCoreViews.find((v) => v.name === 'All Companies')!;
|
||||
|
||||
const meta: Meta = {
|
||||
title: 'Modules/ObjectRecord/RecordTable/RecordTable',
|
||||
component: RecordTableWithWrappers,
|
||||
@@ -28,7 +30,7 @@ const meta: Meta = {
|
||||
ObjectMetadataItemsDecorator,
|
||||
],
|
||||
args: {
|
||||
recordTableId: `companies-${mockedViewsData[0].id}`,
|
||||
recordTableId: `companies-${companyView.id}`,
|
||||
viewBarId: 'view-bar',
|
||||
objectNameSingular: 'company',
|
||||
},
|
||||
|
||||
+19
-1
@@ -1,14 +1,32 @@
|
||||
import { type CurrentWorkspaceMember } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { type ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { getRecordFromRecordNode } from '@/object-record/cache/utils/getRecordFromRecordNode';
|
||||
import { updateRecordFromCache } from '@/object-record/cache/utils/updateRecordFromCache';
|
||||
import { generateDepthRecordGqlFieldsFromRecord } from '@/object-record/graphql/record-gql-fields/utils/generateDepthRecordGqlFieldsFromRecord';
|
||||
import { type FieldActorForInputValue } from '@/object-record/record-field/ui/types/FieldMetadata';
|
||||
import { computeOptimisticRecordFromInput } from '@/object-record/utils/computeOptimisticRecordFromInput';
|
||||
import { type WorkspaceMember } from '@/workspace-member/types/WorkspaceMember';
|
||||
import { InMemoryCache } from '@apollo/client';
|
||||
import { mockCurrentWorkspaceMembers } from '~/testing/mock-data/workspace-members';
|
||||
import { mockedWorkspaceMemberRecords } from '~/testing/mock-data/generated/data/workspaceMembers/mock-workspaceMembers-data';
|
||||
import { generatedMockObjectMetadataItems } from '~/testing/utils/generatedMockObjectMetadataItems';
|
||||
import { getMockFieldMetadataItemOrThrow } from '~/testing/utils/getMockFieldMetadataItemOrThrow';
|
||||
import { getMockObjectMetadataItemOrThrow } from '~/testing/utils/getMockObjectMetadataItemOrThrow';
|
||||
|
||||
const mockCurrentWorkspaceMembers: CurrentWorkspaceMember[] =
|
||||
mockedWorkspaceMemberRecords.map((record) => {
|
||||
const workspaceMember = getRecordFromRecordNode<WorkspaceMember>({
|
||||
recordNode: record,
|
||||
});
|
||||
const {
|
||||
createdAt: _createdAt,
|
||||
updatedAt: _updatedAt,
|
||||
userId: _userId,
|
||||
__typename: _typename,
|
||||
...rest
|
||||
} = workspaceMember;
|
||||
return rest as CurrentWorkspaceMember;
|
||||
});
|
||||
|
||||
describe('computeOptimisticRecordFromInput', () => {
|
||||
const currentWorkspaceMember = mockCurrentWorkspaceMembers[0];
|
||||
const currentWorkspaceMemberFullname = `${currentWorkspaceMember.name.firstName} ${currentWorkspaceMember.name.lastName}`;
|
||||
|
||||
Reference in New Issue
Block a user