8a7a19f312
## Summary Unifies test mocking tooling across Jest and Storybook, replaces handcrafted mock data with auto-generated server-fetched data, and restructures the mock data generation script for maintainability. ### Mock data generation - Split `generate-mock-data.ts` into three focused modules under `scripts/mock-data/`: - `utils.ts` — shared authentication, GraphQL client, and file writer - `generate-metadata.ts` — fetches object metadata from `/metadata` - `generate-record-data.ts` — fetches record data from `/graphql` using metadata-driven dynamic queries - The orchestrator (`generate-mock-data.ts`) authenticates once and passes the token to both generators - Company records are now fetched from the actual server (limited to 10 records) instead of being handcrafted - Generated files are organized under `generated/metadata/objects/` and `generated/data/companies/` ### Unified test utilities - Consolidated Jest and MSW mocking into shared utilities that compose production code (`prefillRecord`, `getRecordNodeFromRecord`, `getRecordConnectionFromRecords`) with mock metadata - Renamed `generateEmptyJestRecordNode` → `generateMockRecordNode` and moved to `testing/utils/` - Extracted `generateMockRecordConnection` into its own file - Removed `sanitizeInputForPrefill` workaround (no longer needed with correctly shaped generated data)
29 lines
1016 B
TypeScript
29 lines
1016 B
TypeScript
import { getRecordConnectionFromRecords } from '@/object-record/cache/utils/getRecordConnectionFromRecords';
|
|
import { generatedMockObjectMetadataItems } from '~/testing/utils/generatedMockObjectMetadataItems';
|
|
import { getMockObjectMetadataItemOrThrow } from '~/testing/utils/getMockObjectMetadataItemOrThrow';
|
|
import { generateMockRecord } from '~/testing/utils/generateMockRecordNode';
|
|
|
|
export const generateMockRecordConnection = ({
|
|
objectNameSingular,
|
|
records,
|
|
computeReferences = false,
|
|
}: {
|
|
objectNameSingular: string;
|
|
records: Record<string, unknown>[];
|
|
computeReferences?: boolean;
|
|
}) => {
|
|
const objectMetadataItem =
|
|
getMockObjectMetadataItemOrThrow(objectNameSingular);
|
|
|
|
const prefilledRecords = records.map((recordInput) =>
|
|
generateMockRecord({ objectNameSingular, input: recordInput }),
|
|
);
|
|
|
|
return getRecordConnectionFromRecords({
|
|
objectMetadataItems: generatedMockObjectMetadataItems,
|
|
objectMetadataItem,
|
|
records: prefilledRecords,
|
|
computeReferences,
|
|
});
|
|
};
|