e01b641a05
## 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.
20 lines
732 B
TypeScript
20 lines
732 B
TypeScript
import { z } from 'zod';
|
|
|
|
import { type IndexMetadataItem } from '@/object-metadata/types/IndexMetadataItem';
|
|
import { indexFieldMetadataItemSchema } from '@/object-metadata/validation-schemas/indexFieldMetadataItemSchema';
|
|
import { IndexType } from '~/generated-metadata/graphql';
|
|
|
|
export const indexMetadataItemSchema = z.object({
|
|
__typename: z.literal('Index'),
|
|
id: z.uuid(),
|
|
name: z.string(),
|
|
indexFieldMetadatas: z.array(indexFieldMetadataItemSchema),
|
|
createdAt: z.string(),
|
|
updatedAt: z.string(),
|
|
indexType: z.enum(IndexType),
|
|
indexWhereClause: z.string().nullable(),
|
|
isUnique: z.boolean(),
|
|
isCustom: z.boolean().nullable().optional(),
|
|
objectMetadata: z.any(),
|
|
}) satisfies z.ZodType<IndexMetadataItem>;
|