test(frontend): use orval to generate MSW mocks DEV-2232#7219
test(frontend): use orval to generate MSW mocks DEV-2232#7219magicznyleszek wants to merge 89 commits into
Conversation
|
@greptile-apps review |
|
@greptile-apps review |
…x/kpi into leszek/dev-2232-orval-msw-gen
|
Too many files changed for review. ( Bypass the limit by tagging |
|
@copilot resolve the merge conflicts in this pull request |
…-msw-gen # Conflicts: # jsapp/js/api/react-query/survey-data/index.ts
Resolved the merge conflict in |
|
@copilot resolve the merge conflicts in this pull request |
…-msw-gen # Conflicts: # jsapp/js/components/submissions/DataTableWrapper.stories.tsx # orval.config.js
Resolved two merge conflicts:
|
🗒️ Checklist
#Support Docs Updates, if any<type>(<scope>)<!>: <title> DEV-1234Front endand/orBack endorworkflow📣 Summary
Migrates from manually maintained API mocks to Orval-generated ones for type-safe mocking in Storybook stories and tests. Ensures OpenAPI schema is the single source of truth for both API types and mock data.
💭 Notes
Changes in this branch are quite extensive. Unfortunatelly enabling mock generation through Orval spilled into type inconsistencies that needed to be addressed.
Orval MSW Integration
jsapp/js/api/models/jsapp/js/api/react-query/.mocks.tsfiles to use Orval-generated factories instead of manual mocksMock Generation Strategy
mode: 'tags-split'- Generates mocks in separate files to prevent bundling faker/msw (~600KB) in productionreact-query/module-name/index.ts(runtime) +react-query/module-name/msw.ts(mocks)from '#/api/react-query/module-name/msw'from '#/api/react-query/module-name'Post-Processing Scripts (6 scripts run after Orval generation)
orval-rename-to-index.js- Renamesmodule/module.ts→module/index.ts,module/module.msw.ts→module/msw.tsfor clean importsorval-fix-referenced-additional-properties.js- Fixes Orval bug with$refinadditionalProperties(issue #1077)orval-fix-mock-factory-type-assertions.js- Addsas TypeNamefor types with conflicting index signatures (updated for new file structure)orval-make-trailing-slash-optional.js- Makes trailing slashes optional in MSW URL patterns (Django REST Framework compatibility)orval-remove-mock-delays.js- Removesawait delay(1000)that slows down testsEnhanced OpenAPI Schema
{type: 'string', nullable: true}to{type: ['string', 'null']}for Orval compatibilityNULLABLE_STRING_SCHEMA,NULLABLE_ARRAY_SCHEMAto replace inline dict spreadsASSET_CONTENT_SCHEMAintoASSET_CONTENT_REQUEST_SCHEMA(string for PATCH) andASSET_CONTENT_RESPONSE_SCHEMA(object for GET)analysis_form_json,advanced_features,permissions,files)oneOfunions for supplemental data (handling 6 action types)Jest Configuration
unit.config.tsBroadcastChannelpolyfill for MSW in test environmentsetupUnitTest.tsto initialize MSW serverStorybook Migration
jsapp/js/components/submissions/DataTableWrapperPollingStoriesUtils.tsxas I wasn't able to make them work with the modified code and didn't want to spend too much time on thisObsolete Factories (replaced by Orval generation)
jsapp/js/endpoints/asset.factory.tsjsapp/js/endpoints/bulkAction.factory.tsjsapp/js/endpoints/formMedia.factory.tsjsapp/js/endpoints/assetHistoryLog.factory.tsjsapp/js/endpoints/assetHistoryActions.mocks.tsKept Factories (dynamic data that can't be generated)
assetData.factory.ts- Creates submission data with randomized valuesserviceUsage.factory.ts- Dynamic usage metricsorganizationServiceUsage.factory.ts- Dynamic organization metricsModule System Fix
orval.operationName.jsfrom ES modules to CommonJS (require/module.exports)ERR_REQUIRE_ESMerror whenorval.config.jsloads the custom operation name function.jsas CommonJS without"type": "module"in package.jsonTypeScript Type Cleanup
countryformat inassetUtils.tsandLibraryAssetForm.tsxArray.isArray()checks withas anycasts - backend standardization (Dec 2022) ensures array, but pre-migration assets may have single object/mswsuffix)FormLanguagesManager.tsx- content is now correctly typed as stringPython Linting Fixes
SURVEY_ROW_SCHEMA,SURVEY_CHOICE_SCHEMA--max-line-length=88Other changes
dataInterface.tstypes (mainlyAssetResponse) as some properties are now optional and some required👀 Preview steps
Ensure that: