Introduce npx nx mock:generate twenty-front (#18237)

## Add codegen script for frontend test mock data

### Summary

- Adds a new `npx nx mock:generate twenty-front` and
`generate-mock-data.ts` script that fetches object metadata from a
running server's `/metadata` endpoint, authenticates with default seeds,
and writes the result to a generated TypeScript file
(`src/testing/mock-data/generated/mock-metadata-query-result.ts`). This
replaces hand-maintained mock metadata with server-sourced data,
ensuring tests always reflect the real schema.
- Updates all frontend tests to be compatible with the newly generated
metadata, fixing hard-coded GraphQL queries, Zod validation schemas,
snapshot expectations, and Apollo mock mismatches.

### What changed

**New files**
- `scripts/generate-mock-data.ts` — codegen script that authenticates
against the server, queries `/metadata` for all object metadata (with
explicit `__typename` at every level), and writes a typed `.ts` file.
- `project.json` — added `mock:generate` Nx target (`dotenv npx tsx
scripts/generate-mock-data.ts`).

**Schema validation updates**
- `objectMetadataItemSchema.ts` — added `universalIdentifier`, made
`duplicateCriteria` nullable.
- `fieldMetadataItemSchema.ts` — added `universalIdentifier`, `morphId`,
`morphRelations`, restructured relation schema.
- `indexMetadataItemSchema.ts` — added optional `isCustom` field.
This commit is contained in:
Charles Bochet
2026-02-25 21:40:05 +01:00
committed by GitHub
parent 50be97422d
commit e01b641a05
25 changed files with 24997 additions and 18246 deletions
@@ -21,18 +21,7 @@ const DEFAULT_ACTION = {
objectName: 'person',
objectRecordId: '',
objectRecord: {},
fieldsToUpdate: [
'updatedAt',
'averageEstimatedNumberOfAtomsInTheUniverse',
'comments',
'createdAt',
'deletedAt',
'name',
'participants',
'percentageOfCompletion',
'score',
'shortNotes',
],
fieldsToUpdate: ['city', 'emails', 'jobTitle', 'name', 'phones'],
},
outputSchema: {},
errorHandlingOptions: {
@@ -107,7 +96,7 @@ export const DisabledWithEmptyValues: Story = {
const firstSelectedUpdatableField = await within(
await canvas.findByTestId('workflow-fields-multi-select'),
).findByText('Creation date');
).findByText('City');
await userEvent.click(firstSelectedUpdatableField);
@@ -164,7 +153,7 @@ export const DisabledWithDefaultStaticValues: Story = {
const firstSelectedUpdatableField = await within(
await canvas.findByTestId('workflow-fields-multi-select'),
).findByText('Creation date');
).findByText('City');
await userEvent.click(firstSelectedUpdatableField);
@@ -215,7 +204,7 @@ export const DisabledWithDefaultVariableValues: Story = {
const firstSelectedUpdatableField = await within(
await canvas.findByTestId('workflow-fields-multi-select'),
).findByText('Creation date');
).findByText('City');
await userEvent.click(firstSelectedUpdatableField);