Skip to content

Fix more tests 2#18293

Merged
charlesBochet merged 8 commits intomainfrom
fix-more-tests-2
Feb 27, 2026
Merged

Fix more tests 2#18293
charlesBochet merged 8 commits intomainfrom
fix-more-tests-2

Conversation

@charlesBochet
Copy link
Copy Markdown
Member

@charlesBochet charlesBochet commented Feb 27, 2026

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

  • Lint, typecheck, unit tests pass
  • Storybook tests pass in CI

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 88 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 27, 2026

Greptile Summary

This PR systematically migrates the test infrastructure from manually maintained mock data to auto-generated mock data fetched from a real backend, improving maintainability and reducing drift between test data and production schemas.

Key Changes:

  • Added generation scripts for roles, views, API keys, and billing plans mock data
  • Replaced manual mock data files (people.ts, tasks.ts, views.ts, etc.) with auto-generated versions containing complete, realistic data structures
  • Introduced utility functions getMockObjectMetadataItemOrThrow and generateMockRecord for safer mock data access
  • Refactored generatedMockObjectMetadataItems to reuse existing utility functions instead of duplicating transformation logic
  • Updated 88 test and story files to use the new generated mock data with consistent import patterns
  • Added proper error handling for optional features (billing plans, API keys) in the generation script

Benefits:

  • Mock data now stays synchronized with backend schema changes through regeneration
  • Tests and stories use more realistic data with complete relation structures
  • Reduced code duplication in mock data generation
  • Better type safety with utility functions that throw on missing metadata items

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a well-structured test infrastructure refactoring with consistent patterns throughout
  • Score reflects systematic migration with no breaking changes to production code - only test/mock infrastructure updated. Changes follow consistent patterns, include proper error handling, use existing utility functions appropriately, and adhere to project coding standards. The 88 files changed represent a coordinated refactoring rather than ad-hoc changes.
  • No files require special attention. All changes follow the same migration pattern consistently.

Important Files Changed

Filename Overview
packages/twenty-front/scripts/generate-mock-data.ts Added imports and calls to generate roles, views, billing plans, and API keys with proper error handling for optional features
packages/twenty-front/scripts/mock-data/generate-roles.ts New script to fetch and generate roles mock data with comprehensive query including all role relations and permissions
packages/twenty-front/scripts/mock-data/generate-views.ts New script to fetch and generate core views mock data with nested relations like viewFields, viewFilters, and viewSorts
packages/twenty-front/src/testing/utils/generatedMockObjectMetadataItems.ts Refactored to use existing utility functions (mapPaginatedObjectMetadataItemsToObjectMetadataItems, enrichObjectMetadataItemsWithPermissions) instead of duplicating logic
packages/twenty-front/src/testing/graphqlMocks.ts Updated to use generated mock data imports, simplified views mock structure to use nested viewFields from generated data instead of separate filtering
packages/twenty-front/src/testing/utils/generateMockRecord.ts New utility function to generate mock records using prefillRecord and getMockObjectMetadataItemOrThrow
packages/twenty-front/src/testing/utils/getMockObjectMetadataItemOrThrow.ts New utility function to safely retrieve mock object metadata items by name with error handling
packages/twenty-front/src/modules/object-record/hooks/tests/useDeleteOneRecord.test.tsx Updated to use generated mock data and getMockObjectMetadataItemOrThrow, properly flattens record nodes before use
packages/twenty-front/src/modules/object-record/record-table/stories/RecordTable.stories.tsx Updated to use generated mock data, now finds company view dynamically instead of hardcoding index
packages/twenty-front/src/modules/settings/roles/role-assignment/components/stories/SettingsRoleAssignment.stories.tsx Updated to use generated roles mock data and added UserContext provider with date/time format configuration

Last reviewed commit: cf1a432

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

88 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copilot AI review requested due to automatic review settings February 27, 2026 21:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates hand-written test mock data files to auto-generated equivalents derived from a real Twenty instance. It removes the maintenance burden of manually kept mock data and ensures consistency with actual server responses.

Changes:

  • Removes 9 hand-written mock files (workspace-members.ts, views.ts, view-fields.ts, favorite.ts, connected-accounts.ts, companiesWithRelations.ts, calendar.ts, api-keys.ts, accounts.ts) and introduces new auto-generated files under src/testing/mock-data/generated/
  • Adds generator scripts for views, billing plans, API keys, workspace members, favorites, connected accounts, and calendar events
  • Updates 16 test/story files to consume the new generated mock data, and fixes the WorkflowEditActionEmailBase story assertion to match the new mock recipient email

Reviewed changes

Copilot reviewed 29 out of 37 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
workspace-members.ts Deleted; replaced by mock-workspaceMembers-data.ts
views.ts Deleted; replaced by mock-views-data.ts
view-fields.ts Deleted; view fields are now embedded in each view in mock-views-data.ts
favorite.ts Deleted; replaced by mock-favorites-data.ts
connected-accounts.ts Deleted; replaced by mock-connectedAccounts-data.ts
companiesWithRelations.ts Deleted; replaced by mock-companies-data.ts
calendar.ts Deleted; replaced by mock-calendarEvents-data.ts
api-keys.ts Deleted; replaced by mock-api-keys-data.ts
accounts.ts Deleted; replaced by mock-connectedAccounts-data.ts
mock-api-keys-data.ts New generated file with 1 API key
mock-favorites-data.ts New generated file with 10 favorite records
mock-favoriteFolders-data.ts New generated file (empty array)
mock-connectedAccounts-data.ts New generated file with 3 connected accounts
mock-calendarEvents-data.ts New generated file with 10 calendar events
mock-roles-data.ts Minor field-order change in last entry
graphqlMocks.ts Switches to generated data for views, workspace members, favorites, and API keys
RecordTableDecorator.tsx Uses generated mockedCoreViews instead of old mockedViewsData
ObjectMetadataItemsDecorator.tsx Uses generated workspace members for current workspace member
WorkflowEditActionEmailBase.stories.tsx Switches to generated connected accounts; fixes email assertion
useApplyCurrentViewSorts/Filters/FilterGroups.test.tsx Switch to generated views
ViewBarFilterDropdown.stories.tsx, RecordCalendarMonth.stories.tsx, RecordTable.stories.tsx Switch to generated views
useDeleteOneObjectMetadataItem.test.tsx, useDeleteOneRecord.test.tsx Switch to generated data
computeOptimisticRecordFromInput.test.ts, useActivityTargetObjectRecords.test.tsx Switch to generated workspace members
useDeleteOneRecord.test.tsx.snap Updated snapshots to match new generated company data
generate-views.ts, generate-billing-plans.ts, generate-api-keys.ts New generator scripts
generate-record-data.ts Adds new object types to generate
generate-mock-data.ts Registers new generators in the main script

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +55 to +56
connectedAccountId: mockedConnectedAccountRecords[0]
.accountOwnerId as string,
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The connectedAccountId field in CONFIGURED_SEND_EMAIL_ACTION is set to mockedConnectedAccountRecords[0].accountOwnerId, which is the workspace member's ID ("20202020-77d5-4cb6-b60a-f4a835a85d61"), not the connected account's own id ("20202020-0cc8-4d60-a3a4-803245698908"). The connectedAccountId field should reference the connected account record itself. The WorkflowEditActionEmailBase component uses connectedAccountId to match against account.id (see accounts.find((account) => account.id === formData.connectedAccountId)), so this mismatch means the "Configured" story will fail to find and display the selected account, making the story misleading. It should use mockedConnectedAccountRecords[0].id as string.

Suggested change
connectedAccountId: mockedConnectedAccountRecords[0]
.accountOwnerId as string,
connectedAccountId: mockedConnectedAccountRecords[0].id as string,

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:53445

This environment will automatically shut down when the PR is closed or after 5 hours.

@charlesBochet charlesBochet merged commit 9342b16 into main Feb 27, 2026
72 checks passed
@charlesBochet charlesBochet deleted the fix-more-tests-2 branch February 27, 2026 22:11
@twenty-eng-sync
Copy link
Copy Markdown

Hey @charlesBochet! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants