diff --git a/jsapp/jest/setupUnitTest.ts b/jsapp/jest/setupUnitTest.ts index 2eef8a8d3e..2814c3963a 100644 --- a/jsapp/jest/setupUnitTest.ts +++ b/jsapp/jest/setupUnitTest.ts @@ -1,6 +1,7 @@ // Polyfill global fetch (for Node 20 and older) import 'whatwg-fetch' import { TextDecoder, TextEncoder } from 'util' +import { ReadableStream, TransformStream, WritableStream } from 'stream/web' import chai from 'chai' import $ from 'jquery' @@ -9,6 +10,34 @@ import $ from 'jquery' Object.defineProperty(globalThis, 'TextEncoder', { value: TextEncoder, configurable: true }) Object.defineProperty(globalThis, 'TextDecoder', { value: TextDecoder, configurable: true }) +// MSW now uses Web Streams for SSE/WebSocket internals. +// jsdom does not always expose these globals, so we provide them from Node. +// This prevents runtime errors like "WritableStream is not defined". +if (typeof globalThis.WritableStream === 'undefined') { + Object.defineProperty(globalThis, 'WritableStream', { value: WritableStream, configurable: true }) +} + +if (typeof globalThis.ReadableStream === 'undefined') { + Object.defineProperty(globalThis, 'ReadableStream', { value: ReadableStream, configurable: true }) +} + +if (typeof globalThis.TransformStream === 'undefined') { + Object.defineProperty(globalThis, 'TransformStream', { value: TransformStream, configurable: true }) +} + +// Some test environments miss BroadcastChannel. +// MSW expects it for WebSocket mocking, so this minimal fallback keeps tests stable. +if (typeof globalThis.BroadcastChannel === 'undefined') { + // @ts-expect-error: Minimal polyfill for test environment + globalThis.BroadcastChannel = class BroadcastChannel { + constructor(public name: string) {} + postMessage() {} + close() {} + addEventListener() {} + removeEventListener() {} + } +} + // Add global t() mock (see /static/js/global_t.js) global.t = (str: string) => str diff --git a/jsapp/jest/unit.config.ts b/jsapp/jest/unit.config.ts index f71421fca5..5ff676f9f1 100644 --- a/jsapp/jest/unit.config.ts +++ b/jsapp/jest/unit.config.ts @@ -27,11 +27,11 @@ const config: Config = { }, // Extensions to try in order (for import statements with no extension) - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'coffee'], + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'mjs', 'coffee'], // Transformers (SWC for JS/TS, CoffeeScript for .coffee) transform: { - '^.+\\.(js|jsx|ts|tsx)$': '@swc/jest', + '^.+\\.(mjs|js|jsx|ts|tsx)$': '@swc/jest', '^.+\\.coffee$': '/coffeeTransformer.js', }, @@ -41,6 +41,13 @@ const config: Config = { ...defaults.testPathIgnorePatterns, // 📦 exclude '/node_modules/' ], + // By default Jest skips transforming node_modules. + // These packages are explicitly allowlisted because they can publish ESM output, + // which otherwise causes parse errors like "unexpected token export/import" in tests. + transformIgnorePatterns: [ + 'node_modules/(?!(msw|@mswjs|@open-draft|@bundled-es-modules|headers-polyfill|outvariant|is-node-process|strict-event-emitter|statuses|until-async|rettime)/)', + ], + // Set up test environment testEnvironment: 'jsdom', diff --git a/jsapp/js/account/DeleteAccountBanner.stories.tsx b/jsapp/js/account/DeleteAccountBanner.stories.tsx index f06f16847f..f3ebf7bdf7 100644 --- a/jsapp/js/account/DeleteAccountBanner.stories.tsx +++ b/jsapp/js/account/DeleteAccountBanner.stories.tsx @@ -13,10 +13,7 @@ const meta: Meta = { argTypes: {}, parameters: { msw: { - handlers: { - organization: organizationMock(), - assets: assetsMock(), - }, + handlers: [organizationMock(), assetsMock()], }, a11y: { test: 'todo' }, }, @@ -61,9 +58,7 @@ export const UserHasAssets: Story = { export const UserHasNoAssets: Story = { parameters: { msw: { - handlers: { - assets: assetsMock({ count: 0 }), - }, + handlers: [organizationMock(), assetsMock({ count: 0 })], }, }, play: async ({ canvasElement }) => { @@ -80,9 +75,7 @@ export const UserHasNoAssets: Story = { export const UserOwnsMMO: Story = { parameters: { msw: { - handlers: { - organization: organizationMock({ is_mmo: true }), - }, + handlers: [organizationMock({ is_mmo: true }), assetsMock()], }, }, play: async ({ canvasElement }) => { diff --git a/jsapp/js/api/models/_dataResponseSupplementalDetails.ts b/jsapp/js/api/models/_dataResponseSupplementalDetails.ts index 413dc9c2ed..18ad181237 100644 --- a/jsapp/js/api/models/_dataResponseSupplementalDetails.ts +++ b/jsapp/js/api/models/_dataResponseSupplementalDetails.ts @@ -1,7 +1,3 @@ -import type { SupplementalDetailsAutomaticQual } from './supplementalDetailsAutomaticQual' -import type { SupplementalDetailsAutomaticTranscription } from './supplementalDetailsAutomaticTranscription' -import type { SupplementalDetailsAutomaticTranslation } from './supplementalDetailsAutomaticTranslation' -import type { SupplementalDetailsManualQual } from './supplementalDetailsManualQual' /** * Generated by orval v7.10.0 🍺 * Do not edit manually. @@ -13,18 +9,22 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ -import type { SupplementalDetailsManualTranscription } from './supplementalDetailsManualTranscription' -import type { SupplementalDetailsManualTranslation } from './supplementalDetailsManualTranslation' +import type { _DataResponseSupplementalDetailsOneOf } from './_dataResponseSupplementalDetailsOneOf' +import type { _DataResponseSupplementalDetailsOneOfFive } from './_dataResponseSupplementalDetailsOneOfFive' +import type { _DataResponseSupplementalDetailsOneOfFour } from './_dataResponseSupplementalDetailsOneOfFour' +import type { _DataResponseSupplementalDetailsOneOfSix } from './_dataResponseSupplementalDetailsOneOfSix' +import type { _DataResponseSupplementalDetailsOneOfThree } from './_dataResponseSupplementalDetailsOneOfThree' +import type { _DataResponseSupplementalDetailsOneOfTwo } from './_dataResponseSupplementalDetailsOneOfTwo' /** * Action-specific supplemental data attached to this submission. Structure varies by action type (transcription, translation, qual). Top-level keys are question XPaths, values are action objects. * @nullable */ export type _DataResponseSupplementalDetails = - | SupplementalDetailsManualTranscription - | SupplementalDetailsManualTranslation - | SupplementalDetailsAutomaticTranscription - | SupplementalDetailsAutomaticTranslation - | SupplementalDetailsManualQual - | SupplementalDetailsAutomaticQual + | _DataResponseSupplementalDetailsOneOf + | _DataResponseSupplementalDetailsOneOfTwo + | _DataResponseSupplementalDetailsOneOfThree + | _DataResponseSupplementalDetailsOneOfFour + | _DataResponseSupplementalDetailsOneOfFive + | _DataResponseSupplementalDetailsOneOfSix | null diff --git a/jsapp/js/api/models/supplementalDetailsManualTranscription.ts b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOf.ts similarity index 94% rename from jsapp/js/api/models/supplementalDetailsManualTranscription.ts rename to jsapp/js/api/models/_dataResponseSupplementalDetailsOneOf.ts index 232bc81bcf..186d3df07f 100644 --- a/jsapp/js/api/models/supplementalDetailsManualTranscription.ts +++ b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOf.ts @@ -14,7 +14,7 @@ import type { SupplementalDataManualTranscription } from './supplementalDataManu /** * Manual transcription supplemental details */ -export interface SupplementalDetailsManualTranscription { +export type _DataResponseSupplementalDetailsOneOf = { [key: string]: { manual_transcription: SupplementalDataManualTranscription } diff --git a/jsapp/js/api/models/supplementalDetailsManualQual.ts b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfFive.ts similarity index 94% rename from jsapp/js/api/models/supplementalDetailsManualQual.ts rename to jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfFive.ts index 23db7e10da..74a7615b53 100644 --- a/jsapp/js/api/models/supplementalDetailsManualQual.ts +++ b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfFive.ts @@ -14,7 +14,7 @@ import type { SupplementalDataManualQual } from './supplementalDataManualQual' /** * Manual qualitative supplemental details */ -export interface SupplementalDetailsManualQual { +export type _DataResponseSupplementalDetailsOneOfFive = { [key: string]: { manual_qual: SupplementalDataManualQual } diff --git a/jsapp/js/api/models/supplementalDetailsAutomaticTranslation.ts b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfFour.ts similarity index 94% rename from jsapp/js/api/models/supplementalDetailsAutomaticTranslation.ts rename to jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfFour.ts index 674af6ea2b..62bfef30b7 100644 --- a/jsapp/js/api/models/supplementalDetailsAutomaticTranslation.ts +++ b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfFour.ts @@ -14,7 +14,7 @@ import type { SupplementalDataAutomaticTranslation } from './supplementalDataAut /** * Automatic translation supplemental details */ -export interface SupplementalDetailsAutomaticTranslation { +export type _DataResponseSupplementalDetailsOneOfFour = { [key: string]: { automatic_google_translation: SupplementalDataAutomaticTranslation } diff --git a/jsapp/js/api/models/supplementalDetailsAutomaticQual.ts b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfSix.ts similarity index 94% rename from jsapp/js/api/models/supplementalDetailsAutomaticQual.ts rename to jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfSix.ts index 8d384cbf6f..f00733571f 100644 --- a/jsapp/js/api/models/supplementalDetailsAutomaticQual.ts +++ b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfSix.ts @@ -14,7 +14,7 @@ import type { SupplementalDataAutomaticQual } from './supplementalDataAutomaticQ /** * Automatic qualitative supplemental details */ -export interface SupplementalDetailsAutomaticQual { +export type _DataResponseSupplementalDetailsOneOfSix = { [key: string]: { automatic_bedrock_qual: SupplementalDataAutomaticQual } diff --git a/jsapp/js/api/models/supplementalDetailsAutomaticTranscription.ts b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfThree.ts similarity index 94% rename from jsapp/js/api/models/supplementalDetailsAutomaticTranscription.ts rename to jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfThree.ts index a4ecc60813..1396668554 100644 --- a/jsapp/js/api/models/supplementalDetailsAutomaticTranscription.ts +++ b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfThree.ts @@ -14,7 +14,7 @@ import type { SupplementalDataAutomaticTranscription } from './supplementalDataA /** * Automatic transcription supplemental details */ -export interface SupplementalDetailsAutomaticTranscription { +export type _DataResponseSupplementalDetailsOneOfThree = { [key: string]: { automatic_google_transcription: SupplementalDataAutomaticTranscription } diff --git a/jsapp/js/api/models/supplementalDetailsManualTranslation.ts b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfTwo.ts similarity index 94% rename from jsapp/js/api/models/supplementalDetailsManualTranslation.ts rename to jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfTwo.ts index fe2b39d204..99273df07c 100644 --- a/jsapp/js/api/models/supplementalDetailsManualTranslation.ts +++ b/jsapp/js/api/models/_dataResponseSupplementalDetailsOneOfTwo.ts @@ -14,7 +14,7 @@ import type { SupplementalDataManualTranslation } from './supplementalDataManual /** * Manual translation supplemental details */ -export interface SupplementalDetailsManualTranslation { +export type _DataResponseSupplementalDetailsOneOfTwo = { [key: string]: { manual_translation: SupplementalDataManualTranslation } diff --git a/jsapp/js/api/models/asset.ts b/jsapp/js/api/models/asset.ts index fc1e7ad0c1..4abf6d9b5b 100644 --- a/jsapp/js/api/models/asset.ts +++ b/jsapp/js/api/models/asset.ts @@ -1,3 +1,4 @@ +import type { AssetAccessTypes } from './assetAccessTypes' import type { AssetAdvancedFeatures } from './assetAdvancedFeatures' import type { AssetAnalysisFormJson } from './assetAnalysisFormJson' import type { AssetAssignablePermissionsItem } from './assetAssignablePermissionsItem' @@ -12,8 +13,10 @@ import type { AssetDownloadsItem } from './assetDownloadsItem' import type { AssetEffectivePermissionsItem } from './assetEffectivePermissionsItem' import type { AssetEmbedsItem } from './assetEmbedsItem' import type { AssetExportSettings } from './assetExportSettings' +import type { AssetFilesItem } from './assetFilesItem' import type { AssetMapCustom } from './assetMapCustom' import type { AssetMapStyles } from './assetMapStyles' +import type { AssetPermissionsItem } from './assetPermissionsItem' import type { AssetProjectOwnership } from './assetProjectOwnership' import type { AssetReportCustom } from './assetReportCustom' import type { AssetReportStyles } from './assetReportStyles' @@ -41,25 +44,30 @@ export interface Asset { parent?: string | null settings?: AssetSettings asset_type: AssetTypeEnum - readonly files: readonly string[] + readonly files: readonly AssetFilesItem[] readonly summary: AssetSummary date_created?: string date_modified?: string /** @nullable */ date_deployed?: string | null - readonly version_id: string - readonly version__content_hash: string + /** @nullable */ + readonly version_id: string | null + /** @nullable */ + readonly version__content_hash: string | null readonly version_count: number readonly has_deployment: boolean - readonly deployed_version_id: string + /** @nullable */ + readonly deployed_version_id: string | null readonly deployed_versions: AssetDeployedVersions readonly deployment__links: AssetDeploymentLinks readonly deployment__active: boolean readonly deployment__data_download_links: AssetDeploymentDataDownloadLinks readonly deployment__submission_count: number - readonly deployment__last_submission_time: string + /** @nullable */ + readonly deployment__last_submission_time: string | null readonly deployment__encrypted: boolean - readonly deployment__uuid: string + /** @nullable */ + readonly deployment__uuid: string | null readonly deployment_status: AssetDeploymentStatusEnum report_styles?: AssetReportStyles report_custom?: AssetReportCustom @@ -79,7 +87,7 @@ export interface Asset { /** @maxLength 255 */ name?: string readonly assignable_permissions: readonly AssetAssignablePermissionsItem[] - readonly permissions: readonly string[] + readonly permissions: readonly AssetPermissionsItem[] readonly effective_permissions: readonly AssetEffectivePermissionsItem[] readonly exports: string readonly export_settings: readonly AssetExportSettings[] @@ -87,7 +95,8 @@ export interface Asset { readonly children: AssetChildren readonly subscribers_count: number readonly status: string - readonly access_types: readonly string[] + /** @nullable */ + readonly access_types: AssetAccessTypes data_sharing?: AssetDataSharing readonly paired_data: string /** @nullable */ diff --git a/jsapp/js/api/models/assetAccessTypes.ts b/jsapp/js/api/models/assetAccessTypes.ts new file mode 100644 index 0000000000..34b3823507 --- /dev/null +++ b/jsapp/js/api/models/assetAccessTypes.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetAccessTypes = readonly string[] | null | null | null diff --git a/jsapp/js/api/models/assetAdvancedFeatures.ts b/jsapp/js/api/models/assetAdvancedFeatures.ts index 406729372c..4273cbf894 100644 --- a/jsapp/js/api/models/assetAdvancedFeatures.ts +++ b/jsapp/js/api/models/assetAdvancedFeatures.ts @@ -1,3 +1,4 @@ +import type { AssetAdvancedFeaturesQual } from './assetAdvancedFeaturesQual' /** * Generated by orval v7.10.0 🍺 * Do not edit manually. @@ -9,5 +10,12 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { AssetAdvancedFeaturesTranscript } from './assetAdvancedFeaturesTranscript' +import type { AssetAdvancedFeaturesTranslation } from './assetAdvancedFeaturesTranslation' -export type AssetAdvancedFeatures = { [key: string]: unknown } +export type AssetAdvancedFeatures = { + transcript?: AssetAdvancedFeaturesTranscript + translation?: AssetAdvancedFeaturesTranslation + qual?: AssetAdvancedFeaturesQual + _version?: string +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesQual.ts b/jsapp/js/api/models/assetAdvancedFeaturesQual.ts new file mode 100644 index 0000000000..3df982412c --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesQual.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetAdvancedFeaturesQualQualSurveyItem } from './assetAdvancedFeaturesQualQualSurveyItem' + +export type AssetAdvancedFeaturesQual = { + qual_survey?: AssetAdvancedFeaturesQualQualSurveyItem[] +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItem.ts b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItem.ts new file mode 100644 index 0000000000..9b7d6e55b0 --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItem.ts @@ -0,0 +1,24 @@ +import type { AssetAdvancedFeaturesQualQualSurveyItemChoicesItem } from './assetAdvancedFeaturesQualQualSurveyItemChoicesItem' +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetAdvancedFeaturesQualQualSurveyItemLabels } from './assetAdvancedFeaturesQualQualSurveyItemLabels' +import type { AssetAdvancedFeaturesQualQualSurveyItemOptions } from './assetAdvancedFeaturesQualQualSurveyItemOptions' + +export type AssetAdvancedFeaturesQualQualSurveyItem = { + type: string + labels: AssetAdvancedFeaturesQualQualSurveyItemLabels + uuid?: string + options?: AssetAdvancedFeaturesQualQualSurveyItemOptions + xpath: string + scope: string + choices?: AssetAdvancedFeaturesQualQualSurveyItemChoicesItem[] +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItem.ts b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItem.ts new file mode 100644 index 0000000000..bd3de84f77 --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItem.ts @@ -0,0 +1,19 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetAdvancedFeaturesQualQualSurveyItemChoicesItemLabels } from './assetAdvancedFeaturesQualQualSurveyItemChoicesItemLabels' +import type { AssetAdvancedFeaturesQualQualSurveyItemChoicesItemOptions } from './assetAdvancedFeaturesQualQualSurveyItemChoicesItemOptions' + +export type AssetAdvancedFeaturesQualQualSurveyItemChoicesItem = { + labels: AssetAdvancedFeaturesQualQualSurveyItemChoicesItemLabels + uuid: string + options?: AssetAdvancedFeaturesQualQualSurveyItemChoicesItemOptions +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItemLabels.ts b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItemLabels.ts new file mode 100644 index 0000000000..e55ca56c53 --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItemLabels.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAdvancedFeaturesQualQualSurveyItemChoicesItemLabels = { + _default: string + [key: string]: string +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItemOptions.ts b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItemOptions.ts new file mode 100644 index 0000000000..34a7c8272b --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemChoicesItemOptions.ts @@ -0,0 +1,15 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAdvancedFeaturesQualQualSurveyItemChoicesItemOptions = { + deleted?: boolean +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemLabels.ts b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemLabels.ts new file mode 100644 index 0000000000..73fc2ba640 --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemLabels.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAdvancedFeaturesQualQualSurveyItemLabels = { + _default: string + [key: string]: string +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemOptions.ts b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemOptions.ts new file mode 100644 index 0000000000..3652ddf58c --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesQualQualSurveyItemOptions.ts @@ -0,0 +1,15 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAdvancedFeaturesQualQualSurveyItemOptions = { + deleted?: boolean +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesTranscript.ts b/jsapp/js/api/models/assetAdvancedFeaturesTranscript.ts new file mode 100644 index 0000000000..f2a64c6de4 --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesTranscript.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAdvancedFeaturesTranscript = { + values?: string[] + languages?: string[] +} diff --git a/jsapp/js/api/models/assetAdvancedFeaturesTranslation.ts b/jsapp/js/api/models/assetAdvancedFeaturesTranslation.ts new file mode 100644 index 0000000000..36e4a1a7b9 --- /dev/null +++ b/jsapp/js/api/models/assetAdvancedFeaturesTranslation.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAdvancedFeaturesTranslation = { + values?: string[] + languages?: string[] +} diff --git a/jsapp/js/api/models/assetAnalysisFormJson.ts b/jsapp/js/api/models/assetAnalysisFormJson.ts index 76a43bcf66..fbd4ed0b42 100644 --- a/jsapp/js/api/models/assetAnalysisFormJson.ts +++ b/jsapp/js/api/models/assetAnalysisFormJson.ts @@ -9,7 +9,8 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { AssetAnalysisFormJsonAdditionalFieldsItem } from './assetAnalysisFormJsonAdditionalFieldsItem' export type AssetAnalysisFormJson = { - readonly additional_fields?: string[] + readonly additional_fields: AssetAnalysisFormJsonAdditionalFieldsItem[] } diff --git a/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItem.ts b/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItem.ts new file mode 100644 index 0000000000..6f4bc4544f --- /dev/null +++ b/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItem.ts @@ -0,0 +1,23 @@ +import type { AssetAnalysisFormJsonAdditionalFieldsItemChoicesItem } from './assetAnalysisFormJsonAdditionalFieldsItemChoicesItem' +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetAnalysisFormJsonAdditionalFieldsItemType } from './assetAnalysisFormJsonAdditionalFieldsItemType' + +export type AssetAnalysisFormJsonAdditionalFieldsItem = { + language?: string + source: string + type: AssetAnalysisFormJsonAdditionalFieldsItemType + name: string + dtpath: string + label?: string + choices?: AssetAnalysisFormJsonAdditionalFieldsItemChoicesItem[] +} diff --git a/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemChoicesItem.ts b/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemChoicesItem.ts new file mode 100644 index 0000000000..923c1f4756 --- /dev/null +++ b/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemChoicesItem.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetAnalysisFormJsonAdditionalFieldsItemChoicesItemLabels } from './assetAnalysisFormJsonAdditionalFieldsItemChoicesItemLabels' + +export type AssetAnalysisFormJsonAdditionalFieldsItemChoicesItem = { + uuid: string + labels: AssetAnalysisFormJsonAdditionalFieldsItemChoicesItemLabels +} diff --git a/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemChoicesItemLabels.ts b/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemChoicesItemLabels.ts new file mode 100644 index 0000000000..8ff13f9b63 --- /dev/null +++ b/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemChoicesItemLabels.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAnalysisFormJsonAdditionalFieldsItemChoicesItemLabels = { + _default: string + [key: string]: string +} diff --git a/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemType.ts b/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemType.ts new file mode 100644 index 0000000000..35870b522a --- /dev/null +++ b/jsapp/js/api/models/assetAnalysisFormJsonAdditionalFieldsItemType.ts @@ -0,0 +1,29 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAnalysisFormJsonAdditionalFieldsItemType = + (typeof AssetAnalysisFormJsonAdditionalFieldsItemType)[keyof typeof AssetAnalysisFormJsonAdditionalFieldsItemType] + +// eslint-disable-next-line @typescript-eslint/no-redeclare +export const AssetAnalysisFormJsonAdditionalFieldsItemType = { + transcript: 'transcript', + translation: 'translation', + qualVerification: 'qualVerification', + qualSource: 'qualSource', + qualInteger: 'qualInteger', + qualTags: 'qualTags', + qualText: 'qualText', + qualNote: 'qualNote', + qualAutoKeywordCount: 'qualAutoKeywordCount', + qualSelectMultiple: 'qualSelectMultiple', + qualSelectOne: 'qualSelectOne', +} as const diff --git a/jsapp/js/api/models/assetAssignablePermissionsItem.ts b/jsapp/js/api/models/assetAssignablePermissionsItem.ts index 01a6b52e0f..9ccff97525 100644 --- a/jsapp/js/api/models/assetAssignablePermissionsItem.ts +++ b/jsapp/js/api/models/assetAssignablePermissionsItem.ts @@ -9,5 +9,9 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { AssetAssignablePermissionsItemLabel } from './assetAssignablePermissionsItemLabel' -export type AssetAssignablePermissionsItem = { [key: string]: unknown } +export type AssetAssignablePermissionsItem = { + url: string + label: AssetAssignablePermissionsItemLabel +} diff --git a/jsapp/js/api/models/assetAssignablePermissionsItemLabel.ts b/jsapp/js/api/models/assetAssignablePermissionsItemLabel.ts new file mode 100644 index 0000000000..f843695f62 --- /dev/null +++ b/jsapp/js/api/models/assetAssignablePermissionsItemLabel.ts @@ -0,0 +1,14 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetAssignablePermissionsItemLabelOneOf } from './assetAssignablePermissionsItemLabelOneOf' + +export type AssetAssignablePermissionsItemLabel = string | AssetAssignablePermissionsItemLabelOneOf diff --git a/jsapp/js/api/models/assetAssignablePermissionsItemLabelOneOf.ts b/jsapp/js/api/models/assetAssignablePermissionsItemLabelOneOf.ts new file mode 100644 index 0000000000..00822c2d6c --- /dev/null +++ b/jsapp/js/api/models/assetAssignablePermissionsItemLabelOneOf.ts @@ -0,0 +1,19 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetAssignablePermissionsItemLabelOneOf = { + default: string + view_submissions?: string + change_submissions?: string + delete_submissions?: string + validate_submissions?: string +} diff --git a/jsapp/js/api/models/assetContent.ts b/jsapp/js/api/models/assetContent.ts index aa0cb8c0a3..f78fb4e2d1 100644 --- a/jsapp/js/api/models/assetContent.ts +++ b/jsapp/js/api/models/assetContent.ts @@ -1,3 +1,5 @@ +import type { AssetContentChoicesItem } from './assetContentChoicesItem' +import type { AssetContentKoboLockingProfilesItem } from './assetContentKoboLockingProfilesItem' import type { AssetContentSettings } from './assetContentSettings' /** * Generated by orval v7.10.0 🍺 @@ -11,11 +13,17 @@ The endpoints are grouped by area of intended use. Each category contains relate * OpenAPI spec version: 2.0.0 (api_v2) */ import type { AssetContentSurveyItem } from './assetContentSurveyItem' +import type { AssetContentTranslations0 } from './assetContentTranslations0' +import type { AssetContentTranslationsItem } from './assetContentTranslationsItem' export type AssetContent = { schema?: string survey?: AssetContentSurveyItem[] + choices?: AssetContentChoicesItem[] settings?: AssetContentSettings translated?: string[] - translations?: string[] + translations?: AssetContentTranslationsItem[] + /** @nullable */ + translations_0?: AssetContentTranslations0 + 'kobo--locking-profiles'?: AssetContentKoboLockingProfilesItem[] } diff --git a/jsapp/js/api/models/assetContentChoicesItem.ts b/jsapp/js/api/models/assetContentChoicesItem.ts new file mode 100644 index 0000000000..3130a5a358 --- /dev/null +++ b/jsapp/js/api/models/assetContentChoicesItem.ts @@ -0,0 +1,23 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetContentChoicesItemLabelItem } from './assetContentChoicesItemLabelItem' + +export type AssetContentChoicesItem = { + $autovalue: string + $kuid: string + label?: AssetContentChoicesItemLabelItem[] + list_name: string + name: string + 'media::image'?: string[] + $autoname?: string + [key: string]: unknown +} diff --git a/jsapp/js/api/models/assetContentChoicesItemLabelItem.ts b/jsapp/js/api/models/assetContentChoicesItemLabelItem.ts new file mode 100644 index 0000000000..015ac4c6a4 --- /dev/null +++ b/jsapp/js/api/models/assetContentChoicesItemLabelItem.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetContentChoicesItemLabelItem = string | null | null | null diff --git a/jsapp/js/api/models/assetContentKoboLockingProfilesItem.ts b/jsapp/js/api/models/assetContentKoboLockingProfilesItem.ts new file mode 100644 index 0000000000..8aa4fe26f5 --- /dev/null +++ b/jsapp/js/api/models/assetContentKoboLockingProfilesItem.ts @@ -0,0 +1,13 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetContentKoboLockingProfilesItem = { [key: string]: unknown } diff --git a/jsapp/js/api/models/assetContentSettings.ts b/jsapp/js/api/models/assetContentSettings.ts index f20d3cc94a..962ee49463 100644 --- a/jsapp/js/api/models/assetContentSettings.ts +++ b/jsapp/js/api/models/assetContentSettings.ts @@ -9,5 +9,17 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { AssetContentSettingsDefaultLanguage } from './assetContentSettingsDefaultLanguage' -export type AssetContentSettings = { [key: string]: unknown } +export type AssetContentSettings = { + name?: string + version?: string + id_string?: string + style?: string + form_id?: string + title?: string + 'kobo--lock_all'?: boolean + 'kobo--locking-profile'?: string + /** @nullable */ + default_language?: AssetContentSettingsDefaultLanguage +} diff --git a/jsapp/js/api/models/assetContentSettingsDefaultLanguage.ts b/jsapp/js/api/models/assetContentSettingsDefaultLanguage.ts new file mode 100644 index 0000000000..20d6ed7d56 --- /dev/null +++ b/jsapp/js/api/models/assetContentSettingsDefaultLanguage.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetContentSettingsDefaultLanguage = string | null | null | null diff --git a/jsapp/js/api/models/assetContentSurveyItem.ts b/jsapp/js/api/models/assetContentSurveyItem.ts index be3661fe12..73fc1119a7 100644 --- a/jsapp/js/api/models/assetContentSurveyItem.ts +++ b/jsapp/js/api/models/assetContentSurveyItem.ts @@ -1,3 +1,4 @@ +import type { AssetContentSurveyItemHintItem } from './assetContentSurveyItemHintItem' /** * Generated by orval v7.10.0 🍺 * Do not edit manually. @@ -9,5 +10,27 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { AssetContentSurveyItemLabelItem } from './assetContentSurveyItemLabelItem' -export type AssetContentSurveyItem = { [key: string]: unknown } +export type AssetContentSurveyItem = { + $kuid: string + type: string + $xpath?: string + $autoname?: string + calculation?: string + label?: AssetContentSurveyItemLabelItem[] + hint?: AssetContentSurveyItemHintItem[] + name?: string + required?: boolean + appearance?: string + parameters?: string + 'kobo--matrix_list'?: string + 'kobo--rank-constraint-message'?: string + 'kobo--rank-items'?: string + 'kobo--score-choices'?: string + 'kobo--locking-profile'?: string + tags?: string[] + select_from_list_name?: string + 'body::accept'?: string + [key: string]: unknown +} diff --git a/jsapp/js/api/models/assetContentSurveyItemHintItem.ts b/jsapp/js/api/models/assetContentSurveyItemHintItem.ts new file mode 100644 index 0000000000..8c30359718 --- /dev/null +++ b/jsapp/js/api/models/assetContentSurveyItemHintItem.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetContentSurveyItemHintItem = string | null | null | null diff --git a/jsapp/js/api/models/assetContentSurveyItemLabelItem.ts b/jsapp/js/api/models/assetContentSurveyItemLabelItem.ts new file mode 100644 index 0000000000..dc26779d53 --- /dev/null +++ b/jsapp/js/api/models/assetContentSurveyItemLabelItem.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetContentSurveyItemLabelItem = string | null | null | null diff --git a/jsapp/js/api/models/assetContentTranslations0.ts b/jsapp/js/api/models/assetContentTranslations0.ts new file mode 100644 index 0000000000..028fc28057 --- /dev/null +++ b/jsapp/js/api/models/assetContentTranslations0.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetContentTranslations0 = string | null | null | null diff --git a/jsapp/js/api/models/assetContentTranslationsItem.ts b/jsapp/js/api/models/assetContentTranslationsItem.ts new file mode 100644 index 0000000000..9541097171 --- /dev/null +++ b/jsapp/js/api/models/assetContentTranslationsItem.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetContentTranslationsItem = string | null | null | null diff --git a/jsapp/js/api/models/assetDeployedVersions.ts b/jsapp/js/api/models/assetDeployedVersions.ts index 5d1c916e0c..3ce235a854 100644 --- a/jsapp/js/api/models/assetDeployedVersions.ts +++ b/jsapp/js/api/models/assetDeployedVersions.ts @@ -9,11 +9,15 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { AssetDeployedVersionsNext } from './assetDeployedVersionsNext' +import type { AssetDeployedVersionsPrevious } from './assetDeployedVersionsPrevious' import type { AssetDeployedVersionsResultsItem } from './assetDeployedVersionsResultsItem' export type AssetDeployedVersions = { - readonly count?: number - readonly next?: string - readonly previous?: string - readonly results?: AssetDeployedVersionsResultsItem[] + readonly count: number + /** @nullable */ + readonly next: AssetDeployedVersionsNext + /** @nullable */ + readonly previous: AssetDeployedVersionsPrevious + readonly results: AssetDeployedVersionsResultsItem[] } diff --git a/jsapp/js/api/models/assetDeployedVersionsNext.ts b/jsapp/js/api/models/assetDeployedVersionsNext.ts new file mode 100644 index 0000000000..ff579c1200 --- /dev/null +++ b/jsapp/js/api/models/assetDeployedVersionsNext.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetDeployedVersionsNext = string | null | null | null diff --git a/jsapp/js/api/models/assetDeployedVersionsPrevious.ts b/jsapp/js/api/models/assetDeployedVersionsPrevious.ts new file mode 100644 index 0000000000..a56d174732 --- /dev/null +++ b/jsapp/js/api/models/assetDeployedVersionsPrevious.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetDeployedVersionsPrevious = string | null | null | null diff --git a/jsapp/js/api/models/assetDeployedVersionsResultsItem.ts b/jsapp/js/api/models/assetDeployedVersionsResultsItem.ts index 45b00a1dcc..b163ad4928 100644 --- a/jsapp/js/api/models/assetDeployedVersionsResultsItem.ts +++ b/jsapp/js/api/models/assetDeployedVersionsResultsItem.ts @@ -11,9 +11,9 @@ The endpoints are grouped by area of intended use. Each category contains relate */ export type AssetDeployedVersionsResultsItem = { - uid?: string - url?: string - content_hash?: string - date_deployed?: string - date_modified?: string + uid: string + url: string + content_hash: string + date_deployed: string + date_modified: string } diff --git a/jsapp/js/api/models/assetDeploymentDataDownloadLinks.ts b/jsapp/js/api/models/assetDeploymentDataDownloadLinks.ts index 0fe0eab133..acda90fe4e 100644 --- a/jsapp/js/api/models/assetDeploymentDataDownloadLinks.ts +++ b/jsapp/js/api/models/assetDeploymentDataDownloadLinks.ts @@ -10,4 +10,13 @@ The endpoints are grouped by area of intended use. Each category contains relate * OpenAPI spec version: 2.0.0 (api_v2) */ -export type AssetDeploymentDataDownloadLinks = { [key: string]: unknown } +export type AssetDeploymentDataDownloadLinks = { + readonly csv_legacy: string + readonly csv: string + readonly geojson?: string + readonly kml_legacy: string + readonly spss_labels?: string + readonly xls_legacy: string + readonly xls: string + readonly zip_legacy: string +} diff --git a/jsapp/js/api/models/assetDownloadsItem.ts b/jsapp/js/api/models/assetDownloadsItem.ts index 77100ae7b7..39c13c364c 100644 --- a/jsapp/js/api/models/assetDownloadsItem.ts +++ b/jsapp/js/api/models/assetDownloadsItem.ts @@ -11,6 +11,6 @@ The endpoints are grouped by area of intended use. Each category contains relate */ export type AssetDownloadsItem = { - format?: string - url?: string + format: string + url: string } diff --git a/jsapp/js/api/models/assetEmbedsItem.ts b/jsapp/js/api/models/assetEmbedsItem.ts index 5d484d31f3..a5ecd96225 100644 --- a/jsapp/js/api/models/assetEmbedsItem.ts +++ b/jsapp/js/api/models/assetEmbedsItem.ts @@ -11,6 +11,6 @@ The endpoints are grouped by area of intended use. Each category contains relate */ export type AssetEmbedsItem = { - format?: string - url?: string + format: string + url: string } diff --git a/jsapp/js/api/models/assetFilesItem.ts b/jsapp/js/api/models/assetFilesItem.ts new file mode 100644 index 0000000000..e0ac38dd96 --- /dev/null +++ b/jsapp/js/api/models/assetFilesItem.ts @@ -0,0 +1,25 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetFilesItemMetadata } from './assetFilesItemMetadata' + +export type AssetFilesItem = { + uid?: string + url?: string + asset?: string + user?: string + user__username?: string + file_type?: string + description?: string + date_created?: string + content?: string + metadata?: AssetFilesItemMetadata +} diff --git a/jsapp/js/api/models/assetReportStylesSpecifiedEnd.ts b/jsapp/js/api/models/assetFilesItemMetadata.ts similarity index 92% rename from jsapp/js/api/models/assetReportStylesSpecifiedEnd.ts rename to jsapp/js/api/models/assetFilesItemMetadata.ts index d1e6f400f7..2216a8883e 100644 --- a/jsapp/js/api/models/assetReportStylesSpecifiedEnd.ts +++ b/jsapp/js/api/models/assetFilesItemMetadata.ts @@ -10,4 +10,4 @@ The endpoints are grouped by area of intended use. Each category contains relate * OpenAPI spec version: 2.0.0 (api_v2) */ -export type AssetReportStylesSpecifiedEnd = { [key: string]: unknown } +export type AssetFilesItemMetadata = { [key: string]: unknown } diff --git a/jsapp/js/api/models/assetMapStyles.ts b/jsapp/js/api/models/assetMapStyles.ts index 54acd7be83..19bf203fd0 100644 --- a/jsapp/js/api/models/assetMapStyles.ts +++ b/jsapp/js/api/models/assetMapStyles.ts @@ -10,4 +10,8 @@ The endpoints are grouped by area of intended use. Each category contains relate * OpenAPI spec version: 2.0.0 (api_v2) */ -export type AssetMapStyles = { [key: string]: unknown } +export type AssetMapStyles = { + colorSet?: string + querylimit?: string + selectedQuestion?: string +} diff --git a/jsapp/js/api/models/assetPermissionsItem.ts b/jsapp/js/api/models/assetPermissionsItem.ts new file mode 100644 index 0000000000..4a0fceb38a --- /dev/null +++ b/jsapp/js/api/models/assetPermissionsItem.ts @@ -0,0 +1,21 @@ +import type { AssetPermissionsItemLabel } from './assetPermissionsItemLabel' +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetPermissionsItemPartialPermissionsItem } from './assetPermissionsItemPartialPermissionsItem' + +export type AssetPermissionsItem = { + url: string + user: string + permission: string + partial_permissions?: AssetPermissionsItemPartialPermissionsItem[] + label?: AssetPermissionsItemLabel +} diff --git a/jsapp/js/api/models/assetPermissionsItemLabel.ts b/jsapp/js/api/models/assetPermissionsItemLabel.ts new file mode 100644 index 0000000000..b234b3475d --- /dev/null +++ b/jsapp/js/api/models/assetPermissionsItemLabel.ts @@ -0,0 +1,14 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetPermissionsItemLabelOneOf } from './assetPermissionsItemLabelOneOf' + +export type AssetPermissionsItemLabel = string | AssetPermissionsItemLabelOneOf diff --git a/jsapp/js/api/models/assetPermissionsItemLabelOneOf.ts b/jsapp/js/api/models/assetPermissionsItemLabelOneOf.ts new file mode 100644 index 0000000000..ac6acb2df6 --- /dev/null +++ b/jsapp/js/api/models/assetPermissionsItemLabelOneOf.ts @@ -0,0 +1,19 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetPermissionsItemLabelOneOf = { + default: string + view_submissions?: string + change_submissions?: string + delete_submissions?: string + validate_submissions?: string +} diff --git a/jsapp/js/api/models/assetPermissionsItemPartialPermissionsItem.ts b/jsapp/js/api/models/assetPermissionsItemPartialPermissionsItem.ts new file mode 100644 index 0000000000..3450be6b61 --- /dev/null +++ b/jsapp/js/api/models/assetPermissionsItemPartialPermissionsItem.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetPermissionsItemPartialPermissionsItemFiltersItem } from './assetPermissionsItemPartialPermissionsItemFiltersItem' + +export type AssetPermissionsItemPartialPermissionsItem = { + url?: string + filters?: AssetPermissionsItemPartialPermissionsItemFiltersItem[] +} diff --git a/jsapp/js/api/models/assetPermissionsItemPartialPermissionsItemFiltersItem.ts b/jsapp/js/api/models/assetPermissionsItemPartialPermissionsItemFiltersItem.ts new file mode 100644 index 0000000000..9de455bf45 --- /dev/null +++ b/jsapp/js/api/models/assetPermissionsItemPartialPermissionsItemFiltersItem.ts @@ -0,0 +1,13 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetPermissionsItemPartialPermissionsItemFiltersItem = { [key: string]: unknown } diff --git a/jsapp/js/api/models/assetReportStylesDefault.ts b/jsapp/js/api/models/assetReportStylesDefault.ts index 16ae5e258b..e8c71e69ab 100644 --- a/jsapp/js/api/models/assetReportStylesDefault.ts +++ b/jsapp/js/api/models/assetReportStylesDefault.ts @@ -10,4 +10,10 @@ The endpoints are grouped by area of intended use. Each category contains relate * OpenAPI spec version: 2.0.0 (api_v2) */ -export type AssetReportStylesDefault = { [key: string]: unknown } +export type AssetReportStylesDefault = { + groupDataBy?: string + report_type?: string + report_colors?: string[] + translationIndex?: number + graphWidth?: number +} diff --git a/jsapp/js/api/models/assetReportStylesKuidNames.ts b/jsapp/js/api/models/assetReportStylesKuidNames.ts index f62fcc3569..4f68fad558 100644 --- a/jsapp/js/api/models/assetReportStylesKuidNames.ts +++ b/jsapp/js/api/models/assetReportStylesKuidNames.ts @@ -10,7 +10,4 @@ The endpoints are grouped by area of intended use. Each category contains relate * OpenAPI spec version: 2.0.0 (api_v2) */ -export type AssetReportStylesKuidNames = { - end?: string - start?: string -} +export type AssetReportStylesKuidNames = { [key: string]: unknown } diff --git a/jsapp/js/api/models/assetReportStylesSpecified.ts b/jsapp/js/api/models/assetReportStylesSpecified.ts index 2cd19025fd..e42b98e877 100644 --- a/jsapp/js/api/models/assetReportStylesSpecified.ts +++ b/jsapp/js/api/models/assetReportStylesSpecified.ts @@ -9,10 +9,5 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ -import type { AssetReportStylesSpecifiedEnd } from './assetReportStylesSpecifiedEnd' -import type { AssetReportStylesSpecifiedStart } from './assetReportStylesSpecifiedStart' -export type AssetReportStylesSpecified = { - end?: AssetReportStylesSpecifiedEnd - start?: AssetReportStylesSpecifiedStart -} +export type AssetReportStylesSpecified = { [key: string]: unknown } diff --git a/jsapp/js/api/models/assetSettings.ts b/jsapp/js/api/models/assetSettings.ts index d30a59db9d..51368c40e1 100644 --- a/jsapp/js/api/models/assetSettings.ts +++ b/jsapp/js/api/models/assetSettings.ts @@ -1,3 +1,7 @@ +import type { AssetSettingsCollectsPii } from './assetSettingsCollectsPii' +import type { AssetSettingsCountry } from './assetSettingsCountry' +import type { AssetSettingsOperationalPurpose } from './assetSettingsOperationalPurpose' +import type { AssetSettingsOrganization } from './assetSettingsOrganization' /** * Generated by orval v7.10.0 🍺 * Do not edit manually. @@ -12,11 +16,16 @@ The endpoints are grouped by area of intended use. Each category contains relate import type { AssetSettingsSector } from './assetSettingsSector' export type AssetSettings = { + /** @nullable */ sector?: AssetSettingsSector - country?: string[] + /** @nullable */ + country?: AssetSettingsCountry description?: string - collects_pii?: string - organization?: string + /** @nullable */ + collects_pii?: AssetSettingsCollectsPii + /** @nullable */ + organization?: AssetSettingsOrganization country_codes?: string[] - operational_purpose?: string + /** @nullable */ + operational_purpose?: AssetSettingsOperationalPurpose } diff --git a/jsapp/js/api/models/assetSettingsCollectsPii.ts b/jsapp/js/api/models/assetSettingsCollectsPii.ts new file mode 100644 index 0000000000..5e712e58f9 --- /dev/null +++ b/jsapp/js/api/models/assetSettingsCollectsPii.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetSettingsCollectsPiiAnyOf } from './assetSettingsCollectsPiiAnyOf' + +/** + * @nullable + */ +export type AssetSettingsCollectsPii = AssetSettingsCollectsPiiAnyOf | null | null diff --git a/jsapp/js/api/models/assetSettingsCollectsPiiAnyOf.ts b/jsapp/js/api/models/assetSettingsCollectsPiiAnyOf.ts new file mode 100644 index 0000000000..3ce713fed6 --- /dev/null +++ b/jsapp/js/api/models/assetSettingsCollectsPiiAnyOf.ts @@ -0,0 +1,19 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetSettingsCollectsPiiAnyOf = { + label?: string + value?: string +} | null diff --git a/jsapp/js/api/models/assetSettingsCountry.ts b/jsapp/js/api/models/assetSettingsCountry.ts new file mode 100644 index 0000000000..4eb8ab5f12 --- /dev/null +++ b/jsapp/js/api/models/assetSettingsCountry.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetSettingsCountryAnyOfItem } from './assetSettingsCountryAnyOfItem' + +/** + * @nullable + */ +export type AssetSettingsCountry = AssetSettingsCountryAnyOfItem[] | null | null | null diff --git a/jsapp/js/api/models/assetSettingsCountryAnyOfItem.ts b/jsapp/js/api/models/assetSettingsCountryAnyOfItem.ts new file mode 100644 index 0000000000..8ef3145fe6 --- /dev/null +++ b/jsapp/js/api/models/assetSettingsCountryAnyOfItem.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetSettingsCountryAnyOfItem = { + label?: string + value?: string +} diff --git a/jsapp/js/api/models/assetSettingsOperationalPurpose.ts b/jsapp/js/api/models/assetSettingsOperationalPurpose.ts new file mode 100644 index 0000000000..20d4652b68 --- /dev/null +++ b/jsapp/js/api/models/assetSettingsOperationalPurpose.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetSettingsOperationalPurposeAnyOf } from './assetSettingsOperationalPurposeAnyOf' + +/** + * @nullable + */ +export type AssetSettingsOperationalPurpose = AssetSettingsOperationalPurposeAnyOf | null | null diff --git a/jsapp/js/api/models/assetSettingsOperationalPurposeAnyOf.ts b/jsapp/js/api/models/assetSettingsOperationalPurposeAnyOf.ts new file mode 100644 index 0000000000..1c5738ad12 --- /dev/null +++ b/jsapp/js/api/models/assetSettingsOperationalPurposeAnyOf.ts @@ -0,0 +1,19 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetSettingsOperationalPurposeAnyOf = { + label?: string + value?: string +} | null diff --git a/jsapp/js/api/models/assetSettingsOrganization.ts b/jsapp/js/api/models/assetSettingsOrganization.ts new file mode 100644 index 0000000000..61aa994758 --- /dev/null +++ b/jsapp/js/api/models/assetSettingsOrganization.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetSettingsOrganization = string | null | null | null diff --git a/jsapp/js/api/models/assetSettingsSector.ts b/jsapp/js/api/models/assetSettingsSector.ts index 367917e121..ad55f751f3 100644 --- a/jsapp/js/api/models/assetSettingsSector.ts +++ b/jsapp/js/api/models/assetSettingsSector.ts @@ -9,5 +9,9 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { AssetSettingsSectorAnyOf } from './assetSettingsSectorAnyOf' -export type AssetSettingsSector = { [key: string]: unknown } +/** + * @nullable + */ +export type AssetSettingsSector = AssetSettingsSectorAnyOf | null | null diff --git a/jsapp/js/api/models/assetSettingsSectorAnyOf.ts b/jsapp/js/api/models/assetSettingsSectorAnyOf.ts new file mode 100644 index 0000000000..5fd48282ad --- /dev/null +++ b/jsapp/js/api/models/assetSettingsSectorAnyOf.ts @@ -0,0 +1,19 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetSettingsSectorAnyOf = { + label?: string + value?: string +} | null diff --git a/jsapp/js/api/models/assetSummary.ts b/jsapp/js/api/models/assetSummary.ts index 4f9cca9d28..a14b200ab6 100644 --- a/jsapp/js/api/models/assetSummary.ts +++ b/jsapp/js/api/models/assetSummary.ts @@ -1,3 +1,4 @@ +import type { AssetSummaryDefaultTranslation } from './assetSummaryDefaultTranslation' /** * Generated by orval v7.10.0 🍺 * Do not edit manually. @@ -20,5 +21,7 @@ export type AssetSummary = { readonly languages?: string[] readonly row_count?: number readonly name_quality?: AssetSummaryNameQuality - readonly default_translation?: string + /** @nullable */ + readonly default_translation?: AssetSummaryDefaultTranslation + readonly naming_conflicts?: string[] } diff --git a/jsapp/js/api/models/assetSummaryDefaultTranslation.ts b/jsapp/js/api/models/assetSummaryDefaultTranslation.ts new file mode 100644 index 0000000000..944833cc83 --- /dev/null +++ b/jsapp/js/api/models/assetSummaryDefaultTranslation.ts @@ -0,0 +1,16 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +/** + * @nullable + */ +export type AssetSummaryDefaultTranslation = string | null | null | null diff --git a/jsapp/js/api/models/assetSummaryNameQuality.ts b/jsapp/js/api/models/assetSummaryNameQuality.ts index a0c8d6a869..65456cb8de 100644 --- a/jsapp/js/api/models/assetSummaryNameQuality.ts +++ b/jsapp/js/api/models/assetSummaryNameQuality.ts @@ -9,5 +9,12 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { AssetSummaryNameQualityFirsts } from './assetSummaryNameQualityFirsts' -export type AssetSummaryNameQuality = { [key: string]: unknown } +export type AssetSummaryNameQuality = { + ok?: number + bad?: number + good?: number + total?: number + firsts?: AssetSummaryNameQualityFirsts +} diff --git a/jsapp/js/api/models/assetSummaryNameQualityFirsts.ts b/jsapp/js/api/models/assetSummaryNameQualityFirsts.ts new file mode 100644 index 0000000000..7c15273f57 --- /dev/null +++ b/jsapp/js/api/models/assetSummaryNameQualityFirsts.ts @@ -0,0 +1,18 @@ +import type { AssetSummaryNameQualityFirstsBad } from './assetSummaryNameQualityFirstsBad' +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { AssetSummaryNameQualityFirstsOk } from './assetSummaryNameQualityFirstsOk' + +export type AssetSummaryNameQualityFirsts = { + ok?: AssetSummaryNameQualityFirstsOk + bad?: AssetSummaryNameQualityFirstsBad +} diff --git a/jsapp/js/api/models/assetSummaryNameQualityFirstsBad.ts b/jsapp/js/api/models/assetSummaryNameQualityFirstsBad.ts new file mode 100644 index 0000000000..8d81202383 --- /dev/null +++ b/jsapp/js/api/models/assetSummaryNameQualityFirstsBad.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetSummaryNameQualityFirstsBad = { + name?: string + index?: number + label?: string[] +} diff --git a/jsapp/js/api/models/assetSummaryNameQualityFirstsOk.ts b/jsapp/js/api/models/assetSummaryNameQualityFirstsOk.ts new file mode 100644 index 0000000000..760ffe1411 --- /dev/null +++ b/jsapp/js/api/models/assetSummaryNameQualityFirstsOk.ts @@ -0,0 +1,17 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type AssetSummaryNameQualityFirstsOk = { + name?: string + index?: number + label?: string[] +} diff --git a/jsapp/js/api/models/meListResponse.ts b/jsapp/js/api/models/meListResponse.ts index 542ca14907..9275b0d8bd 100644 --- a/jsapp/js/api/models/meListResponse.ts +++ b/jsapp/js/api/models/meListResponse.ts @@ -23,7 +23,8 @@ export interface MeListResponse { date_joined: string projects_url: string gravatar: string - last_login: string + /** @nullable */ + last_login: string | null extra_details: MeListResponseExtraDetails git_rev: MeListResponseGitRev social_accounts: MeListResponseSocialAccountsItem[] diff --git a/jsapp/js/api/models/meListResponseGitRev.ts b/jsapp/js/api/models/meListResponseGitRev.ts index 7583ddaf3b..8326c026e3 100644 --- a/jsapp/js/api/models/meListResponseGitRev.ts +++ b/jsapp/js/api/models/meListResponseGitRev.ts @@ -9,10 +9,6 @@ The endpoints are grouped by area of intended use. Each category contains relate **General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". * OpenAPI spec version: 2.0.0 (api_v2) */ +import type { MeListResponseGitRevOneOf } from './meListResponseGitRevOneOf' -export type MeListResponseGitRev = { - short?: string - long?: string - branch?: string - tag?: string -} +export type MeListResponseGitRev = boolean | MeListResponseGitRevOneOf diff --git a/jsapp/js/api/models/meListResponseGitRevOneOf.ts b/jsapp/js/api/models/meListResponseGitRevOneOf.ts new file mode 100644 index 0000000000..517c1ef2ec --- /dev/null +++ b/jsapp/js/api/models/meListResponseGitRevOneOf.ts @@ -0,0 +1,22 @@ +import type { MeListResponseGitRevOneOfBranch } from './meListResponseGitRevOneOfBranch' +import type { MeListResponseGitRevOneOfLong } from './meListResponseGitRevOneOfLong' +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import type { MeListResponseGitRevOneOfShort } from './meListResponseGitRevOneOfShort' +import type { MeListResponseGitRevOneOfTag } from './meListResponseGitRevOneOfTag' + +export type MeListResponseGitRevOneOf = { + short?: MeListResponseGitRevOneOfShort + long?: MeListResponseGitRevOneOfLong + branch?: MeListResponseGitRevOneOfBranch + tag?: MeListResponseGitRevOneOfTag +} diff --git a/jsapp/js/api/models/assetReportStylesSpecifiedStart.ts b/jsapp/js/api/models/meListResponseGitRevOneOfBranch.ts similarity index 91% rename from jsapp/js/api/models/assetReportStylesSpecifiedStart.ts rename to jsapp/js/api/models/meListResponseGitRevOneOfBranch.ts index 26c660f883..ee29e9b7a3 100644 --- a/jsapp/js/api/models/assetReportStylesSpecifiedStart.ts +++ b/jsapp/js/api/models/meListResponseGitRevOneOfBranch.ts @@ -10,4 +10,4 @@ The endpoints are grouped by area of intended use. Each category contains relate * OpenAPI spec version: 2.0.0 (api_v2) */ -export type AssetReportStylesSpecifiedStart = { [key: string]: unknown } +export type MeListResponseGitRevOneOfBranch = string | boolean diff --git a/jsapp/js/api/models/meListResponseGitRevOneOfLong.ts b/jsapp/js/api/models/meListResponseGitRevOneOfLong.ts new file mode 100644 index 0000000000..52197c475d --- /dev/null +++ b/jsapp/js/api/models/meListResponseGitRevOneOfLong.ts @@ -0,0 +1,13 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type MeListResponseGitRevOneOfLong = string | boolean diff --git a/jsapp/js/api/models/meListResponseGitRevOneOfShort.ts b/jsapp/js/api/models/meListResponseGitRevOneOfShort.ts new file mode 100644 index 0000000000..30e62492cc --- /dev/null +++ b/jsapp/js/api/models/meListResponseGitRevOneOfShort.ts @@ -0,0 +1,13 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type MeListResponseGitRevOneOfShort = string | boolean diff --git a/jsapp/js/api/models/meListResponseGitRevOneOfTag.ts b/jsapp/js/api/models/meListResponseGitRevOneOfTag.ts new file mode 100644 index 0000000000..a5a800f9c1 --- /dev/null +++ b/jsapp/js/api/models/meListResponseGitRevOneOfTag.ts @@ -0,0 +1,13 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ + +export type MeListResponseGitRevOneOfTag = string | boolean diff --git a/jsapp/js/api/orval.operationName.js b/jsapp/js/api/orval.operationName.js index 9dec97dcb8..a2c45a7e95 100644 --- a/jsapp/js/api/orval.operationName.js +++ b/jsapp/js/api/orval.operationName.js @@ -1,7 +1,7 @@ const { keyword } = require('esutils') /** - * Copied some orvel internals and modified one line in order to drop the annoying `ApiV2` prefix to everything. + * Copied some orval internals and modified one line in order to drop the annoying `ApiV2` prefix to everything. */ const unicodes = (s, prefix) => { @@ -109,7 +109,7 @@ const getOperationId = (operation, route, verb) => { ) } -module.exports = { - operationName: (operation, route, verb) => - sanitize(camel(getOperationId(operation, route, verb)), { es5keyword: true }), -} +const operationName = (operation, route, verb) => + sanitize(camel(getOperationId(operation, route, verb)), { es5keyword: true }) + +module.exports = { operationName } diff --git a/jsapp/js/api/react-query/authentication-allauth-headless.ts b/jsapp/js/api/react-query/authentication-allauth-headless/index.ts similarity index 98% rename from jsapp/js/api/react-query/authentication-allauth-headless.ts rename to jsapp/js/api/react-query/authentication-allauth-headless/index.ts index 23dc31edad..042476b18e 100644 --- a/jsapp/js/api/react-query/authentication-allauth-headless.ts +++ b/jsapp/js/api/react-query/authentication-allauth-headless/index.ts @@ -19,107 +19,107 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { AddAuthenticatorConflictResponse } from '../models/addAuthenticatorConflictResponse' +import type { AddAuthenticatorConflictResponse } from '../../models/addAuthenticatorConflictResponse' -import type { AuthenticatedByCodeResponse } from '../models/authenticatedByCodeResponse' +import type { AuthenticatedByCodeResponse } from '../../models/authenticatedByCodeResponse' -import type { AuthenticatedByPasswordAnd2FAResponse } from '../models/authenticatedByPasswordAnd2FAResponse' +import type { AuthenticatedByPasswordAnd2FAResponse } from '../../models/authenticatedByPasswordAnd2FAResponse' -import type { AuthenticatedByPasswordResponse } from '../models/authenticatedByPasswordResponse' +import type { AuthenticatedByPasswordResponse } from '../../models/authenticatedByPasswordResponse' -import type { AuthenticatedResponse } from '../models/authenticatedResponse' +import type { AuthenticatedResponse } from '../../models/authenticatedResponse' -import type { AuthenticationOrReauthenticationResponse } from '../models/authenticationOrReauthenticationResponse' +import type { AuthenticationOrReauthenticationResponse } from '../../models/authenticationOrReauthenticationResponse' -import type { AuthenticationResponse } from '../models/authenticationResponse' +import type { AuthenticationResponse } from '../../models/authenticationResponse' -import type { AuthenticatorsResponse } from '../models/authenticatorsResponse' +import type { AuthenticatorsResponse } from '../../models/authenticatorsResponse' -import type { ChangePasswordBody } from '../models/changePasswordBody' +import type { ChangePasswordBody } from '../../models/changePasswordBody' -import type { ConfigurationResponse } from '../models/configurationResponse' +import type { ConfigurationResponse } from '../../models/configurationResponse' -import type { ConfirmLoginCodeBody } from '../models/confirmLoginCodeBody' +import type { ConfirmLoginCodeBody } from '../../models/confirmLoginCodeBody' -import type { ConflictResponse } from '../models/conflictResponse' +import type { ConflictResponse } from '../../models/conflictResponse' -import type { EmailAddressesResponse } from '../models/emailAddressesResponse' +import type { EmailAddressesResponse } from '../../models/emailAddressesResponse' -import type { EmailBody } from '../models/emailBody' +import type { EmailBody } from '../../models/emailBody' -import type { EmailVerificationInfoResponse } from '../models/emailVerificationInfoResponse' +import type { EmailVerificationInfoResponse } from '../../models/emailVerificationInfoResponse' -import type { EndSessionsBody } from '../models/endSessionsBody' +import type { EndSessionsBody } from '../../models/endSessionsBody' -import type { ErrorResponse } from '../models/errorResponse' +import type { ErrorResponse } from '../../models/errorResponse' -import type { ForbiddenResponse } from '../models/forbiddenResponse' +import type { ForbiddenResponse } from '../../models/forbiddenResponse' -import type { LoginBody } from '../models/loginBody' +import type { LoginBody } from '../../models/loginBody' -import type { MFAAuthenticateBody } from '../models/mFAAuthenticateBody' +import type { MFAAuthenticateBody } from '../../models/mFAAuthenticateBody' -import type { MarkPrimaryEmailBody } from '../models/markPrimaryEmailBody' +import type { MarkPrimaryEmailBody } from '../../models/markPrimaryEmailBody' -import type { NotFoundResponse } from '../models/notFoundResponse' +import type { NotFoundResponse } from '../../models/notFoundResponse' -import type { PasswordResetInfoResponse } from '../models/passwordResetInfoResponse' +import type { PasswordResetInfoResponse } from '../../models/passwordResetInfoResponse' -import type { PhoneBody } from '../models/phoneBody' +import type { PhoneBody } from '../../models/phoneBody' -import type { PhoneNumberChangeResponse } from '../models/phoneNumberChangeResponse' +import type { PhoneNumberChangeResponse } from '../../models/phoneNumberChangeResponse' -import type { PhoneNumbersResponse } from '../models/phoneNumbersResponse' +import type { PhoneNumbersResponse } from '../../models/phoneNumbersResponse' -import type { ProviderAccountBody } from '../models/providerAccountBody' +import type { ProviderAccountBody } from '../../models/providerAccountBody' -import type { ProviderAccountsResponse } from '../models/providerAccountsResponse' +import type { ProviderAccountsResponse } from '../../models/providerAccountsResponse' -import type { ProviderRedirectBody } from '../models/providerRedirectBody' +import type { ProviderRedirectBody } from '../../models/providerRedirectBody' -import type { ProviderSignupBody } from '../models/providerSignupBody' +import type { ProviderSignupBody } from '../../models/providerSignupBody' -import type { ProviderSignupResponse } from '../models/providerSignupResponse' +import type { ProviderSignupResponse } from '../../models/providerSignupResponse' -import type { ProviderTokenBody } from '../models/providerTokenBody' +import type { ProviderTokenBody } from '../../models/providerTokenBody' -import type { ReauthenticateBody } from '../models/reauthenticateBody' +import type { ReauthenticateBody } from '../../models/reauthenticateBody' -import type { ReauthenticationRequiredResponse } from '../models/reauthenticationRequiredResponse' +import type { ReauthenticationRequiredResponse } from '../../models/reauthenticationRequiredResponse' -import type { RecoveryCodesResponse } from '../models/recoveryCodesResponse' +import type { RecoveryCodesResponse } from '../../models/recoveryCodesResponse' -import type { RefreshTokenBody } from '../models/refreshTokenBody' +import type { RefreshTokenBody } from '../../models/refreshTokenBody' -import type { RefreshTokenResponse } from '../models/refreshTokenResponse' +import type { RefreshTokenResponse } from '../../models/refreshTokenResponse' -import type { RequestPasswordBody } from '../models/requestPasswordBody' +import type { RequestPasswordBody } from '../../models/requestPasswordBody' -import type { ResetPasswordBody } from '../models/resetPasswordBody' +import type { ResetPasswordBody } from '../../models/resetPasswordBody' -import type { SessionGoneResponse } from '../models/sessionGoneResponse' +import type { SessionGoneResponse } from '../../models/sessionGoneResponse' -import type { SessionsResponse } from '../models/sessionsResponse' +import type { SessionsResponse } from '../../models/sessionsResponse' -import type { SetupTOTPBody } from '../models/setupTOTPBody' +import type { SetupTOTPBody } from '../../models/setupTOTPBody' -import type { SignupBody } from '../models/signupBody' +import type { SignupBody } from '../../models/signupBody' -import type { StatusOKResponse } from '../models/statusOKResponse' +import type { StatusOKResponse } from '../../models/statusOKResponse' -import type { TOTPAuthenticatorNotFoundResponse } from '../models/tOTPAuthenticatorNotFoundResponse' +import type { TOTPAuthenticatorNotFoundResponse } from '../../models/tOTPAuthenticatorNotFoundResponse' -import type { TOTPAuthenticatorResponse } from '../models/tOTPAuthenticatorResponse' +import type { TOTPAuthenticatorResponse } from '../../models/tOTPAuthenticatorResponse' -import type { TooManyRequestsResponse } from '../models/tooManyRequestsResponse' +import type { TooManyRequestsResponse } from '../../models/tooManyRequestsResponse' -import type { UnauthenticatedResponse } from '../models/unauthenticatedResponse' +import type { UnauthenticatedResponse } from '../../models/unauthenticatedResponse' -import type { VerifyEmailBody } from '../models/verifyEmailBody' +import type { VerifyEmailBody } from '../../models/verifyEmailBody' -import type { VerifyPhoneBody } from '../models/verifyPhoneBody' +import type { VerifyPhoneBody } from '../../models/verifyPhoneBody' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/authentication-allauth-headless/msw.ts b/jsapp/js/api/react-query/authentication-allauth-headless/msw.ts new file mode 100644 index 0000000000..1360bd115d --- /dev/null +++ b/jsapp/js/api/react-query/authentication-allauth-headless/msw.ts @@ -0,0 +1,4125 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { AuthenticatedByCodeResponse } from '../../models/authenticatedByCodeResponse' + +import type { AuthenticatedByPasswordAnd2FAResponse } from '../../models/authenticatedByPasswordAnd2FAResponse' + +import type { AuthenticatedByPasswordResponse } from '../../models/authenticatedByPasswordResponse' + +import type { AuthenticatedResponse } from '../../models/authenticatedResponse' + +import { AuthenticatorType } from '../../models/authenticatorType' + +import type { AuthenticatorsResponse } from '../../models/authenticatorsResponse' + +import type { ConfigurationResponse } from '../../models/configurationResponse' + +import type { EmailAddressesResponse } from '../../models/emailAddressesResponse' + +import type { EmailVerificationInfoResponse } from '../../models/emailVerificationInfoResponse' + +import type { PasswordResetInfoResponse } from '../../models/passwordResetInfoResponse' + +import type { PhoneNumberChangeResponse } from '../../models/phoneNumberChangeResponse' + +import type { PhoneNumbersResponse } from '../../models/phoneNumbersResponse' + +import type { ProviderAccountsResponse } from '../../models/providerAccountsResponse' + +import type { ProviderSignupResponse } from '../../models/providerSignupResponse' + +import type { RecoveryCodesAuthenticator } from '../../models/recoveryCodesAuthenticator' + +import type { RecoveryCodesResponse } from '../../models/recoveryCodesResponse' + +import type { RefreshTokenResponse } from '../../models/refreshTokenResponse' + +import type { SessionsResponse } from '../../models/sessionsResponse' + +import type { StatusOKResponse } from '../../models/statusOKResponse' + +import type { TOTPAuthenticator } from '../../models/tOTPAuthenticator' + +import type { TOTPAuthenticatorResponse } from '../../models/tOTPAuthenticatorResponse' + +import type { WebAuthnAuthenticator } from '../../models/webAuthnAuthenticator' + +export const getApiV2AllauthBrowserV1ConfigGetResponseMock = ( + overrideResponse: Partial = {}, +): ConfigurationResponse => ({ + data: { + account: { + login_methods: faker.helpers.arrayElement([ + faker.helpers.arrayElements(['email', 'username'] as const), + undefined, + ]), + is_open_for_signup: faker.datatype.boolean(), + email_verification_by_code_enabled: faker.datatype.boolean(), + login_by_code_enabled: faker.datatype.boolean(), + password_reset_by_code_enabled: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + socialaccount: faker.helpers.arrayElement([ + { + providers: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + openid_configuration_url: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + flows: faker.helpers.arrayElements(['provider_redirect', 'provider_token'] as const), + })), + }, + undefined, + ]), + mfa: faker.helpers.arrayElement([ + { supported_types: faker.helpers.arrayElements(Object.values(AuthenticatorType)) }, + undefined, + ]), + usersessions: faker.helpers.arrayElement([{ track_activity: faker.datatype.boolean() }, undefined]), + }, + status: faker.helpers.arrayElement([200] as const), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1ConfigGetResponseMock = ( + overrideResponse: Partial = {}, +): ConfigurationResponse => ({ + data: { + account: { + login_methods: faker.helpers.arrayElement([ + faker.helpers.arrayElements(['email', 'username'] as const), + undefined, + ]), + is_open_for_signup: faker.datatype.boolean(), + email_verification_by_code_enabled: faker.datatype.boolean(), + login_by_code_enabled: faker.datatype.boolean(), + password_reset_by_code_enabled: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + socialaccount: faker.helpers.arrayElement([ + { + providers: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + openid_configuration_url: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + flows: faker.helpers.arrayElements(['provider_redirect', 'provider_token'] as const), + })), + }, + undefined, + ]), + mfa: faker.helpers.arrayElement([ + { supported_types: faker.helpers.arrayElements(Object.values(AuthenticatorType)) }, + undefined, + ]), + usersessions: faker.helpers.arrayElement([{ track_activity: faker.datatype.boolean() }, undefined]), + }, + status: faker.helpers.arrayElement([200] as const), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthLoginPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthLoginPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthSignupPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthSignupPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthEmailVerifyGetResponseMock = ( + overrideResponse: Partial = {}, +): EmailVerificationInfoResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + meta: { is_authenticating: faker.datatype.boolean() }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthEmailVerifyPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthEmailVerifyGetResponseMock = ( + overrideResponse: Partial = {}, +): EmailVerificationInfoResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + meta: { is_authenticating: faker.datatype.boolean() }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthEmailVerifyPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthEmailVerifyResendPostResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthAppV1AuthEmailVerifyResendPostResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthBrowserV1AuthPhoneVerifyPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthPhoneVerifyPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthPhoneVerifyResendPostResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthAppV1AuthPhoneVerifyResendPostResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthBrowserV1AuthReauthenticatePostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthReauthenticatePostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthPasswordRequestPostResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthAppV1AuthPasswordRequestPostResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthBrowserV1AuthPasswordResetGetResponseMock = ( + overrideResponse: Partial = {}, +): PasswordResetInfoResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: faker.helpers.arrayElement([ + { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthPasswordResetPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthPasswordResetGetResponseMock = ( + overrideResponse: Partial = {}, +): PasswordResetInfoResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: faker.helpers.arrayElement([ + { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthPasswordResetPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthProviderTokenPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthProviderTokenPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthProviderSignupGetResponseMock = ( + overrideResponse: Partial = {}, +): ProviderSignupResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + email: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + account: { + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + provider: { + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + openid_configuration_url: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + flows: faker.helpers.arrayElements(['provider_redirect', 'provider_token'] as const), + }, + }, + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthProviderSignupPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthProviderSignupGetResponseMock = ( + overrideResponse: Partial = {}, +): ProviderSignupResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + email: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + account: { + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + provider: { + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + openid_configuration_url: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + flows: faker.helpers.arrayElements(['provider_redirect', 'provider_token'] as const), + }, + }, + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthProviderSignupPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1Auth2faAuthenticatePostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordAnd2FAResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1Auth2faAuthenticatePostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordAnd2FAResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1Auth2faReauthenticatePostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordAnd2FAResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1Auth2faReauthenticatePostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByPasswordAnd2FAResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthCodeConfirmPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByCodeResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthCodeConfirmPostResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedByCodeResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountProvidersGetResponseMock = ( + overrideResponse: Partial = {}, +): ProviderAccountsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + provider: { + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + openid_configuration_url: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + flows: faker.helpers.arrayElements(['provider_redirect', 'provider_token'] as const), + }, + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountProvidersDeleteResponseMock = ( + overrideResponse: Partial = {}, +): ProviderAccountsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + provider: { + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + openid_configuration_url: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + flows: faker.helpers.arrayElements(['provider_redirect', 'provider_token'] as const), + }, + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountProvidersGetResponseMock = ( + overrideResponse: Partial = {}, +): ProviderAccountsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + provider: { + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + openid_configuration_url: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + flows: faker.helpers.arrayElements(['provider_redirect', 'provider_token'] as const), + }, + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountProvidersDeleteResponseMock = ( + overrideResponse: Partial = {}, +): ProviderAccountsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + provider: { + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + openid_configuration_url: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + flows: faker.helpers.arrayElements(['provider_redirect', 'provider_token'] as const), + }, + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountEmailGetResponseMock = ( + overrideResponse: Partial = {}, +): EmailAddressesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountEmailPostResponseMock = ( + overrideResponse: Partial = {}, +): EmailAddressesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountEmailPutResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthBrowserV1AccountEmailPatchResponseMock = ( + overrideResponse: Partial = {}, +): EmailAddressesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountEmailDeleteResponseMock = ( + overrideResponse: Partial = {}, +): EmailAddressesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountEmailGetResponseMock = ( + overrideResponse: Partial = {}, +): EmailAddressesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountEmailPostResponseMock = ( + overrideResponse: Partial = {}, +): EmailAddressesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountEmailPutResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthAppV1AccountEmailPatchResponseMock = ( + overrideResponse: Partial = {}, +): EmailAddressesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountEmailDeleteResponseMock = ( + overrideResponse: Partial = {}, +): EmailAddressesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountPhoneGetResponseMock = ( + overrideResponse: Partial = {}, +): PhoneNumbersResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountPhonePostResponseMock = ( + overrideResponse: Partial = {}, +): PhoneNumberChangeResponse => ({ + status: faker.helpers.arrayElement([202] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountPhoneGetResponseMock = ( + overrideResponse: Partial = {}, +): PhoneNumbersResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountPhonePostResponseMock = ( + overrideResponse: Partial = {}, +): PhoneNumberChangeResponse => ({ + status: faker.helpers.arrayElement([202] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsGetResponseTOTPAuthenticatorMock = ( + overrideResponse: Partial = {}, +): TOTPAuthenticator => ({ + ...{ + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ type: faker.helpers.arrayElement(['totp'] as const) }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsGetResponseRecoveryCodesAuthenticatorMock = ( + overrideResponse: Partial = {}, +): RecoveryCodesAuthenticator => ({ + ...{ + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ + type: faker.helpers.arrayElement(['recovery_codes'] as const), + total_code_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + unused_code_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsGetResponseWebAuthnAuthenticatorMock = ( + overrideResponse: Partial = {}, +): WebAuthnAuthenticator => ({ + ...{ + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ + type: faker.helpers.arrayElement(['webauthn'] as const), + id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + is_passwordless: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsGetResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatorsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { ...getApiV2AllauthBrowserV1AccountAuthenticatorsGetResponseTOTPAuthenticatorMock() }, + { ...getApiV2AllauthBrowserV1AccountAuthenticatorsGetResponseRecoveryCodesAuthenticatorMock() }, + { ...getApiV2AllauthBrowserV1AccountAuthenticatorsGetResponseWebAuthnAuthenticatorMock() }, + ]), + ), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountAuthenticatorsGetResponseTOTPAuthenticatorMock = ( + overrideResponse: Partial = {}, +): TOTPAuthenticator => ({ + ...{ + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ type: faker.helpers.arrayElement(['totp'] as const) }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountAuthenticatorsGetResponseRecoveryCodesAuthenticatorMock = ( + overrideResponse: Partial = {}, +): RecoveryCodesAuthenticator => ({ + ...{ + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ + type: faker.helpers.arrayElement(['recovery_codes'] as const), + total_code_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + unused_code_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountAuthenticatorsGetResponseWebAuthnAuthenticatorMock = ( + overrideResponse: Partial = {}, +): WebAuthnAuthenticator => ({ + ...{ + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ + type: faker.helpers.arrayElement(['webauthn'] as const), + id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + is_passwordless: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountAuthenticatorsGetResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatorsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { ...getApiV2AllauthAppV1AccountAuthenticatorsGetResponseTOTPAuthenticatorMock() }, + { ...getApiV2AllauthAppV1AccountAuthenticatorsGetResponseRecoveryCodesAuthenticatorMock() }, + { ...getApiV2AllauthAppV1AccountAuthenticatorsGetResponseWebAuthnAuthenticatorMock() }, + ]), + ), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsTotpGetResponseMock = ( + overrideResponse: Partial = {}, +): TOTPAuthenticatorResponse => ({ + status: faker.helpers.arrayElement([200] as const), + meta: faker.helpers.arrayElement([ + { recovery_codes_generated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + data: { + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ type: faker.helpers.arrayElement(['totp'] as const) }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsTotpPostResponseMock = ( + overrideResponse: Partial = {}, +): TOTPAuthenticatorResponse => ({ + status: faker.helpers.arrayElement([200] as const), + meta: faker.helpers.arrayElement([ + { recovery_codes_generated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + data: { + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ type: faker.helpers.arrayElement(['totp'] as const) }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsTotpDeleteResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthAppV1AccountAuthenticatorsTotpGetResponseMock = ( + overrideResponse: Partial = {}, +): TOTPAuthenticatorResponse => ({ + status: faker.helpers.arrayElement([200] as const), + meta: faker.helpers.arrayElement([ + { recovery_codes_generated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + data: { + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ type: faker.helpers.arrayElement(['totp'] as const) }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountAuthenticatorsTotpPostResponseMock = ( + overrideResponse: Partial = {}, +): TOTPAuthenticatorResponse => ({ + status: faker.helpers.arrayElement([200] as const), + meta: faker.helpers.arrayElement([ + { recovery_codes_generated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + data: { + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ type: faker.helpers.arrayElement(['totp'] as const) }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountAuthenticatorsTotpDeleteResponseMock = ( + overrideResponse: Partial = {}, +): StatusOKResponse => ({ status: faker.helpers.arrayElement([200] as const), ...overrideResponse }) + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsRecoveryCodesGetResponseMock = ( + overrideResponse: Partial = {}, +): RecoveryCodesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + ...{ + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ + type: faker.helpers.arrayElement(['recovery_codes'] as const), + total_code_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + unused_code_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + }, + ...{ + unused_codes: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AccountAuthenticatorsRecoveryCodesGetResponseMock = ( + overrideResponse: Partial = {}, +): RecoveryCodesResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + ...{ + ...{ + last_used_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + }, + ...{ + type: faker.helpers.arrayElement(['recovery_codes'] as const), + total_code_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + unused_code_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + }, + ...{ + unused_codes: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthSessionGetResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthSessionGetResponseMock = ( + overrideResponse: Partial = {}, +): AuthenticatedResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + user: { + id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + display: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + has_usable_password: faker.datatype.boolean(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + methods: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + { + method: faker.helpers.arrayElement(['password_reset'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['code'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + phone: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['password'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + reauthenticated: faker.datatype.boolean(), + }, + { + method: faker.helpers.arrayElement(['socialaccount'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + { + method: faker.helpers.arrayElement(['mfa'] as const), + at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + type: faker.helpers.arrayElement(Object.values(AuthenticatorType)), + reauthenticated: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ]), + ), + }, + meta: { + ...{ + session_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + access_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...{ is_authenticated: faker.datatype.boolean() }, + }, + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1TokensRefreshPostResponseMock = ( + overrideResponse: Partial = {}, +): RefreshTokenResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: { + access_token: faker.string.alpha({ length: { min: 10, max: 20 } }), + refresh_token: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthSessionsGetResponseMock = ( + overrideResponse: Partial = {}, +): SessionsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user_agent: faker.string.alpha({ length: { min: 10, max: 20 } }), + ip: faker.string.alpha({ length: { min: 10, max: 20 } }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + is_current: faker.datatype.boolean(), + id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + last_seen_at: faker.helpers.arrayElement([ + faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + undefined, + ]), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1AuthSessionsDeleteResponseMock = ( + overrideResponse: Partial = {}, +): SessionsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user_agent: faker.string.alpha({ length: { min: 10, max: 20 } }), + ip: faker.string.alpha({ length: { min: 10, max: 20 } }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + is_current: faker.datatype.boolean(), + id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + last_seen_at: faker.helpers.arrayElement([ + faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + undefined, + ]), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthSessionsGetResponseMock = ( + overrideResponse: Partial = {}, +): SessionsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user_agent: faker.string.alpha({ length: { min: 10, max: 20 } }), + ip: faker.string.alpha({ length: { min: 10, max: 20 } }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + is_current: faker.datatype.boolean(), + id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + last_seen_at: faker.helpers.arrayElement([ + faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + undefined, + ]), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthAppV1AuthSessionsDeleteResponseMock = ( + overrideResponse: Partial = {}, +): SessionsResponse => ({ + status: faker.helpers.arrayElement([200] as const), + data: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user_agent: faker.string.alpha({ length: { min: 10, max: 20 } }), + ip: faker.string.alpha({ length: { min: 10, max: 20 } }), + created_at: faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + is_current: faker.datatype.boolean(), + id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + last_seen_at: faker.helpers.arrayElement([ + faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + undefined, + ]), + })), + ...overrideResponse, +}) + +export const getApiV2AllauthBrowserV1ConfigGetMockHandler = ( + overrideResponse?: + | ConfigurationResponse + | ((info: Parameters[1]>[0]) => Promise | ConfigurationResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/config', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1ConfigGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1ConfigGetMockHandler = ( + overrideResponse?: + | ConfigurationResponse + | ((info: Parameters[1]>[0]) => Promise | ConfigurationResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/config', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1ConfigGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthLoginPostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/login', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthLoginPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthLoginPostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/login', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthLoginPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthSignupPostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/signup', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthSignupPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthSignupPostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/signup', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthSignupPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthEmailVerifyGetMockHandler = ( + overrideResponse?: + | EmailVerificationInfoResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailVerificationInfoResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/auth/email/verify', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthEmailVerifyGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthEmailVerifyPostMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/email/verify', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthEmailVerifyPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthEmailVerifyGetMockHandler = ( + overrideResponse?: + | EmailVerificationInfoResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailVerificationInfoResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/auth/email/verify', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthEmailVerifyGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthEmailVerifyPostMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/email/verify', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthEmailVerifyPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthEmailVerifyResendPostMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/email/verify/resend', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthEmailVerifyResendPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthEmailVerifyResendPostMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/email/verify/resend', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthEmailVerifyResendPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthPhoneVerifyPostMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/phone/verify', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthPhoneVerifyPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthPhoneVerifyPostMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/phone/verify', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthPhoneVerifyPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthPhoneVerifyResendPostMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/phone/verify/resend', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthPhoneVerifyResendPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthPhoneVerifyResendPostMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/phone/verify/resend', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthPhoneVerifyResendPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthReauthenticatePostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/reauthenticate', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthReauthenticatePostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthReauthenticatePostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/reauthenticate', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthReauthenticatePostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthPasswordRequestPostMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/password/request', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthPasswordRequestPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthPasswordRequestPostMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/password/request', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthPasswordRequestPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthPasswordResetGetMockHandler = ( + overrideResponse?: + | PasswordResetInfoResponse + | (( + info: Parameters[1]>[0], + ) => Promise | PasswordResetInfoResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/auth/password/reset', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthPasswordResetGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthPasswordResetPostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/password/reset', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthPasswordResetPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthPasswordResetGetMockHandler = ( + overrideResponse?: + | PasswordResetInfoResponse + | (( + info: Parameters[1]>[0], + ) => Promise | PasswordResetInfoResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/auth/password/reset', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthPasswordResetGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthPasswordResetPostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/password/reset', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthPasswordResetPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthProviderRedirectPostMockHandler = ( + overrideResponse?: unknown | ((info: Parameters[1]>[0]) => Promise | unknown), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/provider/redirect', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AllauthBrowserV1AuthProviderTokenPostMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/provider/token', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthProviderTokenPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthProviderTokenPostMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/provider/token', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthProviderTokenPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthProviderSignupGetMockHandler = ( + overrideResponse?: + | ProviderSignupResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProviderSignupResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/auth/provider/signup', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthProviderSignupGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthProviderSignupPostMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/provider/signup', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthProviderSignupPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthProviderSignupGetMockHandler = ( + overrideResponse?: + | ProviderSignupResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProviderSignupResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/auth/provider/signup', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthProviderSignupGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthProviderSignupPostMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/provider/signup', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthProviderSignupPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1Auth2faAuthenticatePostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordAnd2FAResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordAnd2FAResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/2fa/authenticate', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1Auth2faAuthenticatePostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1Auth2faAuthenticatePostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordAnd2FAResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordAnd2FAResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/2fa/authenticate', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1Auth2faAuthenticatePostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1Auth2faReauthenticatePostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordAnd2FAResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordAnd2FAResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/2fa/reauthenticate', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1Auth2faReauthenticatePostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1Auth2faReauthenticatePostMockHandler = ( + overrideResponse?: + | AuthenticatedByPasswordAnd2FAResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByPasswordAnd2FAResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/2fa/reauthenticate', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1Auth2faReauthenticatePostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthCodeConfirmPostMockHandler = ( + overrideResponse?: + | AuthenticatedByCodeResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByCodeResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/auth/code/confirm', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthCodeConfirmPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthCodeConfirmPostMockHandler = ( + overrideResponse?: + | AuthenticatedByCodeResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatedByCodeResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/auth/code/confirm', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthCodeConfirmPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountProvidersGetMockHandler = ( + overrideResponse?: + | ProviderAccountsResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProviderAccountsResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/account/providers', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountProvidersGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountProvidersDeleteMockHandler = ( + overrideResponse?: + | ProviderAccountsResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProviderAccountsResponse), +) => { + return http.delete('*/api/v2/allauth/browser/v1/account/providers', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountProvidersDeleteResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountProvidersGetMockHandler = ( + overrideResponse?: + | ProviderAccountsResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProviderAccountsResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/account/providers', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountProvidersGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountProvidersDeleteMockHandler = ( + overrideResponse?: + | ProviderAccountsResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProviderAccountsResponse), +) => { + return http.delete('*/api/v2/allauth/app/v1/account/providers', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountProvidersDeleteResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountEmailGetMockHandler = ( + overrideResponse?: + | EmailAddressesResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailAddressesResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountEmailGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountEmailPostMockHandler = ( + overrideResponse?: + | EmailAddressesResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailAddressesResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountEmailPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountEmailPutMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.put('*/api/v2/allauth/browser/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountEmailPutResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountEmailPatchMockHandler = ( + overrideResponse?: + | EmailAddressesResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailAddressesResponse), +) => { + return http.patch('*/api/v2/allauth/browser/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountEmailPatchResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountEmailDeleteMockHandler = ( + overrideResponse?: + | EmailAddressesResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailAddressesResponse), +) => { + return http.delete('*/api/v2/allauth/browser/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountEmailDeleteResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountEmailGetMockHandler = ( + overrideResponse?: + | EmailAddressesResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailAddressesResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountEmailGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountEmailPostMockHandler = ( + overrideResponse?: + | EmailAddressesResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailAddressesResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountEmailPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountEmailPutMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.put('*/api/v2/allauth/app/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountEmailPutResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountEmailPatchMockHandler = ( + overrideResponse?: + | EmailAddressesResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailAddressesResponse), +) => { + return http.patch('*/api/v2/allauth/app/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountEmailPatchResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountEmailDeleteMockHandler = ( + overrideResponse?: + | EmailAddressesResponse + | (( + info: Parameters[1]>[0], + ) => Promise | EmailAddressesResponse), +) => { + return http.delete('*/api/v2/allauth/app/v1/account/email', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountEmailDeleteResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountPhoneGetMockHandler = ( + overrideResponse?: + | PhoneNumbersResponse + | ((info: Parameters[1]>[0]) => Promise | PhoneNumbersResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/account/phone', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountPhoneGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountPhonePostMockHandler = ( + overrideResponse?: + | PhoneNumberChangeResponse + | (( + info: Parameters[1]>[0], + ) => Promise | PhoneNumberChangeResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/account/phone', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountPhonePostResponseMock(), + ), + { status: 202, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountPhoneGetMockHandler = ( + overrideResponse?: + | PhoneNumbersResponse + | ((info: Parameters[1]>[0]) => Promise | PhoneNumbersResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/account/phone', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountPhoneGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountPhonePostMockHandler = ( + overrideResponse?: + | PhoneNumberChangeResponse + | (( + info: Parameters[1]>[0], + ) => Promise | PhoneNumberChangeResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/account/phone', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountPhonePostResponseMock(), + ), + { status: 202, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsGetMockHandler = ( + overrideResponse?: + | AuthenticatorsResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatorsResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/account/authenticators', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountAuthenticatorsGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountAuthenticatorsGetMockHandler = ( + overrideResponse?: + | AuthenticatorsResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AuthenticatorsResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/account/authenticators', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountAuthenticatorsGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsTotpGetMockHandler = ( + overrideResponse?: + | TOTPAuthenticatorResponse + | (( + info: Parameters[1]>[0], + ) => Promise | TOTPAuthenticatorResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/account/authenticators/totp', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountAuthenticatorsTotpGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsTotpPostMockHandler = ( + overrideResponse?: + | TOTPAuthenticatorResponse + | (( + info: Parameters[1]>[0], + ) => Promise | TOTPAuthenticatorResponse), +) => { + return http.post('*/api/v2/allauth/browser/v1/account/authenticators/totp', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountAuthenticatorsTotpPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsTotpDeleteMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.delete('*/api/v2/allauth/browser/v1/account/authenticators/totp', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountAuthenticatorsTotpDeleteResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountAuthenticatorsTotpGetMockHandler = ( + overrideResponse?: + | TOTPAuthenticatorResponse + | (( + info: Parameters[1]>[0], + ) => Promise | TOTPAuthenticatorResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/account/authenticators/totp', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountAuthenticatorsTotpGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountAuthenticatorsTotpPostMockHandler = ( + overrideResponse?: + | TOTPAuthenticatorResponse + | (( + info: Parameters[1]>[0], + ) => Promise | TOTPAuthenticatorResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/account/authenticators/totp', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountAuthenticatorsTotpPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountAuthenticatorsTotpDeleteMockHandler = ( + overrideResponse?: + | StatusOKResponse + | ((info: Parameters[1]>[0]) => Promise | StatusOKResponse), +) => { + return http.delete('*/api/v2/allauth/app/v1/account/authenticators/totp', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountAuthenticatorsTotpDeleteResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsRecoveryCodesGetMockHandler = ( + overrideResponse?: + | RecoveryCodesResponse + | ((info: Parameters[1]>[0]) => Promise | RecoveryCodesResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/account/authenticators/recovery-codes', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AccountAuthenticatorsRecoveryCodesGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountAuthenticatorsRecoveryCodesPostMockHandler = ( + overrideResponse?: unknown | ((info: Parameters[1]>[0]) => Promise | unknown), +) => { + return http.post('*/api/v2/allauth/browser/v1/account/authenticators/recovery-codes', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AllauthAppV1AccountAuthenticatorsRecoveryCodesGetMockHandler = ( + overrideResponse?: + | RecoveryCodesResponse + | ((info: Parameters[1]>[0]) => Promise | RecoveryCodesResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/account/authenticators/recovery-codes', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AccountAuthenticatorsRecoveryCodesGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AccountAuthenticatorsRecoveryCodesPostMockHandler = ( + overrideResponse?: unknown | ((info: Parameters[1]>[0]) => Promise | unknown), +) => { + return http.post('*/api/v2/allauth/app/v1/account/authenticators/recovery-codes', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AllauthBrowserV1AuthSessionGetMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | ((info: Parameters[1]>[0]) => Promise | AuthenticatedResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/auth/session', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthSessionGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthSessionDeleteMockHandler = ( + overrideResponse?: unknown | ((info: Parameters[1]>[0]) => Promise | unknown), +) => { + return http.delete('*/api/v2/allauth/browser/v1/auth/session', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AllauthAppV1AuthSessionGetMockHandler = ( + overrideResponse?: + | AuthenticatedResponse + | ((info: Parameters[1]>[0]) => Promise | AuthenticatedResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/auth/session', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthSessionGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthSessionDeleteMockHandler = ( + overrideResponse?: unknown | ((info: Parameters[1]>[0]) => Promise | unknown), +) => { + return http.delete('*/api/v2/allauth/app/v1/auth/session', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AllauthAppV1TokensRefreshPostMockHandler = ( + overrideResponse?: + | RefreshTokenResponse + | ((info: Parameters[1]>[0]) => Promise | RefreshTokenResponse), +) => { + return http.post('*/api/v2/allauth/app/v1/tokens/refresh', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1TokensRefreshPostResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AccountPasswordChangePostMockHandler = ( + overrideResponse?: unknown | ((info: Parameters[1]>[0]) => Promise | unknown), +) => { + return http.post('*/api/v2/allauth/browser/v1/account/password/change', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AllauthAppV1AccountPasswordChangePostMockHandler = ( + overrideResponse?: unknown | ((info: Parameters[1]>[0]) => Promise | unknown), +) => { + return http.post('*/api/v2/allauth/app/v1/account/password/change', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AllauthBrowserV1AuthSessionsGetMockHandler = ( + overrideResponse?: + | SessionsResponse + | ((info: Parameters[1]>[0]) => Promise | SessionsResponse), +) => { + return http.get('*/api/v2/allauth/browser/v1/auth/sessions', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthSessionsGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthBrowserV1AuthSessionsDeleteMockHandler = ( + overrideResponse?: + | SessionsResponse + | ((info: Parameters[1]>[0]) => Promise | SessionsResponse), +) => { + return http.delete('*/api/v2/allauth/browser/v1/auth/sessions', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthBrowserV1AuthSessionsDeleteResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthSessionsGetMockHandler = ( + overrideResponse?: + | SessionsResponse + | ((info: Parameters[1]>[0]) => Promise | SessionsResponse), +) => { + return http.get('*/api/v2/allauth/app/v1/auth/sessions', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthSessionsGetResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AllauthAppV1AuthSessionsDeleteMockHandler = ( + overrideResponse?: + | SessionsResponse + | ((info: Parameters[1]>[0]) => Promise | SessionsResponse), +) => { + return http.delete('*/api/v2/allauth/app/v1/auth/sessions', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AllauthAppV1AuthSessionsDeleteResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getAuthenticationAllauthHeadlessMock = () => [ + getApiV2AllauthBrowserV1ConfigGetMockHandler(), + getApiV2AllauthAppV1ConfigGetMockHandler(), + getApiV2AllauthBrowserV1AuthLoginPostMockHandler(), + getApiV2AllauthAppV1AuthLoginPostMockHandler(), + getApiV2AllauthBrowserV1AuthSignupPostMockHandler(), + getApiV2AllauthAppV1AuthSignupPostMockHandler(), + getApiV2AllauthBrowserV1AuthEmailVerifyGetMockHandler(), + getApiV2AllauthBrowserV1AuthEmailVerifyPostMockHandler(), + getApiV2AllauthAppV1AuthEmailVerifyGetMockHandler(), + getApiV2AllauthAppV1AuthEmailVerifyPostMockHandler(), + getApiV2AllauthBrowserV1AuthEmailVerifyResendPostMockHandler(), + getApiV2AllauthAppV1AuthEmailVerifyResendPostMockHandler(), + getApiV2AllauthBrowserV1AuthPhoneVerifyPostMockHandler(), + getApiV2AllauthAppV1AuthPhoneVerifyPostMockHandler(), + getApiV2AllauthBrowserV1AuthPhoneVerifyResendPostMockHandler(), + getApiV2AllauthAppV1AuthPhoneVerifyResendPostMockHandler(), + getApiV2AllauthBrowserV1AuthReauthenticatePostMockHandler(), + getApiV2AllauthAppV1AuthReauthenticatePostMockHandler(), + getApiV2AllauthBrowserV1AuthPasswordRequestPostMockHandler(), + getApiV2AllauthAppV1AuthPasswordRequestPostMockHandler(), + getApiV2AllauthBrowserV1AuthPasswordResetGetMockHandler(), + getApiV2AllauthBrowserV1AuthPasswordResetPostMockHandler(), + getApiV2AllauthAppV1AuthPasswordResetGetMockHandler(), + getApiV2AllauthAppV1AuthPasswordResetPostMockHandler(), + getApiV2AllauthBrowserV1AuthProviderRedirectPostMockHandler(), + getApiV2AllauthBrowserV1AuthProviderTokenPostMockHandler(), + getApiV2AllauthAppV1AuthProviderTokenPostMockHandler(), + getApiV2AllauthBrowserV1AuthProviderSignupGetMockHandler(), + getApiV2AllauthBrowserV1AuthProviderSignupPostMockHandler(), + getApiV2AllauthAppV1AuthProviderSignupGetMockHandler(), + getApiV2AllauthAppV1AuthProviderSignupPostMockHandler(), + getApiV2AllauthBrowserV1Auth2faAuthenticatePostMockHandler(), + getApiV2AllauthAppV1Auth2faAuthenticatePostMockHandler(), + getApiV2AllauthBrowserV1Auth2faReauthenticatePostMockHandler(), + getApiV2AllauthAppV1Auth2faReauthenticatePostMockHandler(), + getApiV2AllauthBrowserV1AuthCodeConfirmPostMockHandler(), + getApiV2AllauthAppV1AuthCodeConfirmPostMockHandler(), + getApiV2AllauthBrowserV1AccountProvidersGetMockHandler(), + getApiV2AllauthBrowserV1AccountProvidersDeleteMockHandler(), + getApiV2AllauthAppV1AccountProvidersGetMockHandler(), + getApiV2AllauthAppV1AccountProvidersDeleteMockHandler(), + getApiV2AllauthBrowserV1AccountEmailGetMockHandler(), + getApiV2AllauthBrowserV1AccountEmailPostMockHandler(), + getApiV2AllauthBrowserV1AccountEmailPutMockHandler(), + getApiV2AllauthBrowserV1AccountEmailPatchMockHandler(), + getApiV2AllauthBrowserV1AccountEmailDeleteMockHandler(), + getApiV2AllauthAppV1AccountEmailGetMockHandler(), + getApiV2AllauthAppV1AccountEmailPostMockHandler(), + getApiV2AllauthAppV1AccountEmailPutMockHandler(), + getApiV2AllauthAppV1AccountEmailPatchMockHandler(), + getApiV2AllauthAppV1AccountEmailDeleteMockHandler(), + getApiV2AllauthBrowserV1AccountPhoneGetMockHandler(), + getApiV2AllauthBrowserV1AccountPhonePostMockHandler(), + getApiV2AllauthAppV1AccountPhoneGetMockHandler(), + getApiV2AllauthAppV1AccountPhonePostMockHandler(), + getApiV2AllauthBrowserV1AccountAuthenticatorsGetMockHandler(), + getApiV2AllauthAppV1AccountAuthenticatorsGetMockHandler(), + getApiV2AllauthBrowserV1AccountAuthenticatorsTotpGetMockHandler(), + getApiV2AllauthBrowserV1AccountAuthenticatorsTotpPostMockHandler(), + getApiV2AllauthBrowserV1AccountAuthenticatorsTotpDeleteMockHandler(), + getApiV2AllauthAppV1AccountAuthenticatorsTotpGetMockHandler(), + getApiV2AllauthAppV1AccountAuthenticatorsTotpPostMockHandler(), + getApiV2AllauthAppV1AccountAuthenticatorsTotpDeleteMockHandler(), + getApiV2AllauthBrowserV1AccountAuthenticatorsRecoveryCodesGetMockHandler(), + getApiV2AllauthBrowserV1AccountAuthenticatorsRecoveryCodesPostMockHandler(), + getApiV2AllauthAppV1AccountAuthenticatorsRecoveryCodesGetMockHandler(), + getApiV2AllauthAppV1AccountAuthenticatorsRecoveryCodesPostMockHandler(), + getApiV2AllauthBrowserV1AuthSessionGetMockHandler(), + getApiV2AllauthBrowserV1AuthSessionDeleteMockHandler(), + getApiV2AllauthAppV1AuthSessionGetMockHandler(), + getApiV2AllauthAppV1AuthSessionDeleteMockHandler(), + getApiV2AllauthAppV1TokensRefreshPostMockHandler(), + getApiV2AllauthBrowserV1AccountPasswordChangePostMockHandler(), + getApiV2AllauthAppV1AccountPasswordChangePostMockHandler(), + getApiV2AllauthBrowserV1AuthSessionsGetMockHandler(), + getApiV2AllauthBrowserV1AuthSessionsDeleteMockHandler(), + getApiV2AllauthAppV1AuthSessionsGetMockHandler(), + getApiV2AllauthAppV1AuthSessionsDeleteMockHandler(), +] diff --git a/jsapp/js/api/react-query/configuration.ts b/jsapp/js/api/react-query/configuration/index.ts similarity index 96% rename from jsapp/js/api/react-query/configuration.ts rename to jsapp/js/api/react-query/configuration/index.ts index 1ec1a26109..c6fac2287d 100644 --- a/jsapp/js/api/react-query/configuration.ts +++ b/jsapp/js/api/react-query/configuration/index.ts @@ -12,9 +12,9 @@ The endpoints are grouped by area of intended use. Each category contains relate import { useQuery } from '@tanstack/react-query' import type { QueryFunction, QueryKey, UseQueryOptions, UseQueryResult } from '@tanstack/react-query' -import type { EnvironmentResponse } from '../models/environmentResponse' +import type { EnvironmentResponse } from '../../models/environmentResponse' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/configuration/msw.ts b/jsapp/js/api/react-query/configuration/msw.ts new file mode 100644 index 0000000000..eddd8a8e82 --- /dev/null +++ b/jsapp/js/api/react-query/configuration/msw.ts @@ -0,0 +1,140 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { EnvironmentResponse } from '../../models/environmentResponse' + +export const getApiV2EnvironmentRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): EnvironmentResponse => ({ + terms_of_service_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + privacy_policy_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + source_code_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + support_email: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + support_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + academy_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + community_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + frontend_min_retry_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + frontend_max_retry_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + use_team_label: faker.datatype.boolean(), + usage_limit_enforcement: faker.datatype.boolean(), + allow_self_account_deletion: faker.datatype.boolean(), + project_history_log_lifespan: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + sector_choices: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + Array.from({ length: faker.number.int({ min: 2, max: 2 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ), + operational_purpose_choices: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + Array.from({ length: faker.number.int({ min: 2, max: 2 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ), + country_choices: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + Array.from({ length: faker.number.int({ min: 2, max: 2 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ), + interface_languages: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + Array.from({ length: faker.number.int({ min: 2, max: 2 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ), + mfa_localized_help_text: faker.string.alpha({ length: { min: 10, max: 20 } }), + mfa_enabled: faker.datatype.boolean(), + mfa_code_length: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + superuser_auth_enforcement: faker.datatype.boolean(), + enable_password_entropy_meter: faker.datatype.boolean(), + enable_custom_password_guidance_text: faker.datatype.boolean(), + custom_password_localized_help_text: faker.string.alpha({ length: { min: 10, max: 20 } }), + project_metadata_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + options: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: { + [faker.string.alphanumeric(5)]: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + })), + undefined, + ]), + })), + extra_project_metadata_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map( + () => ({ + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + options: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: { + [faker.string.alphanumeric(5)]: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + })), + undefined, + ]), + }), + ), + user_metadata_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + options: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: { + [faker.string.alphanumeric(5)]: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + })), + undefined, + ]), + })), + social_apps: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + provider: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + client_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + provider_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + })), + asr_mt_features_enabled: faker.datatype.boolean(), + submission_placeholder: faker.string.alpha({ length: { min: 10, max: 20 } }), + stripe_public_key: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + terms_of_service__sitewidemessage__exists: faker.datatype.boolean(), + open_rosa_server: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2EnvironmentRetrieveMockHandler = ( + overrideResponse?: + | EnvironmentResponse + | ((info: Parameters[1]>[0]) => Promise | EnvironmentResponse), +) => { + return http.get('*/api/v2/environment{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2EnvironmentRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getConfigurationMock = () => [getApiV2EnvironmentRetrieveMockHandler()] diff --git a/jsapp/js/api/react-query/form-content.ts b/jsapp/js/api/react-query/form-content/index.ts similarity index 97% rename from jsapp/js/api/react-query/form-content.ts rename to jsapp/js/api/react-query/form-content/index.ts index 3fdcda034f..57ce837713 100644 --- a/jsapp/js/api/react-query/form-content.ts +++ b/jsapp/js/api/react-query/form-content/index.ts @@ -19,27 +19,27 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { AssetSnapshotCreateRequest } from '../models/assetSnapshotCreateRequest' +import type { AssetSnapshotCreateRequest } from '../../models/assetSnapshotCreateRequest' -import type { AssetSnapshotResponse } from '../models/assetSnapshotResponse' +import type { AssetSnapshotResponse } from '../../models/assetSnapshotResponse' -import type { AssetSnapshotsListParams } from '../models/assetSnapshotsListParams' +import type { AssetSnapshotsListParams } from '../../models/assetSnapshotsListParams' -import type { AssetSnapshotsRetrieveParams } from '../models/assetSnapshotsRetrieveParams' +import type { AssetSnapshotsRetrieveParams } from '../../models/assetSnapshotsRetrieveParams' -import type { AssetValidContentResponse } from '../models/assetValidContentResponse' +import type { AssetValidContentResponse } from '../../models/assetValidContentResponse' -import type { ContentResponse } from '../models/contentResponse' +import type { ContentResponse } from '../../models/contentResponse' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { OpenRosaXFormResponse } from '../models/openRosaXFormResponse' +import type { OpenRosaXFormResponse } from '../../models/openRosaXFormResponse' -import type { PaginatedAssetSnapshotResponseList } from '../models/paginatedAssetSnapshotResponseList' +import type { PaginatedAssetSnapshotResponseList } from '../../models/paginatedAssetSnapshotResponseList' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/form-content/msw.ts b/jsapp/js/api/react-query/form-content/msw.ts new file mode 100644 index 0000000000..3538558c8c --- /dev/null +++ b/jsapp/js/api/react-query/form-content/msw.ts @@ -0,0 +1,548 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { AssetSnapshotResponse } from '../../models/assetSnapshotResponse' + +import type { AssetValidContentResponse } from '../../models/assetValidContentResponse' + +import type { ContentResponse } from '../../models/contentResponse' + +import type { OpenRosaXFormResponse } from '../../models/openRosaXFormResponse' + +import type { PaginatedAssetSnapshotResponseList } from '../../models/paginatedAssetSnapshotResponseList' + +export const getApiV2AssetSnapshotsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetSnapshotResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + owner: faker.internet.url(), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + xml: faker.internet.url(), + enketopreviewlink: faker.internet.url(), + asset: faker.internet.url(), + asset_version_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + details: { + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + warnings: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + code: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + message: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + }, + source: { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { form_title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]) }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translation: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + })), + ...overrideResponse, +}) + +export const getApiV2AssetSnapshotsCreateResponseMock = ( + overrideResponse: Partial = {}, +): AssetSnapshotResponse => ({ + url: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + owner: faker.internet.url(), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + xml: faker.internet.url(), + enketopreviewlink: faker.internet.url(), + asset: faker.internet.url(), + asset_version_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + details: { + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + warnings: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + code: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + message: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + }, + source: { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { form_title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]) }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translation: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetSnapshotsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): AssetSnapshotResponse => ({ + url: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + owner: faker.internet.url(), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + xml: faker.internet.url(), + enketopreviewlink: faker.internet.url(), + asset: faker.internet.url(), + asset_version_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + details: { + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + warnings: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + code: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + message: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + }, + source: { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { form_title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]) }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translation: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetSnapshotsXformRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): OpenRosaXFormResponse => ({ + html: { + head: faker.helpers.arrayElement([ + { + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + model: faker.helpers.arrayElement([ + { + instance: faker.helpers.arrayElement([ + { + instanceUuid: faker.helpers.arrayElement([ + { + fieldName: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + meta: faker.helpers.arrayElement([ + { + instanceID: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + body: faker.helpers.arrayElement([ + { + input: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + hint: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetSnapshotsXmlWithDisclaimerRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): OpenRosaXFormResponse => ({ + html: { + head: faker.helpers.arrayElement([ + { + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + model: faker.helpers.arrayElement([ + { + instance: faker.helpers.arrayElement([ + { + instanceUuid: faker.helpers.arrayElement([ + { + fieldName: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + meta: faker.helpers.arrayElement([ + { + instanceID: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + body: faker.helpers.arrayElement([ + { + input: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + hint: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsContentRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ContentResponse => ({ + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + data: { + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + settings: faker.helpers.arrayElement([{}, undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsTableViewRetrieveResponseMock = (): string => faker.word.sample() + +export const getApiV2AssetsValidContentRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): AssetValidContentResponse => ({ + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + data: { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $kuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([{}, undefined]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsXlsRetrieveResponseMock = (): string => faker.word.sample() + +export const getApiV2AssetSnapshotsListMockHandler = ( + overrideResponse?: + | PaginatedAssetSnapshotResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAssetSnapshotResponseList), +) => { + return http.get('*/api/v2/asset_snapshots{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetSnapshotsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetSnapshotsCreateMockHandler = ( + overrideResponse?: + | AssetSnapshotResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AssetSnapshotResponse), +) => { + return http.post('*/api/v2/asset_snapshots{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetSnapshotsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetSnapshotsRetrieveMockHandler = ( + overrideResponse?: + | AssetSnapshotResponse + | ((info: Parameters[1]>[0]) => Promise | AssetSnapshotResponse), +) => { + return http.get('*/api/v2/asset_snapshots/:uidAssetSnapshot{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetSnapshotsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetSnapshotsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/asset_snapshots/:uidAssetSnapshot{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetSnapshotsPreviewRetrieveMockHandler = ( + overrideResponse?: unknown | ((info: Parameters[1]>[0]) => Promise | unknown), +) => { + return http.get('*/api/v2/asset_snapshots/:uidAssetSnapshot/preview{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AssetSnapshotsXformRetrieveMockHandler = ( + overrideResponse?: + | OpenRosaXFormResponse + | ((info: Parameters[1]>[0]) => Promise | OpenRosaXFormResponse), +) => { + return http.get('*/api/v2/asset_snapshots/:uidAssetSnapshot/xform{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetSnapshotsXformRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetSnapshotsXmlWithDisclaimerRetrieveMockHandler = ( + overrideResponse?: + | OpenRosaXFormResponse + | ((info: Parameters[1]>[0]) => Promise | OpenRosaXFormResponse), +) => { + return http.get('*/api/v2/asset_snapshots/:uidAssetSnapshot/xml_with_disclaimer{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetSnapshotsXmlWithDisclaimerRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsContentRetrieveMockHandler = ( + overrideResponse?: + | ContentResponse + | ((info: Parameters[1]>[0]) => Promise | ContentResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/content{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsContentRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsTableViewRetrieveMockHandler = ( + overrideResponse?: string | ((info: Parameters[1]>[0]) => Promise | string), +) => { + return http.get('*/api/v2/assets/:uidAsset/table_view{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsTableViewRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsValidContentRetrieveMockHandler = ( + overrideResponse?: + | AssetValidContentResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AssetValidContentResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/valid_content{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsValidContentRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsXlsRetrieveMockHandler = ( + overrideResponse?: string | ((info: Parameters[1]>[0]) => Promise | string), +) => { + return http.get('*/api/v2/assets/:uidAsset/xls{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsXlsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getFormContentMock = () => [ + getApiV2AssetSnapshotsListMockHandler(), + getApiV2AssetSnapshotsCreateMockHandler(), + getApiV2AssetSnapshotsRetrieveMockHandler(), + getApiV2AssetSnapshotsDestroyMockHandler(), + getApiV2AssetSnapshotsPreviewRetrieveMockHandler(), + getApiV2AssetSnapshotsXformRetrieveMockHandler(), + getApiV2AssetSnapshotsXmlWithDisclaimerRetrieveMockHandler(), + getApiV2AssetsContentRetrieveMockHandler(), + getApiV2AssetsTableViewRetrieveMockHandler(), + getApiV2AssetsValidContentRetrieveMockHandler(), + getApiV2AssetsXlsRetrieveMockHandler(), +] diff --git a/jsapp/js/api/react-query/library-collections.ts b/jsapp/js/api/react-query/library-collections/index.ts similarity index 96% rename from jsapp/js/api/react-query/library-collections.ts rename to jsapp/js/api/react-query/library-collections/index.ts index 4fe65d0299..67ac4d8d2f 100644 --- a/jsapp/js/api/react-query/library-collections.ts +++ b/jsapp/js/api/react-query/library-collections/index.ts @@ -19,19 +19,19 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { AssetSubscriptionRequest } from '../models/assetSubscriptionRequest' +import type { AssetSubscriptionRequest } from '../../models/assetSubscriptionRequest' -import type { AssetSubscriptionResponse } from '../models/assetSubscriptionResponse' +import type { AssetSubscriptionResponse } from '../../models/assetSubscriptionResponse' -import type { AssetSubscriptionsListParams } from '../models/assetSubscriptionsListParams' +import type { AssetSubscriptionsListParams } from '../../models/assetSubscriptionsListParams' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { PaginatedAssetSubscriptionResponseList } from '../models/paginatedAssetSubscriptionResponseList' +import type { PaginatedAssetSubscriptionResponseList } from '../../models/paginatedAssetSubscriptionResponseList' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/library-collections/msw.ts b/jsapp/js/api/react-query/library-collections/msw.ts new file mode 100644 index 0000000000..f359d37a94 --- /dev/null +++ b/jsapp/js/api/react-query/library-collections/msw.ts @@ -0,0 +1,130 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { AssetSubscriptionResponse } from '../../models/assetSubscriptionResponse' + +import type { PaginatedAssetSubscriptionResponseList } from '../../models/paginatedAssetSubscriptionResponseList' + +export const getApiV2AssetSubscriptionsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetSubscriptionResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + asset: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + ...overrideResponse, +}) + +export const getApiV2AssetSubscriptionsCreateResponseMock = ( + overrideResponse: Partial = {}, +): AssetSubscriptionResponse => ({ + url: faker.internet.url(), + asset: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetSubscriptionsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): AssetSubscriptionResponse => ({ + url: faker.internet.url(), + asset: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetSubscriptionsListMockHandler = ( + overrideResponse?: + | PaginatedAssetSubscriptionResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAssetSubscriptionResponseList), +) => { + return http.get('*/api/v2/asset_subscriptions{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetSubscriptionsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetSubscriptionsCreateMockHandler = ( + overrideResponse?: + | AssetSubscriptionResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AssetSubscriptionResponse), +) => { + return http.post('*/api/v2/asset_subscriptions{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetSubscriptionsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetSubscriptionsRetrieveMockHandler = ( + overrideResponse?: + | AssetSubscriptionResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AssetSubscriptionResponse), +) => { + return http.get('*/api/v2/asset_subscriptions/:uidAssetSubscription{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetSubscriptionsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetSubscriptionsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/asset_subscriptions/:uidAssetSubscription{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} +export const getLibraryCollectionsMock = () => [ + getApiV2AssetSubscriptionsListMockHandler(), + getApiV2AssetSubscriptionsCreateMockHandler(), + getApiV2AssetSubscriptionsRetrieveMockHandler(), + getApiV2AssetSubscriptionsDestroyMockHandler(), +] diff --git a/jsapp/js/api/react-query/logging.ts b/jsapp/js/api/react-query/logging/index.ts similarity index 96% rename from jsapp/js/api/react-query/logging.ts rename to jsapp/js/api/react-query/logging/index.ts index 114f17a663..9f5370be03 100644 --- a/jsapp/js/api/react-query/logging.ts +++ b/jsapp/js/api/react-query/logging/index.ts @@ -19,25 +19,25 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { AccessLogsMeListParams } from '../models/accessLogsMeListParams' +import type { AccessLogsMeListParams } from '../../models/accessLogsMeListParams' -import type { AssetsHistoryListParams } from '../models/assetsHistoryListParams' +import type { AssetsHistoryListParams } from '../../models/assetsHistoryListParams' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ExportCreateResponse } from '../models/exportCreateResponse' +import type { ExportCreateResponse } from '../../models/exportCreateResponse' -import type { ExportListResponse } from '../models/exportListResponse' +import type { ExportListResponse } from '../../models/exportListResponse' -import type { HistoryActionResponse } from '../models/historyActionResponse' +import type { HistoryActionResponse } from '../../models/historyActionResponse' -import type { HistoryExportResponse } from '../models/historyExportResponse' +import type { HistoryExportResponse } from '../../models/historyExportResponse' -import type { PaginatedAccessLogResponseList } from '../models/paginatedAccessLogResponseList' +import type { PaginatedAccessLogResponseList } from '../../models/paginatedAccessLogResponseList' -import type { PaginatedHistoryListResponseList } from '../models/paginatedHistoryListResponseList' +import type { PaginatedHistoryListResponseList } from '../../models/paginatedHistoryListResponseList' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/logging/msw.ts b/jsapp/js/api/react-query/logging/msw.ts new file mode 100644 index 0000000000..25a30748e7 --- /dev/null +++ b/jsapp/js/api/react-query/logging/msw.ts @@ -0,0 +1,407 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { ExportCreateResponse } from '../../models/exportCreateResponse' + +import type { ExportListResponse } from '../../models/exportListResponse' + +import type { HistoryActionResponse } from '../../models/historyActionResponse' + +import type { HistoryExportResponse } from '../../models/historyExportResponse' + +import type { PaginatedAccessLogResponseList } from '../../models/paginatedAccessLogResponseList' + +import type { PaginatedHistoryListResponseList } from '../../models/paginatedHistoryListResponseList' + +export const getApiV2AccessLogsMeListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAccessLogResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user: faker.internet.url(), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + metadata: { + source: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + auth_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + ip_address: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + initial_user_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + initial_user_username: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + authorized_app_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + user_uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + action: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + ...overrideResponse, +}) + +export const getApiV2AccessLogsMeExportListResponseMock = (): ExportListResponse[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 24 } }), + status: faker.string.alpha({ length: { min: 10, max: 32 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + })) + +export const getApiV2AccessLogsMeExportCreateResponseMock = ( + overrideResponse: Partial = {}, +): ExportCreateResponse => ({ status: faker.string.alpha({ length: { min: 10, max: 32 } }), ...overrideResponse }) + +export const getApiV2AssetsHistoryListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedHistoryListResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user: faker.internet.url(), + user_uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + action: faker.string.alpha({ length: { min: 10, max: 20 } }), + metadata: { + source: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + old: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + country: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + removed: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + description: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + old: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + 'data-table': faker.helpers.arrayElement([ + { new: faker.helpers.arrayElement([{}, undefined]), old: faker.helpers.arrayElement([{}, undefined]) }, + undefined, + ]), + }, + undefined, + ]), + asset_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + ip_address: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + log_subtype: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + project_owner: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + latest_version_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'asset-files': faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + md5_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + download_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + permissions: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + latest_deployed_version_uid: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + submission: faker.helpers.arrayElement([ + { + root_uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + submitted_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + hook: faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + active: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + endpoint: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + undefined, + ]), + bulk_action: faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + action_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + question_xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + params: faker.helpers.arrayElement([{}, undefined]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + cancelled_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + total_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + processed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + completed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + failed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + cancelled_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + name: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + old: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + shared_fields: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + ...overrideResponse, +}) + +export const getApiV2AssetsHistoryActionsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): HistoryActionResponse => ({ + actions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ...overrideResponse, +}) + +export const getApiV2AssetsHistoryExportCreateResponseMock = ( + overrideResponse: Partial = {}, +): HistoryExportResponse => ({ status: faker.string.alpha({ length: { min: 10, max: 20 } }), ...overrideResponse }) + +export const getApiV2AccessLogsMeListMockHandler = ( + overrideResponse?: + | PaginatedAccessLogResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAccessLogResponseList), +) => { + return http.get('*/api/v2/access-logs/me{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AccessLogsMeListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AccessLogsMeExportListMockHandler = ( + overrideResponse?: + | ExportListResponse[] + | ((info: Parameters[1]>[0]) => Promise | ExportListResponse[]), +) => { + return http.get('*/api/v2/access-logs/me/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AccessLogsMeExportListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AccessLogsMeExportCreateMockHandler = ( + overrideResponse?: + | ExportCreateResponse + | ((info: Parameters[1]>[0]) => Promise | ExportCreateResponse), +) => { + return http.post('*/api/v2/access-logs/me/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AccessLogsMeExportCreateResponseMock(), + ), + { status: 202, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHistoryListMockHandler = ( + overrideResponse?: + | PaginatedHistoryListResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedHistoryListResponseList), +) => { + return http.get('*/api/v2/assets/:uidAsset/history{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHistoryListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHistoryActionsRetrieveMockHandler = ( + overrideResponse?: + | HistoryActionResponse + | ((info: Parameters[1]>[0]) => Promise | HistoryActionResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/history/actions{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHistoryActionsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHistoryExportCreateMockHandler = ( + overrideResponse?: + | HistoryExportResponse + | (( + info: Parameters[1]>[0], + ) => Promise | HistoryExportResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/history/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHistoryExportCreateResponseMock(), + ), + { status: 202, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getLoggingMock = () => [ + getApiV2AccessLogsMeListMockHandler(), + getApiV2AccessLogsMeExportListMockHandler(), + getApiV2AccessLogsMeExportCreateMockHandler(), + getApiV2AssetsHistoryListMockHandler(), + getApiV2AssetsHistoryActionsRetrieveMockHandler(), + getApiV2AssetsHistoryExportCreateMockHandler(), +] diff --git a/jsapp/js/api/react-query/manage-permissions.ts b/jsapp/js/api/react-query/manage-permissions/index.ts similarity index 98% rename from jsapp/js/api/react-query/manage-permissions.ts rename to jsapp/js/api/react-query/manage-permissions/index.ts index 3e82a76189..82b8f5bd55 100644 --- a/jsapp/js/api/react-query/manage-permissions.ts +++ b/jsapp/js/api/react-query/manage-permissions/index.ts @@ -19,19 +19,19 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { PatchedPermissionAssignmentCloneRequest } from '../models/patchedPermissionAssignmentCloneRequest' +import type { PatchedPermissionAssignmentCloneRequest } from '../../models/patchedPermissionAssignmentCloneRequest' -import type { PermissionAssignmentBulkRequest } from '../models/permissionAssignmentBulkRequest' +import type { PermissionAssignmentBulkRequest } from '../../models/permissionAssignmentBulkRequest' -import type { PermissionAssignmentCreateRequest } from '../models/permissionAssignmentCreateRequest' +import type { PermissionAssignmentCreateRequest } from '../../models/permissionAssignmentCreateRequest' -import type { PermissionAssignmentResponse } from '../models/permissionAssignmentResponse' +import type { PermissionAssignmentResponse } from '../../models/permissionAssignmentResponse' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/manage-permissions/msw.ts b/jsapp/js/api/react-query/manage-permissions/msw.ts new file mode 100644 index 0000000000..938e4e54ff --- /dev/null +++ b/jsapp/js/api/react-query/manage-permissions/msw.ts @@ -0,0 +1,196 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { PermissionAssignmentResponse } from '../../models/permissionAssignmentResponse' + +export const getApiV2AssetsPermissionAssignmentsListResponseMock = (): PermissionAssignmentResponse[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + user: faker.internet.url(), + permission: faker.internet.url(), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + })) + +export const getApiV2AssetsPermissionAssignmentsCreateResponseMock = ( + overrideResponse: Partial = {}, +): PermissionAssignmentResponse => ({ + url: faker.internet.url(), + user: faker.internet.url(), + permission: faker.internet.url(), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsPermissionAssignmentsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PermissionAssignmentResponse => ({ + url: faker.internet.url(), + user: faker.internet.url(), + permission: faker.internet.url(), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsPermissionAssignmentsBulkCreateResponseMock = (): PermissionAssignmentResponse[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + user: faker.internet.url(), + permission: faker.internet.url(), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + })) + +export const getApiV2AssetsPermissionAssignmentsClonePartialUpdateResponseMock = (): PermissionAssignmentResponse[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + user: faker.internet.url(), + permission: faker.internet.url(), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + })) + +export const getApiV2AssetsPermissionAssignmentsListMockHandler = ( + overrideResponse?: + | PermissionAssignmentResponse[] + | (( + info: Parameters[1]>[0], + ) => Promise | PermissionAssignmentResponse[]), +) => { + return http.get('*/api/v2/assets/:uidAsset/permission-assignments{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPermissionAssignmentsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPermissionAssignmentsCreateMockHandler = ( + overrideResponse?: + | PermissionAssignmentResponse + | (( + info: Parameters[1]>[0], + ) => Promise | PermissionAssignmentResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/permission-assignments{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPermissionAssignmentsCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPermissionAssignmentsRetrieveMockHandler = ( + overrideResponse?: + | PermissionAssignmentResponse + | (( + info: Parameters[1]>[0], + ) => Promise | PermissionAssignmentResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/permission-assignments/:uidPermissionAssignment{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPermissionAssignmentsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPermissionAssignmentsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/permission-assignments/:uidPermissionAssignment{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsPermissionAssignmentsBulkCreateMockHandler = ( + overrideResponse?: + | PermissionAssignmentResponse[] + | (( + info: Parameters[1]>[0], + ) => Promise | PermissionAssignmentResponse[]), +) => { + return http.post('*/api/v2/assets/:uidAsset/permission-assignments/bulk{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPermissionAssignmentsBulkCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPermissionAssignmentsBulkDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/permission-assignments/bulk{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsPermissionAssignmentsClonePartialUpdateMockHandler = ( + overrideResponse?: + | PermissionAssignmentResponse[] + | (( + info: Parameters[1]>[0], + ) => Promise | PermissionAssignmentResponse[]), +) => { + return http.patch('*/api/v2/assets/:uidAsset/permission-assignments/clone{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPermissionAssignmentsClonePartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getManagePermissionsMock = () => [ + getApiV2AssetsPermissionAssignmentsListMockHandler(), + getApiV2AssetsPermissionAssignmentsCreateMockHandler(), + getApiV2AssetsPermissionAssignmentsRetrieveMockHandler(), + getApiV2AssetsPermissionAssignmentsDestroyMockHandler(), + getApiV2AssetsPermissionAssignmentsBulkCreateMockHandler(), + getApiV2AssetsPermissionAssignmentsBulkDestroyMockHandler(), + getApiV2AssetsPermissionAssignmentsClonePartialUpdateMockHandler(), +] diff --git a/jsapp/js/api/react-query/manage-projects-and-library-content.ts b/jsapp/js/api/react-query/manage-projects-and-library-content/index.ts similarity index 96% rename from jsapp/js/api/react-query/manage-projects-and-library-content.ts rename to jsapp/js/api/react-query/manage-projects-and-library-content/index.ts index 7a58dfdf50..9a964a2818 100644 --- a/jsapp/js/api/react-query/manage-projects-and-library-content.ts +++ b/jsapp/js/api/react-query/manage-projects-and-library-content/index.ts @@ -19,81 +19,81 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { Asset } from '../models/asset' +import type { Asset } from '../../models/asset' -import type { AssetBulkRequest } from '../models/assetBulkRequest' +import type { AssetBulkRequest } from '../../models/assetBulkRequest' -import type { AssetBulkResponse } from '../models/assetBulkResponse' +import type { AssetBulkResponse } from '../../models/assetBulkResponse' -import type { AssetCreateRequest } from '../models/assetCreateRequest' +import type { AssetCreateRequest } from '../../models/assetCreateRequest' -import type { AssetListCount } from '../models/assetListCount' +import type { AssetListCount } from '../../models/assetListCount' -import type { AssetMetadataResponse } from '../models/assetMetadataResponse' +import type { AssetMetadataResponse } from '../../models/assetMetadataResponse' -import type { AssetsCountsListParams } from '../models/assetsCountsListParams' +import type { AssetsCountsListParams } from '../../models/assetsCountsListParams' -import type { AssetsListParams } from '../models/assetsListParams' +import type { AssetsListParams } from '../../models/assetsListParams' -import type { AssetsMinimalListRetrieveParams } from '../models/assetsMinimalListRetrieveParams' +import type { AssetsMinimalListRetrieveParams } from '../../models/assetsMinimalListRetrieveParams' -import type { AssetsRetrieveParams } from '../models/assetsRetrieveParams' +import type { AssetsRetrieveParams } from '../../models/assetsRetrieveParams' -import type { AssetsVersionsListParams } from '../models/assetsVersionsListParams' +import type { AssetsVersionsListParams } from '../../models/assetsVersionsListParams' -import type { DeploymentCreateRequest } from '../models/deploymentCreateRequest' +import type { DeploymentCreateRequest } from '../../models/deploymentCreateRequest' -import type { DeploymentResponse } from '../models/deploymentResponse' +import type { DeploymentResponse } from '../../models/deploymentResponse' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { HashResponse } from '../models/hashResponse' +import type { HashResponse } from '../../models/hashResponse' -import type { ImportCreateRequest } from '../models/importCreateRequest' +import type { ImportCreateRequest } from '../../models/importCreateRequest' -import type { ImportCreateResponse } from '../models/importCreateResponse' +import type { ImportCreateResponse } from '../../models/importCreateResponse' -import type { ImportResponse } from '../models/importResponse' +import type { ImportResponse } from '../../models/importResponse' -import type { ImportsListParams } from '../models/importsListParams' +import type { ImportsListParams } from '../../models/importsListParams' -import type { PaginatedAssetCountResponseList } from '../models/paginatedAssetCountResponseList' +import type { PaginatedAssetCountResponseList } from '../../models/paginatedAssetCountResponseList' -import type { PaginatedAssetList } from '../models/paginatedAssetList' +import type { PaginatedAssetList } from '../../models/paginatedAssetList' -import type { PaginatedAssetMinimalListList } from '../models/paginatedAssetMinimalListList' +import type { PaginatedAssetMinimalListList } from '../../models/paginatedAssetMinimalListList' -import type { PaginatedImportResponseList } from '../models/paginatedImportResponseList' +import type { PaginatedImportResponseList } from '../../models/paginatedImportResponseList' -import type { PaginatedProjectInviteResponseList } from '../models/paginatedProjectInviteResponseList' +import type { PaginatedProjectInviteResponseList } from '../../models/paginatedProjectInviteResponseList' -import type { PaginatedTagListResponseList } from '../models/paginatedTagListResponseList' +import type { PaginatedTagListResponseList } from '../../models/paginatedTagListResponseList' -import type { PaginatedVersionListResponseList } from '../models/paginatedVersionListResponseList' +import type { PaginatedVersionListResponseList } from '../../models/paginatedVersionListResponseList' -import type { PatchedAssetPatchRequest } from '../models/patchedAssetPatchRequest' +import type { PatchedAssetPatchRequest } from '../../models/patchedAssetPatchRequest' -import type { PatchedDeploymentPatchRequest } from '../models/patchedDeploymentPatchRequest' +import type { PatchedDeploymentPatchRequest } from '../../models/patchedDeploymentPatchRequest' -import type { PatchedInviteUpdatePayload } from '../models/patchedInviteUpdatePayload' +import type { PatchedInviteUpdatePayload } from '../../models/patchedInviteUpdatePayload' -import type { ProjectInviteCreatePayload } from '../models/projectInviteCreatePayload' +import type { ProjectInviteCreatePayload } from '../../models/projectInviteCreatePayload' -import type { ProjectInviteResponse } from '../models/projectInviteResponse' +import type { ProjectInviteResponse } from '../../models/projectInviteResponse' -import type { ProjectOwnershipInvitesListParams } from '../models/projectOwnershipInvitesListParams' +import type { ProjectOwnershipInvitesListParams } from '../../models/projectOwnershipInvitesListParams' -import type { TagRetrieveResponse } from '../models/tagRetrieveResponse' +import type { TagRetrieveResponse } from '../../models/tagRetrieveResponse' -import type { TagsListParams } from '../models/tagsListParams' +import type { TagsListParams } from '../../models/tagsListParams' -import type { TransferListResponse } from '../models/transferListResponse' +import type { TransferListResponse } from '../../models/transferListResponse' -import type { VersionRetrieveResponse } from '../models/versionRetrieveResponse' +import type { VersionRetrieveResponse } from '../../models/versionRetrieveResponse' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/manage-projects-and-library-content/msw.ts b/jsapp/js/api/react-query/manage-projects-and-library-content/msw.ts new file mode 100644 index 0000000000..871125f013 --- /dev/null +++ b/jsapp/js/api/react-query/manage-projects-and-library-content/msw.ts @@ -0,0 +1,5006 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { Asset } from '../../models/asset' + +import type { AssetBulkResponse } from '../../models/assetBulkResponse' + +import { AssetDeploymentStatusEnum } from '../../models/assetDeploymentStatusEnum' + +import type { AssetListCount } from '../../models/assetListCount' + +import type { AssetMetadataResponse } from '../../models/assetMetadataResponse' + +import { AssetTypeEnum } from '../../models/assetTypeEnum' + +import type { DeploymentResponse } from '../../models/deploymentResponse' + +import type { HashResponse } from '../../models/hashResponse' + +import type { ImportCreateResponse } from '../../models/importCreateResponse' + +import type { ImportResponse } from '../../models/importResponse' + +import { InviteStatusChoicesEnum } from '../../models/inviteStatusChoicesEnum' + +import type { PaginatedAssetCountResponseList } from '../../models/paginatedAssetCountResponseList' + +import type { PaginatedAssetList } from '../../models/paginatedAssetList' + +import type { PaginatedAssetMinimalListList } from '../../models/paginatedAssetMinimalListList' + +import type { PaginatedImportResponseList } from '../../models/paginatedImportResponseList' + +import type { PaginatedProjectInviteResponseList } from '../../models/paginatedProjectInviteResponseList' + +import type { PaginatedTagListResponseList } from '../../models/paginatedTagListResponseList' + +import type { PaginatedVersionListResponseList } from '../../models/paginatedVersionListResponseList' + +import type { ProjectInviteResponse } from '../../models/projectInviteResponse' + +import type { TagRetrieveResponse } from '../../models/tagRetrieveResponse' + +import type { TransferListResponse } from '../../models/transferListResponse' + +import type { VersionRetrieveResponse } from '../../models/versionRetrieveResponse' + +export const getApiV2AssetsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + parent: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + country: faker.helpers.arrayElement([faker.helpers.arrayElement([[], null]), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + }, + undefined, + ]), + asset_type: faker.helpers.arrayElement(Object.values(AssetTypeEnum)), + files: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + file_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + content: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + })), + summary: { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + lock_all: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + lock_any: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + firsts: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + bad: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + naming_conflicts: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + date_created: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_deployed: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version__content_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + has_deployment: faker.datatype.boolean(), + deployed_version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployed_versions: { + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + previous: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + }, + deployment__links: {}, + deployment__active: faker.datatype.boolean(), + deployment__data_download_links: { + csv_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + geojson: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kml_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + spss_labels: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + xls_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls: faker.string.alpha({ length: { min: 10, max: 20 } }), + zip_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment__last_submission_time: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + null, + ]), + deployment__encrypted: faker.datatype.boolean(), + deployment__uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + report_styles: faker.helpers.arrayElement([ + { + default: faker.helpers.arrayElement([ + { + groupDataBy: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_colors: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translationIndex: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + graphWidth: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + specified: faker.helpers.arrayElement([{}, undefined]), + kuid_names: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + report_custom: faker.helpers.arrayElement([{}, undefined]), + advanced_features: faker.helpers.arrayElement([ + { + transcript: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + translation: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + qual: faker.helpers.arrayElement([ + { + qual_survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + scope: faker.string.alpha({ length: { min: 10, max: 20 } }), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + })), + undefined, + ]), + })), + undefined, + ]), + }, + undefined, + ]), + _version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_styles: faker.helpers.arrayElement([ + { + colorSet: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + querylimit: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + selectedQuestion: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_custom: faker.helpers.arrayElement([{}, undefined]), + content: faker.helpers.arrayElement([ + { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + calculation: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + appearance: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + parameters: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--matrix_list': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-constraint-message': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-items': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--score-choices': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + tags: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + select_from_list_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'body::accept': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + })), + undefined, + ]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $autovalue: faker.string.alpha({ length: { min: 10, max: 20 } }), + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + list_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'media::image': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + form_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--lock_all': faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_language: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + translations_0: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + 'kobo--locking-profiles': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + [faker.string.alphanumeric(5)]: {}, + })), + undefined, + ]), + }, + undefined, + ]), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + embeds: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + analysis_form_json: { + additional_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] as const), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + dtpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + })), + undefined, + ]), + })), + }, + xform_link: faker.internet.url(), + hooks_link: faker.internet.url(), + tag_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls_link: faker.internet.url(), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 255 } }), undefined]), + assignable_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + })), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.string.alpha({ length: { min: 10, max: 20 } }), + permission: faker.string.alpha({ length: { min: 10, max: 20 } }), + partial_permissions: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + })), + undefined, + ]), + label: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + undefined, + ]), + })), + effective_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + codename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + exports: faker.internet.url(), + export_settings: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_xlsx: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + data: faker.internet.url(), + children: { + count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + access_types: faker.helpers.arrayElement([[], null]), + data_sharing: faker.helpers.arrayElement([{}, undefined]), + paired_data: faker.internet.url(), + project_ownership: { + [faker.string.alphanumeric(5)]: {}, + }, + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_modified_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + })), + ...overrideResponse, +}) + +export const getApiV2AssetsCreateResponseMock = (overrideResponse: Partial = {}): Asset => ({ + url: faker.internet.url(), + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + parent: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + country: faker.helpers.arrayElement([faker.helpers.arrayElement([[], null]), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + }, + undefined, + ]), + asset_type: faker.helpers.arrayElement(Object.values(AssetTypeEnum)), + files: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + file_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + content: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + })), + summary: { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + lock_all: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + lock_any: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + firsts: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + bad: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + naming_conflicts: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + date_created: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_deployed: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version__content_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + has_deployment: faker.datatype.boolean(), + deployed_version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployed_versions: { + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + previous: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + }, + deployment__links: {}, + deployment__active: faker.datatype.boolean(), + deployment__data_download_links: { + csv_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + geojson: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kml_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + spss_labels: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + xls_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls: faker.string.alpha({ length: { min: 10, max: 20 } }), + zip_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment__last_submission_time: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + null, + ]), + deployment__encrypted: faker.datatype.boolean(), + deployment__uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + report_styles: faker.helpers.arrayElement([ + { + default: faker.helpers.arrayElement([ + { + groupDataBy: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_colors: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translationIndex: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + graphWidth: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + specified: faker.helpers.arrayElement([{}, undefined]), + kuid_names: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + report_custom: faker.helpers.arrayElement([{}, undefined]), + advanced_features: faker.helpers.arrayElement([ + { + transcript: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + translation: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + qual: faker.helpers.arrayElement([ + { + qual_survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + scope: faker.string.alpha({ length: { min: 10, max: 20 } }), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + })), + undefined, + ]), + })), + undefined, + ]), + }, + undefined, + ]), + _version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_styles: faker.helpers.arrayElement([ + { + colorSet: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + querylimit: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + selectedQuestion: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_custom: faker.helpers.arrayElement([{}, undefined]), + content: faker.helpers.arrayElement([ + { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + calculation: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + appearance: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + parameters: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--matrix_list': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-constraint-message': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-items': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--score-choices': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + tags: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + select_from_list_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'body::accept': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $autovalue: faker.string.alpha({ length: { min: 10, max: 20 } }), + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + list_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'media::image': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + form_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--lock_all': faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_language: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + translations_0: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + 'kobo--locking-profiles': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + [faker.string.alphanumeric(5)]: {}, + })), + undefined, + ]), + }, + undefined, + ]), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + embeds: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + analysis_form_json: { + additional_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] as const), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + dtpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + })), + undefined, + ]), + })), + }, + xform_link: faker.internet.url(), + hooks_link: faker.internet.url(), + tag_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls_link: faker.internet.url(), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 255 } }), undefined]), + assignable_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + })), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.string.alpha({ length: { min: 10, max: 20 } }), + permission: faker.string.alpha({ length: { min: 10, max: 20 } }), + partial_permissions: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + })), + undefined, + ]), + label: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + undefined, + ]), + })), + effective_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + codename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + exports: faker.internet.url(), + export_settings: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_xlsx: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + data: faker.internet.url(), + children: { + count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + access_types: faker.helpers.arrayElement([[], null]), + data_sharing: faker.helpers.arrayElement([{}, undefined]), + paired_data: faker.internet.url(), + project_ownership: { + [faker.string.alphanumeric(5)]: {}, + }, + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_modified_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ...overrideResponse, +}) + +export const getApiV2AssetsRetrieveResponseMock = (overrideResponse: Partial = {}): Asset => ({ + url: faker.internet.url(), + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + parent: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + country: faker.helpers.arrayElement([faker.helpers.arrayElement([[], null]), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + }, + undefined, + ]), + asset_type: faker.helpers.arrayElement(Object.values(AssetTypeEnum)), + files: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + file_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + content: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + })), + summary: { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + lock_all: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + lock_any: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + firsts: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + bad: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + naming_conflicts: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + date_created: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_deployed: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version__content_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + has_deployment: faker.datatype.boolean(), + deployed_version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployed_versions: { + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + previous: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + }, + deployment__links: {}, + deployment__active: faker.datatype.boolean(), + deployment__data_download_links: { + csv_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + geojson: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kml_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + spss_labels: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + xls_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls: faker.string.alpha({ length: { min: 10, max: 20 } }), + zip_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment__last_submission_time: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + null, + ]), + deployment__encrypted: faker.datatype.boolean(), + deployment__uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + report_styles: faker.helpers.arrayElement([ + { + default: faker.helpers.arrayElement([ + { + groupDataBy: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_colors: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translationIndex: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + graphWidth: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + specified: faker.helpers.arrayElement([{}, undefined]), + kuid_names: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + report_custom: faker.helpers.arrayElement([{}, undefined]), + advanced_features: faker.helpers.arrayElement([ + { + transcript: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + translation: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + qual: faker.helpers.arrayElement([ + { + qual_survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + scope: faker.string.alpha({ length: { min: 10, max: 20 } }), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + })), + undefined, + ]), + })), + undefined, + ]), + }, + undefined, + ]), + _version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_styles: faker.helpers.arrayElement([ + { + colorSet: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + querylimit: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + selectedQuestion: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_custom: faker.helpers.arrayElement([{}, undefined]), + content: faker.helpers.arrayElement([ + { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + calculation: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + appearance: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + parameters: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--matrix_list': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-constraint-message': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-items': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--score-choices': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + tags: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + select_from_list_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'body::accept': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $autovalue: faker.string.alpha({ length: { min: 10, max: 20 } }), + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + list_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'media::image': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + form_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--lock_all': faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_language: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + translations_0: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + 'kobo--locking-profiles': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + [faker.string.alphanumeric(5)]: {}, + })), + undefined, + ]), + }, + undefined, + ]), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + embeds: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + analysis_form_json: { + additional_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] as const), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + dtpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + })), + undefined, + ]), + })), + }, + xform_link: faker.internet.url(), + hooks_link: faker.internet.url(), + tag_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls_link: faker.internet.url(), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 255 } }), undefined]), + assignable_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + })), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.string.alpha({ length: { min: 10, max: 20 } }), + permission: faker.string.alpha({ length: { min: 10, max: 20 } }), + partial_permissions: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + })), + undefined, + ]), + label: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + undefined, + ]), + })), + effective_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + codename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + exports: faker.internet.url(), + export_settings: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_xlsx: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + data: faker.internet.url(), + children: { + count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + access_types: faker.helpers.arrayElement([[], null]), + data_sharing: faker.helpers.arrayElement([{}, undefined]), + paired_data: faker.internet.url(), + project_ownership: { + [faker.string.alphanumeric(5)]: {}, + }, + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_modified_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ...overrideResponse, +}) + +export const getApiV2AssetsPartialUpdateResponseMock = (overrideResponse: Partial = {}): Asset => ({ + url: faker.internet.url(), + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + parent: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + country: faker.helpers.arrayElement([faker.helpers.arrayElement([[], null]), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + }, + undefined, + ]), + asset_type: faker.helpers.arrayElement(Object.values(AssetTypeEnum)), + files: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + file_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + content: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + })), + summary: { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + lock_all: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + lock_any: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + firsts: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + bad: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + naming_conflicts: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + date_created: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_deployed: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version__content_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + has_deployment: faker.datatype.boolean(), + deployed_version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployed_versions: { + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + previous: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + }, + deployment__links: {}, + deployment__active: faker.datatype.boolean(), + deployment__data_download_links: { + csv_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + geojson: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kml_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + spss_labels: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + xls_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls: faker.string.alpha({ length: { min: 10, max: 20 } }), + zip_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment__last_submission_time: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + null, + ]), + deployment__encrypted: faker.datatype.boolean(), + deployment__uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + report_styles: faker.helpers.arrayElement([ + { + default: faker.helpers.arrayElement([ + { + groupDataBy: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_colors: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translationIndex: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + graphWidth: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + specified: faker.helpers.arrayElement([{}, undefined]), + kuid_names: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + report_custom: faker.helpers.arrayElement([{}, undefined]), + advanced_features: faker.helpers.arrayElement([ + { + transcript: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + translation: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + qual: faker.helpers.arrayElement([ + { + qual_survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + scope: faker.string.alpha({ length: { min: 10, max: 20 } }), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + })), + undefined, + ]), + })), + undefined, + ]), + }, + undefined, + ]), + _version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_styles: faker.helpers.arrayElement([ + { + colorSet: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + querylimit: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + selectedQuestion: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_custom: faker.helpers.arrayElement([{}, undefined]), + content: faker.helpers.arrayElement([ + { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + calculation: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + appearance: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + parameters: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--matrix_list': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-constraint-message': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-items': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--score-choices': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + tags: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + select_from_list_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'body::accept': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $autovalue: faker.string.alpha({ length: { min: 10, max: 20 } }), + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + list_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'media::image': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + form_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--lock_all': faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_language: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + translations_0: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + 'kobo--locking-profiles': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + [faker.string.alphanumeric(5)]: {}, + })), + undefined, + ]), + }, + undefined, + ]), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + embeds: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + analysis_form_json: { + additional_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] as const), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + dtpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + })), + undefined, + ]), + })), + }, + xform_link: faker.internet.url(), + hooks_link: faker.internet.url(), + tag_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls_link: faker.internet.url(), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 255 } }), undefined]), + assignable_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + })), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.string.alpha({ length: { min: 10, max: 20 } }), + permission: faker.string.alpha({ length: { min: 10, max: 20 } }), + partial_permissions: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + })), + undefined, + ]), + label: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + undefined, + ]), + })), + effective_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + codename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + exports: faker.internet.url(), + export_settings: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_xlsx: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + data: faker.internet.url(), + children: { + count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + access_types: faker.helpers.arrayElement([[], null]), + data_sharing: faker.helpers.arrayElement([{}, undefined]), + paired_data: faker.internet.url(), + project_ownership: { + [faker.string.alphanumeric(5)]: {}, + }, + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_modified_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ...overrideResponse, +}) + +export const getApiV2AssetsCountsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetCountResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + daily_submission_count: { + '2020-10-20': faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + total_submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + })), + ...overrideResponse, +}) + +export const getApiV2AssetsDeploymentRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): DeploymentResponse => ({ + backend: faker.string.alpha({ length: { min: 10, max: 20 } }), + active: faker.datatype.boolean(), + version_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + asset: { + url: faker.internet.url(), + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + parent: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + country: faker.helpers.arrayElement([faker.helpers.arrayElement([[], null]), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + }, + undefined, + ]), + asset_type: faker.helpers.arrayElement(Object.values(AssetTypeEnum)), + files: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + file_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + content: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + })), + summary: { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + lock_all: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + lock_any: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + firsts: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + bad: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + naming_conflicts: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + date_created: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_deployed: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version__content_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + has_deployment: faker.datatype.boolean(), + deployed_version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployed_versions: { + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + previous: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + }, + deployment__links: {}, + deployment__active: faker.datatype.boolean(), + deployment__data_download_links: { + csv_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + geojson: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kml_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + spss_labels: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + xls_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls: faker.string.alpha({ length: { min: 10, max: 20 } }), + zip_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment__last_submission_time: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + null, + ]), + deployment__encrypted: faker.datatype.boolean(), + deployment__uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + report_styles: faker.helpers.arrayElement([ + { + default: faker.helpers.arrayElement([ + { + groupDataBy: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_colors: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translationIndex: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + graphWidth: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + specified: faker.helpers.arrayElement([{}, undefined]), + kuid_names: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + report_custom: faker.helpers.arrayElement([{}, undefined]), + advanced_features: faker.helpers.arrayElement([ + { + transcript: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + translation: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + qual: faker.helpers.arrayElement([ + { + qual_survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + scope: faker.string.alpha({ length: { min: 10, max: 20 } }), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + })), + undefined, + ]), + })), + undefined, + ]), + }, + undefined, + ]), + _version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_styles: faker.helpers.arrayElement([ + { + colorSet: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + querylimit: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + selectedQuestion: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_custom: faker.helpers.arrayElement([{}, undefined]), + content: faker.helpers.arrayElement([ + { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + calculation: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + appearance: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + parameters: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--matrix_list': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-constraint-message': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-items': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--score-choices': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + tags: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + select_from_list_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'body::accept': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + })), + undefined, + ]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $autovalue: faker.string.alpha({ length: { min: 10, max: 20 } }), + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + list_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'media::image': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + form_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--lock_all': faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_language: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + translations_0: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + 'kobo--locking-profiles': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + [faker.string.alphanumeric(5)]: {}, + })), + undefined, + ]), + }, + undefined, + ]), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + embeds: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + analysis_form_json: { + additional_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] as const), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + dtpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + })), + undefined, + ]), + })), + }, + xform_link: faker.internet.url(), + hooks_link: faker.internet.url(), + tag_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls_link: faker.internet.url(), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 255 } }), undefined]), + assignable_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + })), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.string.alpha({ length: { min: 10, max: 20 } }), + permission: faker.string.alpha({ length: { min: 10, max: 20 } }), + partial_permissions: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + })), + undefined, + ]), + label: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + undefined, + ]), + })), + effective_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + codename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + exports: faker.internet.url(), + export_settings: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_xlsx: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + data: faker.internet.url(), + children: { + count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + access_types: faker.helpers.arrayElement([[], null]), + data_sharing: faker.helpers.arrayElement([{}, undefined]), + paired_data: faker.internet.url(), + project_ownership: { + [faker.string.alphanumeric(5)]: {}, + }, + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_modified_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDeploymentCreateResponseMock = ( + overrideResponse: Partial = {}, +): DeploymentResponse => ({ + backend: faker.string.alpha({ length: { min: 10, max: 20 } }), + active: faker.datatype.boolean(), + version_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + asset: { + url: faker.internet.url(), + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + parent: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + country: faker.helpers.arrayElement([faker.helpers.arrayElement([[], null]), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + }, + undefined, + ]), + asset_type: faker.helpers.arrayElement(Object.values(AssetTypeEnum)), + files: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + file_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + content: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + })), + summary: { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + lock_all: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + lock_any: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + firsts: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + bad: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + naming_conflicts: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + date_created: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_deployed: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version__content_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + has_deployment: faker.datatype.boolean(), + deployed_version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployed_versions: { + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + previous: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + }, + deployment__links: {}, + deployment__active: faker.datatype.boolean(), + deployment__data_download_links: { + csv_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + geojson: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kml_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + spss_labels: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + xls_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls: faker.string.alpha({ length: { min: 10, max: 20 } }), + zip_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment__last_submission_time: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + null, + ]), + deployment__encrypted: faker.datatype.boolean(), + deployment__uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + report_styles: faker.helpers.arrayElement([ + { + default: faker.helpers.arrayElement([ + { + groupDataBy: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_colors: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translationIndex: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + graphWidth: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + specified: faker.helpers.arrayElement([{}, undefined]), + kuid_names: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + report_custom: faker.helpers.arrayElement([{}, undefined]), + advanced_features: faker.helpers.arrayElement([ + { + transcript: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + translation: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + qual: faker.helpers.arrayElement([ + { + qual_survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + scope: faker.string.alpha({ length: { min: 10, max: 20 } }), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + })), + undefined, + ]), + })), + undefined, + ]), + }, + undefined, + ]), + _version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_styles: faker.helpers.arrayElement([ + { + colorSet: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + querylimit: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + selectedQuestion: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_custom: faker.helpers.arrayElement([{}, undefined]), + content: faker.helpers.arrayElement([ + { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + calculation: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + appearance: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + parameters: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--matrix_list': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-constraint-message': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-items': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--score-choices': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + tags: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + select_from_list_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'body::accept': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + })), + undefined, + ]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $autovalue: faker.string.alpha({ length: { min: 10, max: 20 } }), + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + list_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'media::image': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + form_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--lock_all': faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_language: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + translations_0: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + 'kobo--locking-profiles': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + [faker.string.alphanumeric(5)]: {}, + })), + undefined, + ]), + }, + undefined, + ]), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + embeds: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + analysis_form_json: { + additional_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] as const), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + dtpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + })), + undefined, + ]), + })), + }, + xform_link: faker.internet.url(), + hooks_link: faker.internet.url(), + tag_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls_link: faker.internet.url(), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 255 } }), undefined]), + assignable_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + })), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.string.alpha({ length: { min: 10, max: 20 } }), + permission: faker.string.alpha({ length: { min: 10, max: 20 } }), + partial_permissions: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + })), + undefined, + ]), + label: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + undefined, + ]), + })), + effective_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + codename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + exports: faker.internet.url(), + export_settings: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_xlsx: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + data: faker.internet.url(), + children: { + count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + access_types: faker.helpers.arrayElement([[], null]), + data_sharing: faker.helpers.arrayElement([{}, undefined]), + paired_data: faker.internet.url(), + project_ownership: { + [faker.string.alphanumeric(5)]: {}, + }, + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_modified_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDeploymentPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): DeploymentResponse => ({ + backend: faker.string.alpha({ length: { min: 10, max: 20 } }), + active: faker.datatype.boolean(), + version_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + asset: { + url: faker.internet.url(), + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + parent: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + country: faker.helpers.arrayElement([faker.helpers.arrayElement([[], null]), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + }, + undefined, + ]), + asset_type: faker.helpers.arrayElement(Object.values(AssetTypeEnum)), + files: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + file_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + content: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + })), + summary: { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + lock_all: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + lock_any: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + firsts: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + bad: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + naming_conflicts: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + date_created: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_deployed: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version__content_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + has_deployment: faker.datatype.boolean(), + deployed_version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployed_versions: { + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + previous: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + }, + deployment__links: {}, + deployment__active: faker.datatype.boolean(), + deployment__data_download_links: { + csv_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + geojson: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kml_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + spss_labels: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + xls_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls: faker.string.alpha({ length: { min: 10, max: 20 } }), + zip_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment__last_submission_time: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + null, + ]), + deployment__encrypted: faker.datatype.boolean(), + deployment__uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + report_styles: faker.helpers.arrayElement([ + { + default: faker.helpers.arrayElement([ + { + groupDataBy: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_colors: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translationIndex: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + graphWidth: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + specified: faker.helpers.arrayElement([{}, undefined]), + kuid_names: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + report_custom: faker.helpers.arrayElement([{}, undefined]), + advanced_features: faker.helpers.arrayElement([ + { + transcript: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + translation: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + qual: faker.helpers.arrayElement([ + { + qual_survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + scope: faker.string.alpha({ length: { min: 10, max: 20 } }), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + })), + undefined, + ]), + })), + undefined, + ]), + }, + undefined, + ]), + _version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_styles: faker.helpers.arrayElement([ + { + colorSet: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + querylimit: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + selectedQuestion: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_custom: faker.helpers.arrayElement([{}, undefined]), + content: faker.helpers.arrayElement([ + { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + calculation: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + appearance: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + parameters: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--matrix_list': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-constraint-message': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-items': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--score-choices': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + tags: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + select_from_list_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'body::accept': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + })), + undefined, + ]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $autovalue: faker.string.alpha({ length: { min: 10, max: 20 } }), + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + list_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'media::image': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + form_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--lock_all': faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_language: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + translations_0: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + 'kobo--locking-profiles': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + [faker.string.alphanumeric(5)]: {}, + })), + undefined, + ]), + }, + undefined, + ]), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + embeds: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + analysis_form_json: { + additional_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] as const), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + dtpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + })), + undefined, + ]), + })), + }, + xform_link: faker.internet.url(), + hooks_link: faker.internet.url(), + tag_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls_link: faker.internet.url(), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 255 } }), undefined]), + assignable_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + })), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.string.alpha({ length: { min: 10, max: 20 } }), + permission: faker.string.alpha({ length: { min: 10, max: 20 } }), + partial_permissions: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + })), + undefined, + ]), + label: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + undefined, + ]), + })), + effective_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + codename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + exports: faker.internet.url(), + export_settings: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_xlsx: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + data: faker.internet.url(), + children: { + count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + access_types: faker.helpers.arrayElement([[], null]), + data_sharing: faker.helpers.arrayElement([{}, undefined]), + paired_data: faker.internet.url(), + project_ownership: { + [faker.string.alphanumeric(5)]: {}, + }, + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_modified_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsVersionsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedVersionListResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + ...overrideResponse, +}) + +export const getApiV2AssetsVersionsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): VersionRetrieveResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + content: { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $kuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + default_language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translation: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsXformRetrieveResponseMock = (): string => faker.word.sample() + +export const getApiV2AssetsBulkCreateResponseMock = ( + overrideResponse: Partial = {}, +): AssetBulkResponse => ({ detail: faker.string.alpha({ length: { min: 10, max: 20 } }), ...overrideResponse }) + +export const getApiV2AssetsCountsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): AssetListCount => ({ + deployed_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + archived_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + draft_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + ...overrideResponse, +}) + +export const getApiV2AssetsHashRetrieveResponseMock = (overrideResponse: Partial = {}): HashResponse => ({ + hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsMetadataRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): AssetMetadataResponse => ({ + languages: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + countries: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ), + sectors: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ), + organizations: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ...overrideResponse, +}) + +export const getApiV2AssetsMinimalListRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetMinimalListList => ({ + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 22 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + })), + ...overrideResponse, +}) + +export const getApiV2ImportsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedImportResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + messages: { + updated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kind: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + summary: faker.helpers.arrayElement([ + { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + language: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + first: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + undefined, + ]), + owner__username: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + })), + undefined, + ]), + 'audit-logs': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + source: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset_id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + new_name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + old_name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + ip_address: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + project_owner: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + latest_version_uid: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + })), + undefined, + ]), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + error_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + ...overrideResponse, +}) + +export const getApiV2ImportsCreateResponseMock = ( + overrideResponse: Partial = {}, +): ImportCreateResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2ImportsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ImportResponse => ({ + url: faker.internet.url(), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + messages: { + updated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kind: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + summary: faker.helpers.arrayElement([ + { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + language: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + first: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + undefined, + ]), + owner__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + 'audit-logs': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + source: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset_id: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + new_name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + old_name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + ip_address: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + project_owner: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + latest_version_uid: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + })), + undefined, + ]), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + error_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + ...overrideResponse, +}) + +export const getApiV2ProjectOwnershipInvitesListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedProjectInviteResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + 'sender | recipient': faker.internet.url(), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + transfers: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + asset: faker.helpers.arrayElement([faker.internet.url(), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + })), + })), + ...overrideResponse, +}) + +export const getApiV2ProjectOwnershipInvitesCreateResponseMock = ( + overrideResponse: Partial = {}, +): ProjectInviteResponse => ({ + url: faker.internet.url(), + 'sender | recipient': faker.internet.url(), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + transfers: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + asset: faker.helpers.arrayElement([faker.internet.url(), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + })), + ...overrideResponse, +}) + +export const getApiV2ProjectOwnershipInvitesRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ProjectInviteResponse => ({ + url: faker.internet.url(), + 'sender | recipient': faker.internet.url(), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + transfers: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + asset: faker.helpers.arrayElement([faker.internet.url(), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + })), + ...overrideResponse, +}) + +export const getApiV2ProjectOwnershipInvitesPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): ProjectInviteResponse => ({ + url: faker.internet.url(), + 'sender | recipient': faker.internet.url(), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + transfers: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + asset: faker.helpers.arrayElement([faker.internet.url(), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + })), + ...overrideResponse, +}) + +export const getApiV2ProjectOwnershipInvitesTransfersRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): TransferListResponse => ({ + url: faker.internet.url(), + asset: faker.internet.url(), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + error: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + statuses: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + ...overrideResponse, +}) + +export const getApiV2TagsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedTagListResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + })), + ...overrideResponse, +}) + +export const getApiV2TagsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): TagRetrieveResponse => ({ + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + assets: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.internet.url(), + ), + parent: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsListMockHandler = ( + overrideResponse?: + | PaginatedAssetList + | ((info: Parameters[1]>[0]) => Promise | PaginatedAssetList), +) => { + return http.get('*/api/v2/assets{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsCreateMockHandler = ( + overrideResponse?: Asset | ((info: Parameters[1]>[0]) => Promise | Asset), +) => { + return http.post('*/api/v2/assets{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsRetrieveMockHandler = ( + overrideResponse?: Asset | ((info: Parameters[1]>[0]) => Promise | Asset), +) => { + return http.get('*/api/v2/assets/:uidAsset{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPartialUpdateMockHandler = ( + overrideResponse?: Asset | ((info: Parameters[1]>[0]) => Promise | Asset), +) => { + return http.patch('*/api/v2/assets/:uidAsset{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsCountsListMockHandler = ( + overrideResponse?: + | PaginatedAssetCountResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAssetCountResponseList), +) => { + return http.get('*/api/v2/assets/:uidAsset/counts{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsCountsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDeploymentRetrieveMockHandler = ( + overrideResponse?: + | DeploymentResponse + | ((info: Parameters[1]>[0]) => Promise | DeploymentResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/deployment{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDeploymentRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDeploymentCreateMockHandler = ( + overrideResponse?: + | DeploymentResponse + | ((info: Parameters[1]>[0]) => Promise | DeploymentResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/deployment{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDeploymentCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDeploymentPartialUpdateMockHandler = ( + overrideResponse?: + | DeploymentResponse + | ((info: Parameters[1]>[0]) => Promise | DeploymentResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/deployment{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDeploymentPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsVersionsListMockHandler = ( + overrideResponse?: + | PaginatedVersionListResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedVersionListResponseList), +) => { + return http.get('*/api/v2/assets/:uidAsset/versions{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsVersionsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsVersionsRetrieveMockHandler = ( + overrideResponse?: + | VersionRetrieveResponse + | (( + info: Parameters[1]>[0], + ) => Promise | VersionRetrieveResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/versions/:uidVersion{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsVersionsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsXformRetrieveMockHandler = ( + overrideResponse?: string | ((info: Parameters[1]>[0]) => Promise | string), +) => { + return http.get('*/api/v2/assets/:uidAsset/xform{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsXformRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsBulkCreateMockHandler = ( + overrideResponse?: + | AssetBulkResponse + | ((info: Parameters[1]>[0]) => Promise | AssetBulkResponse), +) => { + return http.post('*/api/v2/assets/bulk{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsBulkCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsCountsRetrieveMockHandler = ( + overrideResponse?: + | AssetListCount + | ((info: Parameters[1]>[0]) => Promise | AssetListCount), +) => { + return http.get('*/api/v2/assets/counts{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsCountsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHashRetrieveMockHandler = ( + overrideResponse?: + | HashResponse + | ((info: Parameters[1]>[0]) => Promise | HashResponse), +) => { + return http.get('*/api/v2/assets/hash{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHashRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsMetadataRetrieveMockHandler = ( + overrideResponse?: + | AssetMetadataResponse + | ((info: Parameters[1]>[0]) => Promise | AssetMetadataResponse), +) => { + return http.get('*/api/v2/assets/metadata{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsMetadataRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsMinimalListRetrieveMockHandler = ( + overrideResponse?: + | PaginatedAssetMinimalListList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAssetMinimalListList), +) => { + return http.get('*/api/v2/assets/minimal-list{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsMinimalListRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ImportsListMockHandler = ( + overrideResponse?: + | PaginatedImportResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedImportResponseList), +) => { + return http.get('*/api/v2/imports{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ImportsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ImportsCreateMockHandler = ( + overrideResponse?: + | ImportCreateResponse + | ((info: Parameters[1]>[0]) => Promise | ImportCreateResponse), +) => { + return http.post('*/api/v2/imports{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ImportsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ImportsRetrieveMockHandler = ( + overrideResponse?: + | ImportResponse + | ((info: Parameters[1]>[0]) => Promise | ImportResponse), +) => { + return http.get('*/api/v2/imports/:uidImport{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ImportsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectOwnershipInvitesListMockHandler = ( + overrideResponse?: + | PaginatedProjectInviteResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedProjectInviteResponseList), +) => { + return http.get('*/api/v2/project-ownership/invites{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectOwnershipInvitesListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectOwnershipInvitesCreateMockHandler = ( + overrideResponse?: + | ProjectInviteResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProjectInviteResponse), +) => { + return http.post('*/api/v2/project-ownership/invites{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectOwnershipInvitesCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectOwnershipInvitesRetrieveMockHandler = ( + overrideResponse?: + | ProjectInviteResponse + | ((info: Parameters[1]>[0]) => Promise | ProjectInviteResponse), +) => { + return http.get('*/api/v2/project-ownership/invites/:uidInvite{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectOwnershipInvitesRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectOwnershipInvitesPartialUpdateMockHandler = ( + overrideResponse?: + | ProjectInviteResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProjectInviteResponse), +) => { + return http.patch('*/api/v2/project-ownership/invites/:uidInvite{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectOwnershipInvitesPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectOwnershipInvitesDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/project-ownership/invites/:uidInvite{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2ProjectOwnershipInvitesTransfersRetrieveMockHandler = ( + overrideResponse?: + | TransferListResponse + | ((info: Parameters[1]>[0]) => Promise | TransferListResponse), +) => { + return http.get('*/api/v2/project-ownership/invites/:uidInvite/transfers/:uidTransfer{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectOwnershipInvitesTransfersRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2TagsListMockHandler = ( + overrideResponse?: + | PaginatedTagListResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedTagListResponseList), +) => { + return http.get('*/api/v2/tags{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2TagsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2TagsRetrieveMockHandler = ( + overrideResponse?: + | TagRetrieveResponse + | ((info: Parameters[1]>[0]) => Promise | TagRetrieveResponse), +) => { + return http.get('*/api/v2/tags/:taguidUid{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2TagsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getManageProjectsAndLibraryContentMock = () => [ + getApiV2AssetsListMockHandler(), + getApiV2AssetsCreateMockHandler(), + getApiV2AssetsRetrieveMockHandler(), + getApiV2AssetsPartialUpdateMockHandler(), + getApiV2AssetsDestroyMockHandler(), + getApiV2AssetsCountsListMockHandler(), + getApiV2AssetsDeploymentRetrieveMockHandler(), + getApiV2AssetsDeploymentCreateMockHandler(), + getApiV2AssetsDeploymentPartialUpdateMockHandler(), + getApiV2AssetsVersionsListMockHandler(), + getApiV2AssetsVersionsRetrieveMockHandler(), + getApiV2AssetsXformRetrieveMockHandler(), + getApiV2AssetsBulkCreateMockHandler(), + getApiV2AssetsCountsRetrieveMockHandler(), + getApiV2AssetsHashRetrieveMockHandler(), + getApiV2AssetsMetadataRetrieveMockHandler(), + getApiV2AssetsMinimalListRetrieveMockHandler(), + getApiV2ImportsListMockHandler(), + getApiV2ImportsCreateMockHandler(), + getApiV2ImportsRetrieveMockHandler(), + getApiV2ProjectOwnershipInvitesListMockHandler(), + getApiV2ProjectOwnershipInvitesCreateMockHandler(), + getApiV2ProjectOwnershipInvitesRetrieveMockHandler(), + getApiV2ProjectOwnershipInvitesPartialUpdateMockHandler(), + getApiV2ProjectOwnershipInvitesDestroyMockHandler(), + getApiV2ProjectOwnershipInvitesTransfersRetrieveMockHandler(), + getApiV2TagsListMockHandler(), + getApiV2TagsRetrieveMockHandler(), +] diff --git a/jsapp/js/api/react-query/other.ts b/jsapp/js/api/react-query/other/index.ts similarity index 96% rename from jsapp/js/api/react-query/other.ts rename to jsapp/js/api/react-query/other/index.ts index ad79449a4c..90e69d0c30 100644 --- a/jsapp/js/api/react-query/other.ts +++ b/jsapp/js/api/react-query/other/index.ts @@ -19,61 +19,61 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { ChangePlan } from '../models/changePlan' +import type { ChangePlan } from '../../models/changePlan' -import type { CheckoutLink } from '../models/checkoutLink' +import type { CheckoutLink } from '../../models/checkoutLink' -import type { CustomerPortal } from '../models/customerPortal' +import type { CustomerPortal } from '../../models/customerPortal' -import type { CustomerPortalPostResponse } from '../models/customerPortalPostResponse' +import type { CustomerPortalPostResponse } from '../../models/customerPortalPostResponse' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { Language } from '../models/language' +import type { Language } from '../../models/language' -import type { LanguagesListParams } from '../models/languagesListParams' +import type { LanguagesListParams } from '../../models/languagesListParams' -import type { OneTimeAddOn } from '../models/oneTimeAddOn' +import type { OneTimeAddOn } from '../../models/oneTimeAddOn' -import type { PaginatedLanguageListList } from '../models/paginatedLanguageListList' +import type { PaginatedLanguageListList } from '../../models/paginatedLanguageListList' -import type { PaginatedOneTimeAddOnList } from '../models/paginatedOneTimeAddOnList' +import type { PaginatedOneTimeAddOnList } from '../../models/paginatedOneTimeAddOnList' -import type { PaginatedPermissionResponseList } from '../models/paginatedPermissionResponseList' +import type { PaginatedPermissionResponseList } from '../../models/paginatedPermissionResponseList' -import type { PaginatedProductList } from '../models/paginatedProductList' +import type { PaginatedProductList } from '../../models/paginatedProductList' -import type { PaginatedSubscriptionList } from '../models/paginatedSubscriptionList' +import type { PaginatedSubscriptionList } from '../../models/paginatedSubscriptionList' -import type { PaginatedTranscriptionServiceList } from '../models/paginatedTranscriptionServiceList' +import type { PaginatedTranscriptionServiceList } from '../../models/paginatedTranscriptionServiceList' -import type { PaginatedTranslationServiceList } from '../models/paginatedTranslationServiceList' +import type { PaginatedTranslationServiceList } from '../../models/paginatedTranslationServiceList' -import type { PermissionResponse } from '../models/permissionResponse' +import type { PermissionResponse } from '../../models/permissionResponse' -import type { PermissionsListParams } from '../models/permissionsListParams' +import type { PermissionsListParams } from '../../models/permissionsListParams' -import type { StripeAddonsListParams } from '../models/stripeAddonsListParams' +import type { StripeAddonsListParams } from '../../models/stripeAddonsListParams' -import type { StripeProductsListParams } from '../models/stripeProductsListParams' +import type { StripeProductsListParams } from '../../models/stripeProductsListParams' -import type { StripeSubscriptionsListParams } from '../models/stripeSubscriptionsListParams' +import type { StripeSubscriptionsListParams } from '../../models/stripeSubscriptionsListParams' -import type { Subscription } from '../models/subscription' +import type { Subscription } from '../../models/subscription' -import type { TermsOfServiceResponse } from '../models/termsOfServiceResponse' +import type { TermsOfServiceResponse } from '../../models/termsOfServiceResponse' -import type { TranscriptionService } from '../models/transcriptionService' +import type { TranscriptionService } from '../../models/transcriptionService' -import type { TranscriptionServicesListParams } from '../models/transcriptionServicesListParams' +import type { TranscriptionServicesListParams } from '../../models/transcriptionServicesListParams' -import type { TranslationService } from '../models/translationService' +import type { TranslationService } from '../../models/translationService' -import type { TranslationServicesListParams } from '../models/translationServicesListParams' +import type { TranslationServicesListParams } from '../../models/translationServicesListParams' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/other/msw.ts b/jsapp/js/api/react-query/other/msw.ts new file mode 100644 index 0000000000..de2cdd0fcc --- /dev/null +++ b/jsapp/js/api/react-query/other/msw.ts @@ -0,0 +1,1051 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import { BlankEnum } from '../../models/blankEnum' + +import type { ChangePlan } from '../../models/changePlan' + +import type { CheckoutLink } from '../../models/checkoutLink' + +import { CollectionMethodEnum } from '../../models/collectionMethodEnum' + +import type { CustomerPortalPostResponse } from '../../models/customerPortalPostResponse' + +import type { Language } from '../../models/language' + +import type { OneTimeAddOn } from '../../models/oneTimeAddOn' + +import type { PaginatedLanguageListList } from '../../models/paginatedLanguageListList' + +import type { PaginatedOneTimeAddOnList } from '../../models/paginatedOneTimeAddOnList' + +import type { PaginatedPermissionResponseList } from '../../models/paginatedPermissionResponseList' + +import type { PaginatedProductList } from '../../models/paginatedProductList' + +import type { PaginatedSubscriptionList } from '../../models/paginatedSubscriptionList' + +import type { PaginatedTranscriptionServiceList } from '../../models/paginatedTranscriptionServiceList' + +import type { PaginatedTranslationServiceList } from '../../models/paginatedTranslationServiceList' + +import type { PermissionResponse } from '../../models/permissionResponse' + +import { ProrationBehaviorEnum } from '../../models/prorationBehaviorEnum' + +import { StripeIntervalEnum } from '../../models/stripeIntervalEnum' + +import { StripePriceType } from '../../models/stripePriceType' + +import { StripeProductType } from '../../models/stripeProductType' + +import { StripeUsageType } from '../../models/stripeUsageType' + +import type { Subscription } from '../../models/subscription' + +import { SubscriptionScheduleStatusEnum } from '../../models/subscriptionScheduleStatusEnum' + +import { SubscriptionStatusEnum } from '../../models/subscriptionStatusEnum' + +import type { TermsOfServiceResponse } from '../../models/termsOfServiceResponse' + +import type { TranscriptionService } from '../../models/transcriptionService' + +import type { TranslationService } from '../../models/translationService' + +export const getApiV2LanguagesListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedLanguageListList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 200 } }), + code: faker.string.alpha({ length: { min: 10, max: 10 } }), + featured: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + transcription_services: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + code: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + translation_services: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + code: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + url: faker.internet.url(), + })), + ...overrideResponse, +}) + +export const getApiV2LanguagesRetrieveResponseMock = (overrideResponse: Partial = {}): Language => ({ + name: faker.string.alpha({ length: { min: 10, max: 200 } }), + code: faker.string.alpha({ length: { min: 10, max: 10 } }), + featured: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + transcription_services: { + [faker.string.alphanumeric(5)]: { + [faker.string.alphanumeric(5)]: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + translation_services: { + [faker.string.alphanumeric(5)]: { + [faker.string.alphanumeric(5)]: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + regions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + code: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 200 } }), + })), + ...overrideResponse, +}) + +export const getApiV2PermissionsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedPermissionResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + codename: faker.string.alpha({ length: { min: 10, max: 20 } }), + implied: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.internet.url(), + ), + contradictory: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.internet.url(), + ), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + ...overrideResponse, +}) + +export const getApiV2PermissionsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PermissionResponse => ({ + url: faker.internet.url(), + codename: faker.string.alpha({ length: { min: 10, max: 20 } }), + implied: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.internet.url(), + ), + contradictory: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.internet.url(), + ), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2StripeAddonsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedOneTimeAddOnList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.string.alpha({ length: { min: 10, max: 27 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + is_available: faker.datatype.boolean(), + usage_limits: faker.helpers.arrayElement([{}, undefined]), + total_usage_limits: { + [faker.string.alphanumeric(5)]: {}, + }, + limits_remaining: faker.helpers.arrayElement([{}, undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + product: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + })), + ...overrideResponse, +}) + +export const getApiV2StripeAddonsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): OneTimeAddOn => ({ + id: faker.string.alpha({ length: { min: 10, max: 27 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + is_available: faker.datatype.boolean(), + usage_limits: faker.helpers.arrayElement([{}, undefined]), + total_usage_limits: { + [faker.string.alphanumeric(5)]: {}, + }, + limits_remaining: faker.helpers.arrayElement([{}, undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + product: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + ...overrideResponse, +}) + +export const getApiV2StripeChangePlanRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ChangePlan => ({ + price_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + subscription_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + quantity: faker.helpers.arrayElement([ + faker.number.int({ min: 1, max: undefined, multipleOf: undefined }), + undefined, + ]), + ...overrideResponse, +}) + +export const getApiV2StripeCheckoutLinkCreateResponseMock = ( + overrideResponse: Partial = {}, +): CheckoutLink => ({ + price_id: faker.string.alpha({ length: { min: 10, max: 20 } }), + organization_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + quantity: faker.helpers.arrayElement([ + faker.number.int({ min: 1, max: undefined, multipleOf: undefined }), + undefined, + ]), + ...overrideResponse, +}) + +export const getApiV2StripeCustomerPortalCreateResponseMock = ( + overrideResponse: Partial = {}, +): CustomerPortalPostResponse => ({ url: faker.string.alpha({ length: { min: 10, max: 20 } }), ...overrideResponse }) + +export const getApiV2StripeProductsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedProductList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + name: faker.string.alpha({ length: { min: 10, max: 5000 } }), + description: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + type: faker.helpers.arrayElement(Object.values(StripeProductType)), + prices: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + nickname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 250 } }), undefined]), + currency: faker.string.alpha({ length: { min: 10, max: 3 } }), + type: faker.helpers.arrayElement(Object.values(StripePriceType)), + recurring: { + ...{ + interval: faker.helpers.arrayElement(Object.values(StripeIntervalEnum)), + interval_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + meter: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + usage_type: faker.helpers.arrayElement(Object.values(StripeUsageType)), + }, + }, + unit_amount: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.number.int({ min: -9223372036854776000, max: 9223372036854776000, multipleOf: undefined }), + null, + ]), + undefined, + ]), + human_readable_price: faker.string.alpha({ length: { min: 10, max: 20 } }), + metadata: faker.helpers.arrayElement([{}, undefined]), + active: faker.datatype.boolean(), + product: faker.string.alpha({ length: { min: 10, max: 20 } }), + transform_quantity: faker.helpers.arrayElement([{}, undefined]), + })), + metadata: { + [faker.string.alphanumeric(5)]: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + })), + ...overrideResponse, +}) + +export const getApiV2StripeSubscriptionsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedSubscriptionList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + items: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + price: { + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + nickname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 250 } }), undefined]), + currency: faker.string.alpha({ length: { min: 10, max: 3 } }), + type: faker.helpers.arrayElement(Object.values(StripePriceType)), + recurring: { + ...{ + interval: faker.helpers.arrayElement(Object.values(StripeIntervalEnum)), + interval_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + meter: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + usage_type: faker.helpers.arrayElement(Object.values(StripeUsageType)), + }, + }, + unit_amount: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.number.int({ min: -9223372036854776000, max: 9223372036854776000, multipleOf: undefined }), + null, + ]), + undefined, + ]), + human_readable_price: faker.string.alpha({ length: { min: 10, max: 20 } }), + metadata: faker.helpers.arrayElement([{}, undefined]), + active: faker.datatype.boolean(), + product: { + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + name: faker.string.alpha({ length: { min: 10, max: 5000 } }), + description: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + type: faker.helpers.arrayElement(Object.values(StripeProductType)), + metadata: { + [faker.string.alphanumeric(5)]: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + transform_quantity: faker.helpers.arrayElement([{}, undefined]), + }, + quantity: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.number.int({ min: 0, max: 2147483647, multipleOf: undefined }), null]), + undefined, + ]), + })), + schedule: { + phases: { + [faker.string.alphanumeric(5)]: {}, + }, + status: faker.helpers.arrayElement(Object.values(SubscriptionScheduleStatusEnum)), + }, + application_fee_percent: faker.helpers.arrayElement([faker.helpers.fromRegExp('^-?d{0,3}(?:.d{0,2})?$'), null]), + djstripe_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + djstripe_updated: `${faker.date.past().toISOString().split('.')[0]}Z`, + stripe_data: faker.helpers.arrayElement([{}, undefined]), + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + livemode: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + created: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + metadata: faker.helpers.arrayElement([{}, undefined]), + description: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + billing_cycle_anchor: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + billing_thresholds: faker.helpers.arrayElement([{}, undefined]), + cancel_at: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + cancel_at_period_end: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + canceled_at: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + collection_method: faker.helpers.arrayElement(Object.values(CollectionMethodEnum)), + current_period_end: `${faker.date.past().toISOString().split('.')[0]}Z`, + current_period_start: `${faker.date.past().toISOString().split('.')[0]}Z`, + days_until_due: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.number.int({ min: -2147483648, max: 2147483647, multipleOf: undefined }), + null, + ]), + undefined, + ]), + discount: faker.helpers.arrayElement([{}, undefined]), + ended_at: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + next_pending_invoice_item_invoice: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + pause_collection: faker.helpers.arrayElement([{}, undefined]), + pending_invoice_item_interval: faker.helpers.arrayElement([{}, undefined]), + pending_update: faker.helpers.arrayElement([{}, undefined]), + proration_behavior: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.helpers.arrayElement(Object.values(ProrationBehaviorEnum)), + faker.helpers.arrayElement(Object.values(BlankEnum)), + ]), + undefined, + ]), + proration_date: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + quantity: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.number.int({ min: -2147483648, max: 2147483647, multipleOf: undefined }), + null, + ]), + undefined, + ]), + start_date: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + status: faker.helpers.arrayElement(Object.values(SubscriptionStatusEnum)), + trial_end: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + trial_start: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + djstripe_owner_account: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + customer: faker.string.alpha({ length: { min: 10, max: 20 } }), + default_payment_method: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + default_source: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + latest_invoice: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + pending_setup_intent: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + plan: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), null]), + undefined, + ]), + default_tax_rates: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + ), + undefined, + ]), + })), + ...overrideResponse, +}) + +export const getApiV2StripeSubscriptionsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): Subscription => ({ + items: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + price: { + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + nickname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 250 } }), undefined]), + currency: faker.string.alpha({ length: { min: 10, max: 3 } }), + type: faker.helpers.arrayElement(Object.values(StripePriceType)), + recurring: { + ...{ + interval: faker.helpers.arrayElement(Object.values(StripeIntervalEnum)), + interval_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + meter: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + usage_type: faker.helpers.arrayElement(Object.values(StripeUsageType)), + }, + }, + unit_amount: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.number.int({ min: -9223372036854776000, max: 9223372036854776000, multipleOf: undefined }), + null, + ]), + undefined, + ]), + human_readable_price: faker.string.alpha({ length: { min: 10, max: 20 } }), + metadata: faker.helpers.arrayElement([{}, undefined]), + active: faker.datatype.boolean(), + product: { + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + name: faker.string.alpha({ length: { min: 10, max: 5000 } }), + description: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + type: faker.helpers.arrayElement(Object.values(StripeProductType)), + metadata: { + [faker.string.alphanumeric(5)]: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + transform_quantity: faker.helpers.arrayElement([{}, undefined]), + }, + quantity: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.number.int({ min: 0, max: 2147483647, multipleOf: undefined }), null]), + undefined, + ]), + })), + schedule: { + phases: { + [faker.string.alphanumeric(5)]: {}, + }, + status: faker.helpers.arrayElement(Object.values(SubscriptionScheduleStatusEnum)), + }, + application_fee_percent: faker.helpers.arrayElement([faker.helpers.fromRegExp('^-?d{0,3}(?:.d{0,2})?$'), null]), + djstripe_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + djstripe_updated: `${faker.date.past().toISOString().split('.')[0]}Z`, + stripe_data: faker.helpers.arrayElement([{}, undefined]), + id: faker.string.alpha({ length: { min: 10, max: 255 } }), + livemode: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + created: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + metadata: faker.helpers.arrayElement([{}, undefined]), + description: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + billing_cycle_anchor: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + billing_thresholds: faker.helpers.arrayElement([{}, undefined]), + cancel_at: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + cancel_at_period_end: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + canceled_at: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + collection_method: faker.helpers.arrayElement(Object.values(CollectionMethodEnum)), + current_period_end: `${faker.date.past().toISOString().split('.')[0]}Z`, + current_period_start: `${faker.date.past().toISOString().split('.')[0]}Z`, + days_until_due: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.number.int({ min: -2147483648, max: 2147483647, multipleOf: undefined }), null]), + undefined, + ]), + discount: faker.helpers.arrayElement([{}, undefined]), + ended_at: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + next_pending_invoice_item_invoice: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + pause_collection: faker.helpers.arrayElement([{}, undefined]), + pending_invoice_item_interval: faker.helpers.arrayElement([{}, undefined]), + pending_update: faker.helpers.arrayElement([{}, undefined]), + proration_behavior: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.helpers.arrayElement(Object.values(ProrationBehaviorEnum)), + faker.helpers.arrayElement(Object.values(BlankEnum)), + ]), + undefined, + ]), + proration_date: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + quantity: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.number.int({ min: -2147483648, max: 2147483647, multipleOf: undefined }), null]), + undefined, + ]), + start_date: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + status: faker.helpers.arrayElement(Object.values(SubscriptionStatusEnum)), + trial_end: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + trial_start: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + djstripe_owner_account: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + customer: faker.string.alpha({ length: { min: 10, max: 20 } }), + default_payment_method: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + default_source: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + latest_invoice: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + pending_setup_intent: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + plan: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), null]), + undefined, + ]), + default_tax_rates: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + ), + undefined, + ]), + ...overrideResponse, +}) + +export const getApiV2TermsOfServiceListResponseMock = (): TermsOfServiceResponse[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + slug: faker.string.alpha({ length: { min: 10, max: 20 } }), + body: faker.string.alpha({ length: { min: 10, max: 20 } }), + })) + +export const getApiV2TermsOfServiceRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): TermsOfServiceResponse => ({ + url: faker.internet.url(), + slug: faker.string.alpha({ length: { min: 10, max: 20 } }), + body: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2TranscriptionServicesListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedTranscriptionServiceList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 100 } }), + code: faker.string.alpha({ length: { min: 10, max: 10 } }), + })), + ...overrideResponse, +}) + +export const getApiV2TranscriptionServicesRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): TranscriptionService => ({ + name: faker.string.alpha({ length: { min: 10, max: 100 } }), + code: faker.string.alpha({ length: { min: 10, max: 10 } }), + ...overrideResponse, +}) + +export const getApiV2TranslationServicesListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedTranslationServiceList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.string.alpha({ length: { min: 10, max: 100 } }), + code: faker.string.alpha({ length: { min: 10, max: 10 } }), + })), + ...overrideResponse, +}) + +export const getApiV2TranslationServicesRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): TranslationService => ({ + name: faker.string.alpha({ length: { min: 10, max: 100 } }), + code: faker.string.alpha({ length: { min: 10, max: 10 } }), + ...overrideResponse, +}) + +export const getApiV2LanguagesListMockHandler = ( + overrideResponse?: + | PaginatedLanguageListList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedLanguageListList), +) => { + return http.get('*/api/v2/languages{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2LanguagesListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2LanguagesRetrieveMockHandler = ( + overrideResponse?: Language | ((info: Parameters[1]>[0]) => Promise | Language), +) => { + return http.get('*/api/v2/languages/:code{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2LanguagesRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2PermissionsListMockHandler = ( + overrideResponse?: + | PaginatedPermissionResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedPermissionResponseList), +) => { + return http.get('*/api/v2/permissions{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2PermissionsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2PermissionsRetrieveMockHandler = ( + overrideResponse?: + | PermissionResponse + | ((info: Parameters[1]>[0]) => Promise | PermissionResponse), +) => { + return http.get('*/api/v2/permissions/:codename{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2PermissionsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2StripeAddonsListMockHandler = ( + overrideResponse?: + | PaginatedOneTimeAddOnList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedOneTimeAddOnList), +) => { + return http.get('*/api/v2/stripe/addons{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2StripeAddonsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2StripeAddonsRetrieveMockHandler = ( + overrideResponse?: + | OneTimeAddOn + | ((info: Parameters[1]>[0]) => Promise | OneTimeAddOn), +) => { + return http.get('*/api/v2/stripe/addons/:id{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2StripeAddonsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2StripeChangePlanRetrieveMockHandler = ( + overrideResponse?: + | ChangePlan + | ((info: Parameters[1]>[0]) => Promise | ChangePlan), +) => { + return http.get('*/api/v2/stripe/change-plan', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2StripeChangePlanRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2StripeCheckoutLinkCreateMockHandler = ( + overrideResponse?: + | CheckoutLink + | ((info: Parameters[1]>[0]) => Promise | CheckoutLink), +) => { + return http.post('*/api/v2/stripe/checkout-link', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2StripeCheckoutLinkCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2StripeCustomerPortalCreateMockHandler = ( + overrideResponse?: + | CustomerPortalPostResponse + | (( + info: Parameters[1]>[0], + ) => Promise | CustomerPortalPostResponse), +) => { + return http.post('*/api/v2/stripe/customer-portal', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2StripeCustomerPortalCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2StripeProductsListMockHandler = ( + overrideResponse?: + | PaginatedProductList + | ((info: Parameters[1]>[0]) => Promise | PaginatedProductList), +) => { + return http.get('*/api/v2/stripe/products{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2StripeProductsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2StripeSubscriptionsListMockHandler = ( + overrideResponse?: + | PaginatedSubscriptionList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedSubscriptionList), +) => { + return http.get('*/api/v2/stripe/subscriptions{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2StripeSubscriptionsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2StripeSubscriptionsRetrieveMockHandler = ( + overrideResponse?: + | Subscription + | ((info: Parameters[1]>[0]) => Promise | Subscription), +) => { + return http.get('*/api/v2/stripe/subscriptions/:id{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2StripeSubscriptionsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2TermsOfServiceListMockHandler = ( + overrideResponse?: + | TermsOfServiceResponse[] + | (( + info: Parameters[1]>[0], + ) => Promise | TermsOfServiceResponse[]), +) => { + return http.get('*/api/v2/terms-of-service{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2TermsOfServiceListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2TermsOfServiceRetrieveMockHandler = ( + overrideResponse?: + | TermsOfServiceResponse + | (( + info: Parameters[1]>[0], + ) => Promise | TermsOfServiceResponse), +) => { + return http.get('*/api/v2/terms-of-service/:slug{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2TermsOfServiceRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2TranscriptionServicesListMockHandler = ( + overrideResponse?: + | PaginatedTranscriptionServiceList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedTranscriptionServiceList), +) => { + return http.get('*/api/v2/transcription-services{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2TranscriptionServicesListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2TranscriptionServicesRetrieveMockHandler = ( + overrideResponse?: + | TranscriptionService + | ((info: Parameters[1]>[0]) => Promise | TranscriptionService), +) => { + return http.get('*/api/v2/transcription-services/:code{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2TranscriptionServicesRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2TranslationServicesListMockHandler = ( + overrideResponse?: + | PaginatedTranslationServiceList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedTranslationServiceList), +) => { + return http.get('*/api/v2/translation-services{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2TranslationServicesListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2TranslationServicesRetrieveMockHandler = ( + overrideResponse?: + | TranslationService + | ((info: Parameters[1]>[0]) => Promise | TranslationService), +) => { + return http.get('*/api/v2/translation-services/:code{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2TranslationServicesRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getOtherMock = () => [ + getApiV2LanguagesListMockHandler(), + getApiV2LanguagesRetrieveMockHandler(), + getApiV2PermissionsListMockHandler(), + getApiV2PermissionsRetrieveMockHandler(), + getApiV2StripeAddonsListMockHandler(), + getApiV2StripeAddonsRetrieveMockHandler(), + getApiV2StripeChangePlanRetrieveMockHandler(), + getApiV2StripeCheckoutLinkCreateMockHandler(), + getApiV2StripeCustomerPortalCreateMockHandler(), + getApiV2StripeProductsListMockHandler(), + getApiV2StripeSubscriptionsListMockHandler(), + getApiV2StripeSubscriptionsRetrieveMockHandler(), + getApiV2TermsOfServiceListMockHandler(), + getApiV2TermsOfServiceRetrieveMockHandler(), + getApiV2TranscriptionServicesListMockHandler(), + getApiV2TranscriptionServicesRetrieveMockHandler(), + getApiV2TranslationServicesListMockHandler(), + getApiV2TranslationServicesRetrieveMockHandler(), +] diff --git a/jsapp/js/api/react-query/scim.ts b/jsapp/js/api/react-query/scim/index.ts similarity index 97% rename from jsapp/js/api/react-query/scim.ts rename to jsapp/js/api/react-query/scim/index.ts index 214c76c99a..bc1385070e 100644 --- a/jsapp/js/api/react-query/scim.ts +++ b/jsapp/js/api/react-query/scim/index.ts @@ -19,37 +19,37 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { PaginatedScimGroupList } from '../models/paginatedScimGroupList' +import type { PaginatedScimGroupList } from '../../models/paginatedScimGroupList' -import type { PaginatedScimUserList } from '../models/paginatedScimUserList' +import type { PaginatedScimUserList } from '../../models/paginatedScimUserList' -import type { PatchedScimGroup } from '../models/patchedScimGroup' +import type { PatchedScimGroup } from '../../models/patchedScimGroup' -import type { PatchedScimUser } from '../models/patchedScimUser' +import type { PatchedScimUser } from '../../models/patchedScimUser' -import type { ScimError } from '../models/scimError' +import type { ScimError } from '../../models/scimError' -import type { ScimGroup } from '../models/scimGroup' +import type { ScimGroup } from '../../models/scimGroup' -import type { ScimUser } from '../models/scimUser' +import type { ScimUser } from '../../models/scimUser' -import type { ScimV2GroupsListParams } from '../models/scimV2GroupsListParams' +import type { ScimV2GroupsListParams } from '../../models/scimV2GroupsListParams' -import type { ScimV2ResourceTypesRetrieve200 } from '../models/scimV2ResourceTypesRetrieve200' +import type { ScimV2ResourceTypesRetrieve200 } from '../../models/scimV2ResourceTypesRetrieve200' -import type { ScimV2SchemasRetrieve200 } from '../models/scimV2SchemasRetrieve200' +import type { ScimV2SchemasRetrieve200 } from '../../models/scimV2SchemasRetrieve200' -import type { ScimV2ServiceProviderConfigRetrieve200 } from '../models/scimV2ServiceProviderConfigRetrieve200' +import type { ScimV2ServiceProviderConfigRetrieve200 } from '../../models/scimV2ServiceProviderConfigRetrieve200' -import type { ScimV2UsersCreate400 } from '../models/scimV2UsersCreate400' +import type { ScimV2UsersCreate400 } from '../../models/scimV2UsersCreate400' -import type { ScimV2UsersCreate409 } from '../models/scimV2UsersCreate409' +import type { ScimV2UsersCreate409 } from '../../models/scimV2UsersCreate409' -import type { ScimV2UsersListParams } from '../models/scimV2UsersListParams' +import type { ScimV2UsersListParams } from '../../models/scimV2UsersListParams' -import type { ScimV2UsersUpdate409 } from '../models/scimV2UsersUpdate409' +import type { ScimV2UsersUpdate409 } from '../../models/scimV2UsersUpdate409' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' // https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497 type IfEquals = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? A : B diff --git a/jsapp/js/api/react-query/scim/msw.ts b/jsapp/js/api/react-query/scim/msw.ts new file mode 100644 index 0000000000..ec33e2a8a2 --- /dev/null +++ b/jsapp/js/api/react-query/scim/msw.ts @@ -0,0 +1,487 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { PaginatedScimGroupList } from '../../models/paginatedScimGroupList' + +import type { PaginatedScimUserList } from '../../models/paginatedScimUserList' + +import type { ScimGroup } from '../../models/scimGroup' + +import type { ScimUser } from '../../models/scimUser' + +import type { ScimV2ResourceTypesRetrieve200 } from '../../models/scimV2ResourceTypesRetrieve200' + +import type { ScimV2SchemasRetrieve200 } from '../../models/scimV2SchemasRetrieve200' + +import type { ScimV2ServiceProviderConfigRetrieve200 } from '../../models/scimV2ServiceProviderConfigRetrieve200' + +export const getApiV2ScimV2GroupsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedScimGroupList => ({ + schemas: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + totalResults: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + itemsPerPage: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + startIndex: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + Resources: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + displayName: faker.string.alpha({ length: { min: 10, max: 20 } }), + externalId: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + members: {}, + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + ...overrideResponse, +}) + +export const getApiV2ScimV2GroupsCreateResponseMock = (overrideResponse: Partial = {}): ScimGroup => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + displayName: faker.string.alpha({ length: { min: 10, max: 20 } }), + externalId: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + members: {}, + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + ...overrideResponse, +}) + +export const getApiV2ScimV2GroupsRetrieveResponseMock = (overrideResponse: Partial = {}): ScimGroup => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + displayName: faker.string.alpha({ length: { min: 10, max: 20 } }), + externalId: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + members: {}, + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + ...overrideResponse, +}) + +export const getApiV2ScimV2GroupsUpdateResponseMock = (overrideResponse: Partial = {}): ScimGroup => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + displayName: faker.string.alpha({ length: { min: 10, max: 20 } }), + externalId: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + members: {}, + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + ...overrideResponse, +}) + +export const getApiV2ScimV2GroupsPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): ScimGroup => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + displayName: faker.string.alpha({ length: { min: 10, max: 20 } }), + externalId: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + members: {}, + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + ...overrideResponse, +}) + +export const getApiV2ScimV2ResourceTypesRetrieveResponseMock = (): ScimV2ResourceTypesRetrieve200 => ({ + [faker.string.alphanumeric(5)]: {}, +}) + +export const getApiV2ScimV2SchemasRetrieveResponseMock = (): ScimV2SchemasRetrieve200 => ({ + [faker.string.alphanumeric(5)]: {}, +}) + +export const getApiV2ScimV2ServiceProviderConfigRetrieveResponseMock = (): ScimV2ServiceProviderConfigRetrieve200 => ({ + [faker.string.alphanumeric(5)]: {}, +}) + +export const getApiV2ScimV2UsersListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedScimUserList => ({ + schemas: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + totalResults: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + itemsPerPage: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + startIndex: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + Resources: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + userName: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: { + [faker.string.alphanumeric(5)]: {}, + }, + emails: {}, + active: faker.datatype.boolean(), + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + ...overrideResponse, +}) + +export const getApiV2ScimV2UsersCreateResponseMock = (overrideResponse: Partial = {}): ScimUser => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + userName: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: { + [faker.string.alphanumeric(5)]: {}, + }, + emails: {}, + active: faker.datatype.boolean(), + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + ...overrideResponse, +}) + +export const getApiV2ScimV2UsersRetrieveResponseMock = (overrideResponse: Partial = {}): ScimUser => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + userName: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: { + [faker.string.alphanumeric(5)]: {}, + }, + emails: {}, + active: faker.datatype.boolean(), + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + ...overrideResponse, +}) + +export const getApiV2ScimV2UsersUpdateResponseMock = (overrideResponse: Partial = {}): ScimUser => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + userName: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: { + [faker.string.alphanumeric(5)]: {}, + }, + emails: {}, + active: faker.datatype.boolean(), + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + ...overrideResponse, +}) + +export const getApiV2ScimV2UsersPartialUpdateResponseMock = (overrideResponse: Partial = {}): ScimUser => ({ + schemas: {}, + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + userName: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: { + [faker.string.alphanumeric(5)]: {}, + }, + emails: {}, + active: faker.datatype.boolean(), + meta: { + [faker.string.alphanumeric(5)]: {}, + }, + ...overrideResponse, +}) + +export const getApiV2ScimV2GroupsListMockHandler = ( + overrideResponse?: + | PaginatedScimGroupList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedScimGroupList), +) => { + return http.get('*/api/v2/scim/v2/:idpSlug/Groups', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2GroupsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2GroupsCreateMockHandler = ( + overrideResponse?: + | ScimGroup + | ((info: Parameters[1]>[0]) => Promise | ScimGroup), +) => { + return http.post('*/api/v2/scim/v2/:idpSlug/Groups', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2GroupsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2GroupsRetrieveMockHandler = ( + overrideResponse?: + | ScimGroup + | ((info: Parameters[1]>[0]) => Promise | ScimGroup), +) => { + return http.get('*/api/v2/scim/v2/:idpSlug/Groups/:id', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2GroupsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2GroupsUpdateMockHandler = ( + overrideResponse?: + | ScimGroup + | ((info: Parameters[1]>[0]) => Promise | ScimGroup), +) => { + return http.put('*/api/v2/scim/v2/:idpSlug/Groups/:id', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2GroupsUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2GroupsPartialUpdateMockHandler = ( + overrideResponse?: + | ScimGroup + | ((info: Parameters[1]>[0]) => Promise | ScimGroup), +) => { + return http.patch('*/api/v2/scim/v2/:idpSlug/Groups/:id', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2GroupsPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2GroupsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/scim/v2/:idpSlug/Groups/:id', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2ScimV2ResourceTypesRetrieveMockHandler = ( + overrideResponse?: + | ScimV2ResourceTypesRetrieve200 + | (( + info: Parameters[1]>[0], + ) => Promise | ScimV2ResourceTypesRetrieve200), +) => { + return http.get('*/api/v2/scim/v2/:idpSlug/ResourceTypes', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2ResourceTypesRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2SchemasRetrieveMockHandler = ( + overrideResponse?: + | ScimV2SchemasRetrieve200 + | (( + info: Parameters[1]>[0], + ) => Promise | ScimV2SchemasRetrieve200), +) => { + return http.get('*/api/v2/scim/v2/:idpSlug/Schemas', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2SchemasRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2ServiceProviderConfigRetrieveMockHandler = ( + overrideResponse?: + | ScimV2ServiceProviderConfigRetrieve200 + | (( + info: Parameters[1]>[0], + ) => Promise | ScimV2ServiceProviderConfigRetrieve200), +) => { + return http.get('*/api/v2/scim/v2/:idpSlug/ServiceProviderConfig', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2ServiceProviderConfigRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2UsersListMockHandler = ( + overrideResponse?: + | PaginatedScimUserList + | ((info: Parameters[1]>[0]) => Promise | PaginatedScimUserList), +) => { + return http.get('*/api/v2/scim/v2/:idpSlug/Users', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2UsersListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2UsersCreateMockHandler = ( + overrideResponse?: + | ScimUser + | ((info: Parameters[1]>[0]) => Promise | ScimUser), +) => { + return http.post('*/api/v2/scim/v2/:idpSlug/Users', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2UsersCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2UsersRetrieveMockHandler = ( + overrideResponse?: ScimUser | ((info: Parameters[1]>[0]) => Promise | ScimUser), +) => { + return http.get('*/api/v2/scim/v2/:idpSlug/Users/:id', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2UsersRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2UsersUpdateMockHandler = ( + overrideResponse?: ScimUser | ((info: Parameters[1]>[0]) => Promise | ScimUser), +) => { + return http.put('*/api/v2/scim/v2/:idpSlug/Users/:id', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2UsersUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2UsersPartialUpdateMockHandler = ( + overrideResponse?: + | ScimUser + | ((info: Parameters[1]>[0]) => Promise | ScimUser), +) => { + return http.patch('*/api/v2/scim/v2/:idpSlug/Users/:id', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ScimV2UsersPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ScimV2UsersDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/scim/v2/:idpSlug/Users/:id', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} +export const getScimMock = () => [ + getApiV2ScimV2GroupsListMockHandler(), + getApiV2ScimV2GroupsCreateMockHandler(), + getApiV2ScimV2GroupsRetrieveMockHandler(), + getApiV2ScimV2GroupsUpdateMockHandler(), + getApiV2ScimV2GroupsPartialUpdateMockHandler(), + getApiV2ScimV2GroupsDestroyMockHandler(), + getApiV2ScimV2ResourceTypesRetrieveMockHandler(), + getApiV2ScimV2SchemasRetrieveMockHandler(), + getApiV2ScimV2ServiceProviderConfigRetrieveMockHandler(), + getApiV2ScimV2UsersListMockHandler(), + getApiV2ScimV2UsersCreateMockHandler(), + getApiV2ScimV2UsersRetrieveMockHandler(), + getApiV2ScimV2UsersUpdateMockHandler(), + getApiV2ScimV2UsersPartialUpdateMockHandler(), + getApiV2ScimV2UsersDestroyMockHandler(), +] diff --git a/jsapp/js/api/react-query/server-logs-superusers.ts b/jsapp/js/api/react-query/server-logs-superusers/index.ts similarity index 96% rename from jsapp/js/api/react-query/server-logs-superusers.ts rename to jsapp/js/api/react-query/server-logs-superusers/index.ts index dd8fbd090a..d753203c53 100644 --- a/jsapp/js/api/react-query/server-logs-superusers.ts +++ b/jsapp/js/api/react-query/server-logs-superusers/index.ts @@ -19,33 +19,33 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { AccessLogsListParams } from '../models/accessLogsListParams' +import type { AccessLogsListParams } from '../../models/accessLogsListParams' -import type { AuditLogsListParams } from '../models/auditLogsListParams' +import type { AuditLogsListParams } from '../../models/auditLogsListParams' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { ExportCreateResponse } from '../models/exportCreateResponse' +import type { ExportCreateResponse } from '../../models/exportCreateResponse' -import type { ExportHistoryResponse } from '../models/exportHistoryResponse' +import type { ExportHistoryResponse } from '../../models/exportHistoryResponse' -import type { ExportListResponse } from '../models/exportListResponse' +import type { ExportListResponse } from '../../models/exportListResponse' -import type { PaginatedAuditLogResponseList } from '../models/paginatedAuditLogResponseList' +import type { PaginatedAuditLogResponseList } from '../../models/paginatedAuditLogResponseList' -import type { PaginatedProjectHistoryLogResponseList } from '../models/paginatedProjectHistoryLogResponseList' +import type { PaginatedProjectHistoryLogResponseList } from '../../models/paginatedProjectHistoryLogResponseList' -import type { PaginatedSuperUserAccessLogResponseList } from '../models/paginatedSuperUserAccessLogResponseList' +import type { PaginatedSuperUserAccessLogResponseList } from '../../models/paginatedSuperUserAccessLogResponseList' -import type { PaginatedUserReportsListResponseList } from '../models/paginatedUserReportsListResponseList' +import type { PaginatedUserReportsListResponseList } from '../../models/paginatedUserReportsListResponseList' -import type { ProjectHistoryLogsListParams } from '../models/projectHistoryLogsListParams' +import type { ProjectHistoryLogsListParams } from '../../models/projectHistoryLogsListParams' -import type { UserReportsListParams } from '../models/userReportsListParams' +import type { UserReportsListParams } from '../../models/userReportsListParams' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' type SecondParameter unknown> = Parameters[1] diff --git a/jsapp/js/api/react-query/server-logs-superusers/msw.ts b/jsapp/js/api/react-query/server-logs-superusers/msw.ts new file mode 100644 index 0000000000..ad1322e8d1 --- /dev/null +++ b/jsapp/js/api/react-query/server-logs-superusers/msw.ts @@ -0,0 +1,1062 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import type { ExportCreateResponse } from '../../models/exportCreateResponse' + +import type { ExportHistoryResponse } from '../../models/exportHistoryResponse' + +import type { ExportListResponse } from '../../models/exportListResponse' + +import type { PaginatedAuditLogResponseList } from '../../models/paginatedAuditLogResponseList' + +import type { PaginatedProjectHistoryLogResponseList } from '../../models/paginatedProjectHistoryLogResponseList' + +import type { PaginatedSuperUserAccessLogResponseList } from '../../models/paginatedSuperUserAccessLogResponseList' + +import type { PaginatedUserReportsListResponseList } from '../../models/paginatedUserReportsListResponseList' + +import type { ServiceUsageBalanceData } from '../../models/serviceUsageBalanceData' + +export const getApiV2AccessLogsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedSuperUserAccessLogResponseList => ({ + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user: faker.internet.url(), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + metadata: { + source: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + auth_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + ip_address: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + initial_user_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + initial_user_username: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + authorized_app_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + user_uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + action: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + ...overrideResponse, +}) + +export const getApiV2AccessLogsExportListResponseMock = (): ExportListResponse[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 24 } }), + status: faker.string.alpha({ length: { min: 10, max: 32 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + })) + +export const getApiV2AccessLogsExportCreateResponseMock = ( + overrideResponse: Partial = {}, +): ExportCreateResponse => ({ status: faker.string.alpha({ length: { min: 10, max: 32 } }), ...overrideResponse }) + +export const getApiV2AuditLogsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAuditLogResponseList => ({ + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + app_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + model_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.internet.url(), + user_uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + action: faker.string.alpha({ length: { min: 10, max: 20 } }), + metadata: { + source: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + old: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + country: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + removed: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + description: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + old: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + 'data-table': faker.helpers.arrayElement([ + { new: faker.helpers.arrayElement([{}, undefined]), old: faker.helpers.arrayElement([{}, undefined]) }, + undefined, + ]), + }, + undefined, + ]), + asset_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + auth_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + ip_address: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + log_subtype: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + project_owner: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + latest_version_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'asset-files': faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + md5_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + download_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + permissions: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + latest_deployed_version_uid: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + submission: faker.helpers.arrayElement([ + { + root_uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + submitted_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + hook: faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + active: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + endpoint: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + undefined, + ]), + bulk_action: faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + action_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + question_xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + params: faker.helpers.arrayElement([{}, undefined]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + cancelled_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + total_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + processed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + completed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + failed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + cancelled_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + name: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + old: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + shared_fields: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + log_type: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + ...overrideResponse, +}) + +export const getApiV2ProjectHistoryLogsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedProjectHistoryLogResponseList => ({ + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user: faker.internet.url(), + user_uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + action: faker.string.alpha({ length: { min: 10, max: 20 } }), + metadata: { + source: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + ip_address: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + cloned_from: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + log_subtype: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'paired-data': faker.helpers.arrayElement([ + { + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + source_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source_name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + old: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + country: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + removed: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + description: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + old: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + 'data-table': faker.helpers.arrayElement([ + { new: faker.helpers.arrayElement([{}, undefined]), old: faker.helpers.arrayElement([{}, undefined]) }, + undefined, + ]), + }, + undefined, + ]), + 'asset-files': faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + md5_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + download_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + permissions: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + project_owner: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + latest_version_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + submission: faker.helpers.arrayElement([ + { + root_uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + submitted_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + hook: faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + active: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + endpoint: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + undefined, + ]), + bulk_action: faker.helpers.arrayElement([ + { + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + action_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + question_xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + params: faker.helpers.arrayElement([{}, undefined]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + cancelled_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + total_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + processed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + completed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + failed_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + cancelled_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + name: faker.helpers.arrayElement([ + { + new: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + old: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + shared_fields: faker.helpers.arrayElement([ + { + added: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + removed: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + ...overrideResponse, +}) + +export const getApiV2ProjectHistoryLogsExportRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ExportHistoryResponse => ({ status: faker.string.alpha({ length: { min: 10, max: 20 } }), ...overrideResponse }) + +export const getApiV2ProjectHistoryLogsExportCreateResponseMock = ( + overrideResponse: Partial = {}, +): ExportHistoryResponse => ({ status: faker.string.alpha({ length: { min: 10, max: 20 } }), ...overrideResponse }) + +export const getApiV2UserReportsListResponseServiceUsageBalanceDataMock = ( + overrideResponse: Partial = {}, +): ServiceUsageBalanceData => ({ + ...{ + effective_limit: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + balance_value: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + balance_percent: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + exceeded: faker.datatype.boolean(), + }, + ...overrideResponse, +}) + +export const getApiV2UserReportsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedUserReportsListResponseList => ({ + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + user_uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + first_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.internet.email(), + is_superuser: faker.datatype.boolean(), + is_staff: faker.datatype.boolean(), + is_active: faker.datatype.boolean(), + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + last_login: `${faker.date.past().toISOString().split('.')[0]}Z`, + validated_email: faker.datatype.boolean(), + mfa_is_active: faker.datatype.boolean(), + sso_is_active: faker.datatype.boolean(), + accepted_tos: faker.datatype.boolean(), + social_accounts: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + provider: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + last_joined: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_joined: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + organizations: { + organization_name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + role: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + extra_details: { + data: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + sector: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + country: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + last_ui_language: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + organization_type: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + organization_website: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + newsletter_subscription: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + undefined, + ]), + date_removed: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + validated_password: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + password_date_changed: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + date_removal_requested: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + }, + subscriptions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + items: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + price: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + nickname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + currency: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + recurring: faker.helpers.arrayElement([ + { + meter: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + interval: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + usage_type: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + interval_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + aggregate_usage: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + trial_period_days: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + unit_amount: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + human_readable_price: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + metadata: faker.helpers.arrayElement([{}, undefined]), + active: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + product: faker.helpers.arrayElement([ + { + id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([ + { + product_type: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + storage_bytes_limit: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + transform_quantity: faker.helpers.arrayElement([ + { + divide_by: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + round: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + })), + undefined, + ]), + quantity: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + })), + undefined, + ]), + schedule: faker.helpers.arrayElement([ + { + phases: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + items: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + plan: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + price: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + quantity: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + tax_rates: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + ), + undefined, + ]), + billing_thresholds: faker.helpers.arrayElement([{}, undefined]), + })), + undefined, + ]), + coupon: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + currency: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + end_date: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + metadata: faker.helpers.arrayElement([{}, undefined]), + trial_end: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + start_date: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + description: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + on_behalf_of: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + automatic_tax: faker.helpers.arrayElement([{}, undefined]), + transfer_data: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + invoice_settings: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + add_invoice_items: faker.helpers.arrayElement([{}, undefined]), + collection_method: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_tax_rates: faker.helpers.arrayElement([{}, undefined]), + billing_thresholds: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + proration_behavior: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + billing_cycle_anchor: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + default_payment_method: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + application_fee_percent: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + })), + undefined, + ]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + djstripe_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + djstripe_updated: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + livemode: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([ + { + request_url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_id: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + kpi_owner_user_id: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + kpi_owner_username: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + undefined, + ]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + application_fee_percent: faker.helpers.arrayElement([ + faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + undefined, + ]), + billing_cycle_anchor: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + billing_thresholds: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + cancel_at: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + cancel_at_period_end: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + canceled_at: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collection_method: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + current_period_end: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + current_period_start: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + days_until_due: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + discount: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + ended_at: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + next_pending_invoice_item_invoice: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + pause_collection: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + pending_invoice_item_interval: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + pending_update: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + proration_behavior: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + proration_date: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + quantity: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + start_date: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + trial_end: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + trial_start: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + djstripe_owner_account: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + customer: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + default_payment_method: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_source: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + latest_invoice: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + pending_setup_intent: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + plan: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + default_tax_rates: faker.helpers.arrayElement([{}, undefined]), + })), + service_usage: { + total_nlp_usage: { + asr_seconds_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + llm_requests_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + mt_characters_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + asr_seconds_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + llm_requests_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + mt_characters_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + total_storage_bytes: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_submission_count: { + retention_days: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + cumulative: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + current_period: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + balances: { + submission: faker.helpers.arrayElement([ + { ...getApiV2UserReportsListResponseServiceUsageBalanceDataMock() }, + null, + ]), + storage_bytes: faker.helpers.arrayElement([ + { ...getApiV2UserReportsListResponseServiceUsageBalanceDataMock() }, + null, + ]), + asr_seconds: faker.helpers.arrayElement([ + { ...getApiV2UserReportsListResponseServiceUsageBalanceDataMock() }, + null, + ]), + mt_characters: faker.helpers.arrayElement([ + { ...getApiV2UserReportsListResponseServiceUsageBalanceDataMock() }, + null, + ]), + llm_requests: faker.helpers.arrayElement([ + { ...getApiV2UserReportsListResponseServiceUsageBalanceDataMock() }, + null, + ]), + }, + current_period_start: `${faker.date.past().toISOString().split('.')[0]}Z`, + current_period_end: `${faker.date.past().toISOString().split('.')[0]}Z`, + }, + account_restricted: faker.datatype.boolean(), + asset_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + active_project_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + last_updated: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + ...overrideResponse, +}) + +export const getApiV2AccessLogsListMockHandler = ( + overrideResponse?: + | PaginatedSuperUserAccessLogResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedSuperUserAccessLogResponseList), +) => { + return http.get('*/api/v2/access-logs{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AccessLogsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AccessLogsExportListMockHandler = ( + overrideResponse?: + | ExportListResponse[] + | ((info: Parameters[1]>[0]) => Promise | ExportListResponse[]), +) => { + return http.get('*/api/v2/access-logs/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AccessLogsExportListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AccessLogsExportCreateMockHandler = ( + overrideResponse?: + | ExportCreateResponse + | ((info: Parameters[1]>[0]) => Promise | ExportCreateResponse), +) => { + return http.post('*/api/v2/access-logs/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AccessLogsExportCreateResponseMock(), + ), + { status: 202, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AuditLogsListMockHandler = ( + overrideResponse?: + | PaginatedAuditLogResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAuditLogResponseList), +) => { + return http.get('*/api/v2/audit-logs{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AuditLogsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectHistoryLogsListMockHandler = ( + overrideResponse?: + | PaginatedProjectHistoryLogResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedProjectHistoryLogResponseList), +) => { + return http.get('*/api/v2/project-history-logs{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectHistoryLogsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectHistoryLogsExportRetrieveMockHandler = ( + overrideResponse?: + | ExportHistoryResponse + | ((info: Parameters[1]>[0]) => Promise | ExportHistoryResponse), +) => { + return http.get('*/api/v2/project-history-logs/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectHistoryLogsExportRetrieveResponseMock(), + ), + { status: 202, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectHistoryLogsExportCreateMockHandler = ( + overrideResponse?: + | ExportHistoryResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ExportHistoryResponse), +) => { + return http.post('*/api/v2/project-history-logs/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectHistoryLogsExportCreateResponseMock(), + ), + { status: 202, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2UserReportsListMockHandler = ( + overrideResponse?: + | PaginatedUserReportsListResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedUserReportsListResponseList), +) => { + return http.get('*/api/v2/user-reports{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2UserReportsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getServerLogsSuperusersMock = () => [ + getApiV2AccessLogsListMockHandler(), + getApiV2AccessLogsExportListMockHandler(), + getApiV2AccessLogsExportCreateMockHandler(), + getApiV2AuditLogsListMockHandler(), + getApiV2ProjectHistoryLogsListMockHandler(), + getApiV2ProjectHistoryLogsExportRetrieveMockHandler(), + getApiV2ProjectHistoryLogsExportCreateMockHandler(), + getApiV2UserReportsListMockHandler(), +] diff --git a/jsapp/js/api/react-query/survey-data-rest-services.ts b/jsapp/js/api/react-query/survey-data-rest-services/index.ts similarity index 97% rename from jsapp/js/api/react-query/survey-data-rest-services.ts rename to jsapp/js/api/react-query/survey-data-rest-services/index.ts index fd075793d0..61387a7e2e 100644 --- a/jsapp/js/api/react-query/survey-data-rest-services.ts +++ b/jsapp/js/api/react-query/survey-data-rest-services/index.ts @@ -19,31 +19,31 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { AssetsHooksListParams } from '../models/assetsHooksListParams' +import type { AssetsHooksListParams } from '../../models/assetsHooksListParams' -import type { AssetsHooksLogsListParams } from '../models/assetsHooksLogsListParams' +import type { AssetsHooksLogsListParams } from '../../models/assetsHooksLogsListParams' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { Hook } from '../models/hook' +import type { Hook } from '../../models/hook' -import type { HookLog } from '../models/hookLog' +import type { HookLog } from '../../models/hookLog' -import type { HookRetryResponse } from '../models/hookRetryResponse' +import type { HookRetryResponse } from '../../models/hookRetryResponse' -import type { LogsRetryResponse } from '../models/logsRetryResponse' +import type { LogsRetryResponse } from '../../models/logsRetryResponse' -import type { PaginatedHookList } from '../models/paginatedHookList' +import type { PaginatedHookList } from '../../models/paginatedHookList' -import type { PaginatedHookLogList } from '../models/paginatedHookLogList' +import type { PaginatedHookLogList } from '../../models/paginatedHookLogList' -import type { PatchedHook } from '../models/patchedHook' +import type { PatchedHook } from '../../models/patchedHook' -import type { PatchedHookLog } from '../models/patchedHookLog' +import type { PatchedHookLog } from '../../models/patchedHookLog' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' // https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497 type IfEquals = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? A : B diff --git a/jsapp/js/api/react-query/survey-data-rest-services/msw.ts b/jsapp/js/api/react-query/survey-data-rest-services/msw.ts new file mode 100644 index 0000000000..d8af3bbb76 --- /dev/null +++ b/jsapp/js/api/react-query/survey-data-rest-services/msw.ts @@ -0,0 +1,433 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import { AuthLevelEnum } from '../../models/authLevelEnum' + +import { ExportTypeEnum } from '../../models/exportTypeEnum' + +import type { Hook } from '../../models/hook' + +import type { HookLog } from '../../models/hookLog' + +import type { HookRetryResponse } from '../../models/hookRetryResponse' + +import type { LogsRetryResponse } from '../../models/logsRetryResponse' + +import type { PaginatedHookList } from '../../models/paginatedHookList' + +import type { PaginatedHookLogList } from '../../models/paginatedHookLogList' + +export const getApiV2AssetsHooksListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedHookList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + active: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + asset: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + auth_level: faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(AuthLevelEnum)), undefined]), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + email_notification: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + endpoint: faker.string.alpha({ length: { min: 10, max: 500 } }), + export_type: faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(ExportTypeEnum)), undefined]), + failed_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + logs_url: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 255 } }), + payload_template: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + pending_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + settings: faker.helpers.arrayElement([ + { + password: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + custom_headers: faker.helpers.arrayElement([ + { + value_field: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value_field_2: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + subset_fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + success_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + })), + ...overrideResponse, +}) + +export const getApiV2AssetsHooksCreateResponseMock = (overrideResponse: Partial = {}): Hook => ({ + active: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + asset: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + auth_level: faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(AuthLevelEnum)), undefined]), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + email_notification: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + endpoint: faker.string.alpha({ length: { min: 10, max: 500 } }), + export_type: faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(ExportTypeEnum)), undefined]), + failed_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + logs_url: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 255 } }), + payload_template: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + pending_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + settings: faker.helpers.arrayElement([ + { + password: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + custom_headers: faker.helpers.arrayElement([ + { + value_field: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value_field_2: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + subset_fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + success_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2AssetsHooksRetrieveResponseMock = (overrideResponse: Partial = {}): Hook => ({ + active: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + asset: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + auth_level: faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(AuthLevelEnum)), undefined]), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + email_notification: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + endpoint: faker.string.alpha({ length: { min: 10, max: 500 } }), + export_type: faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(ExportTypeEnum)), undefined]), + failed_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + logs_url: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 255 } }), + payload_template: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + pending_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + settings: faker.helpers.arrayElement([ + { + password: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + custom_headers: faker.helpers.arrayElement([ + { + value_field: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value_field_2: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + subset_fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + success_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2AssetsHooksPartialUpdateResponseMock = (overrideResponse: Partial = {}): Hook => ({ + active: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + asset: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + auth_level: faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(AuthLevelEnum)), undefined]), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + email_notification: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + endpoint: faker.string.alpha({ length: { min: 10, max: 500 } }), + export_type: faker.helpers.arrayElement([faker.helpers.arrayElement(Object.values(ExportTypeEnum)), undefined]), + failed_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + logs_url: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 255 } }), + payload_template: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + pending_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + settings: faker.helpers.arrayElement([ + { + password: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + custom_headers: faker.helpers.arrayElement([ + { + value_field: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value_field_2: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + }, + undefined, + ]), + subset_fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + success_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2AssetsHooksLogsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedHookLogList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + submission_id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + tries: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.helpers.arrayElement([0, 1, 3, 2] as const), + status_str: faker.string.alpha({ length: { min: 10, max: 20 } }), + status_code: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + message: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + ...overrideResponse, +}) + +export const getApiV2AssetsHooksLogsRetrieveResponseMock = (overrideResponse: Partial = {}): HookLog => ({ + url: faker.internet.url(), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + submission_id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + tries: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.helpers.arrayElement([0, 1, 3, 2] as const), + status_str: faker.string.alpha({ length: { min: 10, max: 20 } }), + status_code: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + message: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + ...overrideResponse, +}) + +export const getApiV2AssetsHooksLogsRetryPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): LogsRetryResponse => ({ + detail: faker.string.alpha({ length: { min: 10, max: 20 } }), + pending_uids: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ...overrideResponse, +}) + +export const getApiV2AssetsHooksRetryPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): HookRetryResponse => ({ + detail: faker.string.alpha({ length: { min: 10, max: 20 } }), + pending_uids: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ...overrideResponse, +}) + +export const getApiV2AssetsHooksListMockHandler = ( + overrideResponse?: + | PaginatedHookList + | ((info: Parameters[1]>[0]) => Promise | PaginatedHookList), +) => { + return http.get('*/api/v2/assets/:uidAsset/hooks{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHooksListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHooksCreateMockHandler = ( + overrideResponse?: Hook | ((info: Parameters[1]>[0]) => Promise | Hook), +) => { + return http.post('*/api/v2/assets/:uidAsset/hooks{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHooksCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHooksRetrieveMockHandler = ( + overrideResponse?: Hook | ((info: Parameters[1]>[0]) => Promise | Hook), +) => { + return http.get('*/api/v2/assets/:uidAsset/hooks/:uidHook{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHooksRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHooksPartialUpdateMockHandler = ( + overrideResponse?: Hook | ((info: Parameters[1]>[0]) => Promise | Hook), +) => { + return http.patch('*/api/v2/assets/:uidAsset/hooks/:uidHook{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHooksPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHooksDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/hooks/:uidHook{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsHooksLogsListMockHandler = ( + overrideResponse?: + | PaginatedHookLogList + | ((info: Parameters[1]>[0]) => Promise | PaginatedHookLogList), +) => { + return http.get('*/api/v2/assets/:uidAsset/hooks/:uidHook/logs{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHooksLogsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHooksLogsRetrieveMockHandler = ( + overrideResponse?: HookLog | ((info: Parameters[1]>[0]) => Promise | HookLog), +) => { + return http.get('*/api/v2/assets/:uidAsset/hooks/:uidHook/logs/:uidLog{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHooksLogsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHooksLogsRetryPartialUpdateMockHandler = ( + overrideResponse?: + | LogsRetryResponse + | ((info: Parameters[1]>[0]) => Promise | LogsRetryResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/hooks/:uidHook/logs/:uidLog/retry{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHooksLogsRetryPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsHooksRetryPartialUpdateMockHandler = ( + overrideResponse?: + | HookRetryResponse + | ((info: Parameters[1]>[0]) => Promise | HookRetryResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/hooks/:uidHook/retry{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsHooksRetryPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getSurveyDataRestServicesMock = () => [ + getApiV2AssetsHooksListMockHandler(), + getApiV2AssetsHooksCreateMockHandler(), + getApiV2AssetsHooksRetrieveMockHandler(), + getApiV2AssetsHooksPartialUpdateMockHandler(), + getApiV2AssetsHooksDestroyMockHandler(), + getApiV2AssetsHooksLogsListMockHandler(), + getApiV2AssetsHooksLogsRetrieveMockHandler(), + getApiV2AssetsHooksLogsRetryPartialUpdateMockHandler(), + getApiV2AssetsHooksRetryPartialUpdateMockHandler(), +] diff --git a/jsapp/js/api/react-query/survey-data.ts b/jsapp/js/api/react-query/survey-data/index.ts similarity index 97% rename from jsapp/js/api/react-query/survey-data.ts rename to jsapp/js/api/react-query/survey-data/index.ts index 35c4068011..dabcc0e9e3 100644 --- a/jsapp/js/api/react-query/survey-data.ts +++ b/jsapp/js/api/react-query/survey-data/index.ts @@ -19,117 +19,117 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { AdvancedFeatureCreateResponse } from '../models/advancedFeatureCreateResponse' +import type { AdvancedFeatureCreateResponse } from '../../models/advancedFeatureCreateResponse' -import type { AdvancedFeaturePostRequest } from '../models/advancedFeaturePostRequest' +import type { AdvancedFeaturePostRequest } from '../../models/advancedFeaturePostRequest' -import type { AdvancedFeatureResponse } from '../models/advancedFeatureResponse' +import type { AdvancedFeatureResponse } from '../../models/advancedFeatureResponse' -import type { AssetAttachmentAudioDurationRequest } from '../models/assetAttachmentAudioDurationRequest' +import type { AssetAttachmentAudioDurationRequest } from '../../models/assetAttachmentAudioDurationRequest' -import type { AssetAttachmentAudioDurationResponse } from '../models/assetAttachmentAudioDurationResponse' +import type { AssetAttachmentAudioDurationResponse } from '../../models/assetAttachmentAudioDurationResponse' -import type { AssetsAdvancedFeaturesBulkActionsListParams } from '../models/assetsAdvancedFeaturesBulkActionsListParams' +import type { AssetsAdvancedFeaturesBulkActionsListParams } from '../../models/assetsAdvancedFeaturesBulkActionsListParams' -import type { AssetsDataAttachmentsListParams } from '../models/assetsDataAttachmentsListParams' +import type { AssetsDataAttachmentsListParams } from '../../models/assetsDataAttachmentsListParams' -import type { AssetsDataListParams } from '../models/assetsDataListParams' +import type { AssetsDataListParams } from '../../models/assetsDataListParams' -import type { AssetsDataRetrieveParams } from '../models/assetsDataRetrieveParams' +import type { AssetsDataRetrieveParams } from '../../models/assetsDataRetrieveParams' -import type { AssetsExportSettingsDataRetrieveParams } from '../models/assetsExportSettingsDataRetrieveParams' +import type { AssetsExportSettingsDataRetrieveParams } from '../../models/assetsExportSettingsDataRetrieveParams' -import type { AssetsExportSettingsListParams } from '../models/assetsExportSettingsListParams' +import type { AssetsExportSettingsListParams } from '../../models/assetsExportSettingsListParams' -import type { AssetsExportsListParams } from '../models/assetsExportsListParams' +import type { AssetsExportsListParams } from '../../models/assetsExportsListParams' -import type { AssetsFilesListParams } from '../models/assetsFilesListParams' +import type { AssetsFilesListParams } from '../../models/assetsFilesListParams' -import type { AssetsPairedDataListParams } from '../models/assetsPairedDataListParams' +import type { AssetsPairedDataListParams } from '../../models/assetsPairedDataListParams' -import type { AttachmentRetrieveParams } from '../models/attachmentRetrieveParams' +import type { AttachmentRetrieveParams } from '../../models/attachmentRetrieveParams' -import type { BulkAcceptRequest } from '../models/bulkAcceptRequest' +import type { BulkAcceptRequest } from '../../models/bulkAcceptRequest' -import type { BulkAcceptResponse } from '../models/bulkAcceptResponse' +import type { BulkAcceptResponse } from '../../models/bulkAcceptResponse' -import type { BulkActionCreateRequest } from '../models/bulkActionCreateRequest' +import type { BulkActionCreateRequest } from '../../models/bulkActionCreateRequest' -import type { BulkActionCreateResponse } from '../models/bulkActionCreateResponse' +import type { BulkActionCreateResponse } from '../../models/bulkActionCreateResponse' -import type { BulkActionListResponse } from '../models/bulkActionListResponse' +import type { BulkActionListResponse } from '../../models/bulkActionListResponse' -import type { BulkActionResponse } from '../models/bulkActionResponse' +import type { BulkActionResponse } from '../../models/bulkActionResponse' -import type { CreateFilePayload } from '../models/createFilePayload' +import type { CreateFilePayload } from '../../models/createFilePayload' -import type { DataBulkDelete } from '../models/dataBulkDelete' +import type { DataBulkDelete } from '../../models/dataBulkDelete' -import type { DataBulkUpdateResponse } from '../models/dataBulkUpdateResponse' +import type { DataBulkUpdateResponse } from '../../models/dataBulkUpdateResponse' -import type { DataResponse } from '../models/dataResponse' +import type { DataResponse } from '../../models/dataResponse' -import type { DataStatusesUpdate } from '../models/dataStatusesUpdate' +import type { DataStatusesUpdate } from '../../models/dataStatusesUpdate' -import type { DataSupplementResponse } from '../models/dataSupplementResponse' +import type { DataSupplementResponse } from '../../models/dataSupplementResponse' -import type { DataValidationStatusUpdateResponse } from '../models/dataValidationStatusUpdateResponse' +import type { DataValidationStatusUpdateResponse } from '../../models/dataValidationStatusUpdateResponse' -import type { EnketoEditResponse } from '../models/enketoEditResponse' +import type { EnketoEditResponse } from '../../models/enketoEditResponse' -import type { EnketoViewResponse } from '../models/enketoViewResponse' +import type { EnketoViewResponse } from '../../models/enketoViewResponse' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { ExportCreatePayload } from '../models/exportCreatePayload' +import type { ExportCreatePayload } from '../../models/exportCreatePayload' -import type { ExportResponse } from '../models/exportResponse' +import type { ExportResponse } from '../../models/exportResponse' -import type { ExportSettingCreatePayload } from '../models/exportSettingCreatePayload' +import type { ExportSettingCreatePayload } from '../../models/exportSettingCreatePayload' -import type { ExportSettingResponse } from '../models/exportSettingResponse' +import type { ExportSettingResponse } from '../../models/exportSettingResponse' -import type { ExternalResponse } from '../models/externalResponse' +import type { ExternalResponse } from '../../models/externalResponse' -import type { FilesResponse } from '../models/filesResponse' +import type { FilesResponse } from '../../models/filesResponse' -import type { PaginatedDataResponseList } from '../models/paginatedDataResponseList' +import type { PaginatedDataResponseList } from '../../models/paginatedDataResponseList' -import type { PaginatedExportResponseList } from '../models/paginatedExportResponseList' +import type { PaginatedExportResponseList } from '../../models/paginatedExportResponseList' -import type { PaginatedExportSettingResponseList } from '../models/paginatedExportSettingResponseList' +import type { PaginatedExportSettingResponseList } from '../../models/paginatedExportSettingResponseList' -import type { PaginatedFilesResponseList } from '../models/paginatedFilesResponseList' +import type { PaginatedFilesResponseList } from '../../models/paginatedFilesResponseList' -import type { PaginatedPairedDataResponseList } from '../models/paginatedPairedDataResponseList' +import type { PaginatedPairedDataResponseList } from '../../models/paginatedPairedDataResponseList' -import type { PairedData } from '../models/pairedData' +import type { PairedData } from '../../models/pairedData' -import type { PairedDataResponse } from '../models/pairedDataResponse' +import type { PairedDataResponse } from '../../models/pairedDataResponse' -import type { PatchedAdvancedFeaturePatchRequest } from '../models/patchedAdvancedFeaturePatchRequest' +import type { PatchedAdvancedFeaturePatchRequest } from '../../models/patchedAdvancedFeaturePatchRequest' -import type { PatchedBulkActionPatchRequest } from '../models/patchedBulkActionPatchRequest' +import type { PatchedBulkActionPatchRequest } from '../../models/patchedBulkActionPatchRequest' -import type { PatchedDataBulkUpdate } from '../models/patchedDataBulkUpdate' +import type { PatchedDataBulkUpdate } from '../../models/patchedDataBulkUpdate' -import type { PatchedDataSupplementPayload } from '../models/patchedDataSupplementPayload' +import type { PatchedDataSupplementPayload } from '../../models/patchedDataSupplementPayload' -import type { PatchedDataValidationStatusUpdatePayload } from '../models/patchedDataValidationStatusUpdatePayload' +import type { PatchedDataValidationStatusUpdatePayload } from '../../models/patchedDataValidationStatusUpdatePayload' -import type { PatchedDataValidationStatusesUpdatePayload } from '../models/patchedDataValidationStatusesUpdatePayload' +import type { PatchedDataValidationStatusesUpdatePayload } from '../../models/patchedDataValidationStatusesUpdatePayload' -import type { PatchedExportSettingUpdatePayload } from '../models/patchedExportSettingUpdatePayload' +import type { PatchedExportSettingUpdatePayload } from '../../models/patchedExportSettingUpdatePayload' -import type { PatchedPairedDataPatchPayload } from '../models/patchedPairedDataPatchPayload' +import type { PatchedPairedDataPatchPayload } from '../../models/patchedPairedDataPatchPayload' -import type { QATagTracker } from '../models/qATagTracker' +import type { QATagTracker } from '../../models/qATagTracker' -import type { ReportResponse } from '../models/reportResponse' +import type { ReportResponse } from '../../models/reportResponse' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' // https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497 type IfEquals = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? A : B diff --git a/jsapp/js/api/react-query/survey-data/msw.ts b/jsapp/js/api/react-query/survey-data/msw.ts new file mode 100644 index 0000000000..dba650224a --- /dev/null +++ b/jsapp/js/api/react-query/survey-data/msw.ts @@ -0,0 +1,3049 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import { ActionEnum } from '../../models/actionEnum' + +import { ActionIdEnum } from '../../models/actionIdEnum' + +import type { AdvancedFeatureCreateResponse } from '../../models/advancedFeatureCreateResponse' + +import type { AdvancedFeatureResponse } from '../../models/advancedFeatureResponse' + +import type { AssetAttachmentAudioDurationResponse } from '../../models/assetAttachmentAudioDurationResponse' + +import type { BulkAcceptResponse } from '../../models/bulkAcceptResponse' + +import type { BulkActionCreateResponse } from '../../models/bulkActionCreateResponse' + +import type { BulkActionListResponse } from '../../models/bulkActionListResponse' + +import type { BulkActionResponse } from '../../models/bulkActionResponse' + +import { BulkActionResponseStatusEnum } from '../../models/bulkActionResponseStatusEnum' + +import { BulkActionSubmissionStatusResponseStatusEnum } from '../../models/bulkActionSubmissionStatusResponseStatusEnum' + +import type { DataBulkUpdateResponse } from '../../models/dataBulkUpdateResponse' + +import type { DataResponse } from '../../models/dataResponse' + +import type { DataStatusesUpdate } from '../../models/dataStatusesUpdate' + +import type { DataSupplementAutomaticQualDataIntegerResponse } from '../../models/dataSupplementAutomaticQualDataIntegerResponse' + +import type { DataSupplementAutomaticQualDataSelectMultipleResponse } from '../../models/dataSupplementAutomaticQualDataSelectMultipleResponse' + +import type { DataSupplementAutomaticQualDataSelectOneResponse } from '../../models/dataSupplementAutomaticQualDataSelectOneResponse' + +import type { DataSupplementAutomaticQualDataTextResponse } from '../../models/dataSupplementAutomaticQualDataTextResponse' + +import type { DataSupplementManualQualDataInteger } from '../../models/dataSupplementManualQualDataInteger' + +import type { DataSupplementManualQualDataSelectMultiple } from '../../models/dataSupplementManualQualDataSelectMultiple' + +import type { DataSupplementManualQualDataSelectOne } from '../../models/dataSupplementManualQualDataSelectOne' + +import type { DataSupplementManualQualDataTags } from '../../models/dataSupplementManualQualDataTags' + +import type { DataSupplementManualQualDataText } from '../../models/dataSupplementManualQualDataText' + +import type { DataSupplementResponse } from '../../models/dataSupplementResponse' + +import type { DataValidationStatus } from '../../models/dataValidationStatus' + +import { DataValidationStatusLabelEnum } from '../../models/dataValidationStatusLabelEnum' + +import { DataValidationStatusUidEnum } from '../../models/dataValidationStatusUidEnum' + +import type { DataValidationStatusUpdateResponse } from '../../models/dataValidationStatusUpdateResponse' + +import type { EnketoEditResponse } from '../../models/enketoEditResponse' + +import type { EnketoViewResponse } from '../../models/enketoViewResponse' + +import type { ExportResponse } from '../../models/exportResponse' + +import type { ExportSettingResponse } from '../../models/exportSettingResponse' + +import type { ExternalResponse } from '../../models/externalResponse' + +import type { FilesResponse } from '../../models/filesResponse' + +import type { PaginatedDataResponseList } from '../../models/paginatedDataResponseList' + +import type { PaginatedExportResponseList } from '../../models/paginatedExportResponseList' + +import type { PaginatedExportSettingResponseList } from '../../models/paginatedExportSettingResponseList' + +import type { PaginatedFilesResponseList } from '../../models/paginatedFilesResponseList' + +import type { PaginatedPairedDataResponseList } from '../../models/paginatedPairedDataResponseList' + +import type { PairedDataResponse } from '../../models/pairedDataResponse' + +import type { QATagTracker } from '../../models/qATagTracker' + +import { QualSelectQuestionParamsTypeEnum } from '../../models/qualSelectQuestionParamsTypeEnum' + +import { QualSimpleQuestionParamsTypeEnum } from '../../models/qualSimpleQuestionParamsTypeEnum' + +import type { ReportResponse } from '../../models/reportResponse' + +import type { SupplementalDataContentAutomaticComplete } from '../../models/supplementalDataContentAutomaticComplete' + +import type { SupplementalDataContentAutomaticDeleted } from '../../models/supplementalDataContentAutomaticDeleted' + +import type { SupplementalDataContentAutomaticFailed } from '../../models/supplementalDataContentAutomaticFailed' + +import type { SupplementalDataContentAutomaticInProgress } from '../../models/supplementalDataContentAutomaticInProgress' + +export const getApiV2AssetsAdvancedFeaturesListResponseMock = (): AdvancedFeatureResponse[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + action: faker.helpers.arrayElement(Object.values(ActionEnum)), + params: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { language: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + type: faker.helpers.arrayElement(Object.values(QualSimpleQuestionParamsTypeEnum)), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + }, + { + uuid: faker.string.uuid(), + type: faker.helpers.arrayElement(Object.values(QualSelectQuestionParamsTypeEnum)), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + choices: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.uuid(), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + })), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + }, + ]), + { uuid: faker.string.uuid() }, + ]), + ), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + })) + +export const getApiV2AssetsAdvancedFeaturesCreateResponseMock = ( + overrideResponse: Partial = {}, +): AdvancedFeatureCreateResponse => ({ + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + action: faker.helpers.arrayElement(Object.values(ActionEnum)), + params: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { language: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + type: faker.helpers.arrayElement(Object.values(QualSimpleQuestionParamsTypeEnum)), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + hint: faker.helpers.arrayElement([{}, undefined]), + }, + { + uuid: faker.string.uuid(), + type: faker.helpers.arrayElement(Object.values(QualSelectQuestionParamsTypeEnum)), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + choices: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.uuid(), + hint: faker.helpers.arrayElement([{}, undefined]), + })), + hint: faker.helpers.arrayElement([{}, undefined]), + }, + ]), + { uuid: faker.string.uuid() }, + ]), + ), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsAdvancedFeaturesRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): AdvancedFeatureResponse => ({ + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + action: faker.helpers.arrayElement(Object.values(ActionEnum)), + params: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { language: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + type: faker.helpers.arrayElement(Object.values(QualSimpleQuestionParamsTypeEnum)), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + }, + { + uuid: faker.string.uuid(), + type: faker.helpers.arrayElement(Object.values(QualSelectQuestionParamsTypeEnum)), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + choices: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.uuid(), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + })), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + }, + ]), + { uuid: faker.string.uuid() }, + ]), + ), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsAdvancedFeaturesPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): AdvancedFeatureResponse => ({ + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + action: faker.helpers.arrayElement(Object.values(ActionEnum)), + params: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([ + { language: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + type: faker.helpers.arrayElement(Object.values(QualSimpleQuestionParamsTypeEnum)), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + }, + { + uuid: faker.string.uuid(), + type: faker.helpers.arrayElement(Object.values(QualSelectQuestionParamsTypeEnum)), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + choices: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.uuid(), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + })), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + hint: faker.helpers.arrayElement([{}, undefined]), + }, + ]), + { uuid: faker.string.uuid() }, + ]), + ), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsAdvancedFeaturesBulkActionsListResponseMock = ( + overrideResponse: Partial = {}, +): BulkActionListResponse => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + previous: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + status: faker.helpers.arrayElement(Object.values(BulkActionResponseStatusEnum)), + action_id: faker.helpers.arrayElement(Object.values(ActionIdEnum)), + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + submission_uuids: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + submission_statuses: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + status: faker.helpers.arrayElement(Object.values(BulkActionSubmissionStatusResponseStatusEnum)), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + })), + params: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + progress: faker.number.int({ min: 0, max: 100, multipleOf: undefined }), + created_by: { username: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + cancelled_by: faker.helpers.arrayElement([ + { ...{ username: faker.string.alpha({ length: { min: 10, max: 20 } }) } }, + undefined, + ]), + })), + ...overrideResponse, +}) + +export const getApiV2AssetsAdvancedFeaturesBulkActionsCreateResponseMock = ( + overrideResponse: Partial = {}, +): BulkActionCreateResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + status: faker.helpers.arrayElement(Object.values(BulkActionResponseStatusEnum)), + action_id: faker.helpers.arrayElement(Object.values(ActionIdEnum)), + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + submission_uuids: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + submission_statuses: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + status: faker.helpers.arrayElement(Object.values(BulkActionSubmissionStatusResponseStatusEnum)), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + })), + params: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + progress: faker.number.int({ min: 0, max: 100, multipleOf: undefined }), + created_by: { username: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + cancelled_by: faker.helpers.arrayElement([ + { ...{ username: faker.string.alpha({ length: { min: 10, max: 20 } }) } }, + undefined, + ]), + skipped_uuids: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ...overrideResponse, +}) + +export const getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): BulkActionResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + status: faker.helpers.arrayElement(Object.values(BulkActionResponseStatusEnum)), + action_id: faker.helpers.arrayElement(Object.values(ActionIdEnum)), + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + submission_uuids: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + submission_statuses: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + status: faker.helpers.arrayElement(Object.values(BulkActionSubmissionStatusResponseStatusEnum)), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + })), + params: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + progress: faker.number.int({ min: 0, max: 100, multipleOf: undefined }), + created_by: { username: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + cancelled_by: faker.helpers.arrayElement([ + { ...{ username: faker.string.alpha({ length: { min: 10, max: 20 } }) } }, + undefined, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsAdvancedFeaturesBulkActionsPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): BulkActionResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + status: faker.helpers.arrayElement(Object.values(BulkActionResponseStatusEnum)), + action_id: faker.helpers.arrayElement(Object.values(ActionIdEnum)), + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + submission_uuids: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + submission_statuses: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + status: faker.helpers.arrayElement(Object.values(BulkActionSubmissionStatusResponseStatusEnum)), + error: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + })), + params: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + progress: faker.number.int({ min: 0, max: 100, multipleOf: undefined }), + created_by: { username: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + cancelled_by: faker.helpers.arrayElement([ + { ...{ username: faker.string.alpha({ length: { min: 10, max: 20 } }) } }, + undefined, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsAttachmentsAudioDurationCreateResponseMock = ( + overrideResponse: Partial = {}, +): AssetAttachmentAudioDurationResponse => ({ + attachments: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + seconds: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + })), + total: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataValidationStatusMock = ( + overrideResponse: Partial = {}, +): DataValidationStatus => ({ + ...{ + timestamp: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + uid: faker.helpers.arrayElement(Object.values(DataValidationStatusUidEnum)), + by_whom: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement(Object.values(DataValidationStatusLabelEnum)), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseSupplementalDataContentAutomaticInProgressMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticInProgress => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'in_progress', + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseSupplementalDataContentAutomaticFailedMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticFailed => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'failed', + error: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseSupplementalDataContentAutomaticCompleteMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticComplete => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'complete', + value: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseSupplementalDataContentAutomaticDeletedMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticDeleted => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'deleted', + value: null, + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementManualQualDataIntegerMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataInteger => ({ + ...{ + value: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementManualQualDataTextMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataText => ({ + ...{ value: faker.string.alpha({ length: { min: 10, max: 20 } }), uuid: faker.string.uuid() }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementManualQualDataSelectOneMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataSelectOne => ({ + ...{ value: faker.string.uuid(), uuid: faker.string.uuid() }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementManualQualDataSelectMultipleMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataSelectMultiple => ({ + ...{ + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.uuid(), + ), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementManualQualDataTagsMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataTags => ({ + ...{ + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementAutomaticQualDataIntegerResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataIntegerResponse => ({ + ...faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + value: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + status: 'complete', + }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementAutomaticQualDataTextResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataTextResponse => ({ + ...faker.helpers.arrayElement([ + { uuid: faker.string.uuid(), value: faker.string.alpha({ length: { min: 10, max: 20 } }), status: 'complete' }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementAutomaticQualDataSelectOneResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataSelectOneResponse => ({ + ...faker.helpers.arrayElement([ + { uuid: faker.string.uuid(), value: faker.string.uuid(), status: 'complete' }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseDataSupplementAutomaticQualDataSelectMultipleResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataSelectMultipleResponse => ({ + ...faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.uuid(), + ), + status: 'complete', + }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedDataResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + 'formhub/uuid': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + __version__: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/instanceID': faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/rootUuid': faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/deprecatedID': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + _xform_id_string: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + _attachments: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + download_url: faker.internet.url(), + download_large_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + download_medium_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + download_small_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + mimetype: faker.string.alpha({ length: { min: 10, max: 20 } }), + media_file_basename: faker.string.alpha({ length: { min: 10, max: 20 } }), + filename: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + is_deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + _status: faker.string.alpha({ length: { min: 10, max: 20 } }), + _geolocation: Array.from({ length: faker.number.int({ min: 2, max: 2 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), null]), + ), + _submission_time: `${faker.date.past().toISOString().split('.')[0]}Z`, + _validation_status: faker.helpers.arrayElement([{ ...getApiV2AssetsDataListResponseDataValidationStatusMock() }]), + _submitted_by: faker.string.alpha({ length: { min: 10, max: 20 } }), + _supplementalDetails: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + { + [faker.string.alphanumeric(5)]: { + manual_transcription: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: `${faker.date.past().toISOString().split('.')[0]}Z`, + _data: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + })), + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + manual_translation: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dependency: { + _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.uuid(), + }, + _data: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_google_transcription: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataListResponseSupplementalDataContentAutomaticInProgressMock() }, + { ...getApiV2AssetsDataListResponseSupplementalDataContentAutomaticFailedMock() }, + { ...getApiV2AssetsDataListResponseSupplementalDataContentAutomaticCompleteMock() }, + { ...getApiV2AssetsDataListResponseSupplementalDataContentAutomaticDeletedMock() }, + ]), + })), + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_google_translation: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dependency: { + _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.uuid(), + }, + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataListResponseSupplementalDataContentAutomaticInProgressMock() }, + { ...getApiV2AssetsDataListResponseSupplementalDataContentAutomaticFailedMock() }, + { ...getApiV2AssetsDataListResponseSupplementalDataContentAutomaticCompleteMock() }, + { ...getApiV2AssetsDataListResponseSupplementalDataContentAutomaticDeletedMock() }, + ]), + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + manual_qual: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataListResponseDataSupplementManualQualDataIntegerMock() }, + { ...getApiV2AssetsDataListResponseDataSupplementManualQualDataTextMock() }, + { ...getApiV2AssetsDataListResponseDataSupplementManualQualDataSelectOneMock() }, + { ...getApiV2AssetsDataListResponseDataSupplementManualQualDataSelectMultipleMock() }, + { ...getApiV2AssetsDataListResponseDataSupplementManualQualDataTagsMock() }, + ]), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateVerified: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _uuid: faker.string.uuid(), + verified: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_bedrock_qual: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataListResponseDataSupplementAutomaticQualDataIntegerResponseMock() }, + { ...getApiV2AssetsDataListResponseDataSupplementAutomaticQualDataTextResponseMock() }, + { ...getApiV2AssetsDataListResponseDataSupplementAutomaticQualDataSelectOneResponseMock() }, + { ...getApiV2AssetsDataListResponseDataSupplementAutomaticQualDataSelectMultipleResponseMock() }, + ]), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateVerified: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _uuid: faker.string.uuid(), + _dependency: faker.helpers.arrayElement([ + { _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), _uuid: faker.string.uuid() }, + undefined, + ]), + verified: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + }, + }, + }, + }, + ]), + undefined, + ]), + })), + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataValidationStatusMock = ( + overrideResponse: Partial = {}, +): DataValidationStatus => ({ + ...{ + timestamp: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + uid: faker.helpers.arrayElement(Object.values(DataValidationStatusUidEnum)), + by_whom: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement(Object.values(DataValidationStatusLabelEnum)), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticInProgressMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticInProgress => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'in_progress', + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticFailedMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticFailed => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'failed', + error: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticCompleteMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticComplete => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'complete', + value: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticDeletedMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticDeleted => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'deleted', + value: null, + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataIntegerMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataInteger => ({ + ...{ + value: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataTextMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataText => ({ + ...{ value: faker.string.alpha({ length: { min: 10, max: 20 } }), uuid: faker.string.uuid() }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataSelectOneMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataSelectOne => ({ + ...{ value: faker.string.uuid(), uuid: faker.string.uuid() }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataSelectMultipleMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataSelectMultiple => ({ + ...{ + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.uuid(), + ), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataTagsMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataTags => ({ + ...{ + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementAutomaticQualDataIntegerResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataIntegerResponse => ({ + ...faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + value: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + status: 'complete', + }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementAutomaticQualDataTextResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataTextResponse => ({ + ...faker.helpers.arrayElement([ + { uuid: faker.string.uuid(), value: faker.string.alpha({ length: { min: 10, max: 20 } }), status: 'complete' }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementAutomaticQualDataSelectOneResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataSelectOneResponse => ({ + ...faker.helpers.arrayElement([ + { uuid: faker.string.uuid(), value: faker.string.uuid(), status: 'complete' }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseDataSupplementAutomaticQualDataSelectMultipleResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataSelectMultipleResponse => ({ + ...faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.uuid(), + ), + status: 'complete', + }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataRetrieveResponseMock = (overrideResponse: Partial = {}): DataResponse => ({ + _id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + 'formhub/uuid': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + __version__: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/instanceID': faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/rootUuid': faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/deprecatedID': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + _xform_id_string: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + _attachments: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + download_url: faker.internet.url(), + download_large_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + download_medium_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + download_small_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + mimetype: faker.string.alpha({ length: { min: 10, max: 20 } }), + media_file_basename: faker.string.alpha({ length: { min: 10, max: 20 } }), + filename: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + is_deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + _status: faker.string.alpha({ length: { min: 10, max: 20 } }), + _geolocation: Array.from({ length: faker.number.int({ min: 2, max: 2 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), null]), + ), + _submission_time: `${faker.date.past().toISOString().split('.')[0]}Z`, + _validation_status: faker.helpers.arrayElement([{ ...getApiV2AssetsDataRetrieveResponseDataValidationStatusMock() }]), + _submitted_by: faker.string.alpha({ length: { min: 10, max: 20 } }), + _supplementalDetails: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + { + [faker.string.alphanumeric(5)]: { + manual_transcription: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: `${faker.date.past().toISOString().split('.')[0]}Z`, + _data: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + })), + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + manual_translation: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dependency: { + _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.uuid(), + }, + _data: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_google_transcription: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticInProgressMock() }, + { ...getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticFailedMock() }, + { ...getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticCompleteMock() }, + { ...getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticDeletedMock() }, + ]), + })), + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_google_translation: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dependency: { + _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.uuid(), + }, + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticInProgressMock() }, + { ...getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticFailedMock() }, + { ...getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticCompleteMock() }, + { ...getApiV2AssetsDataRetrieveResponseSupplementalDataContentAutomaticDeletedMock() }, + ]), + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + manual_qual: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataIntegerMock() }, + { ...getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataTextMock() }, + { ...getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataSelectOneMock() }, + { ...getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataSelectMultipleMock() }, + { ...getApiV2AssetsDataRetrieveResponseDataSupplementManualQualDataTagsMock() }, + ]), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateVerified: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _uuid: faker.string.uuid(), + verified: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_bedrock_qual: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataRetrieveResponseDataSupplementAutomaticQualDataIntegerResponseMock() }, + { ...getApiV2AssetsDataRetrieveResponseDataSupplementAutomaticQualDataTextResponseMock() }, + { ...getApiV2AssetsDataRetrieveResponseDataSupplementAutomaticQualDataSelectOneResponseMock() }, + { ...getApiV2AssetsDataRetrieveResponseDataSupplementAutomaticQualDataSelectMultipleResponseMock() }, + ]), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateVerified: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _uuid: faker.string.uuid(), + _dependency: faker.helpers.arrayElement([ + { _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), _uuid: faker.string.uuid() }, + undefined, + ]), + verified: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + }, + }, + }, + }, + ]), + undefined, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataValidationStatusMock = ( + overrideResponse: Partial = {}, +): DataValidationStatus => ({ + ...{ + timestamp: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + uid: faker.helpers.arrayElement(Object.values(DataValidationStatusUidEnum)), + by_whom: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement(Object.values(DataValidationStatusLabelEnum)), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticInProgressMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticInProgress => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'in_progress', + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticFailedMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticFailed => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'failed', + error: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticCompleteMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticComplete => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'complete', + value: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticDeletedMock = ( + overrideResponse: Partial = {}, +): SupplementalDataContentAutomaticDeleted => ({ + ...{ + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status: 'deleted', + value: null, + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataIntegerMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataInteger => ({ + ...{ + value: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataTextMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataText => ({ + ...{ value: faker.string.alpha({ length: { min: 10, max: 20 } }), uuid: faker.string.uuid() }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataSelectOneMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataSelectOne => ({ + ...{ value: faker.string.uuid(), uuid: faker.string.uuid() }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataSelectMultipleMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataSelectMultiple => ({ + ...{ + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.uuid(), + ), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataTagsMock = ( + overrideResponse: Partial = {}, +): DataSupplementManualQualDataTags => ({ + ...{ + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + uuid: faker.string.uuid(), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementAutomaticQualDataIntegerResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataIntegerResponse => ({ + ...faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + value: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + null, + ]), + status: 'complete', + }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementAutomaticQualDataTextResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataTextResponse => ({ + ...faker.helpers.arrayElement([ + { uuid: faker.string.uuid(), value: faker.string.alpha({ length: { min: 10, max: 20 } }), status: 'complete' }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementAutomaticQualDataSelectOneResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataSelectOneResponse => ({ + ...faker.helpers.arrayElement([ + { uuid: faker.string.uuid(), value: faker.string.uuid(), status: 'complete' }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseDataSupplementAutomaticQualDataSelectMultipleResponseMock = ( + overrideResponse: Omit, 'status'> = {}, +): DataSupplementAutomaticQualDataSelectMultipleResponse => ({ + ...faker.helpers.arrayElement([ + { + uuid: faker.string.uuid(), + value: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.uuid(), + ), + status: 'complete', + }, + { uuid: faker.string.uuid(), status: 'failed', error: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataDuplicateCreateResponseMock = ( + overrideResponse: Partial = {}, +): DataResponse => ({ + _id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + 'formhub/uuid': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + __version__: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/instanceID': faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/rootUuid': faker.string.alpha({ length: { min: 10, max: 20 } }), + 'meta/deprecatedID': faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + _xform_id_string: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + _attachments: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + download_url: faker.internet.url(), + download_large_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + download_medium_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + download_small_url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + mimetype: faker.string.alpha({ length: { min: 10, max: 20 } }), + media_file_basename: faker.string.alpha({ length: { min: 10, max: 20 } }), + filename: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + question_xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + is_deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + _status: faker.string.alpha({ length: { min: 10, max: 20 } }), + _geolocation: Array.from({ length: faker.number.int({ min: 2, max: 2 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), null]), + ), + _submission_time: `${faker.date.past().toISOString().split('.')[0]}Z`, + _validation_status: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataDuplicateCreateResponseDataValidationStatusMock() }, + ]), + _submitted_by: faker.string.alpha({ length: { min: 10, max: 20 } }), + _supplementalDetails: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + { + [faker.string.alphanumeric(5)]: { + manual_transcription: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: `${faker.date.past().toISOString().split('.')[0]}Z`, + _data: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + })), + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + manual_translation: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dependency: { + _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.uuid(), + }, + _data: { + language: faker.string.alpha({ length: { min: 10, max: 20 } }), + locale: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + }, + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_google_transcription: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticInProgressMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticFailedMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticCompleteMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticDeletedMock() }, + ]), + })), + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_google_translation: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _uuid: faker.string.uuid(), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dependency: { + _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), + _uuid: faker.string.uuid(), + }, + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticInProgressMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticFailedMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticCompleteMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseSupplementalDataContentAutomaticDeletedMock() }, + ]), + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + manual_qual: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataIntegerMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataTextMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataSelectOneMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataSelectMultipleMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementManualQualDataTagsMock() }, + ]), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateVerified: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _uuid: faker.string.uuid(), + verified: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + }, + }, + }, + }, + { + [faker.string.alphanumeric(5)]: { + automatic_bedrock_qual: { + [faker.string.alphanumeric(5)]: { + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateModified: `${faker.date.past().toISOString().split('.')[0]}Z`, + _versions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + _data: faker.helpers.arrayElement([ + { ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementAutomaticQualDataIntegerResponseMock() }, + { ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementAutomaticQualDataTextResponseMock() }, + { + ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementAutomaticQualDataSelectOneResponseMock(), + }, + { + ...getApiV2AssetsDataDuplicateCreateResponseDataSupplementAutomaticQualDataSelectMultipleResponseMock(), + }, + ]), + _dateAccepted: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _dateCreated: `${faker.date.past().toISOString().split('.')[0]}Z`, + _dateVerified: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + undefined, + ]), + _uuid: faker.string.uuid(), + _dependency: faker.helpers.arrayElement([ + { _actionId: faker.string.alpha({ length: { min: 10, max: 20 } }), _uuid: faker.string.uuid() }, + undefined, + ]), + verified: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + })), + }, + }, + }, + }, + ]), + undefined, + ]), + ...overrideResponse, +}) + +export const getApiV2AssetsDataEditRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): EnketoEditResponse => ({ + url: faker.internet.url(), + version: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataEnketoEditRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): EnketoEditResponse => ({ + url: faker.internet.url(), + version: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataEnketoRedirectEditRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): EnketoEditResponse => ({ + url: faker.internet.url(), + version: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataEnketoRedirectViewRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): EnketoViewResponse => ({ + url: faker.internet.url(), + version: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataEnketoViewRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): EnketoViewResponse => ({ + url: faker.internet.url(), + version: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataValidationStatusRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): DataValidationStatusUpdateResponse => ({ + timestamp: `${faker.date.past().toISOString().split('.')[0]}Z`, + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + by_whom: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataValidationStatusPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): DataValidationStatusUpdateResponse => ({ + timestamp: `${faker.date.past().toISOString().split('.')[0]}Z`, + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + by_whom: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataSupplementRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): DataSupplementResponse => + ({ _version: faker.string.alpha({ length: { min: 10, max: 20 } }), ...overrideResponse }) as DataSupplementResponse + +export const getApiV2AssetsDataSupplementPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): DataSupplementResponse => + ({ _version: faker.string.alpha({ length: { min: 10, max: 20 } }), ...overrideResponse }) as DataSupplementResponse + +export const getApiV2AssetsDataBulkPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): DataBulkUpdateResponse => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + successes: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + failures: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + status_code: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + message: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + ...overrideResponse, +}) + +export const getApiV2AssetsDataSupplementsBulkCreateResponseMock = ( + overrideResponse: Partial = {}, +): BulkAcceptResponse => ({ + accepted_count: faker.number.int({ min: 0, max: undefined, multipleOf: undefined }), + ...overrideResponse, +}) + +export const getApiV2AssetsDataValidationStatusesPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): DataStatusesUpdate => ({ detail: faker.string.alpha({ length: { min: 10, max: 20 } }), ...overrideResponse }) + +export const getApiV2AssetsExportSettingsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedExportSettingResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + data_url_csv: faker.internet.url(), + data_url_xlsx: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + lang: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + group_sep: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + multiple_select: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + include_media_url: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + xls_types_as_text: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + hierarchy_in_labels: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + fields_from_all_versions: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + })), + ...overrideResponse, +}) + +export const getApiV2AssetsExportSettingsCreateResponseMock = ( + overrideResponse: Partial = {}, +): ExportSettingResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + data_url_csv: faker.internet.url(), + data_url_xlsx: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + lang: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + group_sep: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + multiple_select: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + include_media_url: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + xls_types_as_text: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + hierarchy_in_labels: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + fields_from_all_versions: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsExportSettingsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ExportSettingResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + data_url_csv: faker.internet.url(), + data_url_xlsx: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + lang: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + group_sep: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + multiple_select: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + include_media_url: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + xls_types_as_text: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + hierarchy_in_labels: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + fields_from_all_versions: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsExportSettingsPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): ExportSettingResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + data_url_csv: faker.internet.url(), + data_url_xlsx: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + lang: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + group_sep: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + multiple_select: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + include_media_url: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + xls_types_as_text: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + hierarchy_in_labels: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + fields_from_all_versions: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsExportsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedExportResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + message: {}, + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + last_submission_time: `${faker.date.past().toISOString().split('.')[0]}Z`, + result: faker.internet.url(), + data: { + lang: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + source: faker.helpers.arrayElement([faker.internet.url(), undefined]), + group_sep: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + multiple_select: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + include_media_url: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + hierarchy_in_labels: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + processing_time_seconds: faker.helpers.arrayElement([ + faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + undefined, + ]), + fields_from_all_versions: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + })), + ...overrideResponse, +}) + +export const getApiV2AssetsExportsCreateResponseMock = ( + overrideResponse: Partial = {}, +): ExportResponse => ({ + url: faker.internet.url(), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + message: {}, + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + last_submission_time: `${faker.date.past().toISOString().split('.')[0]}Z`, + result: faker.internet.url(), + data: { + lang: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + source: faker.helpers.arrayElement([faker.internet.url(), undefined]), + group_sep: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + multiple_select: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + include_media_url: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + hierarchy_in_labels: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + processing_time_seconds: faker.helpers.arrayElement([ + faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + undefined, + ]), + fields_from_all_versions: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsExportsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ExportResponse => ({ + url: faker.internet.url(), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + message: {}, + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + last_submission_time: `${faker.date.past().toISOString().split('.')[0]}Z`, + result: faker.internet.url(), + data: { + lang: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + source: faker.helpers.arrayElement([faker.internet.url(), undefined]), + group_sep: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + multiple_select: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + include_media_url: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + hierarchy_in_labels: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + processing_time_seconds: faker.helpers.arrayElement([ + faker.number.float({ min: undefined, max: undefined, fractionDigits: 2 }), + undefined, + ]), + fields_from_all_versions: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsFilesListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedFilesResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + asset: faker.internet.url(), + user: faker.internet.url(), + user__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + file_type: faker.string.alpha({ length: { min: 10, max: 20 } }), + description: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + content: faker.internet.url(), + metadata: { + hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + mimetype: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + })), + ...overrideResponse, +}) + +export const getApiV2AssetsFilesCreateResponseMock = ( + overrideResponse: Partial = {}, +): FilesResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + asset: faker.internet.url(), + user: faker.internet.url(), + user__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + file_type: faker.string.alpha({ length: { min: 10, max: 20 } }), + description: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + content: faker.internet.url(), + metadata: { + hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + mimetype: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsFilesRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): FilesResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + asset: faker.internet.url(), + user: faker.internet.url(), + user__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + file_type: faker.string.alpha({ length: { min: 10, max: 20 } }), + description: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + content: faker.internet.url(), + metadata: { + hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + mimetype: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsPairedDataListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedPairedDataResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + source: faker.internet.url(), + source__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + filename: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + })), + ...overrideResponse, +}) + +export const getApiV2AssetsPairedDataCreateResponseMock = ( + overrideResponse: Partial = {}, +): PairedDataResponse => ({ + source: faker.internet.url(), + source__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + filename: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2AssetsPairedDataRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PairedDataResponse => ({ + source: faker.internet.url(), + source__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + filename: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2AssetsPairedDataPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): PairedDataResponse => ({ + source: faker.internet.url(), + source__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + filename: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2AssetsPairedDataExternalRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ExternalResponse => ({ + root: { + data: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + field_value_1: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + field_value_2: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + }, + ...overrideResponse, +}) + +export const getApiV2AssetsQualQuestionsTagsListResponseMock = (): QATagTracker[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + value: faker.string.alpha({ length: { min: 10, max: 255 } }), + })) + +export const getApiV2AssetsReportsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ReportResponse => ({ + url: faker.internet.url(), + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + list: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + row: faker.helpers.arrayElement([ + { type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]) }, + undefined, + ]), + data: faker.helpers.arrayElement([ + { + total_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + not_provided: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + provided: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + show_graph: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + }, + undefined, + ]), + kuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([{}, undefined]), + })), + ...overrideResponse, +}) + +export const getApiV2AssetsAdvancedFeaturesListMockHandler = ( + overrideResponse?: + | AdvancedFeatureResponse[] + | (( + info: Parameters[1]>[0], + ) => Promise | AdvancedFeatureResponse[]), +) => { + return http.get('*/api/v2/assets/:uidAsset/advanced-features{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAdvancedFeaturesListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAdvancedFeaturesCreateMockHandler = ( + overrideResponse?: + | AdvancedFeatureCreateResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AdvancedFeatureCreateResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/advanced-features{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAdvancedFeaturesCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAdvancedFeaturesRetrieveMockHandler = ( + overrideResponse?: + | AdvancedFeatureResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AdvancedFeatureResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/advanced-features/:uidAdvancedFeature{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAdvancedFeaturesRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAdvancedFeaturesPartialUpdateMockHandler = ( + overrideResponse?: + | AdvancedFeatureResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AdvancedFeatureResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/advanced-features/:uidAdvancedFeature{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAdvancedFeaturesPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAdvancedFeaturesBulkActionsListMockHandler = ( + overrideResponse?: + | BulkActionListResponse + | (( + info: Parameters[1]>[0], + ) => Promise | BulkActionListResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/advanced-features/bulk-actions{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAdvancedFeaturesBulkActionsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAdvancedFeaturesBulkActionsCreateMockHandler = ( + overrideResponse?: + | BulkActionCreateResponse + | (( + info: Parameters[1]>[0], + ) => Promise | BulkActionCreateResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/advanced-features/bulk-actions{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAdvancedFeaturesBulkActionsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveMockHandler = ( + overrideResponse?: + | BulkActionResponse + | ((info: Parameters[1]>[0]) => Promise | BulkActionResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/advanced-features/bulk-actions/:actionUid{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAdvancedFeaturesBulkActionsPartialUpdateMockHandler = ( + overrideResponse?: + | BulkActionResponse + | ((info: Parameters[1]>[0]) => Promise | BulkActionResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/advanced-features/bulk-actions/:actionUid{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAdvancedFeaturesBulkActionsPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAttachmentsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/attachments/:id{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsAttachmentsAudioDurationCreateMockHandler = ( + overrideResponse?: + | AssetAttachmentAudioDurationResponse + | (( + info: Parameters[1]>[0], + ) => Promise | AssetAttachmentAudioDurationResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/attachments/audio-duration{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsAttachmentsAudioDurationCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsAttachmentsBulkDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/attachments/bulk{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 202 }) + }) +} + +export const getApiV2AssetsDataListMockHandler = ( + overrideResponse?: + | PaginatedDataResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedDataResponseList), +) => { + return http.get('*/api/v2/assets/:uidAsset/data{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataRetrieveMockHandler = ( + overrideResponse?: + | DataResponse + | ((info: Parameters[1]>[0]) => Promise | DataResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:id{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/data/:id{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsDataDuplicateCreateMockHandler = ( + overrideResponse?: + | DataResponse + | ((info: Parameters[1]>[0]) => Promise | DataResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/data/:id/duplicate{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataDuplicateCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataEditRetrieveMockHandler = ( + overrideResponse?: + | EnketoEditResponse + | ((info: Parameters[1]>[0]) => Promise | EnketoEditResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:id/edit{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataEditRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataEnketoEditRetrieveMockHandler = ( + overrideResponse?: + | EnketoEditResponse + | ((info: Parameters[1]>[0]) => Promise | EnketoEditResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:id/enketo/edit{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataEnketoEditRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataEnketoRedirectEditRetrieveMockHandler = ( + overrideResponse?: + | EnketoEditResponse + | ((info: Parameters[1]>[0]) => Promise | EnketoEditResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:id/enketo/redirect/edit{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataEnketoRedirectEditRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataEnketoRedirectViewRetrieveMockHandler = ( + overrideResponse?: + | EnketoViewResponse + | ((info: Parameters[1]>[0]) => Promise | EnketoViewResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:id/enketo/redirect/view{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataEnketoRedirectViewRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataEnketoViewRetrieveMockHandler = ( + overrideResponse?: + | EnketoViewResponse + | ((info: Parameters[1]>[0]) => Promise | EnketoViewResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:id/enketo/view{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataEnketoViewRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataValidationStatusRetrieveMockHandler = ( + overrideResponse?: + | DataValidationStatusUpdateResponse + | (( + info: Parameters[1]>[0], + ) => Promise | DataValidationStatusUpdateResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:id/validation_status{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataValidationStatusRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataValidationStatusPartialUpdateMockHandler = ( + overrideResponse?: + | DataValidationStatusUpdateResponse + | (( + info: Parameters[1]>[0], + ) => Promise | DataValidationStatusUpdateResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/data/:id/validation_status{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataValidationStatusPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataValidationStatusDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/data/:id/validation_status{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsDataSupplementRetrieveMockHandler = ( + overrideResponse?: + | DataSupplementResponse + | (( + info: Parameters[1]>[0], + ) => Promise | DataSupplementResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:rootUuid/supplement{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataSupplementRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataSupplementPartialUpdateMockHandler = ( + overrideResponse?: + | DataSupplementResponse + | (( + info: Parameters[1]>[0], + ) => Promise | DataSupplementResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/data/:rootUuid/supplement{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataSupplementPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataAttachmentsListMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:uidData/attachments{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getAttachmentRetrieveMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:uidData/attachments/:id{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getAttachmentThumbnailMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.get('*/api/v2/assets/:uidAsset/data/:uidData/attachments/:id/:suffix{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AssetsDataBulkPartialUpdateMockHandler = ( + overrideResponse?: + | DataBulkUpdateResponse + | (( + info: Parameters[1]>[0], + ) => Promise | DataBulkUpdateResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/data/bulk{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataBulkPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataBulkDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/data/bulk{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AssetsDataSupplementsBulkCreateMockHandler = ( + overrideResponse?: + | BulkAcceptResponse + | ((info: Parameters[1]>[0]) => Promise | BulkAcceptResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/data/supplements/bulk{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataSupplementsBulkCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataValidationStatusesPartialUpdateMockHandler = ( + overrideResponse?: + | DataStatusesUpdate + | ((info: Parameters[1]>[0]) => Promise | DataStatusesUpdate), +) => { + return http.patch('*/api/v2/assets/:uidAsset/data/validation_statuses{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsDataValidationStatusesPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsDataValidationStatusesDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/data/validation_statuses{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsExportSettingsListMockHandler = ( + overrideResponse?: + | PaginatedExportSettingResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedExportSettingResponseList), +) => { + return http.get('*/api/v2/assets/:uidAsset/export-settings{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsExportSettingsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsExportSettingsCreateMockHandler = ( + overrideResponse?: + | ExportSettingResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ExportSettingResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/export-settings{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsExportSettingsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsExportSettingsRetrieveMockHandler = ( + overrideResponse?: + | ExportSettingResponse + | ((info: Parameters[1]>[0]) => Promise | ExportSettingResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/export-settings/:uidExportSetting{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsExportSettingsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsExportSettingsPartialUpdateMockHandler = ( + overrideResponse?: + | ExportSettingResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ExportSettingResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/export-settings/:uidExportSetting{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsExportSettingsPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsExportSettingsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/export-settings/:uidExportSetting{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsExportSettingsDataRetrieveMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.get('*/api/v2/assets/:uidAsset/export-settings/:uidExportSetting/data{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AssetsExportsListMockHandler = ( + overrideResponse?: + | PaginatedExportResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedExportResponseList), +) => { + return http.get('*/api/v2/assets/:uidAsset/exports{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsExportsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsExportsCreateMockHandler = ( + overrideResponse?: + | ExportResponse + | ((info: Parameters[1]>[0]) => Promise | ExportResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/exports{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsExportsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsExportsRetrieveMockHandler = ( + overrideResponse?: + | ExportResponse + | ((info: Parameters[1]>[0]) => Promise | ExportResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/exports/:uidExport{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsExportsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsExportsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/exports/:uidExport{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsFilesListMockHandler = ( + overrideResponse?: + | PaginatedFilesResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedFilesResponseList), +) => { + return http.get('*/api/v2/assets/:uidAsset/files{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsFilesListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsFilesCreateMockHandler = ( + overrideResponse?: + | FilesResponse + | ((info: Parameters[1]>[0]) => Promise | FilesResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/files{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsFilesCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsFilesRetrieveMockHandler = ( + overrideResponse?: + | FilesResponse + | ((info: Parameters[1]>[0]) => Promise | FilesResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/files/:uidFile{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsFilesRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsFilesDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/files/:uidFile{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsFilesContentRetrieveMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.get('*/api/v2/assets/:uidAsset/files/:uidFile/content{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 200 }) + }) +} + +export const getApiV2AssetsPairedDataListMockHandler = ( + overrideResponse?: + | PaginatedPairedDataResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedPairedDataResponseList), +) => { + return http.get('*/api/v2/assets/:uidAsset/paired-data{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPairedDataListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPairedDataCreateMockHandler = ( + overrideResponse?: + | PairedDataResponse + | ((info: Parameters[1]>[0]) => Promise | PairedDataResponse), +) => { + return http.post('*/api/v2/assets/:uidAsset/paired-data{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPairedDataCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPairedDataRetrieveMockHandler = ( + overrideResponse?: + | PairedDataResponse + | ((info: Parameters[1]>[0]) => Promise | PairedDataResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/paired-data/:uidPairedData{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPairedDataRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPairedDataPartialUpdateMockHandler = ( + overrideResponse?: + | PairedDataResponse + | ((info: Parameters[1]>[0]) => Promise | PairedDataResponse), +) => { + return http.patch('*/api/v2/assets/:uidAsset/paired-data/:uidPairedData{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPairedDataPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsPairedDataDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/assets/:uidAsset/paired-data/:uidPairedData{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2AssetsPairedDataExternalRetrieveMockHandler = ( + overrideResponse?: + | ExternalResponse + | ((info: Parameters[1]>[0]) => Promise | ExternalResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/paired-data/:uidPairedData/external{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsPairedDataExternalRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsQualQuestionsTagsListMockHandler = ( + overrideResponse?: + | QATagTracker[] + | ((info: Parameters[1]>[0]) => Promise | QATagTracker[]), +) => { + return http.get('*/api/v2/assets/:uidAsset/qual-questions/:uidQaQuestion/tags{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsQualQuestionsTagsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2AssetsReportsRetrieveMockHandler = ( + overrideResponse?: + | ReportResponse + | ((info: Parameters[1]>[0]) => Promise | ReportResponse), +) => { + return http.get('*/api/v2/assets/:uidAsset/reports{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetsReportsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} +export const getSurveyDataMock = () => [ + getApiV2AssetsAdvancedFeaturesListMockHandler(), + getApiV2AssetsAdvancedFeaturesCreateMockHandler(), + getApiV2AssetsAdvancedFeaturesRetrieveMockHandler(), + getApiV2AssetsAdvancedFeaturesPartialUpdateMockHandler(), + getApiV2AssetsAdvancedFeaturesBulkActionsListMockHandler(), + getApiV2AssetsAdvancedFeaturesBulkActionsCreateMockHandler(), + getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveMockHandler(), + getApiV2AssetsAdvancedFeaturesBulkActionsPartialUpdateMockHandler(), + getApiV2AssetsAttachmentsDestroyMockHandler(), + getApiV2AssetsAttachmentsAudioDurationCreateMockHandler(), + getApiV2AssetsAttachmentsBulkDestroyMockHandler(), + getApiV2AssetsDataListMockHandler(), + getApiV2AssetsDataRetrieveMockHandler(), + getApiV2AssetsDataDestroyMockHandler(), + getApiV2AssetsDataDuplicateCreateMockHandler(), + getApiV2AssetsDataEditRetrieveMockHandler(), + getApiV2AssetsDataEnketoEditRetrieveMockHandler(), + getApiV2AssetsDataEnketoRedirectEditRetrieveMockHandler(), + getApiV2AssetsDataEnketoRedirectViewRetrieveMockHandler(), + getApiV2AssetsDataEnketoViewRetrieveMockHandler(), + getApiV2AssetsDataValidationStatusRetrieveMockHandler(), + getApiV2AssetsDataValidationStatusPartialUpdateMockHandler(), + getApiV2AssetsDataValidationStatusDestroyMockHandler(), + getApiV2AssetsDataSupplementRetrieveMockHandler(), + getApiV2AssetsDataSupplementPartialUpdateMockHandler(), + getApiV2AssetsDataAttachmentsListMockHandler(), + getAttachmentRetrieveMockHandler(), + getAttachmentThumbnailMockHandler(), + getApiV2AssetsDataBulkPartialUpdateMockHandler(), + getApiV2AssetsDataBulkDestroyMockHandler(), + getApiV2AssetsDataSupplementsBulkCreateMockHandler(), + getApiV2AssetsDataValidationStatusesPartialUpdateMockHandler(), + getApiV2AssetsDataValidationStatusesDestroyMockHandler(), + getApiV2AssetsExportSettingsListMockHandler(), + getApiV2AssetsExportSettingsCreateMockHandler(), + getApiV2AssetsExportSettingsRetrieveMockHandler(), + getApiV2AssetsExportSettingsPartialUpdateMockHandler(), + getApiV2AssetsExportSettingsDestroyMockHandler(), + getApiV2AssetsExportSettingsDataRetrieveMockHandler(), + getApiV2AssetsExportsListMockHandler(), + getApiV2AssetsExportsCreateMockHandler(), + getApiV2AssetsExportsRetrieveMockHandler(), + getApiV2AssetsExportsDestroyMockHandler(), + getApiV2AssetsFilesListMockHandler(), + getApiV2AssetsFilesCreateMockHandler(), + getApiV2AssetsFilesRetrieveMockHandler(), + getApiV2AssetsFilesDestroyMockHandler(), + getApiV2AssetsFilesContentRetrieveMockHandler(), + getApiV2AssetsPairedDataListMockHandler(), + getApiV2AssetsPairedDataCreateMockHandler(), + getApiV2AssetsPairedDataRetrieveMockHandler(), + getApiV2AssetsPairedDataPartialUpdateMockHandler(), + getApiV2AssetsPairedDataDestroyMockHandler(), + getApiV2AssetsPairedDataExternalRetrieveMockHandler(), + getApiV2AssetsQualQuestionsTagsListMockHandler(), + getApiV2AssetsReportsRetrieveMockHandler(), +] diff --git a/jsapp/js/api/react-query/user-team-organization-usage.ts b/jsapp/js/api/react-query/user-team-organization-usage/index.ts similarity index 96% rename from jsapp/js/api/react-query/user-team-organization-usage.ts rename to jsapp/js/api/react-query/user-team-organization-usage/index.ts index a7be9edf6f..f30710d6c3 100644 --- a/jsapp/js/api/react-query/user-team-organization-usage.ts +++ b/jsapp/js/api/react-query/user-team-organization-usage/index.ts @@ -19,103 +19,103 @@ import type { UseQueryResult, } from '@tanstack/react-query' -import type { AssetListCount } from '../models/assetListCount' +import type { AssetListCount } from '../../models/assetListCount' -import type { AssetUsageListParams } from '../models/assetUsageListParams' +import type { AssetUsageListParams } from '../../models/assetUsageListParams' -import type { EmailAddress } from '../models/emailAddress' +import type { EmailAddress } from '../../models/emailAddress' -import type { EmailRequestPayload } from '../models/emailRequestPayload' +import type { EmailRequestPayload } from '../../models/emailRequestPayload' -import type { ErrorDetail } from '../models/errorDetail' +import type { ErrorDetail } from '../../models/errorDetail' -import type { ErrorObject } from '../models/errorObject' +import type { ErrorObject } from '../../models/errorObject' -import type { InviteCreatePayload } from '../models/inviteCreatePayload' +import type { InviteCreatePayload } from '../../models/inviteCreatePayload' -import type { InviteCreateResponse } from '../models/inviteCreateResponse' +import type { InviteCreateResponse } from '../../models/inviteCreateResponse' -import type { InviteResponse } from '../models/inviteResponse' +import type { InviteResponse } from '../../models/inviteResponse' -import type { MeEmailsListParams } from '../models/meEmailsListParams' +import type { MeEmailsListParams } from '../../models/meEmailsListParams' -import type { MeListResponse } from '../models/meListResponse' +import type { MeListResponse } from '../../models/meListResponse' -import type { MeSocialAccountsListParams } from '../models/meSocialAccountsListParams' +import type { MeSocialAccountsListParams } from '../../models/meSocialAccountsListParams' -import type { MemberListResponse } from '../models/memberListResponse' +import type { MemberListResponse } from '../../models/memberListResponse' -import type { OrganizationResponse } from '../models/organizationResponse' +import type { OrganizationResponse } from '../../models/organizationResponse' -import type { OrganizationServiceUsageResponse } from '../models/organizationServiceUsageResponse' +import type { OrganizationServiceUsageResponse } from '../../models/organizationServiceUsageResponse' -import type { OrganizationsAssetUsageListParams } from '../models/organizationsAssetUsageListParams' +import type { OrganizationsAssetUsageListParams } from '../../models/organizationsAssetUsageListParams' -import type { OrganizationsAssetsMinimalListRetrieveParams } from '../models/organizationsAssetsMinimalListRetrieveParams' +import type { OrganizationsAssetsMinimalListRetrieveParams } from '../../models/organizationsAssetsMinimalListRetrieveParams' -import type { OrganizationsInvitesListParams } from '../models/organizationsInvitesListParams' +import type { OrganizationsInvitesListParams } from '../../models/organizationsInvitesListParams' -import type { OrganizationsListParams } from '../models/organizationsListParams' +import type { OrganizationsListParams } from '../../models/organizationsListParams' -import type { OrganizationsMembersListParams } from '../models/organizationsMembersListParams' +import type { OrganizationsMembersListParams } from '../../models/organizationsMembersListParams' -import type { PaginatedAssetList } from '../models/paginatedAssetList' +import type { PaginatedAssetList } from '../../models/paginatedAssetList' -import type { PaginatedAssetMinimalListList } from '../models/paginatedAssetMinimalListList' +import type { PaginatedAssetMinimalListList } from '../../models/paginatedAssetMinimalListList' -import type { PaginatedAssetUsageResponseList } from '../models/paginatedAssetUsageResponseList' +import type { PaginatedAssetUsageResponseList } from '../../models/paginatedAssetUsageResponseList' -import type { PaginatedCustomAssetUsageList } from '../models/paginatedCustomAssetUsageList' +import type { PaginatedCustomAssetUsageList } from '../../models/paginatedCustomAssetUsageList' -import type { PaginatedEmailAddressList } from '../models/paginatedEmailAddressList' +import type { PaginatedEmailAddressList } from '../../models/paginatedEmailAddressList' -import type { PaginatedInviteResponseList } from '../models/paginatedInviteResponseList' +import type { PaginatedInviteResponseList } from '../../models/paginatedInviteResponseList' -import type { PaginatedMemberListResponseList } from '../models/paginatedMemberListResponseList' +import type { PaginatedMemberListResponseList } from '../../models/paginatedMemberListResponseList' -import type { PaginatedOrganizationResponseList } from '../models/paginatedOrganizationResponseList' +import type { PaginatedOrganizationResponseList } from '../../models/paginatedOrganizationResponseList' -import type { PaginatedProjectViewAssetResponseList } from '../models/paginatedProjectViewAssetResponseList' +import type { PaginatedProjectViewAssetResponseList } from '../../models/paginatedProjectViewAssetResponseList' -import type { PaginatedProjectViewListResponseList } from '../models/paginatedProjectViewListResponseList' +import type { PaginatedProjectViewListResponseList } from '../../models/paginatedProjectViewListResponseList' -import type { PaginatedProjectViewUserResponseList } from '../models/paginatedProjectViewUserResponseList' +import type { PaginatedProjectViewUserResponseList } from '../../models/paginatedProjectViewUserResponseList' -import type { PaginatedSocialAccountList } from '../models/paginatedSocialAccountList' +import type { PaginatedSocialAccountList } from '../../models/paginatedSocialAccountList' -import type { PaginatedUserListResponseList } from '../models/paginatedUserListResponseList' +import type { PaginatedUserListResponseList } from '../../models/paginatedUserListResponseList' -import type { PatchedCurrentUser } from '../models/patchedCurrentUser' +import type { PatchedCurrentUser } from '../../models/patchedCurrentUser' -import type { PatchedInvitePatchPayload } from '../models/patchedInvitePatchPayload' +import type { PatchedInvitePatchPayload } from '../../models/patchedInvitePatchPayload' -import type { PatchedMemberPatchRequest } from '../models/patchedMemberPatchRequest' +import type { PatchedMemberPatchRequest } from '../../models/patchedMemberPatchRequest' -import type { PatchedOrganizationPatchPayload } from '../models/patchedOrganizationPatchPayload' +import type { PatchedOrganizationPatchPayload } from '../../models/patchedOrganizationPatchPayload' -import type { ProjectViewExportCreateResponse } from '../models/projectViewExportCreateResponse' +import type { ProjectViewExportCreateResponse } from '../../models/projectViewExportCreateResponse' -import type { ProjectViewExportResponse } from '../models/projectViewExportResponse' +import type { ProjectViewExportResponse } from '../../models/projectViewExportResponse' -import type { ProjectViewListResponse } from '../models/projectViewListResponse' +import type { ProjectViewListResponse } from '../../models/projectViewListResponse' -import type { ProjectViewsAssetsMinimalListRetrieveParams } from '../models/projectViewsAssetsMinimalListRetrieveParams' +import type { ProjectViewsAssetsMinimalListRetrieveParams } from '../../models/projectViewsAssetsMinimalListRetrieveParams' -import type { ProjectViewsAssetsRetrieveParams } from '../models/projectViewsAssetsRetrieveParams' +import type { ProjectViewsAssetsRetrieveParams } from '../../models/projectViewsAssetsRetrieveParams' -import type { ProjectViewsListParams } from '../models/projectViewsListParams' +import type { ProjectViewsListParams } from '../../models/projectViewsListParams' -import type { ProjectViewsUsersRetrieveParams } from '../models/projectViewsUsersRetrieveParams' +import type { ProjectViewsUsersRetrieveParams } from '../../models/projectViewsUsersRetrieveParams' -import type { ServiceUsageResponse } from '../models/serviceUsageResponse' +import type { ServiceUsageResponse } from '../../models/serviceUsageResponse' -import type { SocialAccount } from '../models/socialAccount' +import type { SocialAccount } from '../../models/socialAccount' -import type { UserRetrieveResponse } from '../models/userRetrieveResponse' +import type { UserRetrieveResponse } from '../../models/userRetrieveResponse' -import type { UsersListParams } from '../models/usersListParams' +import type { UsersListParams } from '../../models/usersListParams' -import { fetchWithAuth } from '../orval.mutator' +import { fetchWithAuth } from '../../orval.mutator' // https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497 type IfEquals = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? A : B diff --git a/jsapp/js/api/react-query/user-team-organization-usage/msw.ts b/jsapp/js/api/react-query/user-team-organization-usage/msw.ts new file mode 100644 index 0000000000..b5cb7c222a --- /dev/null +++ b/jsapp/js/api/react-query/user-team-organization-usage/msw.ts @@ -0,0 +1,2261 @@ +/** + * Generated by orval v7.10.0 🍺 + * Do not edit manually. + * KoboToolbox Primary API + * This page documents all KoboToolbox API endpoints, except for those implementing the OpenRosa protocol, which are [documented separately](/api/openrosa/docs/). + +The endpoints are grouped by area of intended use. Each category contains related endpoints, with detailed documentation on usage and configuration. Use this as a reference to quickly find the right endpoint for managing projects, forms, data, permissions, integrations, logs, and organizational resources. + +**General note**: All projects (whether deployed or draft), as well as all library content (questions, blocks, templates, and collections) in the user-facing application are represented in the API as "assets". + * OpenAPI spec version: 2.0.0 (api_v2) + */ +import { faker } from '@faker-js/faker' + +import { http, HttpResponse } from 'msw' + +import { AssetDeploymentStatusEnum } from '../../models/assetDeploymentStatusEnum' + +import type { AssetListCount } from '../../models/assetListCount' + +import { AssetTypeEnum } from '../../models/assetTypeEnum' + +import { CustomAssetUsageDeploymentStatusEnum } from '../../models/customAssetUsageDeploymentStatusEnum' + +import type { EmailAddress } from '../../models/emailAddress' + +import type { InviteCreateResponse } from '../../models/inviteCreateResponse' + +import type { InviteResponse } from '../../models/inviteResponse' + +import { InviteStatusChoicesEnum } from '../../models/inviteStatusChoicesEnum' + +import { InviteeRoleEnum } from '../../models/inviteeRoleEnum' + +import type { MeListResponse } from '../../models/meListResponse' + +import type { MemberListResponse } from '../../models/memberListResponse' + +import { MemberRoleEnum } from '../../models/memberRoleEnum' + +import type { OrganizationResponse } from '../../models/organizationResponse' + +import type { OrganizationServiceUsageResponse } from '../../models/organizationServiceUsageResponse' + +import { OrganizationTypeEnum } from '../../models/organizationTypeEnum' + +import type { PaginatedAssetList } from '../../models/paginatedAssetList' + +import type { PaginatedAssetMinimalListList } from '../../models/paginatedAssetMinimalListList' + +import type { PaginatedAssetUsageResponseList } from '../../models/paginatedAssetUsageResponseList' + +import type { PaginatedCustomAssetUsageList } from '../../models/paginatedCustomAssetUsageList' + +import type { PaginatedEmailAddressList } from '../../models/paginatedEmailAddressList' + +import type { PaginatedInviteResponseList } from '../../models/paginatedInviteResponseList' + +import type { PaginatedMemberListResponseList } from '../../models/paginatedMemberListResponseList' + +import type { PaginatedOrganizationResponseList } from '../../models/paginatedOrganizationResponseList' + +import type { PaginatedProjectViewAssetResponseList } from '../../models/paginatedProjectViewAssetResponseList' + +import type { PaginatedProjectViewListResponseList } from '../../models/paginatedProjectViewListResponseList' + +import type { PaginatedProjectViewUserResponseList } from '../../models/paginatedProjectViewUserResponseList' + +import type { PaginatedSocialAccountList } from '../../models/paginatedSocialAccountList' + +import type { PaginatedUserListResponseList } from '../../models/paginatedUserListResponseList' + +import type { ProjectViewExportCreateResponse } from '../../models/projectViewExportCreateResponse' + +import type { ProjectViewExportResponse } from '../../models/projectViewExportResponse' + +import type { ProjectViewListResponse } from '../../models/projectViewListResponse' + +import type { ServiceUsageBalanceData } from '../../models/serviceUsageBalanceData' + +import type { ServiceUsageResponse } from '../../models/serviceUsageResponse' + +import type { SocialAccount } from '../../models/socialAccount' + +import type { UserRetrieveResponse } from '../../models/userRetrieveResponse' + +export const getApiV2AssetUsageListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetUsageResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + asset: faker.internet.url(), + asset__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + nlp_usage_current_period: { + total_nlp_asr_seconds: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_nlp_mt_characters: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_nlp_llm_requests: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + nlp_usage_all_time: { + total_nlp_asr_seconds: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_nlp_mt_characters: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_nlp_llm_requests: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + storage_bytes: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + submission_count_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + submission_count_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + })), + ...overrideResponse, +}) + +export const getApiV2OrganizationsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedOrganizationResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 200 } }), + website: faker.string.alpha({ length: { min: 10, max: 255 } }), + organization_type: faker.helpers.arrayElement(Object.values(OrganizationTypeEnum)), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + is_owner: faker.datatype.boolean(), + is_mmo: faker.datatype.boolean(), + request_user_role: faker.helpers.arrayElement(Object.values(MemberRoleEnum)), + members: faker.internet.url(), + assets: faker.internet.url(), + service_usage: faker.internet.url(), + asset_usage: faker.internet.url(), + })), + ...overrideResponse, +}) + +export const getApiV2OrganizationsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): OrganizationResponse => ({ + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 200 } }), + website: faker.string.alpha({ length: { min: 10, max: 255 } }), + organization_type: faker.helpers.arrayElement(Object.values(OrganizationTypeEnum)), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + is_owner: faker.datatype.boolean(), + is_mmo: faker.datatype.boolean(), + request_user_role: faker.helpers.arrayElement(Object.values(MemberRoleEnum)), + members: faker.internet.url(), + assets: faker.internet.url(), + service_usage: faker.internet.url(), + asset_usage: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2OrganizationsPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): OrganizationResponse => ({ + id: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + name: faker.string.alpha({ length: { min: 10, max: 200 } }), + website: faker.string.alpha({ length: { min: 10, max: 255 } }), + organization_type: faker.helpers.arrayElement(Object.values(OrganizationTypeEnum)), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + is_owner: faker.datatype.boolean(), + is_mmo: faker.datatype.boolean(), + request_user_role: faker.helpers.arrayElement(Object.values(MemberRoleEnum)), + members: faker.internet.url(), + assets: faker.internet.url(), + service_usage: faker.internet.url(), + asset_usage: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2OrganizationsAssetUsageListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedCustomAssetUsageList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + asset: faker.internet.url(), + asset__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + nlp_usage_current_period: { + ...{ + total_nlp_asr_seconds: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_nlp_llm_requests: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_nlp_mt_characters: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + }, + nlp_usage_all_time: { + ...{ + total_nlp_asr_seconds: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_nlp_llm_requests: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_nlp_mt_characters: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + }, + storage_bytes: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + submission_count_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + submission_count_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment_status: faker.helpers.arrayElement(Object.values(CustomAssetUsageDeploymentStatusEnum)), + })), + ...overrideResponse, +}) + +export const getApiV2OrganizationsAssetsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + parent: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + settings: faker.helpers.arrayElement([ + { + sector: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + country: faker.helpers.arrayElement([faker.helpers.arrayElement([[], null]), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + organization: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([faker.helpers.arrayElement([null]), undefined]), + }, + undefined, + ]), + asset_type: faker.helpers.arrayElement(Object.values(AssetTypeEnum)), + files: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + asset: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + user__username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + file_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + date_created: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + content: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + metadata: faker.helpers.arrayElement([{}, undefined]), + })), + summary: { + geo: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + labels: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + columns: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + lock_all: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + lock_any: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + row_count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + name_quality: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + bad: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + good: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + total: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + firsts: faker.helpers.arrayElement([ + { + ok: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + bad: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + index: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + default_translation: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + naming_conflicts: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + date_created: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_modified: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_deployed: faker.helpers.arrayElement([ + faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + undefined, + ]), + version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version__content_hash: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + version_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + has_deployment: faker.datatype.boolean(), + deployed_version_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployed_versions: { + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + previous: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.internet.url(), + content_hash: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + })), + }, + deployment__links: {}, + deployment__active: faker.datatype.boolean(), + deployment__data_download_links: { + csv_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + geojson: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + kml_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + spss_labels: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + xls_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls: faker.string.alpha({ length: { min: 10, max: 20 } }), + zip_legacy: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment__last_submission_time: faker.helpers.arrayElement([ + `${faker.date.past().toISOString().split('.')[0]}Z`, + null, + ]), + deployment__encrypted: faker.datatype.boolean(), + deployment__uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + report_styles: faker.helpers.arrayElement([ + { + default: faker.helpers.arrayElement([ + { + groupDataBy: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + report_colors: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translationIndex: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + graphWidth: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + undefined, + ]), + specified: faker.helpers.arrayElement([{}, undefined]), + kuid_names: faker.helpers.arrayElement([{}, undefined]), + }, + undefined, + ]), + report_custom: faker.helpers.arrayElement([{}, undefined]), + advanced_features: faker.helpers.arrayElement([ + { + transcript: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + translation: faker.helpers.arrayElement([ + { + values: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + languages: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + qual: faker.helpers.arrayElement([ + { + qual_survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + xpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + scope: faker.string.alpha({ length: { min: 10, max: 20 } }), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + options: faker.helpers.arrayElement([ + { deleted: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]) }, + undefined, + ]), + })), + undefined, + ]), + })), + undefined, + ]), + }, + undefined, + ]), + _version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_styles: faker.helpers.arrayElement([ + { + colorSet: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + querylimit: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + selectedQuestion: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + map_custom: faker.helpers.arrayElement([{}, undefined]), + content: faker.helpers.arrayElement([ + { + schema: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + survey: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.string.alpha({ length: { min: 10, max: 20 } }), + $xpath: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + calculation: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + hint: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + required: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + appearance: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + parameters: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--matrix_list': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-constraint-message': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--rank-items': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--score-choices': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + tags: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + select_from_list_name: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + 'body::accept': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + })), + undefined, + ]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + $autovalue: faker.string.alpha({ length: { min: 10, max: 20 } }), + $kuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + list_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + 'media::image': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + $autoname: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + settings: faker.helpers.arrayElement([ + { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + version: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + id_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + style: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + form_id: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + title: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + 'kobo--lock_all': faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + 'kobo--locking-profile': faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + default_language: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + }, + undefined, + ]), + translated: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + translations: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + ), + undefined, + ]), + translations_0: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + undefined, + ]), + 'kobo--locking-profiles': faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + [faker.string.alphanumeric(5)]: {}, + })), + undefined, + ]), + }, + undefined, + ]), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + embeds: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + analysis_form_json: { + additional_fields: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + source: faker.string.alpha({ length: { min: 10, max: 20 } }), + type: faker.helpers.arrayElement([ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] as const), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + dtpath: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + choices: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uuid: faker.string.alpha({ length: { min: 10, max: 20 } }), + labels: { _default: faker.string.alpha({ length: { min: 10, max: 20 } }) }, + })), + undefined, + ]), + })), + }, + xform_link: faker.internet.url(), + hooks_link: faker.internet.url(), + tag_string: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + kind: faker.string.alpha({ length: { min: 10, max: 20 } }), + xls_link: faker.internet.url(), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 255 } }), undefined]), + assignable_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + label: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + })), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + user: faker.string.alpha({ length: { min: 10, max: 20 } }), + permission: faker.string.alpha({ length: { min: 10, max: 20 } }), + partial_permissions: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({})), + undefined, + ]), + })), + undefined, + ]), + label: faker.helpers.arrayElement([ + faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + { + default: faker.string.alpha({ length: { min: 10, max: 20 } }), + view_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + change_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + delete_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + validate_submissions: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + ]), + undefined, + ]), + })), + effective_permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + codename: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + exports: faker.internet.url(), + export_settings: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + url: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_csv: faker.string.alpha({ length: { min: 10, max: 20 } }), + data_url_xlsx: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + export_settings: { + [faker.string.alphanumeric(5)]: {}, + }, + })), + data: faker.internet.url(), + children: { + count: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + access_types: faker.helpers.arrayElement([[], null]), + data_sharing: faker.helpers.arrayElement([{}, undefined]), + paired_data: faker.internet.url(), + project_ownership: { + [faker.string.alphanumeric(5)]: {}, + }, + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_modified_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + created_by: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), null]), + })), + ...overrideResponse, +}) + +export const getApiV2OrganizationsAssetsCountsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): AssetListCount => ({ + deployed_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + archived_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + draft_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + ...overrideResponse, +}) + +export const getApiV2OrganizationsAssetsMinimalListRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetMinimalListList => ({ + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 22 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + })), + ...overrideResponse, +}) + +export const getApiV2OrganizationsInvitesListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedInviteResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + invitee_role: faker.helpers.arrayElement(Object.values(InviteeRoleEnum)), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + url: faker.internet.url(), + invited_by: faker.internet.url(), + organization_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + invitee: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + ...overrideResponse, +}) + +export const getApiV2OrganizationsInvitesCreateResponseMock = (): InviteCreateResponse => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + invited_by: faker.internet.url(), + status: faker.string.alpha({ length: { min: 10, max: 20 } }), + invitee_role: faker.helpers.arrayElement(['admin', 'member'] as const), + organization_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + invitee: faker.string.alpha({ length: { min: 10, max: 20 } }), + })) + +export const getApiV2OrganizationsInvitesRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): InviteResponse => ({ + invitee_role: faker.helpers.arrayElement(Object.values(InviteeRoleEnum)), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + url: faker.internet.url(), + invited_by: faker.internet.url(), + organization_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + invitee: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2OrganizationsInvitesPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): InviteResponse => ({ + invitee_role: faker.helpers.arrayElement(Object.values(InviteeRoleEnum)), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + url: faker.internet.url(), + invited_by: faker.internet.url(), + organization_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + invitee: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2OrganizationsMembersListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedMemberListResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + role: faker.helpers.arrayElement(Object.values(MemberRoleEnum)), + url: faker.internet.url(), + user: faker.internet.url(), + user__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + user__email: faker.internet.email(), + user__extra_details__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + user__has_mfa_enabled: faker.datatype.boolean(), + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + user__is_active: faker.datatype.boolean(), + invite: { + ...{ + invitee_role: faker.helpers.arrayElement(Object.values(InviteeRoleEnum)), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + url: faker.internet.url(), + invited_by: faker.internet.url(), + organization_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + invitee: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + })), + ...overrideResponse, +}) + +export const getApiV2OrganizationsMembersRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): MemberListResponse => ({ + role: faker.helpers.arrayElement(Object.values(MemberRoleEnum)), + url: faker.internet.url(), + user: faker.internet.url(), + user__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + user__email: faker.internet.email(), + user__extra_details__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + user__has_mfa_enabled: faker.datatype.boolean(), + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + user__is_active: faker.datatype.boolean(), + invite: { + ...{ + invitee_role: faker.helpers.arrayElement(Object.values(InviteeRoleEnum)), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + url: faker.internet.url(), + invited_by: faker.internet.url(), + organization_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + invitee: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + ...overrideResponse, +}) + +export const getApiV2OrganizationsMembersPartialUpdateResponseMock = ( + overrideResponse: Partial = {}, +): MemberListResponse => ({ + role: faker.helpers.arrayElement(Object.values(MemberRoleEnum)), + url: faker.internet.url(), + user: faker.internet.url(), + user__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + user__email: faker.internet.email(), + user__extra_details__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + user__has_mfa_enabled: faker.datatype.boolean(), + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + user__is_active: faker.datatype.boolean(), + invite: { + ...{ + invitee_role: faker.helpers.arrayElement(Object.values(InviteeRoleEnum)), + status: faker.helpers.arrayElement(Object.values(InviteStatusChoicesEnum)), + url: faker.internet.url(), + invited_by: faker.internet.url(), + organization_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + created: `${faker.date.past().toISOString().split('.')[0]}Z`, + modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + invitee: faker.string.alpha({ length: { min: 10, max: 20 } }), + }, + }, + ...overrideResponse, +}) + +export const getApiV2OrganizationsServiceUsageRetrieveResponseServiceUsageBalanceDataMock = ( + overrideResponse: Partial = {}, +): ServiceUsageBalanceData => ({ + ...{ + effective_limit: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + balance_value: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + balance_percent: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + exceeded: faker.datatype.boolean(), + }, + ...overrideResponse, +}) + +export const getApiV2OrganizationsServiceUsageRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): OrganizationServiceUsageResponse => ({ + total_nlp_usage: { + asr_seconds_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + llm_requests_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + mt_characters_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + asr_seconds_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + llm_requests_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + mt_characters_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + total_storage_bytes: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_submission_count: { + all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + balances: { + submission: faker.helpers.arrayElement([ + { ...getApiV2OrganizationsServiceUsageRetrieveResponseServiceUsageBalanceDataMock() }, + null, + ]), + storage_bytes: faker.helpers.arrayElement([ + { ...getApiV2OrganizationsServiceUsageRetrieveResponseServiceUsageBalanceDataMock() }, + null, + ]), + asr_seconds: faker.helpers.arrayElement([ + { ...getApiV2OrganizationsServiceUsageRetrieveResponseServiceUsageBalanceDataMock() }, + null, + ]), + mt_characters: faker.helpers.arrayElement([ + { ...getApiV2OrganizationsServiceUsageRetrieveResponseServiceUsageBalanceDataMock() }, + null, + ]), + llm_requests: faker.helpers.arrayElement([ + { ...getApiV2OrganizationsServiceUsageRetrieveResponseServiceUsageBalanceDataMock() }, + null, + ]), + }, + current_period_start: `${faker.date.past().toISOString().split('.')[0]}Z`, + current_period_end: `${faker.date.past().toISOString().split('.')[0]}Z`, + last_updated: `${faker.date.past().toISOString().split('.')[0]}Z`, + ...overrideResponse, +}) + +export const getApiV2ProjectViewsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedProjectViewListResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 32 } }), + name: faker.internet.url(), + url: faker.internet.url(), + assets: faker.internet.url(), + assets_export: faker.internet.url(), + users: faker.internet.url(), + users_export: faker.internet.url(), + countries: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + assigned_users: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + })), + ...overrideResponse, +}) + +export const getApiV2ProjectViewsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ProjectViewListResponse => ({ + uid: faker.string.alpha({ length: { min: 10, max: 32 } }), + name: faker.internet.url(), + url: faker.internet.url(), + assets: faker.internet.url(), + assets_export: faker.internet.url(), + users: faker.internet.url(), + users_export: faker.internet.url(), + countries: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + permissions: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + assigned_users: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + ...overrideResponse, +}) + +export const getApiV2ProjectViewsExportRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): ProjectViewExportResponse => ({ + status: faker.string.alpha({ length: { min: 10, max: 32 } }), + result: faker.internet.url(), + ...overrideResponse, +}) + +export const getApiV2ProjectViewsExportCreateResponseMock = ( + overrideResponse: Partial = {}, +): ProjectViewExportCreateResponse => ({ + status: faker.string.alpha({ length: { min: 10, max: 32 } }), + ...overrideResponse, +}) + +export const getApiV2ProjectViewsAssetsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedProjectViewAssetResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + url: faker.internet.url(), + date_created: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_modified: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_deployed: `${faker.date.past().toISOString().split('.')[0]}Z`, + owner: faker.internet.url(), + owner__username: faker.string.alpha({ length: { min: 10, max: 20 } }), + owner__email: faker.internet.email(), + owner__name: faker.string.alpha({ length: { min: 10, max: 20 } }), + owner__organization: faker.string.alpha({ length: { min: 10, max: 20 } }), + uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + settings: { + sector: faker.helpers.arrayElement([ + { + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + undefined, + ]), + country: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + label: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + value: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + undefined, + ]), + description: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + collects_pii: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + country_codes: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + operational_purpose: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + languages: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + has_deployment: faker.datatype.boolean(), + deployment__active: faker.datatype.boolean(), + deployment__submission_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + deployment_status: faker.string.alpha({ length: { min: 10, max: 20 } }), + asset_type: faker.string.alpha({ length: { min: 10, max: 20 } }), + downloads: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + format: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + })), + owner_label: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + ...overrideResponse, +}) + +export const getApiV2ProjectViewsAssetsCountsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): AssetListCount => ({ + deployed_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + archived_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + draft_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + ...overrideResponse, +}) + +export const getApiV2ProjectViewsAssetsMinimalListRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedAssetMinimalListList => ({ + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + uid: faker.string.alpha({ length: { min: 10, max: 22 } }), + name: faker.string.alpha({ length: { min: 10, max: 20 } }), + deployment_status: faker.helpers.arrayElement(Object.values(AssetDeploymentStatusEnum)), + })), + ...overrideResponse, +}) + +export const getApiV2ProjectViewsUsersRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedProjectViewUserResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + is_superuser: faker.datatype.boolean(), + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + last_login: `${faker.date.past().toISOString().split('.')[0]}Z`, + is_active: faker.datatype.boolean(), + email: faker.internet.email(), + asset_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + metadata: { + city: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + sector: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + country: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + last_ui_language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_website: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + project_view_settings: faker.helpers.arrayElement([ + { + my_project_view_name: faker.helpers.arrayElement([ + { + order: faker.helpers.arrayElement([{}, undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + })), + ...overrideResponse, +}) + +export const getApiV2ServiceUsageListResponseServiceUsageBalanceDataMock = ( + overrideResponse: Partial = {}, +): ServiceUsageBalanceData => ({ + ...{ + effective_limit: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + balance_value: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + balance_percent: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + exceeded: faker.datatype.boolean(), + }, + ...overrideResponse, +}) + +export const getApiV2ServiceUsageListResponseMock = (): ServiceUsageResponse[] => + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + total_nlp_usage: { + asr_seconds_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + llm_requests_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + mt_characters_current_period: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + asr_seconds_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + llm_requests_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + mt_characters_all_time: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + }, + total_storage_bytes: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + total_submission_count: { + all_time: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + current_period: faker.helpers.arrayElement([ + faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + undefined, + ]), + }, + balances: { + submission: faker.helpers.arrayElement([ + { ...getApiV2ServiceUsageListResponseServiceUsageBalanceDataMock() }, + null, + ]), + storage_bytes: faker.helpers.arrayElement([ + { ...getApiV2ServiceUsageListResponseServiceUsageBalanceDataMock() }, + null, + ]), + asr_seconds: faker.helpers.arrayElement([ + { ...getApiV2ServiceUsageListResponseServiceUsageBalanceDataMock() }, + null, + ]), + mt_characters: faker.helpers.arrayElement([ + { ...getApiV2ServiceUsageListResponseServiceUsageBalanceDataMock() }, + null, + ]), + llm_requests: faker.helpers.arrayElement([ + { ...getApiV2ServiceUsageListResponseServiceUsageBalanceDataMock() }, + null, + ]), + }, + current_period_start: `${faker.date.past().toISOString().split('.')[0]}Z`, + current_period_end: `${faker.date.past().toISOString().split('.')[0]}Z`, + last_updated: `${faker.date.past().toISOString().split('.')[0]}Z`, + })) + +export const getApiV2UsersListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedUserListResponseList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + id: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + is_superuser: faker.datatype.boolean(), + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + last_login: `${faker.date.past().toISOString().split('.')[0]}Z`, + is_active: faker.datatype.boolean(), + email: faker.internet.email(), + asset_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + metadata: { + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + sector: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + country: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + last_ui_language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_website: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + project_views_settings: faker.helpers.arrayElement([ + { + kobo_my_project: faker.helpers.arrayElement([ + { + order: faker.helpers.arrayElement([{}, undefined]), + fields: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + filters: faker.helpers.arrayElement([ + Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => + faker.string.alpha({ length: { min: 10, max: 20 } }), + ), + undefined, + ]), + }, + undefined, + ]), + }, + undefined, + ]), + }, + })), + ...overrideResponse, +}) + +export const getApiV2UsersRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): UserRetrieveResponse => ({ + url: faker.internet.url(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + public_collection_subscribers_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + public_collections_count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + ...overrideResponse, +}) + +export const getMeRetrieveResponseMock = (overrideResponse: Partial = {}): MeListResponse => ({ + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + first_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.internet.email(), + server_time: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + projects_url: faker.internet.url(), + gravatar: faker.internet.url(), + last_login: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + extra_details: { + bio: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + city: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + sector: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + country: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + twitter: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + linkedin: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + instagram: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + last_ui_language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_website: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + project_views_settings: faker.helpers.arrayElement([{}, undefined]), + require_auth: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + newsletter_subscription: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + git_rev: faker.helpers.arrayElement([ + faker.datatype.boolean(), + { + short: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), faker.datatype.boolean()]), + undefined, + ]), + long: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), faker.datatype.boolean()]), + undefined, + ]), + branch: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), faker.datatype.boolean()]), + undefined, + ]), + tag: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), faker.datatype.boolean()]), + undefined, + ]), + }, + ]), + social_accounts: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + provider: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + last_joined: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_joined: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + validated_password: faker.datatype.boolean(), + accepted_tos: faker.datatype.boolean(), + organization: { + url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + extra_details__uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getMePartialUpdateResponseMock = (overrideResponse: Partial = {}): MeListResponse => ({ + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + first_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + last_name: faker.string.alpha({ length: { min: 10, max: 20 } }), + email: faker.internet.email(), + server_time: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + projects_url: faker.internet.url(), + gravatar: faker.internet.url(), + last_login: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, null]), + extra_details: { + bio: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + city: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + sector: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + country: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + twitter: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + linkedin: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + instagram: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + last_ui_language: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_type: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + organization_website: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + project_views_settings: faker.helpers.arrayElement([{}, undefined]), + require_auth: faker.helpers.arrayElement([faker.datatype.boolean(), undefined]), + newsletter_subscription: faker.helpers.arrayElement([ + faker.string.alpha({ length: { min: 10, max: 20 } }), + undefined, + ]), + }, + git_rev: faker.helpers.arrayElement([ + faker.datatype.boolean(), + { + short: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), faker.datatype.boolean()]), + undefined, + ]), + long: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), faker.datatype.boolean()]), + undefined, + ]), + branch: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), faker.datatype.boolean()]), + undefined, + ]), + tag: faker.helpers.arrayElement([ + faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), faker.datatype.boolean()]), + undefined, + ]), + }, + ]), + social_accounts: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + provider: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + last_joined: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + date_joined: faker.helpers.arrayElement([`${faker.date.past().toISOString().split('.')[0]}Z`, undefined]), + email: faker.helpers.arrayElement([faker.internet.email(), undefined]), + username: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + })), + validated_password: faker.datatype.boolean(), + accepted_tos: faker.datatype.boolean(), + organization: { + url: faker.helpers.arrayElement([faker.internet.url(), undefined]), + name: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + uid: faker.helpers.arrayElement([faker.string.alpha({ length: { min: 10, max: 20 } }), undefined]), + }, + extra_details__uid: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getMeEmailsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedEmailAddressList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + })), + ...overrideResponse, +}) + +export const getMeEmailsCreateResponseMock = (overrideResponse: Partial = {}): EmailAddress => ({ + email: faker.string.alpha({ length: { min: 10, max: 20 } }), + primary: faker.datatype.boolean(), + verified: faker.datatype.boolean(), + ...overrideResponse, +}) + +export const getMeSocialAccountsListResponseMock = ( + overrideResponse: Partial = {}, +): PaginatedSocialAccountList => ({ + count: faker.number.int({ min: undefined, max: undefined, multipleOf: undefined }), + next: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + previous: faker.helpers.arrayElement([faker.helpers.arrayElement([faker.internet.url(), null]), undefined]), + results: Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({ + provider: faker.string.alpha({ length: { min: 10, max: 200 } }), + uid: faker.string.alpha({ length: { min: 10, max: 191 } }), + last_login: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + email: faker.internet.email(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + })), + ...overrideResponse, +}) + +export const getMeSocialAccountsRetrieveResponseMock = ( + overrideResponse: Partial = {}, +): SocialAccount => ({ + provider: faker.string.alpha({ length: { min: 10, max: 200 } }), + uid: faker.string.alpha({ length: { min: 10, max: 191 } }), + last_login: `${faker.date.past().toISOString().split('.')[0]}Z`, + date_joined: `${faker.date.past().toISOString().split('.')[0]}Z`, + email: faker.internet.email(), + username: faker.string.alpha({ length: { min: 10, max: 20 } }), + ...overrideResponse, +}) + +export const getApiV2AssetUsageListMockHandler = ( + overrideResponse?: + | PaginatedAssetUsageResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAssetUsageResponseList), +) => { + return http.get('*/api/v2/asset_usage{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2AssetUsageListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsListMockHandler = ( + overrideResponse?: + | PaginatedOrganizationResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedOrganizationResponseList), +) => { + return http.get('*/api/v2/organizations{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsRetrieveMockHandler = ( + overrideResponse?: + | OrganizationResponse + | ((info: Parameters[1]>[0]) => Promise | OrganizationResponse), +) => { + return http.get('*/api/v2/organizations/:uidOrganization{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsPartialUpdateMockHandler = ( + overrideResponse?: + | OrganizationResponse + | ((info: Parameters[1]>[0]) => Promise | OrganizationResponse), +) => { + return http.patch('*/api/v2/organizations/:uidOrganization{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsAssetUsageListMockHandler = ( + overrideResponse?: + | PaginatedCustomAssetUsageList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedCustomAssetUsageList), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/asset_usage{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsAssetUsageListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsAssetsRetrieveMockHandler = ( + overrideResponse?: + | PaginatedAssetList + | ((info: Parameters[1]>[0]) => Promise | PaginatedAssetList), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/assets{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsAssetsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsAssetsCountsRetrieveMockHandler = ( + overrideResponse?: + | AssetListCount + | ((info: Parameters[1]>[0]) => Promise | AssetListCount), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/assets/counts{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsAssetsCountsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsAssetsMinimalListRetrieveMockHandler = ( + overrideResponse?: + | PaginatedAssetMinimalListList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAssetMinimalListList), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/assets/minimal-list{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsAssetsMinimalListRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsInvitesListMockHandler = ( + overrideResponse?: + | PaginatedInviteResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedInviteResponseList), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/invites{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsInvitesListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsInvitesCreateMockHandler = ( + overrideResponse?: + | InviteCreateResponse + | ((info: Parameters[1]>[0]) => Promise | InviteCreateResponse), +) => { + return http.post('*/api/v2/organizations/:uidOrganization/invites{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsInvitesCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsInvitesRetrieveMockHandler = ( + overrideResponse?: + | InviteResponse + | ((info: Parameters[1]>[0]) => Promise | InviteResponse), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/invites/:guid{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsInvitesRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsInvitesPartialUpdateMockHandler = ( + overrideResponse?: + | InviteResponse + | ((info: Parameters[1]>[0]) => Promise | InviteResponse), +) => { + return http.patch('*/api/v2/organizations/:uidOrganization/invites/:guid{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsInvitesPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsInvitesDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/organizations/:uidOrganization/invites/:guid{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2OrganizationsMembersListMockHandler = ( + overrideResponse?: + | PaginatedMemberListResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedMemberListResponseList), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/members{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsMembersListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsMembersRetrieveMockHandler = ( + overrideResponse?: + | MemberListResponse + | ((info: Parameters[1]>[0]) => Promise | MemberListResponse), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/members/:username{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsMembersRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsMembersPartialUpdateMockHandler = ( + overrideResponse?: + | MemberListResponse + | ((info: Parameters[1]>[0]) => Promise | MemberListResponse), +) => { + return http.patch('*/api/v2/organizations/:uidOrganization/members/:username{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsMembersPartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2OrganizationsMembersDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/api/v2/organizations/:uidOrganization/members/:username{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getApiV2OrganizationsServiceUsageRetrieveMockHandler = ( + overrideResponse?: + | OrganizationServiceUsageResponse + | (( + info: Parameters[1]>[0], + ) => Promise | OrganizationServiceUsageResponse), +) => { + return http.get('*/api/v2/organizations/:uidOrganization/service_usage{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2OrganizationsServiceUsageRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectViewsListMockHandler = ( + overrideResponse?: + | PaginatedProjectViewListResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedProjectViewListResponseList), +) => { + return http.get('*/api/v2/project-views{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectViewsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectViewsRetrieveMockHandler = ( + overrideResponse?: + | ProjectViewListResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProjectViewListResponse), +) => { + return http.get('*/api/v2/project-views/:uidProjectView{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectViewsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectViewsExportRetrieveMockHandler = ( + overrideResponse?: + | ProjectViewExportResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProjectViewExportResponse), +) => { + return http.get('*/api/v2/project-views/:uidProjectView/:objType/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectViewsExportRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectViewsExportCreateMockHandler = ( + overrideResponse?: + | ProjectViewExportCreateResponse + | (( + info: Parameters[1]>[0], + ) => Promise | ProjectViewExportCreateResponse), +) => { + return http.post('*/api/v2/project-views/:uidProjectView/:objType/export{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectViewsExportCreateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectViewsAssetsRetrieveMockHandler = ( + overrideResponse?: + | PaginatedProjectViewAssetResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedProjectViewAssetResponseList), +) => { + return http.get('*/api/v2/project-views/:uidProjectView/assets{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectViewsAssetsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectViewsAssetsCountsRetrieveMockHandler = ( + overrideResponse?: + | AssetListCount + | ((info: Parameters[1]>[0]) => Promise | AssetListCount), +) => { + return http.get('*/api/v2/project-views/:uidProjectView/assets/counts{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectViewsAssetsCountsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectViewsAssetsMinimalListRetrieveMockHandler = ( + overrideResponse?: + | PaginatedAssetMinimalListList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedAssetMinimalListList), +) => { + return http.get('*/api/v2/project-views/:uidProjectView/assets/minimal-list{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectViewsAssetsMinimalListRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ProjectViewsUsersRetrieveMockHandler = ( + overrideResponse?: + | PaginatedProjectViewUserResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedProjectViewUserResponseList), +) => { + return http.get('*/api/v2/project-views/:uidProjectView/users{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ProjectViewsUsersRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2ServiceUsageListMockHandler = ( + overrideResponse?: + | ServiceUsageResponse[] + | (( + info: Parameters[1]>[0], + ) => Promise | ServiceUsageResponse[]), +) => { + return http.get('*/api/v2/service_usage{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2ServiceUsageListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2UsersListMockHandler = ( + overrideResponse?: + | PaginatedUserListResponseList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedUserListResponseList), +) => { + return http.get('*/api/v2/users{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2UsersListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getApiV2UsersRetrieveMockHandler = ( + overrideResponse?: + | UserRetrieveResponse + | ((info: Parameters[1]>[0]) => Promise | UserRetrieveResponse), +) => { + return http.get('*/api/v2/users/:username{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getApiV2UsersRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getMeRetrieveMockHandler = ( + overrideResponse?: + | MeListResponse + | ((info: Parameters[1]>[0]) => Promise | MeListResponse), +) => { + return http.get('*/me{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getMeRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getMePartialUpdateMockHandler = ( + overrideResponse?: + | MeListResponse + | ((info: Parameters[1]>[0]) => Promise | MeListResponse), +) => { + return http.patch('*/me{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getMePartialUpdateResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getMeDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/me{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} + +export const getMeEmailsListMockHandler = ( + overrideResponse?: + | PaginatedEmailAddressList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedEmailAddressList), +) => { + return http.get('*/me/emails{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getMeEmailsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getMeEmailsCreateMockHandler = ( + overrideResponse?: + | EmailAddress + | ((info: Parameters[1]>[0]) => Promise | EmailAddress), +) => { + return http.post('*/me/emails{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getMeEmailsCreateResponseMock(), + ), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getMeSocialAccountsListMockHandler = ( + overrideResponse?: + | PaginatedSocialAccountList + | (( + info: Parameters[1]>[0], + ) => Promise | PaginatedSocialAccountList), +) => { + return http.get('*/me/social-accounts{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getMeSocialAccountsListResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getMeSocialAccountsRetrieveMockHandler = ( + overrideResponse?: + | SocialAccount + | ((info: Parameters[1]>[0]) => Promise | SocialAccount), +) => { + return http.get('*/me/social-accounts/:provider/:uidSocialAccount{/}?', async (info) => { + return new HttpResponse( + JSON.stringify( + overrideResponse !== undefined + ? typeof overrideResponse === 'function' + ? await overrideResponse(info) + : overrideResponse + : getMeSocialAccountsRetrieveResponseMock(), + ), + { status: 200, headers: { 'Content-Type': 'application/json' } }, + ) + }) +} + +export const getMeSocialAccountsDestroyMockHandler = ( + overrideResponse?: void | ((info: Parameters[1]>[0]) => Promise | void), +) => { + return http.delete('*/me/social-accounts/:provider/:uidSocialAccount{/}?', async (info) => { + if (typeof overrideResponse === 'function') { + await overrideResponse(info) + } + return new HttpResponse(null, { status: 204 }) + }) +} +export const getUserTeamOrganizationUsageMock = () => [ + getApiV2AssetUsageListMockHandler(), + getApiV2OrganizationsListMockHandler(), + getApiV2OrganizationsRetrieveMockHandler(), + getApiV2OrganizationsPartialUpdateMockHandler(), + getApiV2OrganizationsAssetUsageListMockHandler(), + getApiV2OrganizationsAssetsRetrieveMockHandler(), + getApiV2OrganizationsAssetsCountsRetrieveMockHandler(), + getApiV2OrganizationsAssetsMinimalListRetrieveMockHandler(), + getApiV2OrganizationsInvitesListMockHandler(), + getApiV2OrganizationsInvitesCreateMockHandler(), + getApiV2OrganizationsInvitesRetrieveMockHandler(), + getApiV2OrganizationsInvitesPartialUpdateMockHandler(), + getApiV2OrganizationsInvitesDestroyMockHandler(), + getApiV2OrganizationsMembersListMockHandler(), + getApiV2OrganizationsMembersRetrieveMockHandler(), + getApiV2OrganizationsMembersPartialUpdateMockHandler(), + getApiV2OrganizationsMembersDestroyMockHandler(), + getApiV2OrganizationsServiceUsageRetrieveMockHandler(), + getApiV2ProjectViewsListMockHandler(), + getApiV2ProjectViewsRetrieveMockHandler(), + getApiV2ProjectViewsExportRetrieveMockHandler(), + getApiV2ProjectViewsExportCreateMockHandler(), + getApiV2ProjectViewsAssetsRetrieveMockHandler(), + getApiV2ProjectViewsAssetsCountsRetrieveMockHandler(), + getApiV2ProjectViewsAssetsMinimalListRetrieveMockHandler(), + getApiV2ProjectViewsUsersRetrieveMockHandler(), + getApiV2ServiceUsageListMockHandler(), + getApiV2UsersListMockHandler(), + getApiV2UsersRetrieveMockHandler(), + getMeRetrieveMockHandler(), + getMePartialUpdateMockHandler(), + getMeDestroyMockHandler(), + getMeEmailsListMockHandler(), + getMeEmailsCreateMockHandler(), + getMeSocialAccountsListMockHandler(), + getMeSocialAccountsRetrieveMockHandler(), + getMeSocialAccountsDestroyMockHandler(), +] diff --git a/jsapp/js/assetUtils.tests.js b/jsapp/js/assetUtils.tests.js index c98248b070..3aa17f9b2f 100644 --- a/jsapp/js/assetUtils.tests.js +++ b/jsapp/js/assetUtils.tests.js @@ -24,9 +24,9 @@ jest.mock('#/api/react-query/user-team-organization-usage', () => ({ })) import { MemberRoleEnum } from '#/api/models/memberRoleEnum' +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import { DeleteBlockerReason, getSurveyFlatPaths, userCanDeleteAssets } from '#/assetUtils' import { surveyWithAllPossibleGroups, surveyWithGroups } from '#/assetUtils.mocks' -import assetFactory from '#/endpoints/asset.factory' describe('getSurveyFlatPaths', () => { it('should return a list of paths for all questions', () => { @@ -164,15 +164,15 @@ describe('userCanDeleteAssets', () => { it('can delete any asset regardless of ownership or submissions', () => { const assets = [ - assetFactory({ created_by: 'bob', deployment__submission_count: 100 }), - assetFactory({ created_by: null, deployment__submission_count: 0 }), + getApiV2AssetsRetrieveResponseMock({ created_by: 'bob', deployment__submission_count: 100 }), + getApiV2AssetsRetrieveResponseMock({ created_by: null, deployment__submission_count: 0 }), ] const results = userCanDeleteAssets(assets) expect(results.every((r) => r.canDelete)).to.be.true }) it('returns canDelete: true even when the project was created by someone else', () => { - const asset = assetFactory({ created_by: 'carol', deployment__submission_count: 999 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'carol', deployment__submission_count: 999 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.true }) @@ -184,13 +184,13 @@ describe('userCanDeleteAssets', () => { }) it('can delete own project with no submissions', () => { - const asset = assetFactory({ created_by: 'alice', deployment__submission_count: 0 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'alice', deployment__submission_count: 0 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.true }) it('is blocked from deleting own project that has submissions', () => { - const asset = assetFactory({ created_by: 'alice', deployment__submission_count: 5 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'alice', deployment__submission_count: 5 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.false if (!result.canDelete) { @@ -199,7 +199,7 @@ describe('userCanDeleteAssets', () => { }) it("is blocked from deleting another member's project (no submissions)", () => { - const asset = assetFactory({ created_by: 'bob', deployment__submission_count: 0 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'bob', deployment__submission_count: 0 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.false if (!result.canDelete) { @@ -208,7 +208,7 @@ describe('userCanDeleteAssets', () => { }) it('permissions blocker takes priority when project belongs to another member and has submissions', () => { - const asset = assetFactory({ created_by: 'bob', deployment__submission_count: 10 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'bob', deployment__submission_count: 10 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.false if (!result.canDelete) { @@ -217,7 +217,7 @@ describe('userCanDeleteAssets', () => { }) it('is blocked when created_by is null', () => { - const asset = assetFactory({ created_by: null, deployment__submission_count: 0 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: null, deployment__submission_count: 0 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.false if (!result.canDelete) { @@ -227,10 +227,10 @@ describe('userCanDeleteAssets', () => { it('returns per-asset results in input order for a mixed set', () => { const assets = [ - assetFactory({ uid: 'a1', created_by: 'alice', deployment__submission_count: 0 }), // ok - assetFactory({ uid: 'a2', created_by: 'alice', deployment__submission_count: 3 }), // submissions - assetFactory({ uid: 'a3', created_by: 'bob', deployment__submission_count: 0 }), // permissions - assetFactory({ uid: 'a4', created_by: 'alice', deployment__submission_count: 0 }), // ok + getApiV2AssetsRetrieveResponseMock({ uid: 'a1', created_by: 'alice', deployment__submission_count: 0 }), // ok + getApiV2AssetsRetrieveResponseMock({ uid: 'a2', created_by: 'alice', deployment__submission_count: 3 }), // submissions + getApiV2AssetsRetrieveResponseMock({ uid: 'a3', created_by: 'bob', deployment__submission_count: 0 }), // permissions + getApiV2AssetsRetrieveResponseMock({ uid: 'a4', created_by: 'alice', deployment__submission_count: 0 }), // ok ] const results = userCanDeleteAssets(assets) @@ -244,7 +244,7 @@ describe('userCanDeleteAssets', () => { }) it('preserves the original asset reference in each result', () => { - const asset = assetFactory({ uid: 'unique-uid', created_by: 'alice' }) + const asset = getApiV2AssetsRetrieveResponseMock({ uid: 'unique-uid', created_by: 'alice' }) const [result] = userCanDeleteAssets([asset]) expect(result.asset).to.equal(asset) }) @@ -253,7 +253,7 @@ describe('userCanDeleteAssets', () => { describe('MMO owner', () => { it('can delete any asset (owner is not subject to MMO member restrictions)', () => { mockedGetQueryData.mockReturnValue(makeOrgResponse({ is_mmo: true, request_user_role: MemberRoleEnum.owner })) - const asset = assetFactory({ created_by: 'bob', deployment__submission_count: 50 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'bob', deployment__submission_count: 50 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.true }) @@ -263,8 +263,8 @@ describe('userCanDeleteAssets', () => { it('can delete all assets regardless of ownership or submissions', () => { mockedGetQueryData.mockReturnValue(makeOrgResponse({ is_mmo: false, request_user_role: MemberRoleEnum.member })) const assets = [ - assetFactory({ created_by: 'bob', deployment__submission_count: 10 }), - assetFactory({ created_by: null }), + getApiV2AssetsRetrieveResponseMock({ created_by: 'bob', deployment__submission_count: 10 }), + getApiV2AssetsRetrieveResponseMock({ created_by: null }), ] const results = userCanDeleteAssets(assets) expect(results.every((r) => r.canDelete)).to.be.true @@ -274,21 +274,21 @@ describe('userCanDeleteAssets', () => { describe('edge cases', () => { it('treats missing org cache data as no restrictions', () => { mockedGetQueryData.mockReturnValue(undefined) - const asset = assetFactory({ created_by: 'bob', deployment__submission_count: 99 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'bob', deployment__submission_count: 99 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.true }) it('treats a non-200 org response as no restrictions', () => { mockedGetQueryData.mockReturnValue({ status: 404, data: { detail: 'Not found' } }) - const asset = assetFactory({ created_by: 'bob', deployment__submission_count: 5 }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'bob', deployment__submission_count: 5 }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.true }) it('treats an account with no organization property as no restrictions', () => { setAccount('alice') - const asset = assetFactory({ created_by: 'bob' }) + const asset = getApiV2AssetsRetrieveResponseMock({ created_by: 'bob' }) const [result] = userCanDeleteAssets([asset]) expect(result.canDelete).to.be.true }) diff --git a/jsapp/js/assetUtils.ts b/jsapp/js/assetUtils.ts index 7ed3b3352f..bf8f792b1e 100644 --- a/jsapp/js/assetUtils.ts +++ b/jsapp/js/assetUtils.ts @@ -154,13 +154,16 @@ export function getCountryDisplayString(asset: AssetResponse | ProjectViewAsset) * and then switching to french would result in seeing spanish labels) */ const countries = [] - // https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#working-with-union-types + // Backend schema specifies country as array, but old assets (pre-Dec 2022) + // may still have it as a single object if they haven't been updated since + // standardization was added, or if the migration was skipped. if (Array.isArray(asset.settings.country)) { for (const country of asset.settings.country) { countries.push(envStore.getCountryLabel(country.value)) } } else { - countries.push(envStore.getCountryLabel(asset.settings.country.value)) + // Legacy fallback: single object format from pre-standardization assets + countries.push(envStore.getCountryLabel((asset.settings.country as any).value)) } if (countries.length === 0) { diff --git a/jsapp/js/attachments/AttachmentActionsDropdown.mocks.ts b/jsapp/js/attachments/AttachmentActionsDropdown.mocks.ts index e2ea1fc1c4..c731b202e6 100644 --- a/jsapp/js/attachments/AttachmentActionsDropdown.mocks.ts +++ b/jsapp/js/attachments/AttachmentActionsDropdown.mocks.ts @@ -1,24 +1,16 @@ +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import { ANY_ROW_TYPE_NAMES, AssetTypeName } from '#/constants' import type { AssetResponse, SubmissionResponse } from '#/dataInterface' -export const assetWithImage: AssetResponse = { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/', - owner: 'http://kf.kobo.local/api/v2/users/zefir/', +export const assetWithImage = getApiV2AssetsRetrieveResponseMock({ + uid: 'aALUCUEKcgKk28owQo3LrA', + name: 'Small image project', owner__username: 'zefir', - last_modified_by: null, - created_by: null, - parent: null, - settings: { - sector: {}, - country: [], - description: '', - collects_pii: null, - organization: '', - country_codes: [], - operational_purpose: null, - }, asset_type: AssetTypeName.survey, - files: [], + deployment_status: 'deployed', + has_deployment: true, + deployment__active: true, + deployment__submission_count: 1, summary: { geo: false, labels: ['Add a picture'], @@ -42,65 +34,6 @@ export const assetWithImage: AssetResponse = { }, default_translation: null, }, - date_created: '2025-03-13T11:21:07.647839Z', - date_modified: '2025-03-13T11:21:36.038403Z', - date_deployed: '2025-03-13T11:21:36.019801Z', - version_id: 'vXCTi4YUvJ8FuwgcdDMDki', - version__content_hash: '82fcae2bf3933d231b963d6ef4dd37f853475ab5', - version_count: 2, - has_deployment: true, - deployed_version_id: 'vXCTi4YUvJ8FuwgcdDMDki', - deployed_versions: { - count: 1, - next: null, - previous: null, - results: [ - { - uid: 'vXCTi4YUvJ8FuwgcdDMDki', - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/versions/vXCTi4YUvJ8FuwgcdDMDki/', - content_hash: '82fcae2bf3933d231b963d6ef4dd37f853475ab5', - date_deployed: '2025-03-13T11:21:36.016537Z', - date_modified: '2025-03-13T11:21:36.016537Z', - }, - ], - }, - deployment__links: { - url: 'http://ee.kobo.local/X63UWDPC', - single_url: 'http://ee.kobo.local/single/X63UWDPC', - single_once_url: 'http://ee.kobo.local/single/1b7edd93e9e4c47629868c8a8163a308', - offline_url: 'http://ee.kobo.local/x/X63UWDPC', - preview_url: 'http://ee.kobo.local/preview/X63UWDPC', - iframe_url: 'http://ee.kobo.local/i/X63UWDPC', - single_iframe_url: 'http://ee.kobo.local/single/i/X63UWDPC', - single_once_iframe_url: 'http://ee.kobo.local/single/i/1b7edd93e9e4c47629868c8a8163a308', - }, - deployment__active: true, - deployment__data_download_links: { - csv_legacy: 'http://kc.kobo.local/zefir/exports/aALUCUEKcgKk28owQo3LrA/csv/', - csv: 'http://kc.kobo.local/zefir/reports/aALUCUEKcgKk28owQo3LrA/export.csv', - kml_legacy: 'http://kc.kobo.local/zefir/exports/aALUCUEKcgKk28owQo3LrA/kml/', - xls_legacy: 'http://kc.kobo.local/zefir/exports/aALUCUEKcgKk28owQo3LrA/xls/', - xls: 'http://kc.kobo.local/zefir/reports/aALUCUEKcgKk28owQo3LrA/export.xlsx', - zip_legacy: 'http://kc.kobo.local/zefir/exports/aALUCUEKcgKk28owQo3LrA/zip/', - }, - deployment__submission_count: 1, - deployment_status: 'deployed', - report_styles: { - default: {}, - specified: { - gd0wv19: {}, - }, - kuid_names: { - gd0wv19: 'gd0wv19', - }, - }, - report_custom: {}, - advanced_features: {}, - analysis_form_json: { - additional_fields: [], - }, - map_styles: {}, - map_custom: {}, content: { schema: '1', survey: [ @@ -117,176 +50,7 @@ export const assetWithImage: AssetResponse = { translated: ['label'], translations: [null], }, - downloads: [ - { - format: 'xls', - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA.xls', - }, - { - format: 'xml', - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA.xml', - }, - ], - embeds: [ - { - format: 'xls', - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/xls/', - }, - { - format: 'xform', - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/xform/', - }, - ], - xform_link: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/xform/', - hooks_link: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/hooks/', - tag_string: '', - uid: 'aALUCUEKcgKk28owQo3LrA', - kind: 'asset', - xls_link: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/xls/', - name: 'Small image project', - assignable_permissions: [ - { - url: 'http://kf.kobo.local/api/v2/permissions/view_asset/', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/change_asset/', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', - label: 'View submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/partial_submissions/', - label: { - default: 'Act on submissions only from specific users', - view_submissions: 'View submissions only from specific users', - change_submissions: 'Edit submissions only from specific users', - delete_submissions: 'Delete submissions only from specific users', - validate_submissions: 'Validate submissions only from specific users', - }, - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', - label: 'Validate submissions', - }, - ], - permissions: [ - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/pcAumEGxWPumiRiotggxP8/', - user: 'http://kf.kobo.local/api/v2/users/AnonymousUser/', - permission: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/ppN82KMksMFmUBJiqZRpUj/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/phSpaAPcqEaTWCCXZpcVVi/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/change_asset/', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/pTGqsL9eQLgAcbQHKvBvvt/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/p458sk4MGkRtvfSGf3yWYi/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/pqgKoy64qwztzVfSmg4hfV/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/pyKd6Zp7BAmCAmLE9FySJK/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', - label: 'Validate submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/pR2nuq5oJVscaUvDdm5o5c/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/view_asset/', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/permission-assignments/pqhwwj6WKLvE4Sxi8EXmxW/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', - label: 'View submissions', - }, - ], - effective_permissions: [ - { - codename: 'change_asset', - }, - { - codename: 'change_submissions', - }, - { - codename: 'delete_submissions', - }, - { - codename: 'view_submissions', - }, - { - codename: 'manage_asset', - }, - { - codename: 'view_asset', - }, - { - codename: 'delete_asset', - }, - { - codename: 'validate_submissions', - }, - { - codename: 'add_submissions', - }, - ], - exports: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/exports/', - export_settings: [], - data: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/data/', - children: { - count: 0, - }, - subscribers_count: 0, - status: 'shared', - access_types: null, - data_sharing: {}, - paired_data: 'http://kf.kobo.local/api/v2/assets/aALUCUEKcgKk28owQo3LrA/paired-data/', - project_ownership: null, - owner_label: 'Test Korp Inc', -} +}) as unknown as AssetResponse export const assetWithImageSubmission: SubmissionResponse = { _id: 67, diff --git a/jsapp/js/components/AssetTagsModal/AssetTagsModal.stories.tsx b/jsapp/js/components/AssetTagsModal/AssetTagsModal.stories.tsx index dfc602efe0..37f1f3a3f1 100644 --- a/jsapp/js/components/AssetTagsModal/AssetTagsModal.stories.tsx +++ b/jsapp/js/components/AssetTagsModal/AssetTagsModal.stories.tsx @@ -1,19 +1,23 @@ import { ModalsProvider } from '@mantine/modals' import type { Meta, StoryObj } from '@storybook/react-webpack5' import { expect, fn, userEvent, waitFor, within } from 'storybook/test' +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import ButtonNew from '#/components/common/ButtonNew' import type { AssetResponse } from '#/dataInterface' -import assetFactory from '#/endpoints/asset.factory' import { assetPatchMock } from '#/endpoints/asset.mocks' import { queryClientDecorator } from '#/query/queryClient.mocks' import { KOBO_MODAL_SHARED_PROPS } from '#/theme/kobo/Modal' import { openAssetTagsModal } from './openAssetTagsModal' -const mockAsset = assetFactory({ +// Cast Orval-generated Asset to legacy AssetResponse type +// The types are structurally compatible at runtime, differences are: +// - Optional fields (date_created, date_modified) that are always present in responses +// - Legacy type has looser field types for backward compatibility +const mockAsset = getApiV2AssetsRetrieveResponseMock({ uid: 'storyAssetTagsUid', name: 'Storybook Asset Tags', tag_string: 'alpha,beta', -}) +}) as unknown as AssetResponse const mockAssetUid = mockAsset.uid const onAssetPatched = fn() diff --git a/jsapp/js/components/activity/FormActivity.stories.tsx b/jsapp/js/components/activity/FormActivity.stories.tsx index cf2c6e6d4f..2f8cd34684 100644 --- a/jsapp/js/components/activity/FormActivity.stories.tsx +++ b/jsapp/js/components/activity/FormActivity.stories.tsx @@ -1,11 +1,11 @@ import type { Meta, StoryObj } from '@storybook/react-webpack5' import { reactRouterParameters, withRouter } from 'storybook-addon-remix-react-router' import { expect, userEvent, waitFor, within } from 'storybook/test' +import { getApiV2AssetsHistoryActionsRetrieveMockHandler } from '#/api/react-query/logging/msw' import assetHistoryMock, { assetHistoryMockWithOngoingBulkProcessing, mockAssetUid, } from '#/endpoints/assetHistory.mocks' -import assetHistoryActionsMock from '#/endpoints/assetHistoryActions.mocks' import { bulkActionCancelMock } from '#/endpoints/bulkActions.mocks' import { queryClientDecorator } from '#/query/queryClient.mocks' import { ROUTES } from '#/router/routerConstants' @@ -17,7 +17,23 @@ const meta: Meta = { argTypes: {}, parameters: { msw: { - handlers: [assetHistoryMock, assetHistoryActionsMock], + handlers: [ + // More specific handler must come first + getApiV2AssetsHistoryActionsRetrieveMockHandler({ + actions: [ + 'bulk-processing', + 'disallow-anonymous-submissions', + 'add-media', + 'add-submission', + 'allow-anonymous-submissions', + 'modify-user-permissions', + 'update-content', + 'deploy', + 'delete-submission', + ], + }), + assetHistoryMock, + ], }, reactRouter: reactRouterParameters({ location: { @@ -71,7 +87,23 @@ export const TestFilteringByActivityType: Story = { export const OngoingBulkProcessing: Story = { parameters: { msw: { - handlers: [assetHistoryMockWithOngoingBulkProcessing, assetHistoryActionsMock, bulkActionCancelMock], + handlers: [ + assetHistoryMockWithOngoingBulkProcessing, + getApiV2AssetsHistoryActionsRetrieveMockHandler({ + actions: [ + 'bulk-processing', + 'disallow-anonymous-submissions', + 'add-media', + 'add-submission', + 'allow-anonymous-submissions', + 'modify-user-permissions', + 'update-content', + 'deploy', + 'delete-submission', + ], + }), + bulkActionCancelMock, + ], }, }, } diff --git a/jsapp/js/components/assetsTable/assetsTableRow.tsx b/jsapp/js/components/assetsTable/assetsTableRow.tsx index ba00b5ed54..7b5a4b1adf 100644 --- a/jsapp/js/components/assetsTable/assetsTableRow.tsx +++ b/jsapp/js/components/assetsTable/assetsTableRow.tsx @@ -74,7 +74,7 @@ class AssetsTableRow extends React.Component { )} - {formatTime(this.props.asset.date_modified)} + {this.props.asset.date_modified ? formatTime(this.props.asset.date_modified) : '-'} ) diff --git a/jsapp/js/components/formSummary/formSummaryProjectInfo.tsx b/jsapp/js/components/formSummary/formSummaryProjectInfo.tsx index 5021d63c99..20206d5cb9 100644 --- a/jsapp/js/components/formSummary/formSummaryProjectInfo.tsx +++ b/jsapp/js/components/formSummary/formSummaryProjectInfo.tsx @@ -122,7 +122,7 @@ export default function FormSummaryProjectInfo(props: FormSummaryProjectInfoProp {/* date modified */} {t('Last modified')} - {formatTime(props.asset.date_modified)} + {props.asset.date_modified ? formatTime(props.asset.date_modified) : '-'} {/* date deployed */} diff --git a/jsapp/js/components/library/assetInfoBox.tsx b/jsapp/js/components/library/assetInfoBox.tsx index 72948669a0..a52a2e76b7 100644 --- a/jsapp/js/components/library/assetInfoBox.tsx +++ b/jsapp/js/components/library/assetInfoBox.tsx @@ -74,13 +74,13 @@ export default class AssetInfoBox extends React.Component - {formatTime(this.props.asset.date_created)} + {this.props.asset.date_created ? formatTime(this.props.asset.date_created) : '-'} {this.state.areDetailsVisible && ( - {formatTime(this.props.asset.date_modified)} + {this.props.asset.date_modified ? formatTime(this.props.asset.date_modified) : '-'} )} diff --git a/jsapp/js/components/locking/lockingConstants.ts b/jsapp/js/components/locking/lockingConstants.ts index 95b191e062..de5c4b5ecc 100644 --- a/jsapp/js/components/locking/lockingConstants.ts +++ b/jsapp/js/components/locking/lockingConstants.ts @@ -1,6 +1,8 @@ export interface AssetLockingProfileDefinition { name: string restrictions: LockingRestrictionName[] + /** Allow additional properties for backend extensions */ + [key: string]: unknown } export interface IndexedAssetLockingProfileDefinition extends AssetLockingProfileDefinition { diff --git a/jsapp/js/components/locking/lockingUtils.mocks.ts b/jsapp/js/components/locking/lockingUtils.mocks.ts index 494a4847ef..a8de005968 100644 --- a/jsapp/js/components/locking/lockingUtils.mocks.ts +++ b/jsapp/js/components/locking/lockingUtils.mocks.ts @@ -1,5 +1,6 @@ import cloneDeep from 'lodash.clonedeep' import merge from 'lodash.merge' +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import { AssetTypeName, GroupTypeBeginName, @@ -11,28 +12,18 @@ import type { AssetResponse } from '#/dataInterface' import { LOCKING_PROFILE_PROP_NAME, LOCK_ALL_PROP_NAME, LockingRestrictionName } from './lockingConstants' /** - * This is a minimal response from asset endpoin. The idea is to make it up - * to date and extend in other test objects (rather than having those huge - * lengthy JSONs). + * This is a minimal response from asset endpoint. Uses Orval-generated factory + * for type safety and to ensure all required fields are present. */ -const minimalAssetResponse = { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/', - owner: 'http://kf.kobo.local/api/v2/users/zefir/', +const minimalAssetResponse = getApiV2AssetsRetrieveResponseMock({ + uid: 'aBcDe12345', + name: 'Test form', owner__username: 'zefir', - last_modified_by: null, - created_by: null, - parent: null, - settings: { - sector: { label: 'Other', value: 'Other' }, - country: [{ label: 'Sweden', value: 'SWE' }], - description: '', - collects_pii: null, - organization: '', - country_codes: ['SWE'], - operational_purpose: null, - }, asset_type: AssetTypeName.survey, - files: [], + deployment_status: 'deployed', + has_deployment: true, + deployment__active: true, + deployment__submission_count: 0, summary: { geo: false, labels: ['Your name'], @@ -56,69 +47,6 @@ const minimalAssetResponse = { }, default_translation: null, }, - date_created: '2024-12-27T13:34:55.637503Z', - date_modified: '2024-12-27T13:35:40.543334Z', - date_deployed: '2024-12-27T13:35:38.897089Z', - version_id: 'veUGfHFYgnfkX9uxo3FoJ6', - version__content_hash: '1685a50ec9695c20eafb17a1b5a0e8ce5946e33c', - version_count: 2, - has_deployment: true, - deployed_version_id: 'veUGfHFYgnfkX9uxo3FoJ6', - deployed_versions: { - count: 1, - next: null, - previous: null, - results: [ - { - uid: 'veUGfHFYgnfkX9uxo3FoJ6', - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/versions/veUGfHFYgnfkX9uxo3FoJ6/', - content_hash: '1685a50ec9695c20eafb17a1b5a0e8ce5946e33c', - date_deployed: '2024-12-27T13:35:38.894580Z', - date_modified: '2024-12-27T13:35:38.894580Z', - }, - ], - }, - deployment__links: { - url: 'http://ee.kobo.local/bNOwZTAI', - single_url: 'http://ee.kobo.local/single/bNOwZTAI', - single_once_url: 'http://ee.kobo.local/single/451523a0f57ad42817198c8b2ae93dc3', - offline_url: 'http://ee.kobo.local/x/bNOwZTAI', - preview_url: 'http://ee.kobo.local/preview/bNOwZTAI', - iframe_url: 'http://ee.kobo.local/i/bNOwZTAI', - single_iframe_url: 'http://ee.kobo.local/single/i/bNOwZTAI', - single_once_iframe_url: 'http://ee.kobo.local/single/i/451523a0f57ad42817198c8b2ae93dc3', - }, - deployment__active: true, - deployment__data_download_links: { - xls_legacy: 'http://kc.kobo.local/zefir/exports/aBcDe12345/xls/', - csv_legacy: 'http://kc.kobo.local/zefir/exports/aBcDe12345/csv/', - zip_legacy: 'http://kc.kobo.local/zefir/exports/aBcDe12345/zip/', - kml_legacy: 'http://kc.kobo.local/zefir/exports/aBcDe12345/kml/', - geojson: 'http://kc.kobo.local/zefir/exports/aBcDe12345/geojson/', - spss_labels: 'http://kc.kobo.local/zefir/exports/aBcDe12345/spss/', - xls: 'http://kc.kobo.local/zefir/reports/aBcDe12345/export.xlsx', - csv: 'http://kc.kobo.local/zefir/reports/aBcDe12345/export.csv', - }, - deployment__submission_count: 0, - deployment_status: 'deployed', - report_styles: { - default: {}, - specified: { - end: {}, - px18z33: {}, - }, - kuid_names: { - end: '4s7wEq869', - px18z33: 'px18z33', - }, - }, - report_custom: {}, - advanced_features: {}, - analysis_form_json: { - additional_fields: [], - }, - map_styles: {}, - map_custom: {}, content: { schema: '1', survey: [ @@ -142,114 +70,7 @@ const minimalAssetResponse = { translated: ['label'], translations: [null], }, - downloads: [ - { format: 'xls', url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345.xls' }, - { format: 'xml', url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345.xml' }, - ], - embeds: [ - { format: 'xls', url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/xls/' }, - { format: 'xform', url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/xform/' }, - ], - xform_link: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/xform/', - hooks_link: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/hooks/', - tag_string: '', - uid: 'aBcDe12345', - kind: 'asset', - xls_link: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/xls/', - name: 'Test form', - assignable_permissions: [ - { url: 'http://kf.kobo.local/api/v2/permissions/view_asset/', label: 'View form' }, - { url: 'http://kf.kobo.local/api/v2/permissions/change_asset/', label: 'Edit form' }, - { url: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', label: 'Manage project' }, - { url: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', label: 'Add submissions' }, - { url: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', label: 'View submissions' }, - { - url: 'http://kf.kobo.local/api/v2/permissions/partial_submissions/', - label: { - default: 'Act on submissions only from specific users', - view_submissions: 'View submissions only from specific users', - change_submissions: 'Edit submissions only from specific users', - delete_submissions: 'Delete submissions only from specific users', - validate_submissions: 'Validate submissions only from specific users', - }, - }, - { url: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', label: 'Edit submissions' }, - { url: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', label: 'Delete submissions' }, - { url: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', label: 'Validate submissions' }, - ], - permissions: [ - { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/permission-assignments/pVQvikEvyQYmQazbNxobN6/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/permission-assignments/pFuSpuH2DYWCpqXL6vQ94x/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/change_asset/', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/permission-assignments/p48wUoqUifRyj8bJssDKJi/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/permission-assignments/ptUCvQdK5ghnoHT5WHF8AA/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/permission-assignments/pUKmhnLN2UXpxsipebgieS/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/permission-assignments/poeQAKvMyjWsQYxejuPKpM/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', - label: 'Validate submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/permission-assignments/pBBjGJRLfMAqdtFvZeNj52/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/view_asset/', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/permission-assignments/p4koRMKP65jdVQuacNPuke/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', - label: 'View submissions', - }, - ], - effective_permissions: [ - { codename: 'change_asset' }, - { codename: 'manage_asset' }, - { codename: 'view_submissions' }, - { codename: 'validate_submissions' }, - { codename: 'change_submissions' }, - { codename: 'delete_asset' }, - { codename: 'view_asset' }, - { codename: 'delete_submissions' }, - { codename: 'add_submissions' }, - ], - exports: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/exports/', - export_settings: [], - data: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/data/', - children: { count: 0 }, - subscribers_count: 0, - status: 'private', - access_types: null, - data_sharing: {}, - paired_data: 'http://kf.kobo.local/api/v2/assets/aBcDe12345/paired-data/', - project_ownership: null, - owner_label: 'Test Korp Inc', -} satisfies AssetResponse +}) as unknown as AssetResponse // need an asset with locking profiles included and used for rows @@ -258,97 +79,104 @@ const minimalAssetResponse = { */ export const simpleTemplate = { ...cloneDeep(minimalAssetResponse), - ...{ - asset_type: AssetTypeName.template, - name: 'Test template', - summary: { - geo: false, - labels: ['Best thing in the world?', 'Person', 'Your name', 'Your age'], - columns: ['type', 'label', 'required', 'select_from_list_name', 'name'], - languages: ['English (en)', 'Polski (pl)'], - row_count: 4, - default_translation: 'English (en)', + asset_type: AssetTypeName.template, + name: 'Test template', + summary: { + geo: false, + labels: ['Best thing in the world?', 'Person', 'Your name', 'Your age'], + columns: ['type', 'label', 'required', 'select_from_list_name', 'name'], + languages: ['English (en)', 'Polski (pl)'], + row_count: 4, + default_translation: 'English (en)', + lock_all: false, + lock_any: false, + name_quality: { + ok: 4, + bad: 0, + good: 0, + total: 4, + firsts: {}, }, - content: { - schema: '1', - survey: [ - { - name: 'start', - type: MetaQuestionTypeName.start, - $kuid: 'ZJRmskGCC', - $autoname: 'start', - }, - { - name: 'end', - type: MetaQuestionTypeName.end, - $kuid: 'JuoCtJWO5', - $autoname: 'end', - }, - { - type: QuestionTypeName.select_one, - $kuid: 'ri0lk77', - label: ['Best thing in the world?', 'Najlepsze na świecie?'], - required: false, - $autoname: 'Best_thing_in_the_world', - select_from_list_name: 'dp8iw04', - }, - { - name: 'person', - type: GroupTypeBeginName.begin_group, - $kuid: 'xl7sb31', - label: ['Person', 'Osoba'], - $autoname: 'person', - }, - { - type: QuestionTypeName.text, - $kuid: 'xw6go48', - label: ['Your name', 'Twoje imię'], - required: false, - $autoname: 'Your_name', - }, - { - type: QuestionTypeName.integer, - $kuid: 'wd3rh84', - label: ['Your age', 'Twój wiek'], - required: false, - $autoname: 'Your_age', - }, - { - type: GroupTypeEndName.end_group, - $kuid: '/xl7sb31', - }, - ], - choices: [ - { - name: 'peace', - $kuid: '7grWIZ8bE', - label: ['Peace', 'Pokój'], - list_name: 'dp8iw04', - $autovalue: 'peace', - }, - { - name: 'love', - $kuid: 'I4x3DFdQl', - label: ['Love', 'Miłość'], - list_name: 'dp8iw04', - $autovalue: 'love', - }, - { - name: 'understanding', - $kuid: 'klWY60huh', - label: ['Understanding', 'Zrozumienie'], - list_name: 'dp8iw04', - $autovalue: 'understanding', - }, - ], - settings: { - default_language: 'English (en)', + }, + content: { + schema: '1', + survey: [ + { + name: 'start', + type: MetaQuestionTypeName.start, + $kuid: 'ZJRmskGCC', + $autoname: 'start', + }, + { + name: 'end', + type: MetaQuestionTypeName.end, + $kuid: 'JuoCtJWO5', + $autoname: 'end', + }, + { + type: QuestionTypeName.select_one, + $kuid: 'ri0lk77', + label: ['Best thing in the world?', 'Najlepsze na świecie?'], + required: false, + $autoname: 'Best_thing_in_the_world', + select_from_list_name: 'dp8iw04', + }, + { + name: 'person', + type: GroupTypeBeginName.begin_group, + $kuid: 'xl7sb31', + label: ['Person', 'Osoba'], + $autoname: 'person', + }, + { + type: QuestionTypeName.text, + $kuid: 'xw6go48', + label: ['Your name', 'Twoje imię'], + required: false, + $autoname: 'Your_name', }, - translated: ['label'], - translations: ['English (en)', 'Polski (pl)'], + { + type: QuestionTypeName.integer, + $kuid: 'wd3rh84', + label: ['Your age', 'Twój wiek'], + required: false, + $autoname: 'Your_age', + }, + { + type: GroupTypeEndName.end_group, + $kuid: '/xl7sb31', + }, + ], + choices: [ + { + name: 'peace', + $kuid: '7grWIZ8bE', + label: ['Peace', 'Pokój'], + list_name: 'dp8iw04', + $autovalue: 'peace', + }, + { + name: 'love', + $kuid: 'I4x3DFdQl', + label: ['Love', 'Miłość'], + list_name: 'dp8iw04', + $autovalue: 'love', + }, + { + name: 'understanding', + $kuid: 'klWY60huh', + label: ['Understanding', 'Zrozumienie'], + list_name: 'dp8iw04', + $autovalue: 'understanding', + }, + ], + settings: { + default_language: 'English (en)', }, + translated: ['label'], + translations: ['English (en)', 'Polski (pl)'], }, -} satisfies AssetResponse +} /** * A template with few questions, a group and additional Polish labels. Some of @@ -357,115 +185,113 @@ export const simpleTemplate = { */ export const simpleTemplateLocked = { ...cloneDeep(simpleTemplate), - ...{ - name: 'Test locked template', - content: { - schema: '1', - survey: [ - { - name: 'start', - type: MetaQuestionTypeName.start, - $kuid: 'ZJRmskGCC', - $autoname: 'start', - }, - { - name: 'end', - type: MetaQuestionTypeName.end, - $kuid: 'JuoCtJWO5', - $autoname: 'end', - }, - { - type: QuestionTypeName.select_one, - $kuid: 'ri0lk77', - label: ['Best thing in the world?', 'Najlepsze na świecie?'], - required: false, - $autoname: 'Best_thing_in_the_world', - select_from_list_name: 'dp8iw04', - 'kobo--locking-profile': 'lock2', - }, - { - name: 'person', - type: GroupTypeBeginName.begin_group, - $kuid: 'xl7sb31', - label: ['Person', 'Osoba'], - $autoname: 'person', - 'kobo--locking-profile': 'lock2', - }, - { - type: QuestionTypeName.text, - $kuid: 'xw6go48', - label: ['Your name', 'Twoje imię'], - required: false, - $autoname: 'Your_name', - }, - { - type: QuestionTypeName.integer, - $kuid: 'wd3rh84', - label: ['Your age', 'Twój wiek'], - required: false, - $autoname: 'Your_age', - 'kobo--locking-profile': 'mycustomlock1', - }, - { - type: GroupTypeEndName.end_group, - $kuid: '/xl7sb31', - }, - ], - choices: [ - { - name: 'peace', - $kuid: '7grWIZ8bE', - label: ['Peace', 'Pokój'], - list_name: 'dp8iw04', - $autovalue: 'peace', - }, - { - name: 'love', - $kuid: 'I4x3DFdQl', - label: ['Love', 'Miłość'], - list_name: 'dp8iw04', - $autovalue: 'love', - }, - { - name: 'understanding', - $kuid: 'klWY60huh', - label: ['Understanding', 'Zrozumienie'], - list_name: 'dp8iw04', - $autovalue: 'understanding', - }, - ], - 'kobo--locking-profiles': [ - { - name: 'mycustomlock1', - restrictions: [ - LockingRestrictionName.choice_add, - LockingRestrictionName.choice_delete, - LockingRestrictionName.choice_label_edit, - LockingRestrictionName.question_settings_edit, - LockingRestrictionName.group_label_edit, - LockingRestrictionName.group_question_order_edit, - LockingRestrictionName.group_add, - LockingRestrictionName.question_order_edit, - ], - }, - { - name: 'lock2', - restrictions: [ - LockingRestrictionName.question_delete, - LockingRestrictionName.group_delete, - LockingRestrictionName.language_edit, - ], - }, - ], - settings: { - default_language: 'English (en)', + name: 'Test locked template', + content: { + schema: '1', + survey: [ + { + name: 'start', + type: MetaQuestionTypeName.start, + $kuid: 'ZJRmskGCC', + $autoname: 'start', + }, + { + name: 'end', + type: MetaQuestionTypeName.end, + $kuid: 'JuoCtJWO5', + $autoname: 'end', + }, + { + type: QuestionTypeName.select_one, + $kuid: 'ri0lk77', + label: ['Best thing in the world?', 'Najlepsze na świecie?'], + required: false, + $autoname: 'Best_thing_in_the_world', + select_from_list_name: 'dp8iw04', + 'kobo--locking-profile': 'lock2', + }, + { + name: 'person', + type: GroupTypeBeginName.begin_group, + $kuid: 'xl7sb31', + label: ['Person', 'Osoba'], + $autoname: 'person', + 'kobo--locking-profile': 'lock2', + }, + { + type: QuestionTypeName.text, + $kuid: 'xw6go48', + label: ['Your name', 'Twoje imię'], + required: false, + $autoname: 'Your_name', + }, + { + type: QuestionTypeName.integer, + $kuid: 'wd3rh84', + label: ['Your age', 'Twój wiek'], + required: false, + $autoname: 'Your_age', 'kobo--locking-profile': 'mycustomlock1', }, - translated: ['label'], - translations: ['English (en)', 'Polski (pl)'], + { + type: GroupTypeEndName.end_group, + $kuid: '/xl7sb31', + }, + ], + choices: [ + { + name: 'peace', + $kuid: '7grWIZ8bE', + label: ['Peace', 'Pokój'], + list_name: 'dp8iw04', + $autovalue: 'peace', + }, + { + name: 'love', + $kuid: 'I4x3DFdQl', + label: ['Love', 'Miłość'], + list_name: 'dp8iw04', + $autovalue: 'love', + }, + { + name: 'understanding', + $kuid: 'klWY60huh', + label: ['Understanding', 'Zrozumienie'], + list_name: 'dp8iw04', + $autovalue: 'understanding', + }, + ], + 'kobo--locking-profiles': [ + { + name: 'mycustomlock1', + restrictions: [ + LockingRestrictionName.choice_add, + LockingRestrictionName.choice_delete, + LockingRestrictionName.choice_label_edit, + LockingRestrictionName.question_settings_edit, + LockingRestrictionName.group_label_edit, + LockingRestrictionName.group_question_order_edit, + LockingRestrictionName.group_add, + LockingRestrictionName.question_order_edit, + ], + }, + { + name: 'lock2', + restrictions: [ + LockingRestrictionName.question_delete, + LockingRestrictionName.group_delete, + LockingRestrictionName.language_edit, + ], + }, + ], + settings: { + default_language: 'English (en)', + 'kobo--locking-profile': 'mycustomlock1', }, + translated: ['label'], + translations: ['English (en)', 'Polski (pl)'], }, -} satisfies AssetResponse +} /** A template with some locking profiles on rows, and a lock all property. */ export const simpleTemplateLockedWithAll = merge(cloneDeep(simpleTemplateLocked), { diff --git a/jsapp/js/components/map/FormMapWrapper.stories.tsx b/jsapp/js/components/map/FormMapWrapper.stories.tsx index 8f0b75b4de..dddd07677d 100644 --- a/jsapp/js/components/map/FormMapWrapper.stories.tsx +++ b/jsapp/js/components/map/FormMapWrapper.stories.tsx @@ -3,9 +3,9 @@ import { http, HttpResponse } from 'msw' import { reactRouterParameters, withRouter } from 'storybook-addon-remix-react-router' import { expect, waitFor, within } from 'storybook/test' import { endpoints } from '#/api.endpoints' +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import { MetaQuestionTypeName, QuestionTypeName } from '#/constants' -import type { PaginatedResponse, SubmissionResponse } from '#/dataInterface' -import assetFactory from '#/endpoints/asset.factory' +import type { AssetResponse, PaginatedResponse, SubmissionResponse } from '#/dataInterface' import assetDataFactory from '#/endpoints/assetData.factory' import { queryClientDecorator } from '#/query/queryClient.mocks' import { ROUTES } from '#/router/routerConstants' @@ -14,13 +14,17 @@ import FormMapWrapper from './formMapWrapper' const mockAssetUid = 'aTestMapAssetUid123' +// Cast Orval-generated Assets to legacy AssetResponse type +// The types are structurally compatible at runtime (see DataTableWrapper.stories.tsx for details) + // Asset with only start-geopoint (no regular geopoint question) -const assetWithOnlyStartGeopoint = assetFactory({ +const assetWithOnlyStartGeopoint = getApiV2AssetsRetrieveResponseMock({ uid: mockAssetUid, name: 'Test Form with Start-Geopoint Only', deployment__active: true, deployment__submission_count: 2, has_deployment: true, + map_styles: {}, summary: { geo: true, labels: ['Your name'], @@ -30,7 +34,7 @@ const assetWithOnlyStartGeopoint = assetFactory({ languages: [], row_count: 2, name_quality: { ok: 2, bad: 0, good: 0, total: 2, firsts: {} }, - default_translation: null, + default_translation: undefined, }, content: { survey: [ @@ -49,15 +53,16 @@ const assetWithOnlyStartGeopoint = assetFactory({ ], choices: [], }, -}) +}) as unknown as AssetResponse // Asset with both start-geopoint AND regular geopoint -const assetWithBothGeopointTypes = assetFactory({ +const assetWithBothGeopointTypes = getApiV2AssetsRetrieveResponseMock({ uid: mockAssetUid, name: 'Test Form with Both Geopoint Types', deployment__active: true, deployment__submission_count: 2, has_deployment: true, + map_styles: {}, summary: { geo: true, labels: ['Your name', 'Where are you?'], @@ -67,7 +72,7 @@ const assetWithBothGeopointTypes = assetFactory({ languages: [], row_count: 3, name_quality: { ok: 3, bad: 0, good: 0, total: 3, firsts: {} }, - default_translation: null, + default_translation: undefined, }, content: { survey: [ @@ -93,7 +98,7 @@ const assetWithBothGeopointTypes = assetFactory({ ], choices: [], }, -}) +}) as unknown as AssetResponse // Submission data with populated start-geopoint const submissionsWithStartGeopoint: SubmissionResponse[] = [ diff --git a/jsapp/js/components/modalForms/LibraryAssetForm.tsx b/jsapp/js/components/modalForms/LibraryAssetForm.tsx index e962c929b6..68c460d9fe 100644 --- a/jsapp/js/components/modalForms/LibraryAssetForm.tsx +++ b/jsapp/js/components/modalForms/LibraryAssetForm.tsx @@ -162,11 +162,13 @@ export const LibraryAssetForm = ({ asset, assetType, onSetModalTitle: _onSetModa return [] } + // Backend schema specifies array, but old assets may have single object if (Array.isArray(value)) { return value.map((item) => item.value) } - return [value.value] + // Legacy fallback: single object from pre-Dec 2022 assets + return [(value as any).value] } const fromSingleSelectValue = (newValue: string | null, option?: LabelValuePair): LabelValuePair | null => { diff --git a/jsapp/js/components/permissions/transferProjects/transferProjects.api.ts b/jsapp/js/components/permissions/transferProjects/transferProjects.api.ts index 51496ff8a8..741206af23 100644 --- a/jsapp/js/components/permissions/transferProjects/transferProjects.api.ts +++ b/jsapp/js/components/permissions/transferProjects/transferProjects.api.ts @@ -42,6 +42,8 @@ export interface ProjectTransferAssetDetail { sender: string recipient: string status: TransferStatuses + /** Allow additional properties for backend extensions */ + [key: string]: unknown } export interface InvitesResponse { diff --git a/jsapp/js/components/reports/reports.utils.tests.ts b/jsapp/js/components/reports/reports.utils.tests.ts index adf0610116..3033bb4f4a 100644 --- a/jsapp/js/components/reports/reports.utils.tests.ts +++ b/jsapp/js/components/reports/reports.utils.tests.ts @@ -1,6 +1,7 @@ import chai from 'chai' +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import { QuestionTypeName } from '#/constants' -import assetFactory from '#/endpoints/asset.factory' +import type { AssetResponse } from '#/dataInterface' import { reportStyleFactory, reportsResponseDataFactory } from './reports.factory' import { buildEffectiveReportStyle, getEffectiveRowReportStyle, populateSelectQuestionLabels } from './reports.utils' import type { ReportsResponse } from './reportsConstants' @@ -134,7 +135,9 @@ describe('populateSelectQuestionLabels', () => { style: reportStyleFactory(), } - const asset = assetFactory({ + // TODO: Improve backend OpenAPI schema for Asset + // - Make date_created and date_modified required (they're auto-populated by Django) + const asset = getApiV2AssetsRetrieveResponseMock({ content: { survey: [ { @@ -161,7 +164,7 @@ describe('populateSelectQuestionLabels', () => { }, ], }, - }) + }) as unknown as AssetResponse populateSelectQuestionLabels(row, asset, 1) diff --git a/jsapp/js/components/submissions/BulkProcessingBanner.stories.tsx b/jsapp/js/components/submissions/BulkProcessingBanner.stories.tsx index ffafc585de..bf40300d96 100644 --- a/jsapp/js/components/submissions/BulkProcessingBanner.stories.tsx +++ b/jsapp/js/components/submissions/BulkProcessingBanner.stories.tsx @@ -1,15 +1,39 @@ import type { Meta, StoryObj } from '@storybook/react-webpack5' import { withRouter } from 'storybook-addon-remix-react-router' -import bulkActionFactory from '#/endpoints/bulkAction.factory' +import { getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock } from '#/api/react-query/survey-data/msw' import BulkProcessingBanner from './BulkProcessingBanner' import { withBulkProcessingBannerSessionReset } from './BulkProcessingBannerStoriesUtils' -const singleJobByCurrentUser = [bulkActionFactory('uuid-1', 'en', { created_by: { username: 'storybook-user' } })] -const singleJobByAnotherUser = [bulkActionFactory('uuid-1', 'en', { created_by: { username: 'other-user' } })] +const singleJobByCurrentUser = [ + getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ + submission_uuids: ['uuid-1'], + params: { language: 'en' }, + created_by: { username: 'storybook-user' }, + }), +] +const singleJobByAnotherUser = [ + getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ + submission_uuids: ['uuid-1'], + params: { language: 'en' }, + created_by: { username: 'other-user' }, + }), +] const multipleJobs = [ - bulkActionFactory('uuid-1', 'en', { created_by: { username: 'storybook-user' } }), - bulkActionFactory('uuid-2', 'fr', { created_by: { username: 'other-user' } }), - bulkActionFactory('uuid-3', 'es', { created_by: { username: 'another-user' } }), + getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ + submission_uuids: ['uuid-1'], + params: { language: 'en' }, + created_by: { username: 'storybook-user' }, + }), + getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ + submission_uuids: ['uuid-2'], + params: { language: 'fr' }, + created_by: { username: 'other-user' }, + }), + getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ + submission_uuids: ['uuid-3'], + params: { language: 'es' }, + created_by: { username: 'another-user' }, + }), ] const meta: Meta = { title: 'Components/BulkProcessingBanner', diff --git a/jsapp/js/components/submissions/BulkProcessingModals/alerts/alertEvaluators.tests.ts b/jsapp/js/components/submissions/BulkProcessingModals/alerts/alertEvaluators.tests.ts index a8ca6b5b9a..ff2cde07bd 100644 --- a/jsapp/js/components/submissions/BulkProcessingModals/alerts/alertEvaluators.tests.ts +++ b/jsapp/js/components/submissions/BulkProcessingModals/alerts/alertEvaluators.tests.ts @@ -1,8 +1,9 @@ import { expect } from 'chai' import { ActionIdEnum } from '#/api/models/actionIdEnum' +import type { BulkActionResponse } from '#/api/models/bulkActionResponse' import { BulkActionResponseStatusEnum } from '#/api/models/bulkActionResponseStatusEnum' +import { getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock } from '#/api/react-query/survey-data/msw' import assetDataFactory from '#/endpoints/assetData.factory' -import bulkActionFactory from '#/endpoints/bulkAction.factory' import { asrExceeded, asrNearLimit, mtExceeded, mtNearLimit, withinLimits } from '#/endpoints/serviceUsage.factory' import { evaluateAlreadyTranscribed, @@ -15,6 +16,18 @@ import { } from './alertEvaluators' import type { AlertEvaluationContext } from './types' +function bulkActionFactory( + uid: string, + language: string, + overrides: Partial = {}, +): BulkActionResponse { + return getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ + uid, + params: { language }, + ...overrides, + }) +} + describe('evaluateNoEligibleSubmissions', () => { const mockSubmissions = [ assetDataFactory(1, { _uuid: 'uuid-1' }), diff --git a/jsapp/js/components/submissions/DataTableWrapper.stories.tsx b/jsapp/js/components/submissions/DataTableWrapper.stories.tsx index 2042666bf1..3dccd7df5b 100644 --- a/jsapp/js/components/submissions/DataTableWrapper.stories.tsx +++ b/jsapp/js/components/submissions/DataTableWrapper.stories.tsx @@ -10,18 +10,18 @@ import type { Decorator } from '@storybook/react' import type { Meta, StoryObj } from '@storybook/react-webpack5' import React, { useEffect } from 'react' import { reactRouterParameters, withRouter } from 'storybook-addon-remix-react-router' -import { expect, waitFor } from 'storybook/test' import subscriptionStore from '#/account/subscriptionStore' import { actions } from '#/actions' import { ActionIdEnum } from '#/api/models/actionIdEnum' import { BulkActionResponseStatusEnum } from '#/api/models/bulkActionResponseStatusEnum' +import { + getApiV2AssetsRetrieveMockHandler, + getApiV2AssetsRetrieveResponseMock, +} from '#/api/react-query/manage-projects-and-library-content/msw' +import { getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock } from '#/api/react-query/survey-data/msw' import { QuestionTypeName } from '#/constants' -import type { AssetResponse } from '#/dataInterface' -import assetFactory from '#/endpoints/asset.factory' -import assetMock from '#/endpoints/asset.mocks' import assetDataFactory from '#/endpoints/assetData.factory' import assetDataMock from '#/endpoints/assetData.mocks' -import bulkActionFactory from '#/endpoints/bulkAction.factory' import bulkActionsMock from '#/endpoints/bulkActions.mocks' import meMock from '#/endpoints/me.mocks' import organizationMock from '#/endpoints/organization.mocks' @@ -32,13 +32,15 @@ import { queryClientDecorator } from '#/query/queryClient.mocks' import { ROUTES } from '#/router/routerConstants' import { withBulkProcessingBannerSessionReset } from './BulkProcessingBannerStoriesUtils' import DataTableWrapper from './DataTableWrapper' -import { - getPollingUpdateStoryHandlers, - getPollingUpdateStoryState, - getPollingUpdateStoryTimeoutMs, - pollingAsset, - resetPollingUpdateStoryHandlers, -} from './DataTableWrapperPollingStoriesUtils' + +// Orval-generated Asset and legacy AssetResponse have minor structural differences. +// Remaining differences are intentional (backward compatibility in legacy type): +// - Optional fields (date_created, date_modified) marked optional for POST/PATCH, always present in GET +// - summary.name_quality has all optional properties for flexibility +// - files structure has minor type differences that don't affect runtime +// +// These casts are safe because both types represent the same runtime data structure +import type { AssetResponse } from '#/dataInterface' // Storybook preview root does not have a fixed height by default, which breaks flexbox stretching for table header // cells. By adding a wrapper with a fixed height to the story, we ensure that `.rt-tr` and `.rt-th` flex children can @@ -147,9 +149,12 @@ const getRouterParams = (assetUid: string) => // Minimal asset and submissions for simple stories // Default story asset and submissions -const minimalAsset = assetFactory({ +const minimalAsset = getApiV2AssetsRetrieveResponseMock({ uid: 'audio-asset-uid', name: 'Audio form', + deployment__active: true, + has_deployment: true, + map_styles: {}, content: { schema: '1', survey: [ @@ -167,7 +172,8 @@ const minimalAsset = assetFactory({ translations: [null], }, effective_permissions: [{ codename: 'change_submissions' }], -}) +}) as unknown as AssetResponse + const minimalSubmissions = [ assetDataFactory(1, { Record_a_sound: 'test1.mp3', @@ -200,9 +206,12 @@ const minimalSubmissions = [ ] // ProcessingColumn story asset and submissions (unique UID) -const processingAsset = assetFactory({ +const processingAsset = getApiV2AssetsRetrieveResponseMock({ uid: 'audio-asset-uid-processing', name: 'Audio form with processing', + deployment__active: true, + has_deployment: true, + map_styles: {}, content: { schema: '1', survey: [ @@ -245,7 +254,8 @@ const processingAsset = assetFactory({ ], }, effective_permissions: [{ codename: 'change_submissions' }], -}) +}) as unknown as AssetResponse + const processingSubmissions = [ assetDataFactory(1, { Record_a_sound: 'test1.mp3', @@ -311,18 +321,22 @@ const processingSubmissions = [ ], }), ] -const processingBulkAction = bulkActionFactory(processingSubmissions[1]['meta/rootUuid'], 'fr', { +const processingBulkAction = getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ status: BulkActionResponseStatusEnum.complete, action_id: ActionIdEnum.automatic_google_translation, question_xpath: 'Record_a_sound', + submission_uuids: [processingSubmissions[1]['meta/rootUuid']], + params: { language: 'fr' }, created_by: { username: 'zefir', }, }) -const processingBulkAction2 = bulkActionFactory(processingSubmissions[2]['meta/rootUuid'], 'es', { +const processingBulkAction2 = getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ status: BulkActionResponseStatusEnum.in_progress, action_id: ActionIdEnum.automatic_google_translation, question_xpath: 'Record_a_sound', + submission_uuids: [processingSubmissions[2]['meta/rootUuid']], + params: { language: 'es' }, created_by: { username: 'other-user', }, @@ -331,9 +345,6 @@ const processingBulkAction2 = bulkActionFactory(processingSubmissions[2]['meta/r const meta: Meta = { title: 'Components/DataTableWrapper', component: DataTableWrapper, - async beforeEach() { - resetPollingUpdateStoryHandlers() - }, args: { asset: minimalAsset, }, @@ -349,7 +360,7 @@ const meta: Meta = { msw: { handlers: [ meMock, - assetMock(minimalAsset.uid, minimalAsset), + getApiV2AssetsRetrieveMockHandler(minimalAsset), assetDataMock(minimalAsset.uid, minimalSubmissions), organizationMock(), organizationServiceUsageMock(), @@ -376,7 +387,7 @@ export const Default: Story = { msw: { handlers: [ meMock, - assetMock(minimalAsset.uid, minimalAsset), + getApiV2AssetsRetrieveMockHandler(minimalAsset), assetDataMock(minimalAsset.uid, minimalSubmissions), organizationMock(), organizationServiceUsageMock(), @@ -398,7 +409,7 @@ export const ProcessingColumnAndBanner: Story = { msw: { handlers: [ meMock, - assetMock(processingAsset.uid, processingAsset), + getApiV2AssetsRetrieveMockHandler(processingAsset), assetDataMock(processingAsset.uid, processingSubmissions), organizationMock(), organizationServiceUsageMock(), @@ -411,41 +422,6 @@ export const ProcessingColumnAndBanner: Story = { loaders: [loadAssetForStory], } -export const ProcessingPollingRefreshesTranslatedCell: Story = { - args: { - asset: pollingAsset, - }, - parameters: { - docs: { - description: { - story: - 'Starts with a Processing placeholder and updates that row after polling (about 8 seconds) when the mocked bulk action item transitions to complete.', - }, - }, - a11y: { test: 'todo' }, - reactRouter: getRouterParams(pollingAsset.uid), - msw: { - handlers: getPollingUpdateStoryHandlers(), - }, - }, - loaders: [loadAssetForStory], - play: async ({ step }) => { - // We intentionally avoid asserting rendered translated text here. - // We tried multiple DOM-based variants (including intermediate - // "Processing" checks), but they remained flaky in CI across browsers. - // This play test focuses on stable polling/refresh behavior via mock state. - await step('Wait for polling to refresh one submission row', async () => { - await waitFor( - async () => { - const storyState = getPollingUpdateStoryState() - await expect(storyState.pollingBulkActionsCalls).toBeGreaterThanOrEqual(2) - await expect(storyState.pollingSubmissionRefreshCalls).toBeGreaterThanOrEqual(1) - }, - { timeout: getPollingUpdateStoryTimeoutMs() }, - ) - }) - }, -} export const ProcessingAndLimitsBannersTogether: Story = { args: { asset: processingAsset, @@ -456,7 +432,7 @@ export const ProcessingAndLimitsBannersTogether: Story = { msw: { handlers: [ meMock, - assetMock(processingAsset.uid, processingAsset), + getApiV2AssetsRetrieveMockHandler(processingAsset), assetDataMock(processingAsset.uid, processingSubmissions), organizationMock(), // Shows both BulkProcessingBanner (active jobs) + OverLimitBanner (exceeded submission limit) @@ -481,7 +457,7 @@ export const StorageLimitWarningBanner: Story = { msw: { handlers: [ meMock, - assetMock(minimalAsset.uid, minimalAsset), + getApiV2AssetsRetrieveMockHandler(minimalAsset), assetDataMock(minimalAsset.uid, minimalSubmissions), organizationMock(), organizationServiceUsageMock(undefined, organizationServiceUsageFactory.storageWarning()), @@ -503,7 +479,7 @@ export const StorageExceededBanner: Story = { msw: { handlers: [ meMock, - assetMock(minimalAsset.uid, minimalAsset), + getApiV2AssetsRetrieveMockHandler(minimalAsset), assetDataMock(minimalAsset.uid, minimalSubmissions), organizationMock(), organizationServiceUsageMock(undefined, organizationServiceUsageFactory.storageExceeded()), @@ -525,7 +501,7 @@ export const SubmissionExceededBanner: Story = { msw: { handlers: [ meMock, - assetMock(minimalAsset.uid, minimalAsset), + getApiV2AssetsRetrieveMockHandler(minimalAsset), assetDataMock(minimalAsset.uid, minimalSubmissions), organizationMock(), organizationServiceUsageMock(undefined, organizationServiceUsageFactory.submissionExceeded()), @@ -547,7 +523,7 @@ export const StorageAndSubmissionExceededBanner: Story = { msw: { handlers: [ meMock, - assetMock(minimalAsset.uid, minimalAsset), + getApiV2AssetsRetrieveMockHandler(minimalAsset), assetDataMock(minimalAsset.uid, minimalSubmissions), organizationMock(), organizationServiceUsageMock(undefined, organizationServiceUsageFactory.bothExceeded()), diff --git a/jsapp/js/components/submissions/DataTableWrapperPollingStoriesUtils.tsx b/jsapp/js/components/submissions/DataTableWrapperPollingStoriesUtils.tsx deleted file mode 100644 index ad786f5ea8..0000000000 --- a/jsapp/js/components/submissions/DataTableWrapperPollingStoriesUtils.tsx +++ /dev/null @@ -1,211 +0,0 @@ -import { http, HttpResponse, type PathParams } from 'msw' -import { endpoints } from '#/api.endpoints' -import { ActionIdEnum } from '#/api/models/actionIdEnum' -import { BulkActionResponseStatusEnum } from '#/api/models/bulkActionResponseStatusEnum' -import { BulkActionSubmissionStatusResponseStatusEnum } from '#/api/models/bulkActionSubmissionStatusResponseStatusEnum' -import { QuestionTypeName } from '#/constants' -import assetFactory from '#/endpoints/asset.factory' -import assetMock from '#/endpoints/asset.mocks' -import assetDataFactory from '#/endpoints/assetData.factory' -import bulkActionFactory from '#/endpoints/bulkAction.factory' -import meMock from '#/endpoints/me.mocks' -import organizationMock from '#/endpoints/organization.mocks' -import organizationServiceUsageMock from '#/endpoints/organizationServiceUsage.mocks' -import { getBulkActionsPollingIntervalMs } from './useDataTableBulkActions' - -let pollingBulkActionsCalls = 0 -let pollingSubmissionRefreshCalls = 0 -let pollingFirstBulkActionsRequestTime: number | null = null -const POLLING_STORY_ASSERTION_GRACE_MS = 6000 -// How long after a story resets before the mock bulk action reports completion. -// Needs to be shorter than the polling interval (8 s for translation) so that -// the first poll always returns in_progress — giving every parallel browser -// enough time to actually render the "Processing" cell before completion fires. -const POLLING_COMPLETE_AFTER_MS = 2000 - -// Dedicated polling story data is kept in a separate file so the main stories -// file remains easy to scan as more table scenarios get added. -export const pollingAsset = assetFactory({ - uid: 'audio-asset-uid-polling', - name: 'Audio form with polling update', - // The backend writes analysis_form_json when a bulk action is created, so - // this entry is present from the moment the story starts — not only after - // polling finishes. Having it here is what keeps the supplemental column in - // its correct position (immediately after the source question) throughout the - // whole lifecycle. The virtual fields from active bulk actions handle the - // "Processing" cell state while the action is still running. - analysis_form_json: { - additional_fields: [ - { - language: 'es', - source: 'Record_a_sound', - type: 'translation', - name: 'translation_es', - dtpath: 'Record_a_sound/translation_es', - }, - ], - }, - content: { - schema: '1', - survey: [ - { - type: QuestionTypeName.audio, - $kuid: 'snd1', - label: ['Record a sound'], - $xpath: 'Record_a_sound', - required: false, - $autoname: 'Record_a_sound', - }, - ], - settings: {}, - translated: ['label'], - translations: [null], - }, - effective_permissions: [{ codename: 'change_submissions' }], -}) - -const pollingSubmissionInitial = assetDataFactory(11, { - Record_a_sound: 'test11.mp3', - _attachments: [ - { - download_url: './test11.mp3', - mimetype: 'audio/x-m3a', - filename: 'uu/attachments/test11.mp3', - media_file_basename: 'test11.mp3', - uid: 'tst11', - is_deleted: false, - question_xpath: 'Record_a_sound', - }, - ], -}) - -const pollingSubmissionUpdated = assetDataFactory(11, { - Record_a_sound: 'test11.mp3', - _supplementalDetails: { - Record_a_sound: { - translation: { - es: { - languageCode: 'es', - value: 'Hola, el procesamiento masivo ha finalizado correctamente.', - }, - }, - }, - }, - _attachments: [ - { - download_url: './test11.mp3', - mimetype: 'audio/x-m3a', - filename: 'uu/attachments/test11.mp3', - media_file_basename: 'test11.mp3', - uid: 'tst11', - is_deleted: false, - question_xpath: 'Record_a_sound', - }, - ], -}) - -const pollingBulkActionInProgress = bulkActionFactory(pollingSubmissionInitial['meta/rootUuid'], 'es', { - uid: 'polling-bulk-action', - status: BulkActionResponseStatusEnum.in_progress, - action_id: ActionIdEnum.automatic_google_translation, - question_xpath: 'Record_a_sound', - submission_statuses: [ - { - uuid: pollingSubmissionInitial['meta/rootUuid'], - status: BulkActionSubmissionStatusResponseStatusEnum.in_progress, - error: null, - }, - ], -}) - -const pollingBulkActionComplete = bulkActionFactory(pollingSubmissionInitial['meta/rootUuid'], 'es', { - uid: 'polling-bulk-action', - status: BulkActionResponseStatusEnum.complete, - action_id: ActionIdEnum.automatic_google_translation, - question_xpath: 'Record_a_sound', - submission_statuses: [ - { - uuid: pollingSubmissionInitial['meta/rootUuid'], - status: BulkActionSubmissionStatusResponseStatusEnum.complete, - error: null, - }, - ], -}) - -export function resetPollingUpdateStoryHandlers() { - pollingBulkActionsCalls = 0 - pollingSubmissionRefreshCalls = 0 - pollingFirstBulkActionsRequestTime = null -} - -export function getPollingUpdateStoryState() { - return { - pollingBulkActionsCalls, - pollingSubmissionRefreshCalls, - } -} - -export function getPollingUpdateStoryTimeoutMs() { - const pollingIntervalMs = getBulkActionsPollingIntervalMs([pollingBulkActionInProgress]) - - if (pollingIntervalMs === false) { - return POLLING_STORY_ASSERTION_GRACE_MS - } - - // The UI change happens after one more poll and one row refresh request, so - // the test allows one computed interval plus a small render/network cushion. - return pollingIntervalMs + POLLING_STORY_ASSERTION_GRACE_MS -} - -export function getPollingUpdateStoryHandlers() { - return [ - meMock, - assetMock(pollingAsset.uid, pollingAsset), - organizationMock(), - organizationServiceUsageMock(), - http.get, never>(endpoints.ASSET_ADVANCED_FEATURES_BULK_ACTIONS, ({ params }) => { - if (params.uid !== pollingAsset.uid) { - return undefined - } - - // Use wall-clock time rather than call count to decide when to switch to - // complete. A call-count threshold is unreliable when multiple browsers - // run the same story in parallel — their polls all share the same counter, - // so the count can cross the threshold before any single browser has had - // a chance to render the "Processing" cell. - pollingBulkActionsCalls += 1 - if (pollingFirstBulkActionsRequestTime === null) { - pollingFirstBulkActionsRequestTime = Date.now() - } - const isComplete = Date.now() - pollingFirstBulkActionsRequestTime >= POLLING_COMPLETE_AFTER_MS - return HttpResponse.json({ - count: 1, - next: null, - previous: null, - results: [isComplete ? pollingBulkActionComplete : pollingBulkActionInProgress], - }) - }), - http.get, never>(endpoints.ASSET_DATA_URL, ({ params, request }) => { - if (params.uid !== pollingAsset.uid) { - return undefined - } - - // DataTable uses the regular list call for the page, and a query-based call - // when refreshing one submission by uuid; we return updated data only for - // that single-row refresh path. - const requestUrl = new URL(request.url) - const hasUuidQuery = Boolean(requestUrl.searchParams.get('query')) - if (hasUuidQuery) { - pollingSubmissionRefreshCalls += 1 - } - const submissions = hasUuidQuery ? [pollingSubmissionUpdated] : [pollingSubmissionInitial] - - return HttpResponse.json({ - count: submissions.length, - next: null, - previous: null, - results: submissions, - }) - }), - ] -} diff --git a/jsapp/js/components/submissions/submissionUtils.mocks.ts b/jsapp/js/components/submissions/submissionUtils.mocks.ts index 3890c83da8..a3c1527d99 100644 --- a/jsapp/js/components/submissions/submissionUtils.mocks.ts +++ b/jsapp/js/components/submissions/submissionUtils.mocks.ts @@ -1,3 +1,4 @@ +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import { AssetTypeName, GroupTypeBeginName, @@ -74,47 +75,12 @@ export const simpleSurveyChoices = [ }, ] as const satisfies SurveyChoice[] -export const simpleSurveyAsset = { - url: '', - owner: '', - owner__username: '', - owner_label: '', - last_modified_by: null, - created_by: null, - date_created: '', - summary: {}, - date_modified: '', - version_id: null, - has_deployment: false, - deployed_version_id: null, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'deployed', - downloads: [], - uid: '', - kind: '', - assignable_permissions: [], - effective_permissions: [], - data: '', - children: { - count: 0, - }, +export const simpleSurveyAsset = getApiV2AssetsRetrieveResponseMock({ content: { survey: simpleSurvey, choices: simpleSurveyChoices, }, - subscribers_count: 0, - status: '', - access_types: null, - project_ownership: null, - parent: null, - settings: {}, asset_type: AssetTypeName.survey, - report_styles: { - default: {}, - specified: {}, - kuid_names: {}, - }, report_custom: {}, map_styles: {}, map_custom: {}, @@ -124,7 +90,7 @@ export const simpleSurveyAsset = { export_settings: [], data_sharing: {}, files: [], -} as const satisfies AssetResponse +}) as unknown as AssetResponse export const simpleSurveySubmission = { __version__: 'vHNo5vFh3KoB7LWhucUkFy', @@ -294,56 +260,14 @@ export const repeatSurvey = [ }, ] as const satisfies SurveyRow[] -export const repeatSurveyAsset = { - url: '', - owner: '', - owner__username: '', - owner_label: '', - last_modified_by: null, - created_by: null, - date_created: '', - summary: {}, - date_modified: '', - version_id: null, - has_deployment: false, - deployed_version_id: null, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'deployed', - downloads: [], - uid: '', - kind: '', - assignable_permissions: [], - effective_permissions: [], - data: '', - children: { - count: 0, - }, +export const repeatSurveyAsset = getApiV2AssetsRetrieveResponseMock({ content: { survey: repeatSurvey, }, - subscribers_count: 0, - status: '', - access_types: null, - project_ownership: null, - parent: null, - settings: {}, asset_type: AssetTypeName.survey, - report_styles: { - default: {}, - specified: {}, - kuid_names: {}, - }, - report_custom: {}, - map_styles: {}, - map_custom: {}, - tag_string: '', - name: '', - permissions: [], - export_settings: [], data_sharing: {}, files: [], -} as const satisfies AssetResponse +}) as unknown as AssetResponse // NOTE: the second repeat submission has no First_name and Middle_name to test stuff better export const repeatSurveySubmission = { @@ -493,56 +417,14 @@ export const nestedRepeatSurvey = [ }, ] as const satisfies SurveyRow[] -export const nestedRepeatSurveyAsset = { - url: '', - owner: '', - owner__username: '', - owner_label: '', - last_modified_by: null, - created_by: null, - date_created: '', - summary: {}, - date_modified: '', - version_id: null, - has_deployment: false, - deployed_version_id: null, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'deployed', - downloads: [], - uid: '', - kind: '', - assignable_permissions: [], - effective_permissions: [], - data: '', - children: { - count: 0, - }, +export const nestedRepeatSurveyAsset = getApiV2AssetsRetrieveResponseMock({ content: { survey: nestedRepeatSurvey, }, - subscribers_count: 0, - status: '', - access_types: null, - project_ownership: null, - parent: null, - settings: {}, asset_type: AssetTypeName.survey, - report_styles: { - default: {}, - specified: {}, - kuid_names: {}, - }, - report_custom: {}, - map_styles: {}, - map_custom: {}, - tag_string: '', - name: '', - permissions: [], - export_settings: [], data_sharing: {}, files: [], -} as const satisfies AssetResponse +}) as unknown as AssetResponse export const nestedRepeatSurveySubmission = { __version__: 'v7sPQZCGQoW8JKYL5Kq79m', @@ -787,57 +669,15 @@ export const matrixSurveyChoices = [ }, ] as const satisfies SurveyChoice[] -export const matrixSurveyAsset = { - url: '', - owner: '', - owner__username: '', - owner_label: '', - last_modified_by: null, - created_by: null, - date_created: '', - summary: {}, - date_modified: '', - version_id: null, - has_deployment: false, - deployed_version_id: null, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'deployed', - downloads: [], - uid: '', - kind: '', - assignable_permissions: [], - effective_permissions: [], - data: '', - children: { - count: 0, - }, +export const matrixSurveyAsset = getApiV2AssetsRetrieveResponseMock({ content: { survey: matrixSurvey, choices: matrixSurveyChoices, }, - subscribers_count: 0, - status: '', - access_types: null, - project_ownership: null, - parent: null, - settings: {}, asset_type: AssetTypeName.survey, - report_styles: { - default: {}, - specified: {}, - kuid_names: {}, - }, - report_custom: {}, - map_styles: {}, - map_custom: {}, - tag_string: '', - name: '', - permissions: [], - export_settings: [], data_sharing: {}, files: [], -} as const satisfies AssetResponse +}) as unknown as AssetResponse export const matrixSurveySubmission = { _id: 22, @@ -1089,57 +929,15 @@ export const groupsSurveyChoices = [ }, ] as const satisfies SurveyChoice[] -export const groupsSurveyAsset = { - url: '', - owner: '', - owner__username: '', - owner_label: '', - last_modified_by: null, - created_by: null, - date_created: '', - summary: {}, - date_modified: '', - version_id: null, - has_deployment: false, - deployed_version_id: null, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'deployed', - downloads: [], - uid: '', - kind: '', - assignable_permissions: [], - effective_permissions: [], - data: '', - children: { - count: 0, - }, +export const groupsSurveyAsset = getApiV2AssetsRetrieveResponseMock({ content: { survey: groupsSurvey, choices: groupsSurveyChoices, }, - subscribers_count: 0, - status: '', - access_types: null, - project_ownership: null, - parent: null, - settings: {}, asset_type: AssetTypeName.survey, - report_styles: { - default: {}, - specified: {}, - kuid_names: {}, - }, - report_custom: {}, - map_styles: {}, - map_custom: {}, - tag_string: '', - name: '', - permissions: [], - export_settings: [], data_sharing: {}, files: [], -} as const satisfies AssetResponse +}) as unknown as AssetResponse export const groupsSurveySubmission = { _id: 23, @@ -1670,57 +1468,15 @@ export const everythingSurveyChoices = [ }, ] as const satisfies SurveyChoice[] -export const everythingSurveyAsset = { - url: '', - owner: '', - owner__username: '', - owner_label: '', - last_modified_by: null, - created_by: null, - date_created: '', - summary: {}, - date_modified: '', - version_id: null, - has_deployment: false, - deployed_version_id: null, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'deployed', - downloads: [], - uid: '', - kind: '', - assignable_permissions: [], - effective_permissions: [], - data: '', - children: { - count: 0, - }, +export const everythingSurveyAsset = getApiV2AssetsRetrieveResponseMock({ content: { survey: everythingSurvey, choices: everythingSurveyChoices, }, - subscribers_count: 0, - status: '', - access_types: null, - project_ownership: null, - parent: null, - settings: {}, asset_type: AssetTypeName.survey, - report_styles: { - default: {}, - specified: {}, - kuid_names: {}, - }, - report_custom: {}, - map_styles: {}, - map_custom: {}, - tag_string: '', - name: '', - permissions: [], - export_settings: [], data_sharing: {}, files: [], -} as const satisfies AssetResponse +}) as unknown as AssetResponse export const everythingSurveySubmission = { _id: 25, @@ -2123,57 +1879,15 @@ export const matrixRepeatSurveyChoices = [ }, ] as const satisfies SurveyChoice[] -export const matrixRepeatSurveyAsset = { - url: '', - owner: '', - owner__username: '', - owner_label: '', - last_modified_by: null, - created_by: null, - date_created: '', - summary: {}, - date_modified: '', - version_id: null, - has_deployment: false, - deployed_version_id: null, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'deployed', - downloads: [], - uid: '', - kind: '', - assignable_permissions: [], - effective_permissions: [], - data: '', - children: { - count: 0, - }, +export const matrixRepeatSurveyAsset = getApiV2AssetsRetrieveResponseMock({ content: { survey: matrixRepeatSurvey, choices: matrixRepeatSurveyChoices, }, - subscribers_count: 0, - status: '', - access_types: null, - project_ownership: null, - parent: null, - settings: {}, asset_type: AssetTypeName.survey, - report_styles: { - default: {}, - specified: {}, - kuid_names: {}, - }, - report_custom: {}, - map_styles: {}, - map_custom: {}, - tag_string: '', - name: '', - permissions: [], - export_settings: [], data_sharing: {}, files: [], -} as const satisfies AssetResponse +}) as unknown as AssetResponse export const matrixRepeatSurveySubmission = { _id: 16, @@ -2372,144 +2086,25 @@ export const submissionWithAttachmentsWithUnicode = { _validation_status: {}, } as const satisfies SubmissionResponse -export const assetWithSupplementalDetails = { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/', - owner: 'http://kf.kobo.local/api/v2/users/kobo/', - owner__username: 'kobo', - owner_label: 'kobo', - last_modified_by: null, - created_by: null, - deployment_status: 'deployed', - effective_permissions: [ - { - codename: 'manage_asset', - }, - { - codename: 'validate_submissions', - }, - { - codename: 'change_asset', - }, - { - codename: 'add_submissions', - }, - { - codename: 'delete_asset', - }, - { - codename: 'view_asset', - }, - { - codename: 'change_submissions', - }, - { - codename: 'delete_submissions', - }, - { - codename: 'view_submissions', - }, - ], - project_ownership: null, - parent: null, - settings: {}, +export const assetWithSupplementalDetails = getApiV2AssetsRetrieveResponseMock({ + uid: 'aDDywpeYGnvuDLTeiveyxZ', + name: 'text and media projekt', asset_type: AssetTypeName.survey, - date_created: '2022-05-12T10:40:02.952931Z', + deployment__active: true, + deployment__submission_count: 3, + has_deployment: true, summary: { geo: false, labels: ['Your name here', 'Your selfie goes here', 'A video? WTF', 'Secret password as an audio file'], columns: ['name', 'type', 'label', 'required', 'calculation'], lock_all: false, lock_any: false, - languages: [null], + languages: [], row_count: 6, - name_quality: { - ok: 0, - bad: 0, - good: 6, - total: 6, - firsts: {}, - }, + name_quality: { ok: 0, bad: 0, good: 6, total: 6, firsts: {} }, naming_conflicts: ['__version__'], default_translation: null, }, - date_modified: '2022-05-12T20:46:11.778140Z', - version_id: 'vMQQP3qgzfmC9XFUkaogSu', - version__content_hash: '85c5bee02e5c2061afb598870e0308e3e0f818b5', - version_count: 6, - has_deployment: true, - deployed_version_id: 'vFFTm5vKJURadwXxntZda6', - deployed_versions: { - count: 1, - next: null, - previous: null, - results: [ - { - uid: 'vFFTm5vKJURadwXxntZda6', - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/versions/vFFTm5vKJURadwXxntZda6/', - content_hash: '85c5bee02e5c2061afb598870e0308e3e0f818b5', - date_deployed: '2022-05-12T10:40:05.215293Z', - date_modified: '2022-05-12 10:40:05.215293+00:00', - }, - ], - }, - deployment__links: { - url: 'http://ee.kobo.local/6PTli7y9', - single_url: 'http://ee.kobo.local/single/6PTli7y9', - single_once_url: 'http://ee.kobo.local/single/fc64e066ac2314795f6f6afe049420dd', - offline_url: 'http://ee.kobo.local/x/6PTli7y9', - preview_url: 'http://ee.kobo.local/preview/6PTli7y9', - iframe_url: 'http://ee.kobo.local/i/6PTli7y9', - single_iframe_url: 'http://ee.kobo.local/single/i/6PTli7y9', - single_once_iframe_url: 'http://ee.kobo.local/single/i/fc64e066ac2314795f6f6afe049420dd', - }, - deployment__active: true, - deployment__data_download_links: { - xls_legacy: 'http://kc.kobo.local/kobo/exports/aDDywpeYGnvuDLTeiveyxZ/xls/', - csv_legacy: 'http://kc.kobo.local/kobo/exports/aDDywpeYGnvuDLTeiveyxZ/csv/', - zip_legacy: 'http://kc.kobo.local/kobo/exports/aDDywpeYGnvuDLTeiveyxZ/zip/', - kml_legacy: 'http://kc.kobo.local/kobo/exports/aDDywpeYGnvuDLTeiveyxZ/kml/', - xls: 'http://kc.kobo.local/kobo/reports/aDDywpeYGnvuDLTeiveyxZ/export.xlsx', - csv: 'http://kc.kobo.local/kobo/reports/aDDywpeYGnvuDLTeiveyxZ/export.csv', - }, - deployment__submission_count: 3, - report_styles: { - default: {}, - specified: { - end: {}, - audit: {}, - start: {}, - today: {}, - deviceid: {}, - username: {}, - _version_: {}, - simserial: {}, - A_video_WTF: {}, - __version__: {}, - phonenumber: {}, - subscriberid: {}, - Your_name_here: {}, - Your_selfie_goes_here: {}, - Secret_password_as_an_audio_file: {}, - }, - kuid_names: { - end: 'VpPsXe5aq', - audit: '4Fbwq3mxP', - start: '8sHgNqqM9', - today: 'HuEzX4mel', - deviceid: 'q8Rvs1sqk', - username: '4dINVeRnR', - _version_: 'kU3D6JQPQ', - simserial: 'WrxreUkAJ', - A_video_WTF: 'bMGj1HZfu', - __version__: 'Hd5Iz0aWv', - phonenumber: 'Oqbll19yc', - subscriberid: '8ojkWhAXU', - Your_name_here: 'RAeXenoDr', - Your_selfie_goes_here: 'MWflesBzX', - Secret_password_as_an_audio_file: '3VHKj8Kt4', - }, - }, - report_custom: {}, advanced_features: { transcript: { values: ['A_video_WTF', 'Secret_password_as_an_audio_file'], @@ -2666,8 +2261,6 @@ export const assetWithSupplementalDetails = { }, ], }, - map_styles: {}, - map_custom: {}, content: { schema: '1', survey: [ @@ -2711,140 +2304,8 @@ export const assetWithSupplementalDetails = { translated: ['label'], translations: [null], }, - downloads: [ - { - format: 'xls', - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ.xls', - }, - { - format: 'xml', - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ.xml', - }, - ], - embeds: [ - { - format: 'xls', - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/xls/', - }, - { - format: 'xform', - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/xform/', - }, - ], - xform_link: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/xform/', - hooks_link: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/hooks/', - tag_string: '', - uid: 'aDDywpeYGnvuDLTeiveyxZ', - kind: 'asset', - xls_link: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/xls/', - name: 'text and media projekt', - assignable_permissions: [ - { - url: 'http://kf.kobo.local/api/v2/permissions/view_asset/', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/change_asset/', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', - label: 'View submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/partial_submissions/', - label: { - default: 'Act on submissions only from specific users', - view_submissions: 'View submissions only from specific users', - change_submissions: 'Edit submissions only from specific users', - delete_submissions: 'Delete submissions only from specific users', - validate_submissions: 'Validate submissions only from specific users', - }, - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', - label: 'Validate submissions', - }, - ], - permissions: [ - { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/permission-assignments/pDbXju7qDP7f4TiPnhvN2V/', - user: 'http://kf.kobo.local/api/v2/users/kobo/', - permission: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/permission-assignments/pRbazEkwqBFAT4K775yWK5/', - user: 'http://kf.kobo.local/api/v2/users/kobo/', - permission: 'http://kf.kobo.local/api/v2/permissions/change_asset/', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/permission-assignments/pAVAdfoKu2zHjgw2ZaPvKk/', - user: 'http://kf.kobo.local/api/v2/users/kobo/', - permission: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/permission-assignments/pETWb6s6ezB9gs7vpMpHhZ/', - user: 'http://kf.kobo.local/api/v2/users/kobo/', - permission: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/permission-assignments/pQoaazdrQ2pBRjqiMpcyc2/', - user: 'http://kf.kobo.local/api/v2/users/kobo/', - permission: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/permission-assignments/pEqtSwGsEJzot98Ms3JJpL/', - user: 'http://kf.kobo.local/api/v2/users/kobo/', - permission: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', - label: 'Validate submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/permission-assignments/p62cADJonW8XuVPkaMSQcj/', - user: 'http://kf.kobo.local/api/v2/users/kobo/', - permission: 'http://kf.kobo.local/api/v2/permissions/view_asset/', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/permission-assignments/p6FKWfL4SuxUqXhsJWdkkB/', - user: 'http://kf.kobo.local/api/v2/users/kobo/', - permission: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', - label: 'View submissions', - }, - ], - exports: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/exports/', - export_settings: [], - data: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/data/', - children: { - count: 0, - }, - subscribers_count: 0, - status: 'private', - access_types: null, - data_sharing: {}, - paired_data: 'http://kf.kobo.local/api/v2/assets/aDDywpeYGnvuDLTeiveyxZ/paired-data/', - files: [], -} as const satisfies AssetResponse + effective_permissions: [{ codename: 'change_submissions' }], +}) as unknown as AssetResponse export const submissionWithSupplementalDetails = { _id: 3, @@ -3460,7 +2921,7 @@ export const assetWithNestedSupplementalDetails = { owner_label: "uu's organization", last_modified_by: 'uu', created_by: null, -} as const satisfies AssetResponse +} as unknown as AssetResponse export const submissionWithNestedSupplementalDetails = { _id: 84, @@ -4033,7 +3494,7 @@ export const assetWithAllQual = { owner_label: "uu's organization", last_modified_by: 'uu', created_by: null, -} as const satisfies AssetResponse +} as unknown as AssetResponse export const submissionWithAllQual = { _id: 81, diff --git a/jsapp/js/components/submissions/tableUtils.mocks.ts b/jsapp/js/components/submissions/tableUtils.mocks.ts index dc02510d29..eb66aba556 100644 --- a/jsapp/js/components/submissions/tableUtils.mocks.ts +++ b/jsapp/js/components/submissions/tableUtils.mocks.ts @@ -1,23 +1,14 @@ +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import { ANY_ROW_TYPE_NAMES, AssetTypeName } from '#/constants' import type { AssetResponse } from '#/dataInterface' -export const assetWithBgAudioAndNLP: AssetResponse = { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt', - owner: 'http://kf.kobo.local/api/v2/users/kobo.json', - owner__username: 'kobo', - owner_label: 'kobo', - last_modified_by: null, - created_by: null, - parent: null, - settings: { - sector: {}, - country: [], - description: '', - organization: '', - country_codes: [], - }, +export const assetWithBgAudioAndNLP = getApiV2AssetsRetrieveResponseMock({ + uid: 'am5q2MmVckuLBXPKsbHjEt', + name: 'text and media projekt', asset_type: AssetTypeName.survey, - files: [], + deployment__active: true, + deployment__submission_count: 1, + has_deployment: true, summary: { geo: false, labels: ['Your name here', 'Your selfie goes here', 'A video? WTF', 'Secret password as an audio file'], @@ -26,96 +17,9 @@ export const assetWithBgAudioAndNLP: AssetResponse = { lock_any: false, languages: [], row_count: 5, - name_quality: { - ok: 0, - bad: 0, - good: 5, - total: 5, - firsts: {}, - }, + name_quality: { ok: 0, bad: 0, good: 5, total: 5, firsts: {} }, default_translation: null, }, - date_created: '2024-10-21T10:20:46.811112Z', - date_modified: '2024-10-23T13:54:50.828315Z', - date_deployed: '2024-10-21T10:21:16.157454Z', - version_id: 'vM3yepjgRLxbQfTy4V7JQ9', - version__content_hash: '8362f2d2c4100490fae4f811bad5296188421855', - version_count: 6, - has_deployment: true, - deployed_version_id: 'vsuXfYXtZpRaXdWcDQe8cS', - deployed_versions: { - count: 1, - next: null, - previous: null, - results: [ - { - uid: 'vsuXfYXtZpRaXdWcDQe8cS', - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/versions/vsuXfYXtZpRaXdWcDQe8cS/', - content_hash: '8362f2d2c4100490fae4f811bad5296188421855', - date_deployed: '2024-10-21T10:21:16.154074Z', - date_modified: '2024-10-21T10:21:16.154074Z', - }, - ], - }, - deployment__links: { - url: 'http://ee.kobo.local/YnqSWtB3', - single_url: 'http://ee.kobo.local/single/YnqSWtB3', - single_once_url: 'http://ee.kobo.local/single/9778636aa5d24eb2f0806bab320e7bc6', - offline_url: 'http://ee.kobo.local/x/YnqSWtB3', - preview_url: 'http://ee.kobo.local/preview/YnqSWtB3', - iframe_url: 'http://ee.kobo.local/i/YnqSWtB3', - single_iframe_url: 'http://ee.kobo.local/single/i/YnqSWtB3', - single_once_iframe_url: 'http://ee.kobo.local/single/i/9778636aa5d24eb2f0806bab320e7bc6', - }, - deployment__active: true, - deployment__data_download_links: { - xls_legacy: 'http://kc.kobo.local/kobo/exports/am5q2MmVckuLBXPKsbHjEt/xls/', - csv_legacy: 'http://kc.kobo.local/kobo/exports/am5q2MmVckuLBXPKsbHjEt/csv/', - zip_legacy: 'http://kc.kobo.local/kobo/exports/am5q2MmVckuLBXPKsbHjEt/zip/', - kml_legacy: 'http://kc.kobo.local/kobo/exports/am5q2MmVckuLBXPKsbHjEt/kml/', - geojson: 'http://kc.kobo.local/kobo/exports/am5q2MmVckuLBXPKsbHjEt/geojson/', - spss_labels: 'http://kc.kobo.local/kobo/exports/am5q2MmVckuLBXPKsbHjEt/spss/', - xls: 'http://kc.kobo.local/kobo/reports/am5q2MmVckuLBXPKsbHjEt/export.xlsx', - csv: 'http://kc.kobo.local/kobo/reports/am5q2MmVckuLBXPKsbHjEt/export.csv', - }, - deployment__submission_count: 1, - deployment_status: 'deployed', - report_styles: { - default: {}, - specified: { - end: {}, - audit: {}, - start: {}, - today: {}, - deviceid: {}, - username: {}, - simserial: {}, - A_video_WTF: {}, - phonenumber: {}, - subscriberid: {}, - Your_name_here: {}, - 'background-audio': {}, - Your_selfie_goes_here: {}, - Secret_password_as_an_audio_file: {}, - }, - kuid_names: { - end: 'MlyFnjOHJ', - audit: 'QG4SJ5LYb', - start: 'M3AXQZPzW', - today: 'aBemgUnm5', - deviceid: 'SzW7bWk8N', - username: 'mQjEGodmD', - simserial: 'QsCIjT134', - A_video_WTF: 'alGpvxEVv', - phonenumber: 'UfrYC0nkS', - subscriberid: '6iTYT9Hk1', - Your_name_here: '25l27nQ3a', - 'background-audio': 'dE9sDyVtS', - Your_selfie_goes_here: 'd0JxfaSC9', - Secret_password_as_an_audio_file: '2sN8g5yJ2', - }, - }, - report_custom: {}, advanced_features: { qual: { qual_survey: [ @@ -193,8 +97,6 @@ export const assetWithBgAudioAndNLP: AssetResponse = { }, ], }, - map_styles: {}, - map_custom: {}, content: { schema: '1', survey: [ @@ -299,195 +201,16 @@ export const assetWithBgAudioAndNLP: AssetResponse = { translated: ['label'], translations: [null], }, - downloads: [ - { - format: 'xls', - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt.xls', - }, - { - format: 'xml', - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt.xml', - }, - ], - embeds: [ - { - format: 'xls', - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/xls/', - }, - { - format: 'xform', - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/xform/', - }, - ], - xform_link: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/xform/', - hooks_link: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/hooks/', - tag_string: '', - uid: 'am5q2MmVckuLBXPKsbHjEt', - kind: 'asset', - xls_link: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/xls/', - name: 'text and media projekt', - assignable_permissions: [ - { - url: 'http://kf.kobo.local/api/v2/permissions/view_asset/', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/change_asset/', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', - label: 'View submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/partial_submissions/', - label: { - default: 'Act on submissions only from specific users', - view_submissions: 'View submissions only from specific users', - change_submissions: 'Edit submissions only from specific users', - delete_submissions: 'Delete submissions only from specific users', - validate_submissions: 'Validate submissions only from specific users', - }, - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', - label: 'Validate submissions', - }, - ], - permissions: [ - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/pUmPzC6pFgDdcB2cxLn9QD/', - user: 'http://kf.kobo.local/api/v2/users/AnonymousUser.json', - permission: 'http://kf.kobo.local/api/v2/permissions/add_submissions.json', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/p6nyXrHUs5BpNJLZPaunvJ/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/add_submissions.json', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/pz7RvRMsYHuJL9TRyQyoDP/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/change_asset.json', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/pM7p797FK3qQjCYADpxojX/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/change_submissions.json', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/p8aL4ifctta3AxvRWeUwsz/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/delete_submissions.json', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/paBd2H3gyWhZQBkGzGvfjE/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/manage_asset.json', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/pAdfYDhVHTWXNMv8CTZxFz/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/validate_submissions.json', - label: 'Validate submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/p782nm85UEcMy56EvxiNMz/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/view_asset.json', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/permission-assignments/pPAFrcPkXTuQFWywccDzr7/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/view_submissions.json', - label: 'View submissions', - }, - ], - effective_permissions: [ - { - codename: 'delete_submissions', - }, - { - codename: 'view_asset', - }, - { - codename: 'change_asset', - }, - { - codename: 'view_submissions', - }, - { - codename: 'delete_asset', - }, - { - codename: 'manage_asset', - }, - { - codename: 'change_submissions', - }, - { - codename: 'validate_submissions', - }, - { - codename: 'add_submissions', - }, - ], - exports: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/exports/', - export_settings: [], - data: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/data.json', - children: { - count: 0, - }, - subscribers_count: 0, - status: 'shared', - access_types: null, - data_sharing: {}, - paired_data: 'http://kf.kobo.local/api/v2/assets/am5q2MmVckuLBXPKsbHjEt/paired-data/', - project_ownership: null, -} + effective_permissions: [{ codename: 'change_submissions' }], +}) as unknown as AssetResponse -export const assetWithNestedGroupsAndNLP: AssetResponse = { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC.json', - owner: 'http://kf.kobo.local/api/v2/users/kobo.json', - owner__username: 'kobo', - owner_label: 'kobo', - last_modified_by: null, - created_by: null, - parent: null, - settings: { - sector: {}, - country: [], - description: '', - collects_pii: null, - organization: '', - country_codes: [], - operational_purpose: null, - }, +export const assetWithNestedGroupsAndNLP = getApiV2AssetsRetrieveResponseMock({ + uid: 'aRai4qmXVG4eukrzpHXAQC', + name: 'Project with audio inside nested group', asset_type: AssetTypeName.survey, - files: [], + deployment__active: true, + deployment__submission_count: 1, + has_deployment: true, summary: { geo: false, labels: ['What did you hear?'], @@ -511,77 +234,6 @@ export const assetWithNestedGroupsAndNLP: AssetResponse = { }, default_translation: null, }, - date_created: '2024-10-24T21:50:14.547659Z', - date_modified: '2024-10-24T22:10:01.271453Z', - date_deployed: '2024-10-24T21:52:53.487365Z', - version_id: 'veWGMzgZCdiNnDvBdxtrQj', - version__content_hash: '778df104b69459fe67b8431bb500433b82e2ee33', - version_count: 7, - has_deployment: true, - deployed_version_id: 'v4MNF9dNVo682gg2KZc5P7', - deployed_versions: { - count: 1, - next: null, - previous: null, - results: [ - { - uid: 'v4MNF9dNVo682gg2KZc5P7', - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/versions/v4MNF9dNVo682gg2KZc5P7/', - content_hash: '778df104b69459fe67b8431bb500433b82e2ee33', - date_deployed: '2024-10-24T21:52:53.478265Z', - date_modified: '2024-10-24T21:52:53.478265Z', - }, - ], - }, - deployment__links: { - url: 'http://ee.kobo.local/iQdYiTID', - single_url: 'http://ee.kobo.local/single/iQdYiTID', - single_once_url: 'http://ee.kobo.local/single/7edea25f7e36766e7558a8a9d2e015f0', - offline_url: 'http://ee.kobo.local/x/iQdYiTID', - preview_url: 'http://ee.kobo.local/preview/iQdYiTID', - iframe_url: 'http://ee.kobo.local/i/iQdYiTID', - single_iframe_url: 'http://ee.kobo.local/single/i/iQdYiTID', - single_once_iframe_url: 'http://ee.kobo.local/single/i/7edea25f7e36766e7558a8a9d2e015f0', - }, - deployment__active: true, - deployment__data_download_links: { - xls_legacy: 'http://kc.kobo.local/kobo/exports/aRai4qmXVG4eukrzpHXAQC/xls/', - csv_legacy: 'http://kc.kobo.local/kobo/exports/aRai4qmXVG4eukrzpHXAQC/csv/', - zip_legacy: 'http://kc.kobo.local/kobo/exports/aRai4qmXVG4eukrzpHXAQC/zip/', - kml_legacy: 'http://kc.kobo.local/kobo/exports/aRai4qmXVG4eukrzpHXAQC/kml/', - geojson: 'http://kc.kobo.local/kobo/exports/aRai4qmXVG4eukrzpHXAQC/geojson/', - spss_labels: 'http://kc.kobo.local/kobo/exports/aRai4qmXVG4eukrzpHXAQC/spss/', - xls: 'http://kc.kobo.local/kobo/reports/aRai4qmXVG4eukrzpHXAQC/export.xlsx', - csv: 'http://kc.kobo.local/kobo/reports/aRai4qmXVG4eukrzpHXAQC/export.csv', - }, - deployment__submission_count: 1, - deployment_status: 'deployed', - report_styles: { - default: {}, - specified: { - end: {}, - start: {}, - sm28q44: {}, - '/kx8rw55': {}, - '/oh5pd61': {}, - '/py8fl89': {}, - inner_group: {}, - outer_group: {}, - middle_group: {}, - }, - kuid_names: { - end: 'wnxtTQ2B1', - start: 'D8zvSJsd3', - sm28q44: 'sm28q44', - '/kx8rw55': '/kx8rw55', - '/oh5pd61': '/oh5pd61', - '/py8fl89': '/py8fl89', - inner_group: 'oh5pd61', - outer_group: 'kx8rw55', - middle_group: 'py8fl89', - }, - }, - report_custom: {}, advanced_features: { transcript: { languages: ['pl'], @@ -610,8 +262,6 @@ export const assetWithNestedGroupsAndNLP: AssetResponse = { }, ], }, - map_styles: {}, - map_custom: {}, content: { schema: '1', survey: [ @@ -664,166 +314,5 @@ export const assetWithNestedGroupsAndNLP: AssetResponse = { translated: ['label'], translations: [null], }, - downloads: [ - { - format: 'xls', - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC.xls', - }, - { - format: 'xml', - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC.xml', - }, - ], - embeds: [ - { - format: 'xls', - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/xls/', - }, - { - format: 'xform', - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/xform/', - }, - ], - xform_link: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/xform/', - hooks_link: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/hooks/', - tag_string: '', - uid: 'aRai4qmXVG4eukrzpHXAQC', - kind: 'asset', - xls_link: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/xls/', - name: 'Project with audio inside nested group', - assignable_permissions: [ - { - url: 'http://kf.kobo.local/api/v2/permissions/view_asset/', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/change_asset/', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', - label: 'View submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/partial_submissions/', - label: { - default: 'Act on submissions only from specific users', - view_submissions: 'View submissions only from specific users', - change_submissions: 'Edit submissions only from specific users', - delete_submissions: 'Delete submissions only from specific users', - validate_submissions: 'Validate submissions only from specific users', - }, - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', - label: 'Validate submissions', - }, - ], - permissions: [ - { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/permission-assignments/pCYMKNGknBkN5vMpsFeBrL/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/add_submissions.json', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/permission-assignments/pWH6k8kQyjT4z3WAheWhTH/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/change_asset.json', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/permission-assignments/pF4feraPmjmGwbs4XGGjMd/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/change_submissions.json', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/permission-assignments/pWXMaN6dAiwWv9kE5s2Mvn/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/delete_submissions.json', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/permission-assignments/peFnddaDPNehS3H95ZuVEe/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/manage_asset.json', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/permission-assignments/pAqCW3fjVQLQNtBX4rxZjg/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/validate_submissions.json', - label: 'Validate submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/permission-assignments/puB4cwPhyJFprC5zXcdD8K/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/view_asset.json', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/permission-assignments/poNyR5qmXJ7Wjq99qMuncR/', - user: 'http://kf.kobo.local/api/v2/users/kobo.json', - permission: 'http://kf.kobo.local/api/v2/permissions/view_submissions.json', - label: 'View submissions', - }, - ], - effective_permissions: [ - { - codename: 'view_submissions', - }, - { - codename: 'validate_submissions', - }, - { - codename: 'add_submissions', - }, - { - codename: 'manage_asset', - }, - { - codename: 'delete_submissions', - }, - { - codename: 'delete_asset', - }, - { - codename: 'view_asset', - }, - { - codename: 'change_asset', - }, - { - codename: 'change_submissions', - }, - ], - exports: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/exports/', - export_settings: [], - data: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/data.json', - children: { - count: 0, - }, - subscribers_count: 0, - status: 'private', - access_types: null, - data_sharing: {}, - paired_data: 'http://kf.kobo.local/api/v2/assets/aRai4qmXVG4eukrzpHXAQC/paired-data/', - project_ownership: null, -} + effective_permissions: [{ codename: 'change_submissions' }], +}) as unknown as AssetResponse diff --git a/jsapp/js/components/submissions/useDataTableBulkActions.tests.ts b/jsapp/js/components/submissions/useDataTableBulkActions.tests.ts index eb4d8a43e4..5cb932362f 100644 --- a/jsapp/js/components/submissions/useDataTableBulkActions.tests.ts +++ b/jsapp/js/components/submissions/useDataTableBulkActions.tests.ts @@ -6,13 +6,15 @@ import { getAssetsAdvancedFeaturesBulkActionsListQueryKey, useAssetsAdvancedFeaturesBulkActionsList, } from '#/api/react-query/survey-data' -import bulkActionFactory from '#/endpoints/bulkAction.factory' +import { getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock } from '#/api/react-query/survey-data/msw' import { useFeatureFlag } from '#/featureFlags' import { useSession } from '#/stores/useSession' import { getBulkActionsPollingIntervalMs, useDataTableBulkActions } from './useDataTableBulkActions' jest.mock('#/api/react-query/survey-data', () => { + const actual = jest.requireActual('#/api/react-query/survey-data') return { + ...actual, getAssetsAdvancedFeaturesBulkActionsListQueryKey: jest.fn( (uidAsset: string, params?: unknown) => ['api', 'v2', 'assets', uidAsset, 'advanced-features', 'bulk-actions', ...(params ? [params] : [])] as const, @@ -47,16 +49,27 @@ jest.mock('#/envStore', () => { } }) +// Use Orval-generated mock factory for type-safe bulk action mocks function buildBulkAction( status: BulkActionResponseStatusEnum, createdByUsername: string, overrides: Partial = {}, ): BulkActionResponse { - // Reuse shared factory defaults, overriding only fields relevant to this hook. - return bulkActionFactory('submission-1', 'fr', { + return getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ uid: `bulk-${status}-${createdByUsername}`, status, - created_by: { username: createdByUsername }, + action_id: ActionIdEnum.automatic_google_transcription, + question_xpath: 'Your_name', + submission_uuids: ['submission-1'], + params: { + language: 'fr', + }, + progress: 0, + created_by: { + username: createdByUsername, + }, + date_created: '2026-01-01T00:00:00Z', + date_modified: '2026-01-01T00:00:00Z', ...overrides, }) } @@ -99,7 +112,7 @@ describe('useDataTableBulkActions', () => { beforeEach(() => { jest.resetAllMocks() getBulkActionsListQueryKeyMock.mockImplementation( - (uidAsset: string, params) => + (uidAsset: string, params?: unknown) => ['api', 'v2', 'assets', uidAsset, 'advanced-features', 'bulk-actions', ...(params ? [params] : [])] as const, ) envStore.data.asr_mt_features_enabled = true diff --git a/jsapp/js/dataInterface.ts b/jsapp/js/dataInterface.ts index e971ba8e58..f343d82f3a 100644 --- a/jsapp/js/dataInterface.ts +++ b/jsapp/js/dataInterface.ts @@ -336,6 +336,8 @@ export interface LabelValuePair { export interface PartialPermissionFilterByUsers { _submitted_by?: string | { $in: string[] } + /** Allow additional question response filters */ + [key: string]: unknown } export type PartialPermissionFilterByResponses = Record @@ -427,6 +429,8 @@ export interface ExportSettingSettings { query?: MongoQuery /** Only for GeoJSON */ flatten?: boolean + /** Allow additional export setting properties */ + [key: string]: unknown } /** @@ -485,6 +489,8 @@ export interface SurveyRow { select_from_list_name?: string /** Used by `file` type to list accepted extensions */ 'body::accept'?: string + /** Allow additional properties for XLSForm custom fields */ + [key: string]: unknown } export interface SurveyChoice { @@ -497,6 +503,8 @@ export interface SurveyChoice { // Possibly deprecated? Most code doesn't use it at all, old reports code was // using it as fallback. $autoname?: string + /** Allow additional properties for XLSForm custom fields */ + [key: string]: unknown } export interface AssetContentSettings { @@ -537,25 +545,27 @@ interface AssetSummary { columns?: string[] lock_all?: boolean lock_any?: boolean - languages?: Array + // Backend returns languages as string[] (never null elements) + // Note: OpenAPI schema correctly specifies string[], this legacy type matches it now + languages?: LangString[] row_count?: number default_translation?: string | null /** To be used in a warning about missing or poorly written question names. */ name_quality?: { - ok: number - bad: number - good: number - total: number - firsts: { + ok?: number + bad?: number + good?: number + total?: number + firsts?: { ok?: { - name: string - index: number - label: string[] + name?: string + index?: number + label?: string[] } bad?: { - name: string - index: number - label: string[] + name?: string + index?: number + label?: string[] } } } @@ -610,7 +620,10 @@ export interface AssetTableSettings extends AssetTableSettingsObject { export interface AssetSettings { sector?: LabelValuePair | null | {} - country?: LabelValuePair | LabelValuePair[] | null + // Backend schema specifies array, but old assets (pre-Dec 2022) may still have + // single object if not updated since standardization or if migration was skipped. + // Runtime: LabelValuePair[] | LabelValuePair | null, but typed as array for new code. + country?: LabelValuePair[] | null description?: string 'data-table'?: AssetTableSettings organization?: string @@ -641,7 +654,7 @@ export interface AssetRequestObject { enabled?: boolean fields?: string[] } - paired_data?: string + paired_data: string advanced_features?: AssetAdvancedFeatures } @@ -685,21 +698,25 @@ export interface AssetResponse extends AssetRequestObject { owner: string owner__username: string owner_label: string - date_created: string + // Always present in GET responses (Django auto-populates on creation) + // OpenAPI marks optional because POST/PATCH don't require it (has default value) + date_created?: string last_modified_by: string | null created_by: string | null summary: AssetSummary - date_modified: string - date_deployed?: string + // Always present in GET responses (Django auto-updates on save) + // OpenAPI marks optional because POST/PATCH don't require it (has default value) + date_modified?: string + date_deployed?: string | null version_id: string | null - version__content_hash?: string | null - version_count?: number + version__content_hash: string | null + version_count: number has_deployment: boolean deployed_version_id: string | null - analysis_form_json?: { + analysis_form_json: { additional_fields: AnalysisFormJsonField[] } - deployed_versions?: { + deployed_versions: { count: number next: string | null previous: string | null @@ -711,7 +728,7 @@ export interface AssetResponse extends AssetRequestObject { date_modified: string }> } - deployment__links?: { + deployment__links: { url?: string single_url?: string single_once_url?: string @@ -722,7 +739,7 @@ export interface AssetResponse extends AssetRequestObject { single_once_iframe_url?: string } deployment__active: boolean - deployment__data_download_links?: { + deployment__data_download_links: { csv_legacy: string csv: string geojson?: string @@ -732,21 +749,21 @@ export interface AssetResponse extends AssetRequestObject { xls: string zip_legacy: string } - deployment__uuid?: string - deployment__encrypted?: boolean + deployment__uuid: string | null + deployment__encrypted: boolean deployment__submission_count: number - deployment__last_submission_time?: string - deployment_status: 'archived' | 'deployed' | 'draft' + deployment__last_submission_time: string | null + deployment_status: 'archived' | 'deployed' | 'draft' | '-' downloads: AssetDownloads - embeds?: Array<{ + embeds: Array<{ format: string url: string }> - xform_link?: string - hooks_link?: string + xform_link: string + hooks_link: string uid: string kind: string - xls_link?: string + xls_link: string assignable_permissions: AssignablePermission[] /** * A list of all permissions (their codenames) that current user has in @@ -754,7 +771,7 @@ export interface AssetResponse extends AssetRequestObject { * that user and ones coming from the Project View definition. */ effective_permissions: Array<{ codename: PermissionCodename }> - exports?: string + exports: string data: string children: { count: number @@ -829,7 +846,7 @@ export interface ProjectViewAsset { has_deployment: boolean deployment__active: boolean deployment__submission_count: number - deployment_status: 'archived' | 'deployed' | 'draft' + deployment_status: 'archived' | 'deployed' | 'draft' | '-' } export interface AssetsResponse extends PaginatedResponse { diff --git a/jsapp/js/endpoints/asset.factory.ts b/jsapp/js/endpoints/asset.factory.ts deleted file mode 100644 index f29f9a3865..0000000000 --- a/jsapp/js/endpoints/asset.factory.ts +++ /dev/null @@ -1,56 +0,0 @@ -// Factory for minimal AssetResponse with audio question and transcript support -import { AssetTypeName } from '#/constants' -import type { AssetResponse } from '#/dataInterface' - -/** - * Creates a minimal AssetResponse for a form with no questions - * @param overrides - For overriding any property of the asset - */ -export default function assetFactory(overrides: Partial = {}): AssetResponse { - return { - url: '', - owner: '', - owner__username: '', - owner_label: '', - last_modified_by: null, - created_by: null, - date_created: '', - summary: {}, - date_modified: '', - version_id: null, - has_deployment: false, - deployed_version_id: null, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'deployed', - downloads: [], - uid: 'mock-asset-uid', - kind: 'form', - assignable_permissions: [], - effective_permissions: [], - data: '', - children: { count: 0 }, - content: { - survey: [], - choices: [], - }, - subscribers_count: 0, - status: '', - access_types: null, - project_ownership: null, - parent: null, - settings: {}, - asset_type: AssetTypeName.survey, - report_styles: { default: {}, specified: {}, kuid_names: {} }, - report_custom: {}, - map_styles: {}, - map_custom: {}, - tag_string: '', - name: 'Test form', - permissions: [], - export_settings: [], - data_sharing: {}, - files: [], - ...overrides, - } -} diff --git a/jsapp/js/endpoints/asset.mocks.ts b/jsapp/js/endpoints/asset.mocks.ts index ceae9e9795..9886c412a8 100644 --- a/jsapp/js/endpoints/asset.mocks.ts +++ b/jsapp/js/endpoints/asset.mocks.ts @@ -1,6 +1,5 @@ import { http, HttpResponse } from 'msw' import { endpoints } from '#/api.endpoints' -import { AssetTypeName, QuestionTypeName } from '#/constants' import type { AssetResponse } from '#/dataInterface' interface AssetPatchMockOptions { @@ -14,24 +13,11 @@ interface AssetPatchMockOptions { // not leak mutations into the next render. const cloneAsset = (asset: AssetResponse): AssetResponse => JSON.parse(JSON.stringify(asset)) as AssetResponse -/** - * Mock API for single asset detail. Use in Storybook tests in `parameters.msw.handlers.asset`. - * - * Usage: assetMock() for default, or assetMock({ name: 'override' }) for custom. - */ -const assetMock = (assetUid: string, override?: Partial) => - http.get(endpoints.ASSET_URL, ({ params }) => { - // Only respond for the correct assetUid - if (params.uid !== assetUid) return undefined - return HttpResponse.json({ - ...defaultMockResponse, - ...override, - uid: params.uid || override?.uid || defaultMockResponse.uid, - }) - }) - /** * Builds a reusable PATCH handler for single-asset stories while keeping the in-memory asset mutable. + * + * This custom handler is kept because it has stateful logic that Orval cannot generate. + * For simple GET requests, use getApiV2AssetsRetrieveMockHandler from Orval instead. */ export const assetPatchMock = ({ asset, @@ -62,187 +48,3 @@ export const assetPatchMock = ({ return HttpResponse.json(responseAsset) }) } - -/** - * Provides a realistic asset detail payload for stories that only need one asset instance. - */ -export const defaultMockResponse: AssetResponse = { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/', - owner: 'http://kf.kobo.local/api/v2/users/zefir/', - owner__username: 'zefir', - parent: null, - settings: { - sector: {}, - country: [], - description: '', - collects_pii: null, - organization: '', - country_codes: [], - operational_purpose: null, - }, - asset_type: AssetTypeName.survey, - files: [], - summary: { - geo: false, - labels: ['Your name'], - columns: ['type', 'label', 'required'], - lock_all: false, - lock_any: false, - languages: [], - row_count: 1, - name_quality: { - ok: 1, - bad: 0, - good: 0, - total: 1, - firsts: { ok: { name: 'Your_name', index: 1, label: ['Your name'] } }, - }, - default_translation: null, - }, - date_created: '2025-09-09T21:08:44.296979Z', - date_modified: '2025-09-09T21:09:04.827003Z', - version_id: 'vt8TMvyLRCyv26nQLcbGBi', - version__content_hash: '822573fdb551228b65ef80359b4499e62421adde', - version_count: 3, - has_deployment: false, - deployed_version_id: null, - deployed_versions: { count: 0, next: null, previous: null, results: [] }, - deployment__links: {}, - deployment__active: false, - deployment__submission_count: 0, - deployment_status: 'draft', - report_styles: { default: {}, specified: { wb1gg11: {} }, kuid_names: { wb1gg11: 'wb1gg11' } }, - report_custom: {}, - advanced_features: {}, - analysis_form_json: { additional_fields: [] }, - map_styles: {}, - map_custom: {}, - content: { - schema: '1', - survey: [ - { - type: QuestionTypeName.text, - $kuid: 'wb1gg11', - label: ['Your name'], - $xpath: 'Your_name', - required: false, - $autoname: 'Your_name', - }, - ], - settings: {}, - translated: ['label'], - translations: [null], - }, - downloads: [ - { format: 'xls', url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5.xls' }, - { format: 'xml', url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5.xml' }, - ], - embeds: [ - { format: 'xls', url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/xls/' }, - { format: 'xform', url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/xform/' }, - ], - xform_link: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/xform/', - hooks_link: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/hooks/', - tag_string: '', - uid: 'abam8JiJ3hHTW3EYp6Tpb5', - kind: 'asset', - xls_link: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/xls/', - name: 'minimal asset first', - assignable_permissions: [ - { url: 'http://kf.kobo.local/api/v2/permissions/view_asset/', label: 'View form' }, - { url: 'http://kf.kobo.local/api/v2/permissions/change_asset/', label: 'Edit form' }, - { url: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', label: 'Manage project' }, - { url: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', label: 'Add submissions' }, - { url: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', label: 'View submissions' }, - { - url: 'http://kf.kobo.local/api/v2/permissions/partial_submissions/', - label: { - default: 'Act on submissions only from specific users', - view_submissions: 'View submissions only from specific users', - change_submissions: 'Edit submissions only from specific users', - delete_submissions: 'Delete submissions only from specific users', - validate_submissions: 'Validate submissions only from specific users', - }, - }, - { url: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', label: 'Edit submissions' }, - { url: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', label: 'Delete submissions' }, - { url: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', label: 'Validate submissions' }, - ], - permissions: [ - { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/permission-assignments/pvSrj5oiVFK2VrhNRXt2yr/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/add_submissions/', - label: 'Add submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/permission-assignments/p9UxbrXnf9KEWfEZdKfy49/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/change_asset/', - label: 'Edit form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/permission-assignments/pmSFAQG4Zji9bxit9McKPY/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/change_submissions/', - label: 'Edit submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/permission-assignments/pZTZtbdNcV4yQ9CMAB7BKo/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/delete_submissions/', - label: 'Delete submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/permission-assignments/pSfM5nnZ4F4i32pwzQxtz9/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/manage_asset/', - label: 'Manage project', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/permission-assignments/pnZXygNRi4subXAeBTZuux/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/validate_submissions/', - label: 'Validate submissions', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/permission-assignments/pxbya4pDjbLY7pY4QSNxMU/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/view_asset/', - label: 'View form', - }, - { - url: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/permission-assignments/phL46hRUcpycdP55e7YYGF/', - user: 'http://kf.kobo.local/api/v2/users/zefir/', - permission: 'http://kf.kobo.local/api/v2/permissions/view_submissions/', - label: 'View submissions', - }, - ], - effective_permissions: [ - { codename: 'change_metadata_asset' }, - { codename: 'change_asset' }, - { codename: 'validate_submissions' }, - { codename: 'manage_asset' }, - { codename: 'delete_submissions' }, - { codename: 'delete_asset' }, - { codename: 'view_asset' }, - { codename: 'view_submissions' }, - { codename: 'change_submissions' }, - { codename: 'add_submissions' }, - ], - exports: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/exports/', - export_settings: [], - data: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/data/', - children: { count: 0 }, - subscribers_count: 0, - status: 'private', - access_types: null, - data_sharing: {}, - paired_data: 'http://kf.kobo.local/api/v2/assets/abam8JiJ3hHTW3EYp6Tpb5/paired-data/', - project_ownership: null, - owner_label: "zefir's MMO organization", - last_modified_by: 'zefir', - created_by: null, -} - -export default assetMock diff --git a/jsapp/js/endpoints/assetData.factory.ts b/jsapp/js/endpoints/assetData.factory.ts index 3b1d7d34a6..a149e407b0 100644 --- a/jsapp/js/endpoints/assetData.factory.ts +++ b/jsapp/js/endpoints/assetData.factory.ts @@ -3,6 +3,12 @@ import type { SubmissionResponse } from '#/dataInterface' /** * Creates a minimal SubmissionResponse for a form with no questions. + * + * Note: NOT migrated to Orval because SubmissionResponse is a legacy type + * defined in dataInterface.ts, not in the OpenAPI schema. It represents + * dynamic form submission data with arbitrary question fields, which cannot + * be statically typed in OpenAPI/Orval. + * * @param testId - Id of the submission * @param overrides - For overriding any property of the submission */ diff --git a/jsapp/js/endpoints/assetData.mocks.ts b/jsapp/js/endpoints/assetData.mocks.ts index b7d4b98351..4b1f6eaa3b 100644 --- a/jsapp/js/endpoints/assetData.mocks.ts +++ b/jsapp/js/endpoints/assetData.mocks.ts @@ -6,6 +6,12 @@ import assetDataFactory from './assetData.factory' /** * MSW handler factory for /api/v2/assets/:uid/data/ endpoint. * Returns a paginated response with one submission, unless overriden. + * + * Note: NOT migrated to Orval because SubmissionResponse is a legacy type + * representing dynamic form submission data. This mock uses assetData.factory.ts + * which cannot be replaced with Orval since submission data has arbitrary fields + * based on form questions (not statically typed in OpenAPI). + * * @param assetUid * @param submissions - A list of `SubmissionResponse`s to be returned * @param override - Optional override for the paginated response diff --git a/jsapp/js/endpoints/assetHistory.mocks.ts b/jsapp/js/endpoints/assetHistory.mocks.ts index 1a572bd658..fc91df44b3 100644 --- a/jsapp/js/endpoints/assetHistory.mocks.ts +++ b/jsapp/js/endpoints/assetHistory.mocks.ts @@ -1,20 +1,58 @@ import { http, HttpResponse, type PathParams } from 'msw' import { endpoints } from '#/api.endpoints' +import type { ProjectHistoryLogResponse } from '#/api/models/projectHistoryLogResponse' +import { getApiV2ProjectHistoryLogsListResponseMock } from '#/api/react-query/server-logs-superusers/msw' import { type ActivityLogsItem, AuditActions, BULK_PROCESSING_ACTION_IDS, } from '#/components/activity/activity.constants' import type { PaginatedResponse } from '#/dataInterface' -import assetHistoryLogFactory, { defaultAssetHistoryAssetUid } from './assetHistoryLog.factory' -export const mockAssetUid = defaultAssetHistoryAssetUid +export const mockAssetUid = 'a1234567890bcdEFGhijkl' + +/** + * Creates a mock history log item using Orval's generated mock. + * + * Since the API doesn't have a single-item retrieve endpoint, Orval only generates + * getApiV2ProjectHistoryLogsListResponseMock (which returns a paginated list). + * This helper extracts a single item from that list and merges overrides. + * + * Note: ActivityLogsItem extends ProjectHistoryLogResponse with typed action/metadata. + */ +type AssetHistoryLogOverrides = Partial> & { + metadata?: Partial +} + +const createHistoryLog = (overrides: AssetHistoryLogOverrides = {}): ActivityLogsItem => { + // Get a sample log from Orval's list mock + const sampleList = getApiV2ProjectHistoryLogsListResponseMock() + const baseLog = sampleList.results[0] as ProjectHistoryLogResponse + + const { metadata, ...rest } = overrides + + return { + ...baseLog, + user: '/api/v2/users/john/', + user_uid: 'umBqhq3XSkkeNEzrFpCfTZ', + username: 'john', + action: AuditActions['update-content'], + metadata: { + ...baseLog.metadata, + source: 'Firefox (Mac OS X)', + asset_uid: mockAssetUid, + ip_address: '192.168.107.1', + ...metadata, + }, + date_created: '2025-04-15T11:31:30Z', + ...rest, + } as ActivityLogsItem +} -type AssetHistoryLogOverrides = Parameters[0] type ActivityPermissions = NonNullable const johnLog = (overrides: AssetHistoryLogOverrides) => - assetHistoryLogFactory({ + createHistoryLog({ user: '/api/v2/users/john/', user_uid: 'umBqhq3XSkkeNEzrFpCfTZ', username: 'john', @@ -22,7 +60,7 @@ const johnLog = (overrides: AssetHistoryLogOverrides) => }) const karinaLog = (overrides: AssetHistoryLogOverrides) => - assetHistoryLogFactory({ + createHistoryLog({ user: '/api/v2/users/karina/', user_uid: 'umBqhq3XSkkeNEzrFpCfTx', username: 'karina', diff --git a/jsapp/js/endpoints/assetHistoryActions.mocks.ts b/jsapp/js/endpoints/assetHistoryActions.mocks.ts deleted file mode 100644 index d7f902fa68..0000000000 --- a/jsapp/js/endpoints/assetHistoryActions.mocks.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { http, HttpResponse, type PathParams } from 'msw' -import { endpoints } from '#/api.endpoints' -import type { AssetHistoryActionsResponse } from '#/components/activity/activity.constants' -import { mockAssetUid } from './assetHistory.mocks' - -/** - * Mock API for listing all available history actions. Use it in Storybook tests in `parameters.msw.handlers[]`. - * Uses same assetUid as assetHistory mock. - */ -const assetHistoryMock = http.get, never, AssetHistoryActionsResponse>( - endpoints.ASSET_HISTORY_ACTIONS.replace(':asset_uid', mockAssetUid), - () => HttpResponse.json(assetHistoryActionsResponse), -) -export default assetHistoryMock - -const assetHistoryActionsResponse: AssetHistoryActionsResponse = { - actions: [ - 'bulk-processing', - 'disallow-anonymous-submissions', - 'add-media', - 'add-submission', - 'allow-anonymous-submissions', - 'modify-user-permissions', - 'update-content', - 'deploy', - 'delete-submission', - ], -} diff --git a/jsapp/js/endpoints/assetHistoryLog.factory.ts b/jsapp/js/endpoints/assetHistoryLog.factory.ts deleted file mode 100644 index dc89c33485..0000000000 --- a/jsapp/js/endpoints/assetHistoryLog.factory.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { type ActivityLogsItem, AuditActions } from '#/components/activity/activity.constants' - -export const defaultAssetHistoryAssetUid = 'a1234567890bcdEFGhijkl' - -type AssetHistoryLogFactoryOverrides = Partial> & { - metadata?: Partial -} - -export default function assetHistoryLogFactory(overrides: AssetHistoryLogFactoryOverrides = {}): ActivityLogsItem { - const { metadata, ...rest } = overrides - - return { - user: '/api/v2/users/john/', - user_uid: 'umBqhq3XSkkeNEzrFpCfTZ', - username: 'john', - action: AuditActions['update-content'], - metadata: { - source: 'Firefox (Mac OS X)', - asset_uid: defaultAssetHistoryAssetUid, - ip_address: '192.168.107.1', - ...metadata, - }, - date_created: '2025-04-15T11:31:30Z', - ...rest, - } -} diff --git a/jsapp/js/endpoints/assets.mocks.ts b/jsapp/js/endpoints/assets.mocks.ts index 4ba0618853..9028cc3407 100644 --- a/jsapp/js/endpoints/assets.mocks.ts +++ b/jsapp/js/endpoints/assets.mocks.ts @@ -1,12 +1,14 @@ -import { http, HttpResponse, type PathParams } from 'msw' -import { endpoints } from '#/api.endpoints' +import { + getApiV2AssetsListMockHandler, + getApiV2AssetsRetrieveResponseMock, +} from '#/api/react-query/manage-projects-and-library-content/msw' import { AssetTypeName, QuestionTypeName } from '#/constants' import type { AssetResponse, PaginatedResponse } from '#/dataInterface' -import assetFactory from './asset.factory' import { mockTemplates } from './assets.templates' /** - * Mock API for assets list. Use it in Storybook tests in `parameters.msw.handlers.assets`. + * Mock API for assets list using Orval-generated handler. + * Use it in Storybook tests in `parameters.msw.handlers.assets`. * * Supports query parameter 'q' for filtering by asset type: * - 'asset_type:template' returns mockTemplates @@ -16,40 +18,39 @@ import { mockTemplates } from './assets.templates' * Note that default response contains only 2 results. */ const assetsMock = (override?: Partial>) => - http.get, never, PaginatedResponse>( - endpoints.ASSETS_URL, - (info) => { - const searchParams = new URL(info.request.url).searchParams - const limit = searchParams.get('limit') !== null ? Number(searchParams.get('limit')) : undefined - const query = searchParams.get('q') + getApiV2AssetsListMockHandler(async (info) => { + const searchParams = new URL(info.request.url).searchParams + const limit = searchParams.get('limit') !== null ? Number(searchParams.get('limit')) : undefined + const query = searchParams.get('q') - // Handle template queries - if (query === 'asset_type:template') { - return HttpResponse.json({ - count: mockTemplates.length, - next: null, - previous: null, - results: mockTemplates.slice(0, limit), - }) + // Handle template queries + if (query === 'asset_type:template') { + return { + count: mockTemplates.length, + next: null, + previous: null, + results: mockTemplates.slice(0, limit), } + } + + // Default behavior for other queries + return { + ...defaultMockResponse, + ...override, + results: (override?.results ?? defaultMockResponse.results).slice(0, limit ?? override?.count ?? undefined), + } + }) - // Default behavior for other queries - return HttpResponse.json({ - ...defaultMockResponse, - ...override, - results: (override?.results ?? defaultMockResponse.results).slice(0, limit ?? override?.count ?? undefined), - }) - }, - ) export default assetsMock -// Default mock assets using assetFactory for cleaner code +// Default mock assets using Orval-generated mocks +// Note: Cast to AssetResponse for backward compatibility (see DataTableWrapper.stories.tsx) const defaultMockResponse: PaginatedResponse = { count: 2, next: null, previous: null, results: [ - assetFactory({ + getApiV2AssetsRetrieveResponseMock({ uid: 'abam8JiJ3hHTW3EYp6Tpb5', name: 'minimal asset first', owner__username: 'zefir', @@ -75,7 +76,7 @@ const defaultMockResponse: PaginatedResponse = { translations: [null], }, }), - assetFactory({ + getApiV2AssetsRetrieveResponseMock({ uid: 'abam8JiJ3hHTW3EYp6Tpb4', name: 'minimal asset second', owner__username: 'zefir', @@ -101,34 +102,35 @@ const defaultMockResponse: PaginatedResponse = { translations: [null], }, }), - ].map((asset) => { - return { - ...asset, - // Override factory defaults with original mock data specifics - owner_label: "zefir's MMO organization", - version__content_hash: - asset.uid === 'abam8JiJ3hHTW3EYp6Tpb5' - ? '822573fdb551228b65ef80359b4499e62421adde' - : '822573fdb551228b65ef80359b4499e62421addf', - version_count: 3, - summary: { - geo: false, - labels: ['Your name'], - columns: ['type', 'label', 'required'], - lock_all: false, - lock_any: false, - languages: [], - row_count: 1, - name_quality: { - ok: 1, - bad: 0, - good: 0, - total: 1, - firsts: { ok: { name: 'Your_name', index: 1, label: ['Your name'] } }, + ].map( + (asset) => + ({ + ...asset, + // Override factory defaults with original mock data specifics + owner_label: "zefir's MMO organization", + version__content_hash: + asset.uid === 'abam8JiJ3hHTW3EYp6Tpb5' + ? '822573fdb551228b65ef80359b4499e62421adde' + : '822573fdb551228b65ef80359b4499e62421addf', + version_count: 3, + summary: { + geo: false, + labels: ['Your name'], + columns: ['type', 'label', 'required'], + lock_all: false, + lock_any: false, + languages: [], + row_count: 1, + name_quality: { + ok: 1, + bad: 0, + good: 0, + total: 1, + firsts: { ok: { name: 'Your_name', index: 1, label: ['Your name'] } }, + }, + default_translation: null, }, - default_translation: null, - }, - report_styles: { default: {}, specified: { wb1gg11: {} }, kuid_names: { wb1gg11: 'wb1gg11' } }, - } - }), + report_styles: { default: {}, specified: { wb1gg11: {} }, kuid_names: { wb1gg11: 'wb1gg11' } }, + }) as unknown as AssetResponse, + ), } diff --git a/jsapp/js/endpoints/assets.templates.ts b/jsapp/js/endpoints/assets.templates.ts index ba47cb1ec4..b93e3f9b2b 100644 --- a/jsapp/js/endpoints/assets.templates.ts +++ b/jsapp/js/endpoints/assets.templates.ts @@ -1,13 +1,12 @@ +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import { AssetTypeName, QuestionTypeName } from '#/constants' -import type { AssetResponse } from '#/dataInterface' -import assetFactory from './asset.factory' /** * Template asset definitions for Storybook stories. * These are used by assets.mocks.ts when the query includes 'asset_type:template' */ -export const templateHealthSurvey: AssetResponse = assetFactory({ +export const templateHealthSurvey = getApiV2AssetsRetrieveResponseMock({ uid: 'template1uid', name: 'Community Health Survey Template', asset_type: AssetTypeName.template, @@ -30,7 +29,7 @@ export const templateHealthSurvey: AssetResponse = assetFactory({ }, }) -export const templateEducationAssessment: AssetResponse = assetFactory({ +export const templateEducationAssessment = getApiV2AssetsRetrieveResponseMock({ uid: 'template2uid', name: 'Education Assessment Form', asset_type: AssetTypeName.template, @@ -53,7 +52,7 @@ export const templateEducationAssessment: AssetResponse = assetFactory({ }, }) -export const templateFeedbackSurvey: AssetResponse = assetFactory({ +export const templateFeedbackSurvey = getApiV2AssetsRetrieveResponseMock({ uid: 'template3uid', name: 'Quick Feedback Survey', asset_type: AssetTypeName.template, diff --git a/jsapp/js/endpoints/bulkAction.factory.ts b/jsapp/js/endpoints/bulkAction.factory.ts deleted file mode 100644 index 0625c8b87a..0000000000 --- a/jsapp/js/endpoints/bulkAction.factory.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { ActionIdEnum } from '#/api/models/actionIdEnum' -import type { BulkActionResponse } from '#/api/models/bulkActionResponse' -import { BulkActionResponseStatusEnum } from '#/api/models/bulkActionResponseStatusEnum' -import { BulkActionSubmissionStatusResponseStatusEnum } from '#/api/models/bulkActionSubmissionStatusResponseStatusEnum' -import type { LanguageCode } from '#/components/languages/languagesStore' - -export default function bulkActionFactory( - submissionUuid: string, - languageCode: LanguageCode, - overrides: Partial = {}, -): BulkActionResponse { - const { progress = 0, ...restOverrides } = overrides - - return { - uid: 'bulk-action-uid', - status: BulkActionResponseStatusEnum.in_progress, - action_id: ActionIdEnum.automatic_google_transcription, - question_xpath: 'Your_name', - submission_uuids: [submissionUuid], - submission_statuses: [ - { - uuid: submissionUuid, - status: BulkActionSubmissionStatusResponseStatusEnum.in_progress, - error: null, - }, - ], - params: { - language: languageCode, - }, - progress, - created_by: { - username: 'zefir', - }, - date_created: '2026-01-01T00:00:00Z', - date_modified: '2026-01-01T00:00:00Z', - ...restOverrides, - } -} diff --git a/jsapp/js/endpoints/bulkActions.mocks.ts b/jsapp/js/endpoints/bulkActions.mocks.ts index d4698671ea..3a65c3e2fe 100644 --- a/jsapp/js/endpoints/bulkActions.mocks.ts +++ b/jsapp/js/endpoints/bulkActions.mocks.ts @@ -1,9 +1,11 @@ import { http, HttpResponse, type PathParams } from 'msw' import { endpoints } from '#/api.endpoints' +import { ActionIdEnum } from '#/api/models/actionIdEnum' import type { BulkActionListResponse } from '#/api/models/bulkActionListResponse' import type { BulkActionResponse } from '#/api/models/bulkActionResponse' import { BulkActionResponseStatusEnum } from '#/api/models/bulkActionResponseStatusEnum' -import bulkActionFactory from './bulkAction.factory' +import { BulkActionSubmissionStatusResponseStatusEnum } from '#/api/models/bulkActionSubmissionStatusResponseStatusEnum' +import { getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock } from '#/api/react-query/survey-data/msw' /** * Mock API for bulk actions list. Use it in Storybook tests in `parameters.msw.handlers.bulkActions`. @@ -30,7 +32,31 @@ const defaultBulkActionsResponse: BulkActionListResponse = { count: 1, next: null, previous: null, - results: [bulkActionFactory('uuid:mock-uuid-1', 'fr')], + results: [ + getApiV2AssetsAdvancedFeaturesBulkActionsRetrieveResponseMock({ + uid: 'bulk-action-uid', + status: BulkActionResponseStatusEnum.in_progress, + action_id: ActionIdEnum.automatic_google_transcription, + question_xpath: 'Your_name', + submission_uuids: ['uuid:mock-uuid-1'], + submission_statuses: [ + { + uuid: 'uuid:mock-uuid-1', + status: BulkActionSubmissionStatusResponseStatusEnum.in_progress, + error: null, + }, + ], + params: { + language: 'fr', + }, + progress: 0, + created_by: { + username: 'zefir', + }, + date_created: '2026-01-01T00:00:00Z', + date_modified: '2026-01-01T00:00:00Z', + }), + ], } /** diff --git a/jsapp/js/endpoints/environment.mocks.ts b/jsapp/js/endpoints/environment.mocks.ts index dbb2a599d5..ee59f55b47 100644 --- a/jsapp/js/endpoints/environment.mocks.ts +++ b/jsapp/js/endpoints/environment.mocks.ts @@ -1,16 +1,10 @@ -import { http, HttpResponse } from 'msw' -import { endpoints } from '#/api.endpoints' -import type { EnvironmentResponse } from '../envStore' +import { getApiV2EnvironmentRetrieveMockHandler } from '#/api/react-query/configuration/msw' /** - * Mock API for environment config. Use it in Storybook tests in `parameters.msw.handlers[]`. + * Production-like environment configuration for testing. + * Contains complete lists of countries, languages, and sectors that the UI depends on. */ -const environmentMock = http.get(endpoints.ENVIRONMENT, () => - HttpResponse.json(environmentResponse), -) -export default environmentMock - -const environmentResponse: EnvironmentResponse = { +const environmentResponse = { terms_of_service_url: '', privacy_policy_url: '', source_code_url: 'https://github.com/kobotoolbox/', @@ -433,3 +427,10 @@ const environmentResponse: EnvironmentResponse = { open_rosa_server: 'http://kc.kobo.local', allow_self_account_deletion: true, } + +/** + * Mock API for environment config using Orval-generated handler with production-like data. + * Use it in Storybook tests in `parameters.msw.handlers[]`. + */ +const environmentMock = getApiV2EnvironmentRetrieveMockHandler(environmentResponse) +export default environmentMock diff --git a/jsapp/js/endpoints/formMedia.factory.ts b/jsapp/js/endpoints/formMedia.factory.ts deleted file mode 100644 index 21f9652a52..0000000000 --- a/jsapp/js/endpoints/formMedia.factory.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { AssetFileResponse } from '#/dataInterface' - -export interface FormMediaItem extends Omit { - metadata: AssetFileResponse['metadata'] & { - // Only present when the media item points to an external URL. - redirect_url?: string - } -} - -export default function formMediaFactory(index: number, overrides: Partial = {}): FormMediaItem { - // Keep IDs deterministic so stories and tests are easy to read and debug. - const uid = overrides.uid ?? `form-media-${index}` - const filename = overrides.metadata?.filename ?? `file-${index}.png` - - return { - uid, - url: `/api/v2/assets/mock-asset-uid/files/${uid}/`, - asset: '/api/v2/assets/mock-asset-uid/', - user: '/api/v2/users/storybook/', - user__username: 'storybook', - file_type: 'form_media', - description: 'default', - date_created: new Date(2026, 0, index).toISOString(), - content: `/media/mock/${filename}`, - ...overrides, - metadata: { - hash: `hash-${index}`, - size: 1024, - type: 'image/png', - filename, - mimetype: 'image/png', - ...overrides.metadata, - }, - } -} diff --git a/jsapp/js/endpoints/formMedia.mocks.ts b/jsapp/js/endpoints/formMedia.mocks.ts index 31bd279920..e567b3dddf 100644 --- a/jsapp/js/endpoints/formMedia.mocks.ts +++ b/jsapp/js/endpoints/formMedia.mocks.ts @@ -1,6 +1,20 @@ -import { http, HttpResponse } from 'msw' -import { endpoints } from '#/api.endpoints' -import formMediaFactory, { type FormMediaItem } from './formMedia.factory' +import type { FilesResponse } from '#/api/models/filesResponse' +import { + getApiV2AssetsFilesCreateMockHandler, + getApiV2AssetsFilesCreateResponseMock, + getApiV2AssetsFilesDestroyMockHandler, + getApiV2AssetsFilesListMockHandler, +} from '#/api/react-query/survey-data/msw' + +/** + * Extended FilesResponse type with redirect_url in metadata. + * Used when the media item points to an external URL. + */ +export interface FormMediaItem extends Omit { + metadata: FilesResponse['metadata'] & { + redirect_url?: string + } +} interface CreateFormMediaPayload { description?: string @@ -18,7 +32,6 @@ interface FormMediaMockOptions { function parsePayloadFromText(textPayload: string): CreateFormMediaPayload { const params = new URLSearchParams(textPayload) - return { description: params.get('description') ?? undefined, file_type: params.get('file_type') ?? undefined, @@ -45,9 +58,50 @@ function waitMs(ms: number): Promise { }) } +/** + * Creates a form media item using Orval's generated mock with deterministic IDs. + * If assetUid is not provided in overrides, uses 'mock-asset-uid' as default. + */ +export function createFormMediaItem(index: number, overrides: Partial = {}): FormMediaItem { + const uid = overrides.uid ?? `form-media-${index}` + const filename = overrides.metadata?.filename ?? `file-${index}.png` + // Extract asset UID from overrides.asset URL if provided, or use overrides.uid, or default + const assetUid = overrides.asset?.match(/\/assets\/([^/]+)\//)?.[1] ?? 'mock-asset-uid' + + return { + ...getApiV2AssetsFilesCreateResponseMock({ + uid, + url: `/api/v2/assets/${assetUid}/files/${uid}/`, + asset: `/api/v2/assets/${assetUid}/`, + user: '/api/v2/users/storybook/', + user__username: 'storybook', + file_type: 'form_media', + description: 'default', + date_created: new Date(2026, 0, index).toISOString(), + content: `/media/mock/${filename}`, + metadata: { + hash: `hash-${index}`, + filename, + mimetype: 'image/png', + }, + }), + ...overrides, + metadata: { + hash: `hash-${index}`, + filename, + mimetype: 'image/png', + ...overrides.metadata, + }, + } as FormMediaItem +} + +/** + * Stateful form media handlers using Orval-generated MSW handlers. + * Maintains an in-memory list that persists across requests within a Storybook session. + */ export function formMediaHandlers( assetUid: string, - seedItems: FormMediaItem[] = [formMediaFactory(1)], + seedItems: FormMediaItem[] = [createFormMediaItem(1)], options: FormMediaMockOptions = {}, ) { // We mutate this local array to mimic backend persistence between requests @@ -55,22 +109,23 @@ export function formMediaHandlers( const mediaItems = [...seedItems] return [ - http.get(endpoints.ASSET_FILES_LIST, ({ params }) => { - if (params.uid !== assetUid) { - return undefined + // GET list - returns current items + getApiV2AssetsFilesListMockHandler(async ({ params }) => { + if (params.uidAsset !== assetUid) { + return undefined as any } - - return HttpResponse.json({ + return { count: mediaItems.length, next: null, previous: null, results: mediaItems, - }) + } }), - http.post(endpoints.ASSET_FILES_LIST, async ({ params, request }) => { - if (params.uid !== assetUid) { - return undefined + // POST create - adds item to list + getApiV2AssetsFilesCreateMockHandler(async ({ params, request }) => { + if (params.uidAsset !== assetUid) { + return undefined as any } const payload = await parsePayload(request) @@ -80,6 +135,7 @@ export function formMediaHandlers( typeof payload.metadata === 'string' ? (JSON.parse(payload.metadata) as Record) : (payload.metadata ?? {}) + const fileName = parsedMetadata.filename as string | undefined // Unknown filenames (or missing delay map) upload immediately. const delayMs = (fileName && options.uploadDelayByFilenameMs?.[fileName]) || 0 @@ -88,14 +144,12 @@ export function formMediaHandlers( } const index = mediaItems.length + 1 - - const newItem = formMediaFactory(index, { + const newItem = createFormMediaItem(index, { uid: `form-media-${index}`, - url: endpoints.ASSET_FILE_DETAIL.replace(':uid', assetUid).replace(':fileUid', `form-media-${index}`), + url: `/api/v2/assets/${assetUid}/files/form-media-${index}/`, + asset: `/api/v2/assets/${assetUid}/`, metadata: { hash: `hash-${index}`, - size: 2048, - type: 'application/octet-stream', filename: (parsedMetadata.filename as string | undefined) || `uploaded-${index}.dat`, mimetype: 'application/octet-stream', redirect_url: parsedMetadata.redirect_url as string | undefined, @@ -104,22 +158,19 @@ export function formMediaHandlers( }) mediaItems.push(newItem) - // Return created item so UI can behave like real API responses. - return HttpResponse.json(newItem, { status: 201 }) + return newItem }), - http.delete(endpoints.ASSET_FILE_DETAIL, ({ params }) => { - if (params.uid !== assetUid) { - return undefined + // DELETE - removes item from list + getApiV2AssetsFilesDestroyMockHandler(async ({ params }) => { + if (params.uidAsset !== assetUid) { + return } - - const itemIndex = mediaItems.findIndex((item) => item.uid === params.fileUid) + const itemIndex = mediaItems.findIndex((item) => item.uid === params.uidFile) if (itemIndex > -1) { mediaItems.splice(itemIndex, 1) } - - return new HttpResponse(null, { status: 204 }) }), ] } diff --git a/jsapp/js/endpoints/languageDetail.mocks.ts b/jsapp/js/endpoints/languageDetail.mocks.ts index 297d594370..e4484bb5be 100644 --- a/jsapp/js/endpoints/languageDetail.mocks.ts +++ b/jsapp/js/endpoints/languageDetail.mocks.ts @@ -1,29 +1,29 @@ -import { http, HttpResponse } from 'msw' -import { endpoints } from '#/api.endpoints' -import type { Language } from '#/api/models/language' +import { getApiV2LanguagesRetrieveMockHandler } from '#/api/react-query/other/msw' -const languageDetailMock = http.get(endpoints.LANGUAGE_DETAIL_URL, () => - HttpResponse.json({ - name: 'English', - code: 'en', - featured: true, - regions: [ - { code: 'en-US', name: 'United States' }, - { code: 'en-GB', name: 'United Kingdom' }, - ], - transcription_services: { - goog: { - 'en-US': 'en-US', - 'en-GB': 'en-GB', - }, +/** + * Mock API for language detail endpoint using Orval-generated handler. + * Uses specific English language data for testing. + */ +const languageDetailMock = getApiV2LanguagesRetrieveMockHandler({ + name: 'English', + code: 'en', + featured: true, + regions: [ + { code: 'en-US', name: 'United States' }, + { code: 'en-GB', name: 'United Kingdom' }, + ], + transcription_services: { + goog: { + 'en-US': 'en-US', + 'en-GB': 'en-GB', }, - translation_services: { - goog: { - 'en-US': 'en-US', - 'en-GB': 'en-GB', - }, + }, + translation_services: { + goog: { + 'en-US': 'en-US', + 'en-GB': 'en-GB', }, - }), -) + }, +}) export default languageDetailMock diff --git a/jsapp/js/endpoints/me.mocks.ts b/jsapp/js/endpoints/me.mocks.ts index 35ee71853d..1ade1873d5 100644 --- a/jsapp/js/endpoints/me.mocks.ts +++ b/jsapp/js/endpoints/me.mocks.ts @@ -1,14 +1,11 @@ -import { http, HttpResponse } from 'msw' -import { endpoints } from '#/api.endpoints' -import type { AccountResponse } from '#/dataInterface' +import type { MeListResponse } from '#/api/models/meListResponse' +import { getMeRetrieveMockHandler } from '#/api/react-query/user-team-organization-usage/msw' /** - * Mock API for session endpoint. Use it in Storybook tests in `parameters.msw.handlers[]`. + * Mock response data for /me/ endpoint. + * Note: AccountResponse (legacy) is compatible with MeListResponse (Orval). */ -const meMock = http.get(endpoints.ME, () => HttpResponse.json(meMockResponse)) -export default meMock - -export const meMockResponse: AccountResponse = { +export const meMockResponse: MeListResponse = { username: 'zefir', first_name: '', last_name: '', @@ -39,3 +36,10 @@ export const meMockResponse: AccountResponse = { }, extra_details__uid: 'uTcCX9wL5royoPb4mHWcBz', } + +/** + * Mock API for session endpoint using Orval-generated handler. + * Use it in Storybook tests in `parameters.msw.handlers[]`. + */ +const meMock = getMeRetrieveMockHandler(meMockResponse) +export default meMock diff --git a/jsapp/js/endpoints/organization.mocks.ts b/jsapp/js/endpoints/organization.mocks.ts index 66b3155205..81792fba40 100644 --- a/jsapp/js/endpoints/organization.mocks.ts +++ b/jsapp/js/endpoints/organization.mocks.ts @@ -1,28 +1,18 @@ -import { http, HttpResponse } from 'msw' import type { OrganizationResponse } from '#/api/models/organizationResponse' -import { getOrganizationsRetrieveUrl } from '#/api/react-query/user-team-organization-usage' +import { getApiV2OrganizationsRetrieveMockHandler } from '#/api/react-query/user-team-organization-usage/msw' import { meMockResponse } from './me.mocks' /** - - * Mock API handler for the main organization endpoint. - * Use in Storybook tests in `parameters.msw.handlers.organization`. - * + * Mock API handler for organization endpoint using Orval-generated handler. * Property `id` is used to generate the URL and populate other response fields that depend on it. * Default value is `meMockResponse.organization!.uid`. */ const organizationMock = (override?: Partial) => { - const id = override?.id ?? meMockResponse.organization!.uid - return http.get(getOrganizationsRetrieveUrl(id), () => - HttpResponse.json({ ...organizationReponse(id), ...override }), - ) -} -export default organizationMock + const id = override?.id ?? meMockResponse.organization?.uid ?? 'default-org-id' -const organizationReponse = (organizationId: string): OrganizationResponse => { - return { - id: organizationId, - url: `http://kf.kobo.local/api/v2/organizations/${organizationId}/`, + return getApiV2OrganizationsRetrieveMockHandler({ + id, + url: `http://kf.kobo.local/api/v2/organizations/${id}/`, name: 'mocked organization', website: '', organization_type: 'none', @@ -31,9 +21,12 @@ const organizationReponse = (organizationId: string): OrganizationResponse => { is_owner: true, is_mmo: false, request_user_role: 'owner', - members: `http://kf.kobo.local/api/v2/organizations/${organizationId}/members/`, - assets: `http://kf.kobo.local/api/v2/organizations/${organizationId}/assets/`, - service_usage: `http://kf.kobo.local/api/v2/organizations/${organizationId}/service_usage/`, - asset_usage: `http://kf.kobo.local/api/v2/organizations/${organizationId}/asset_usage/`, - } + members: `http://kf.kobo.local/api/v2/organizations/${id}/members/`, + assets: `http://kf.kobo.local/api/v2/organizations/${id}/assets/`, + service_usage: `http://kf.kobo.local/api/v2/organizations/${id}/service_usage/`, + asset_usage: `http://kf.kobo.local/api/v2/organizations/${id}/asset_usage/`, + ...override, + }) } + +export default organizationMock diff --git a/jsapp/js/endpoints/organizationServiceUsage.factory.ts b/jsapp/js/endpoints/organizationServiceUsage.factory.ts index b80ef3675e..b6cb31e026 100644 --- a/jsapp/js/endpoints/organizationServiceUsage.factory.ts +++ b/jsapp/js/endpoints/organizationServiceUsage.factory.ts @@ -4,6 +4,12 @@ import type { UserReportsServiceUsageResponse } from '#/api/models/userReportsSe * Factory functions for creating mock usage data with different limit scenarios. * Useful in Storybook to test how the UI responds to warnings and exceeded limits. * + * Note: NOT migrated to Orval because this file provides valuable domain-specific + * presets (storageWarning, storageExceeded, etc.) that calculate percentage-based + * limits. These presets are more useful than raw Orval mocks because they encode + * business logic about when warnings/errors should trigger (80%, 100%, etc.). + * The helper functions make tests more readable than passing raw percentage values. + * * Instead of writing out full balance objects with calculated values, just call * the preset that matches your scenario: * - storageWarning() for 95% storage used (triggers warning banner) diff --git a/jsapp/js/endpoints/organizationServiceUsage.mocks.ts b/jsapp/js/endpoints/organizationServiceUsage.mocks.ts index 52c7b297bf..430e4d74a7 100644 --- a/jsapp/js/endpoints/organizationServiceUsage.mocks.ts +++ b/jsapp/js/endpoints/organizationServiceUsage.mocks.ts @@ -7,6 +7,11 @@ import { meMockResponse } from './me.mocks' * Mock API handler for the /service_usage/ endpoint of an organization. * Use in Storybook tests in `parameters.msw.handlers.organizationServiceUsage`. * + * Note: NOT fully migrated to Orval because it uses organizationServiceUsage.factory.ts + * which provides domain-specific presets (storageWarning, storageExceeded, etc.). + * While we could use Orval's handler, the factory presets are more valuable for tests + * than raw Orval mocks as they encode business logic about when warnings/errors trigger. + * * Property `id` is used to generate the URL and populate other response fields that depend on it. * Default value is coming from `meMockResponse`. * @@ -14,7 +19,7 @@ import { meMockResponse } from './me.mocks' * @param overrideData - Partial override for the service usage response */ const organizationServiceUsageMock = (overrideId?: string, overrideData?: Partial) => { - const id = overrideId ?? meMockResponse.organization!.uid + const id = overrideId ?? meMockResponse.organization?.uid ?? 'default-org-id' const baseResponse = mockServiceUsageResponse() // Deep merge balances if provided diff --git a/jsapp/js/endpoints/serviceUsage.factory.ts b/jsapp/js/endpoints/serviceUsage.factory.ts index 1664e1e7f6..903b0c8f40 100644 --- a/jsapp/js/endpoints/serviceUsage.factory.ts +++ b/jsapp/js/endpoints/serviceUsage.factory.ts @@ -4,6 +4,11 @@ import type { ServiceUsageResponse } from '#/api/models/serviceUsageResponse' * Factory functions for creating mock service usage data with different limit scenarios. * Useful for testing bulk processing alerts for ASR (transcription) and MT (translation). * + * Note: NOT migrated to Orval because this file provides valuable domain-specific + * presets (asrExceeded, mtExceeded, asrNearLimit, etc.) that calculate percentage-based + * quotas. These presets encode business logic about ASR (transcription) and MT (translation) + * service limits and make tests more readable than passing raw quota values to Orval mocks. + * * Instead of writing out full balance objects with calculated values, just call * the preset that matches your scenario: * - asrExceeded() for transcription quota exceeded diff --git a/jsapp/js/endpoints/subscription.mocks.ts b/jsapp/js/endpoints/subscription.mocks.ts index c4c05695fc..f9348cf83c 100644 --- a/jsapp/js/endpoints/subscription.mocks.ts +++ b/jsapp/js/endpoints/subscription.mocks.ts @@ -7,6 +7,11 @@ import type { PaginatedResponse } from '#/dataInterface' * Mock API for stripe subscriptions endpoint. * Use it in Storybook tests in `parameters.msw.handlers[]`. * + * Note: NOT migrated to Orval because the detailed Stripe types (SubscriptionInfo) + * contain more fields than Orval's generated Subscription type. The Stripe SDK types + * have nested structures for items, prices, products, etc. that would require + * significant type mapping to work with Orval's simpler schema. + * * @param overrideData - Partial override for the subscription response */ const subscriptionMock = (overrideData?: Partial>) => { diff --git a/jsapp/js/project/FormLanguagesManager/FormLanguagesManager.stories.tsx b/jsapp/js/project/FormLanguagesManager/FormLanguagesManager.stories.tsx index 8b138d12f2..a587274dd6 100644 --- a/jsapp/js/project/FormLanguagesManager/FormLanguagesManager.stories.tsx +++ b/jsapp/js/project/FormLanguagesManager/FormLanguagesManager.stories.tsx @@ -2,7 +2,10 @@ import { ModalsProvider } from '@mantine/modals' import type { Meta, StoryObj } from '@storybook/react-webpack5' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { expect, fn, userEvent, waitFor, within } from 'storybook/test' +import type { AssetContentSurveyItem } from '#/api/models/assetContentSurveyItem' +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' import ButtonNew from '#/components/common/ButtonNew' +import { QuestionTypeName } from '#/constants' import type { AssetResponse } from '#/dataInterface' import { assetPatchMock } from '#/endpoints/asset.mocks' import { withMinHeightWrapper } from '#/storybookUtils' @@ -13,17 +16,19 @@ const mockAssetUid = 'storyFormLanguagesManagerUid' const onAssetPatched = fn() function buildInitialAsset(): AssetResponse { - const survey = Array.from({ length: 11 }, (_, idx) => { + const survey: AssetContentSurveyItem[] = Array.from({ length: 11 }, (_, idx) => { const index = idx + 1 return { - type: 'text', + $kuid: `kuid_question_${index}`, + type: QuestionTypeName.text, name: `question_${index}`, $autoname: `question_${index}`, label: [`Question ${index}`], } }) - return { + // Cast Orval Asset to legacy AssetResponse (see DataTableWrapper.stories.tsx for details) + return getApiV2AssetsRetrieveResponseMock({ uid: mockAssetUid, name: 'Storybook Form Languages', content: { @@ -34,7 +39,7 @@ function buildInitialAsset(): AssetResponse { choices: [], settings: {}, }, - } as unknown as AssetResponse + }) as unknown as AssetResponse } function createAssetPatchHandler(initialAsset: AssetResponse) { diff --git a/jsapp/js/project/FormLanguagesManager/FormLanguagesManager.tsx b/jsapp/js/project/FormLanguagesManager/FormLanguagesManager.tsx index fdf4a9d7a9..ca0f0a9797 100644 --- a/jsapp/js/project/FormLanguagesManager/FormLanguagesManager.tsx +++ b/jsapp/js/project/FormLanguagesManager/FormLanguagesManager.tsx @@ -1,8 +1,7 @@ -import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' - import { Box, Group, Text } from '@mantine/core' import { useQuery, useQueryClient } from '@tanstack/react-query' import cloneDeep from 'lodash.clonedeep' +import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import type { PaginatedListResponse } from '#/UniversalTable' import { assetsPartialUpdate } from '#/api/react-query/manage-projects-and-library-content' import ButtonNew from '#/components/common/ButtonNew' diff --git a/jsapp/js/project/FormMedia/FormMedia.stories.tsx b/jsapp/js/project/FormMedia/FormMedia.stories.tsx index 9c350a1320..7f1a5787fb 100644 --- a/jsapp/js/project/FormMedia/FormMedia.stories.tsx +++ b/jsapp/js/project/FormMedia/FormMedia.stories.tsx @@ -1,12 +1,11 @@ import type { Meta, StoryObj } from '@storybook/react-webpack5' import { expect, userEvent, waitFor, within } from 'storybook/test' -import assetFactory from '#/endpoints/asset.factory' -import formMediaFactory from '#/endpoints/formMedia.factory' -import { formMediaHandlers } from '#/endpoints/formMedia.mocks' +import { getApiV2AssetsRetrieveResponseMock } from '#/api/react-query/manage-projects-and-library-content/msw' +import { createFormMediaItem, formMediaHandlers } from '#/endpoints/formMedia.mocks' import { queryClientDecorator } from '#/query/queryClient.mocks' import FormMedia from './index' -const mockAsset = assetFactory({ +const mockAsset = getApiV2AssetsRetrieveResponseMock({ uid: 'form-media-story-uid', deployment__active: false, }) @@ -22,13 +21,12 @@ const meta: Meta = { msw: { // Seed with one existing file so the first test step can verify loading. handlers: formMediaHandlers(mockAsset.uid, [ - formMediaFactory(1, { + createFormMediaItem(1, { uid: 'form-media-1', url: `/api/v2/assets/${mockAsset.uid}/files/form-media-1/`, + asset: `/api/v2/assets/${mockAsset.uid}/`, metadata: { hash: 'hash-1', - size: 1024, - type: 'image/png', filename: 'intro-image.png', mimetype: 'image/png', }, diff --git a/jsapp/js/projects/projectsTable/projectsTableRow.tsx b/jsapp/js/projects/projectsTable/projectsTableRow.tsx index c14c719b61..aa5afc3af3 100644 --- a/jsapp/js/projects/projectsTable/projectsTableRow.tsx +++ b/jsapp/js/projects/projectsTable/projectsTableRow.tsx @@ -64,7 +64,7 @@ export default function ProjectsTableRow(props: ProjectsTableRowProps) { return } case 'dateModified': - return formatTime(props.asset.date_modified) + return props.asset.date_modified ? formatTime(props.asset.date_modified) : '-' case 'dateDeployed': if ('date_deployed' in props.asset && props.asset.date_deployed) { return formatTime(props.asset.date_deployed) diff --git a/kpi/schema_extensions/v2/assets/extensions.py b/kpi/schema_extensions/v2/assets/extensions.py index b66ca6fb22..f70ccde8a7 100644 --- a/kpi/schema_extensions/v2/assets/extensions.py +++ b/kpi/schema_extensions/v2/assets/extensions.py @@ -14,12 +14,17 @@ GENERIC_ARRAY_SCHEMA, GENERIC_OBJECT_SCHEMA, GENERIC_STRING_SCHEMA, + NULLABLE_ARRAY_SCHEMA, + NULLABLE_STRING_SCHEMA, USER_URL_SCHEMA, ) from kpi.utils.schema_extensions.url_builder import build_url_type from .schema import ( + ADVANCED_FEATURES_SCHEMA, + ASSIGNABLE_PERMISSION_SCHEMA, ASSET_CLONE_FROM_SCHEMA, - ASSET_CONTENT_SCHEMA, + ASSET_CONTENT_REQUEST_SCHEMA, + ASSET_CONTENT_RESPONSE_SCHEMA, ASSET_ENABLED_SCHEMA, ASSET_FIELDS_SCHEMA, ASSET_NAME_SCHEMA, @@ -29,6 +34,9 @@ BULK_ACTION_SCHEMA, BULK_ASSET_UIDS_SCHEMA, BULK_CONFIRM_SCHEMA, + MAP_STYLES_SCHEMA, + PERMISSION_ASSIGNMENT_SCHEMA, + REPORT_STYLE_SCHEMA, ) @@ -36,14 +44,14 @@ class AccessTypeFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.AccessTypeField' def map_serializer_field(self, auto_schema, direction): - return GENERIC_ARRAY_SCHEMA + return NULLABLE_ARRAY_SCHEMA class AdvancedFeatureFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.AdvancedFeatureField' def map_serializer_field(self, auto_schema, direction): - return GENERIC_OBJECT_SCHEMA + return ADVANCED_FEATURES_SCHEMA class AdvancedSubmissionSchemaFieldExtension(OpenApiSerializerFieldExtension): @@ -64,9 +72,54 @@ class AnalysisFormJsonExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.AnalysisFormJsonField' def map_serializer_field(self, auto_schema, direction): + # Define the structure for each additional_fields item + additional_field_item = build_object_type( + required=['source', 'type', 'name', 'dtpath'], + properties={ + 'language': GENERIC_STRING_SCHEMA, # optional: two letter language code + 'source': GENERIC_STRING_SCHEMA, # required: path to form question + 'type': { + 'type': 'string', + 'enum': [ + 'transcript', + 'translation', + 'qualVerification', + 'qualSource', + 'qualInteger', + 'qualTags', + 'qualText', + 'qualNote', + 'qualAutoKeywordCount', + 'qualSelectMultiple', + 'qualSelectOne', + ] + }, # required: type of additional field + 'name': GENERIC_STRING_SCHEMA, # required + 'dtpath': GENERIC_STRING_SCHEMA, # required: data table path + # optional: question label or 'source'/'verified' + 'label': GENERIC_STRING_SCHEMA, + 'choices': build_array_type( + build_object_type( + required=['uuid', 'labels'], + properties={ + 'uuid': GENERIC_STRING_SCHEMA, + 'labels': build_object_type( + required=['_default'], + properties={ + '_default': GENERIC_STRING_SCHEMA, + }, + additionalProperties=GENERIC_STRING_SCHEMA, + ), # {_default: string, [key: string]: string} + } + ) + ), # optional: for single/multi choice qual questions + } + ) + return build_object_type( + required=['additional_fields'], properties={ - 'additional_fields': GENERIC_ARRAY_SCHEMA, + 'additional_fields': build_array_type(additional_field_item), } ) @@ -125,7 +178,7 @@ def map_serializer(self, auto_schema, direction): build_object_type( required=['content', 'name'], properties={ - 'content': ASSET_CONTENT_SCHEMA, + 'content': ASSET_CONTENT_REQUEST_SCHEMA, 'name': ASSET_NAME_SCHEMA, }, ), @@ -164,7 +217,7 @@ class AssignablePermissionFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.AssignablePermissionField' def map_serializer_field(self, auto_schema, direction): - return build_array_type(schema=GENERIC_OBJECT_SCHEMA) + return build_array_type(schema=ASSIGNABLE_PERMISSION_SCHEMA) class AssetSettingsFieldExtension(OpenApiSerializerFieldExtension): @@ -256,15 +309,11 @@ class ContentFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.ContentField' def map_serializer_field(self, auto_schema, direction): - return build_object_type( - properties={ - 'schema': GENERIC_STRING_SCHEMA, - 'survey': build_array_type(schema=GENERIC_OBJECT_SCHEMA), - 'settings': GENERIC_OBJECT_SCHEMA, - 'translated': GENERIC_ARRAY_SCHEMA, - 'translations': GENERIC_ARRAY_SCHEMA, - } - ) + # WriteableJsonWithSchemaField accepts JSON string for writes, + # returns object for reads + if direction == 'request': + return ASSET_CONTENT_REQUEST_SCHEMA + return ASSET_CONTENT_RESPONSE_SCHEMA class CountDailySubmissionResponseFieldExtension(OpenApiSerializerFieldExtension): @@ -310,7 +359,26 @@ class DeploymentDataDownloadLinksFieldExtension(OpenApiSerializerFieldExtension) ) def map_serializer_field(self, auto_schema, direction): - return GENERIC_OBJECT_SCHEMA + return build_object_type( + required=[ + 'csv_legacy', + 'csv', + 'kml_legacy', + 'xls_legacy', + 'xls', + 'zip_legacy', + ], + properties={ + 'csv_legacy': GENERIC_STRING_SCHEMA, + 'csv': GENERIC_STRING_SCHEMA, + 'geojson': GENERIC_STRING_SCHEMA, # optional + 'kml_legacy': GENERIC_STRING_SCHEMA, + 'spss_labels': GENERIC_STRING_SCHEMA, # optional + 'xls_legacy': GENERIC_STRING_SCHEMA, + 'xls': GENERIC_STRING_SCHEMA, + 'zip_legacy': GENERIC_STRING_SCHEMA, + } + ) class DeploymentLinkFieldExtension(OpenApiSerializerFieldExtension): @@ -325,12 +393,20 @@ class DeployedVersionsFieldExtension(OpenApiSerializerFieldExtension): def map_serializer_field(self, auto_schema, direction): return build_object_type( + required=['count', 'next', 'previous', 'results'], properties={ 'count': build_basic_type(OpenApiTypes.INT), - 'next': GENERIC_STRING_SCHEMA, - 'previous': GENERIC_STRING_SCHEMA, + 'next': NULLABLE_STRING_SCHEMA, + 'previous': NULLABLE_STRING_SCHEMA, 'results': build_array_type( schema=build_object_type( + required=[ + 'uid', + 'url', + 'content_hash', + 'date_deployed', + 'date_modified', + ], properties={ 'uid': GENERIC_STRING_SCHEMA, 'url': build_url_type( @@ -354,6 +430,7 @@ class DownloadsFieldExtension(OpenApiSerializerFieldExtension): def map_serializer_field(self, auto_schema, direction): return build_array_type( schema=build_object_type( + required=['format', 'url'], properties={ 'format': GENERIC_STRING_SCHEMA, 'url': GENERIC_STRING_SCHEMA, @@ -389,7 +466,22 @@ class FileListFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.FileListField' def map_serializer_field(self, auto_schema, direction): - return GENERIC_ARRAY_SCHEMA + # Files is an array of AssetFileSerializer objects + asset_file_schema = build_object_type( + properties={ + 'uid': GENERIC_STRING_SCHEMA, + 'url': GENERIC_STRING_SCHEMA, + 'asset': GENERIC_STRING_SCHEMA, + 'user': GENERIC_STRING_SCHEMA, + 'user__username': GENERIC_STRING_SCHEMA, + 'file_type': GENERIC_STRING_SCHEMA, + 'description': GENERIC_STRING_SCHEMA, + 'date_created': GENERIC_STRING_SCHEMA, + 'content': GENERIC_STRING_SCHEMA, + 'metadata': GENERIC_OBJECT_SCHEMA, + } + ) + return build_array_type(schema=asset_file_schema) class HasDeploymentFieldExtension(OpenApiSerializerFieldExtension): @@ -420,7 +512,7 @@ class MapStylesFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.MapStylesField' def map_serializer_field(self, auto_schema, direction): - return GENERIC_OBJECT_SCHEMA + return MAP_STYLES_SCHEMA class MetadataListFieldExtension(OpenApiSerializerFieldExtension): @@ -466,7 +558,7 @@ class PermissionsFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.PermissionsField' def map_serializer_field(self, auto_schema, direction): - return GENERIC_ARRAY_SCHEMA + return build_array_type(schema=PERMISSION_ASSIGNMENT_SCHEMA) class ReportCustomFieldExtension(OpenApiSerializerFieldExtension): @@ -482,19 +574,11 @@ class ReportStyleFieldExtension(OpenApiSerializerFieldExtension): def map_serializer_field(self, auto_schema, direction): return build_object_type( properties={ - 'default': GENERIC_OBJECT_SCHEMA, - 'specified': build_object_type( - properties={ - 'end': GENERIC_OBJECT_SCHEMA, - 'start': GENERIC_OBJECT_SCHEMA, - } - ), - 'kuid_names': build_object_type( - properties={ - 'end': GENERIC_STRING_SCHEMA, - 'start': GENERIC_STRING_SCHEMA, - } - ), + 'default': REPORT_STYLE_SCHEMA, + # additionalProperties pattern for dynamic row names + 'specified': GENERIC_OBJECT_SCHEMA, + # additionalProperties pattern for dynamic row names + 'kuid_names': GENERIC_OBJECT_SCHEMA, } ) @@ -540,15 +624,37 @@ class SettingsFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.SettingsField' def map_serializer_field(self, auto_schema, direction): + # Base LabelValuePair schema reused for multiple fields + label_value_pair_schema = build_object_type( + properties={ + 'label': GENERIC_STRING_SCHEMA, + 'value': GENERIC_STRING_SCHEMA, + } + ) + + # Orval-compatible nullable object: type: ['object', 'null'] AND nullable: True + nullable_label_value_pair_schema = { + **label_value_pair_schema, + 'type': ['object', 'null'], + 'nullable': True, + } + + # Orval-compatible nullable array: type: ['array', 'null'] AND nullable: True + nullable_label_value_pair_array_schema = { + 'type': ['array', 'null'], + 'items': label_value_pair_schema, + 'nullable': True, + } + return build_object_type( properties={ - 'sector': GENERIC_OBJECT_SCHEMA, - 'country': GENERIC_ARRAY_SCHEMA, + 'sector': nullable_label_value_pair_schema, + 'country': nullable_label_value_pair_array_schema, 'description': GENERIC_STRING_SCHEMA, - 'collects_pii': GENERIC_STRING_SCHEMA, - 'organization': GENERIC_STRING_SCHEMA, + 'collects_pii': nullable_label_value_pair_schema, + 'organization': NULLABLE_STRING_SCHEMA, 'country_codes': GENERIC_ARRAY_SCHEMA, - 'operational_purpose': GENERIC_STRING_SCHEMA, + 'operational_purpose': nullable_label_value_pair_schema, } ) @@ -557,6 +663,27 @@ class SummaryFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.assets.fields.SummaryField' def map_serializer_field(self, auto_schema, direction): + name_quality_first_item_schema = build_object_type( + properties={ + 'name': GENERIC_STRING_SCHEMA, + 'index': build_basic_type(OpenApiTypes.INT), + 'label': GENERIC_ARRAY_SCHEMA, + } + ) + name_quality_schema = build_object_type( + properties={ + 'ok': build_basic_type(OpenApiTypes.INT), + 'bad': build_basic_type(OpenApiTypes.INT), + 'good': build_basic_type(OpenApiTypes.INT), + 'total': build_basic_type(OpenApiTypes.INT), + 'firsts': build_object_type( + properties={ + 'ok': name_quality_first_item_schema, + 'bad': name_quality_first_item_schema, + } + ), + } + ) return build_object_type( properties={ 'geo': build_basic_type(OpenApiTypes.BOOL), @@ -566,8 +693,9 @@ def map_serializer_field(self, auto_schema, direction): 'lock_any': build_basic_type(OpenApiTypes.BOOL), 'languages': GENERIC_ARRAY_SCHEMA, 'row_count': build_basic_type(OpenApiTypes.INT), - 'name_quality': GENERIC_OBJECT_SCHEMA, - 'default_translation': GENERIC_STRING_SCHEMA, + 'name_quality': name_quality_schema, + 'default_translation': NULLABLE_STRING_SCHEMA, + 'naming_conflicts': build_array_type(GENERIC_STRING_SCHEMA), } ) diff --git a/kpi/schema_extensions/v2/assets/schema.py b/kpi/schema_extensions/v2/assets/schema.py index c32e6869f4..6a31f5f805 100644 --- a/kpi/schema_extensions/v2/assets/schema.py +++ b/kpi/schema_extensions/v2/assets/schema.py @@ -5,13 +5,16 @@ ) from drf_spectacular.types import OpenApiTypes +from kpi.schema_extensions.v2.generic.schema import NULLABLE_STRING_SCHEMA + """ Common schemas to avoid redundancy """ ASSET_CLONE_FROM_SCHEMA = build_basic_type(OpenApiTypes.STR) -ASSET_CONTENT_SCHEMA = build_basic_type(OpenApiTypes.STR) +# Asset content can be sent as a JSON string (write) or received as an object (read) +ASSET_CONTENT_REQUEST_SCHEMA = build_basic_type(OpenApiTypes.STR) ASSET_ENABLED_SCHEMA = build_basic_type(OpenApiTypes.BOOL) @@ -45,3 +48,210 @@ ) BULK_CONFIRM_SCHEMA = build_basic_type(OpenApiTypes.BOOL) + +# Assignable permissions can have label as string (regular) or object (partial) +ASSIGNABLE_PERMISSION_PARTIAL_LABEL_SCHEMA = build_object_type( + required=['default'], + properties={ + 'default': build_basic_type(OpenApiTypes.STR), + 'view_submissions': build_basic_type(OpenApiTypes.STR), + 'change_submissions': build_basic_type(OpenApiTypes.STR), + 'delete_submissions': build_basic_type(OpenApiTypes.STR), + 'validate_submissions': build_basic_type(OpenApiTypes.STR), + } +) + +ASSIGNABLE_PERMISSION_SCHEMA = build_object_type( + required=['url', 'label'], + properties={ + 'url': build_basic_type(OpenApiTypes.STR), + 'label': { + 'oneOf': [ + build_basic_type(OpenApiTypes.STR), + ASSIGNABLE_PERMISSION_PARTIAL_LABEL_SCHEMA, + ] + }, + } +) + +# Permission assignment response (actual permission grants) +PARTIAL_PERMISSION_FILTER_SCHEMA = build_object_type( + properties={ + 'url': build_basic_type(OpenApiTypes.STR), + 'filters': build_array_type(schema=build_object_type(properties={})), + } +) + +PERMISSION_ASSIGNMENT_SCHEMA = build_object_type( + required=['url', 'user', 'permission'], + properties={ + 'url': build_basic_type(OpenApiTypes.STR), + 'user': build_basic_type(OpenApiTypes.STR), + 'permission': build_basic_type(OpenApiTypes.STR), + 'partial_permissions': build_array_type( + schema=PARTIAL_PERMISSION_FILTER_SCHEMA + ), + 'label': { + 'oneOf': [ + build_basic_type(OpenApiTypes.STR), + ASSIGNABLE_PERMISSION_PARTIAL_LABEL_SCHEMA, + ] + }, + } +) + +REPORT_STYLE_SCHEMA = build_object_type( + properties={ + 'groupDataBy': build_basic_type(OpenApiTypes.STR), + 'report_type': build_basic_type(OpenApiTypes.STR), + 'report_colors': build_array_type(schema=build_basic_type(OpenApiTypes.STR)), + 'translationIndex': build_basic_type(OpenApiTypes.INT), + 'graphWidth': build_basic_type(OpenApiTypes.INT), + } +) + +ANALYSIS_QUESTION_LABELS_SCHEMA = build_object_type( + required=['_default'], + properties={ + '_default': build_basic_type(OpenApiTypes.STR), + }, + additionalProperties=build_basic_type(OpenApiTypes.STR), +) + +ANALYSIS_QUESTION_CHOICE_SCHEMA = build_object_type( + required=['labels', 'uuid'], + properties={ + 'labels': ANALYSIS_QUESTION_LABELS_SCHEMA, + 'uuid': build_basic_type(OpenApiTypes.STR), + 'options': build_object_type( + properties={ + 'deleted': build_basic_type(OpenApiTypes.BOOL), + } + ), + } +) + +ANALYSIS_QUESTION_SCHEMA = build_object_type( + required=['type', 'labels', 'xpath', 'scope'], + properties={ + 'type': build_basic_type(OpenApiTypes.STR), + 'labels': ANALYSIS_QUESTION_LABELS_SCHEMA, + 'uuid': build_basic_type(OpenApiTypes.STR), + 'options': build_object_type( + properties={ + 'deleted': build_basic_type(OpenApiTypes.BOOL), + } + ), + 'xpath': build_basic_type(OpenApiTypes.STR), + 'scope': build_basic_type(OpenApiTypes.STR), + 'choices': build_array_type(schema=ANALYSIS_QUESTION_CHOICE_SCHEMA), + } +) + +ADVANCED_FEATURES_SCHEMA = build_object_type( + properties={ + 'transcript': build_object_type( + properties={ + 'values': build_array_type( + schema=build_basic_type(OpenApiTypes.STR) + ), + 'languages': build_array_type( + schema=build_basic_type(OpenApiTypes.STR) + ), + } + ), + 'translation': build_object_type( + properties={ + 'values': build_array_type( + schema=build_basic_type(OpenApiTypes.STR) + ), + 'languages': build_array_type( + schema=build_basic_type(OpenApiTypes.STR) + ), + } + ), + 'qual': build_object_type( + properties={ + 'qual_survey': build_array_type(schema=ANALYSIS_QUESTION_SCHEMA), + } + ), + '_version': build_basic_type(OpenApiTypes.STR), + } +) + +MAP_STYLES_SCHEMA = build_object_type( + properties={ + 'colorSet': build_basic_type(OpenApiTypes.STR), + 'querylimit': build_basic_type(OpenApiTypes.STR), + 'selectedQuestion': build_basic_type(OpenApiTypes.STR), + } +) + +SURVEY_ROW_SCHEMA = build_object_type( + required=['$kuid', 'type'], + properties={ + '$kuid': build_basic_type(OpenApiTypes.STR), + 'type': build_basic_type(OpenApiTypes.STR), + '$xpath': build_basic_type(OpenApiTypes.STR), + '$autoname': build_basic_type(OpenApiTypes.STR), + 'calculation': build_basic_type(OpenApiTypes.STR), + 'label': build_array_type(schema=NULLABLE_STRING_SCHEMA), + 'hint': build_array_type(schema=NULLABLE_STRING_SCHEMA), + 'name': build_basic_type(OpenApiTypes.STR), + 'required': build_basic_type(OpenApiTypes.BOOL), + 'appearance': build_basic_type(OpenApiTypes.STR), + 'parameters': build_basic_type(OpenApiTypes.STR), + 'kobo--matrix_list': build_basic_type(OpenApiTypes.STR), + 'kobo--rank-constraint-message': build_basic_type(OpenApiTypes.STR), + 'kobo--rank-items': build_basic_type(OpenApiTypes.STR), + 'kobo--score-choices': build_basic_type(OpenApiTypes.STR), + 'kobo--locking-profile': build_basic_type(OpenApiTypes.STR), + 'tags': build_array_type(schema=build_basic_type(OpenApiTypes.STR)), + 'select_from_list_name': build_basic_type(OpenApiTypes.STR), + 'body::accept': build_basic_type(OpenApiTypes.STR), + }, + additionalProperties=True, +) + +SURVEY_CHOICE_SCHEMA = build_object_type( + required=['$autovalue', '$kuid', 'list_name', 'name'], + properties={ + '$autovalue': build_basic_type(OpenApiTypes.STR), + '$kuid': build_basic_type(OpenApiTypes.STR), + 'label': build_array_type(schema=NULLABLE_STRING_SCHEMA), + 'list_name': build_basic_type(OpenApiTypes.STR), + 'name': build_basic_type(OpenApiTypes.STR), + 'media::image': build_array_type(schema=build_basic_type(OpenApiTypes.STR)), + '$autoname': build_basic_type(OpenApiTypes.STR), + }, + additionalProperties=True, +) + +ASSET_CONTENT_SETTINGS_SCHEMA = build_object_type( + properties={ + 'name': build_basic_type(OpenApiTypes.STR), + 'version': build_basic_type(OpenApiTypes.STR), + 'id_string': build_basic_type(OpenApiTypes.STR), + 'style': build_basic_type(OpenApiTypes.STR), + 'form_id': build_basic_type(OpenApiTypes.STR), + 'title': build_basic_type(OpenApiTypes.STR), + 'kobo--lock_all': build_basic_type(OpenApiTypes.BOOL), + 'kobo--locking-profile': build_basic_type(OpenApiTypes.STR), + 'default_language': NULLABLE_STRING_SCHEMA, + } +) + +ASSET_CONTENT_RESPONSE_SCHEMA = build_object_type( + properties={ + 'schema': build_basic_type(OpenApiTypes.STR), + 'survey': build_array_type(schema=SURVEY_ROW_SCHEMA), + 'choices': build_array_type(schema=SURVEY_CHOICE_SCHEMA), + 'settings': ASSET_CONTENT_SETTINGS_SCHEMA, + 'translated': build_array_type(schema=build_basic_type(OpenApiTypes.STR)), + 'translations': build_array_type(schema=NULLABLE_STRING_SCHEMA), + 'translations_0': NULLABLE_STRING_SCHEMA, + 'kobo--locking-profiles': build_array_type( + schema=build_basic_type(OpenApiTypes.OBJECT) + ), + } +) diff --git a/kpi/schema_extensions/v2/data/extensions.py b/kpi/schema_extensions/v2/data/extensions.py index 3dd8a79063..273de2a747 100644 --- a/kpi/schema_extensions/v2/data/extensions.py +++ b/kpi/schema_extensions/v2/data/extensions.py @@ -329,95 +329,92 @@ def map_serializer_field(self, auto_schema, direction): auto_schema, qual_references=references ) + # Note: These schemas are inlined (not registered as components) to avoid + # Orval generating problematic MSW mocks for types with index signatures. + # The oneOf discriminator is sufficient for the API schema. + # + # Structure of each oneOf option: + # { + # [question_xpath]: { + # [action_type]: { ...action_data } + # } + # } + # + # The six oneOf options represent all possible action types that can + # generate supplemental data. Each has a unique property name that acts + # as a discriminator, allowing TypeScript to narrow the union based on + # which property exists. return { 'oneOf': [ - self._register_schema_component( - auto_schema, - 'SupplementalDetailsManualTranscription', - build_object_type( - additionalProperties=build_object_type( - properties={ - 'manual_transcription': supp_references[ - 'action_object_manual' - ], - }, - required=['manual_transcription'], - ), - description='Manual transcription supplemental details', + # Option 1: Human-generated audio/video transcription + build_object_type( + additionalProperties=build_object_type( + properties={ + 'manual_transcription': supp_references[ + 'action_object_manual' + ], + }, + required=['manual_transcription'], ), + description='Manual transcription supplemental details', ), - self._register_schema_component( - auto_schema, - 'SupplementalDetailsManualTranslation', - build_object_type( - additionalProperties=build_object_type( - properties={ - 'manual_translation': supp_references[ - 'translation_map_manual' - ], - }, - required=['manual_translation'], - ), - description='Manual translation supplemental details', + # Option 2: Human-generated text translation + build_object_type( + additionalProperties=build_object_type( + properties={ + 'manual_translation': supp_references[ + 'translation_map_manual' + ], + }, + required=['manual_translation'], ), + description='Manual translation supplemental details', ), - self._register_schema_component( - auto_schema, - 'SupplementalDetailsAutomaticTranscription', - build_object_type( - additionalProperties=build_object_type( - properties={ - 'automatic_google_transcription': supp_references[ - 'action_object_automatic' - ], - }, - required=['automatic_google_transcription'], - ), - description='Automatic transcription supplemental details', + # Option 3: AI-generated audio/video transcription + build_object_type( + additionalProperties=build_object_type( + properties={ + 'automatic_google_transcription': supp_references[ + 'action_object_automatic' + ], + }, + required=['automatic_google_transcription'], ), + description='Automatic transcription supplemental details', ), - self._register_schema_component( - auto_schema, - 'SupplementalDetailsAutomaticTranslation', - build_object_type( - additionalProperties=build_object_type( - properties={ - 'automatic_google_translation': supp_references[ - 'translation_map_automatic' - ], - }, - required=['automatic_google_translation'], - ), - description='Automatic translation supplemental details', + # Option 4: AI-generated text translation + build_object_type( + additionalProperties=build_object_type( + properties={ + 'automatic_google_translation': supp_references[ + 'translation_map_automatic' + ], + }, + required=['automatic_google_translation'], ), + description='Automatic translation supplemental details', ), - self._register_schema_component( - auto_schema, - 'SupplementalDetailsManualQual', - build_object_type( - additionalProperties=build_object_type( - properties={ - 'manual_qual': supp_references['qual_map'], - }, - required=['manual_qual'], - ), - description='Manual qualitative supplemental details', + # Option 5: Human-generated qualitative analysis tags + build_object_type( + additionalProperties=build_object_type( + properties={ + 'manual_qual': supp_references['qual_map'], + }, + required=['manual_qual'], ), + description='Manual qualitative supplemental details', ), - self._register_schema_component( - auto_schema, - 'SupplementalDetailsAutomaticQual', - build_object_type( - additionalProperties=build_object_type( - properties={ - 'automatic_bedrock_qual': supp_references[ - 'qual_map_automatic' - ], - }, - required=['automatic_bedrock_qual'], - ), - description='Automatic qualitative supplemental details', + # Option 6: AI-generated qualitative analysis tags + build_object_type( + additionalProperties=build_object_type( + properties={ + 'automatic_bedrock_qual': supp_references[ + 'qual_map_automatic' + ], + }, + required=['automatic_bedrock_qual'], ), + description='Automatic qualitative supplemental details', ), ], 'nullable': True, # Field is required=False diff --git a/kpi/schema_extensions/v2/generic/schema.py b/kpi/schema_extensions/v2/generic/schema.py index fccc499adb..4f1d19b331 100644 --- a/kpi/schema_extensions/v2/generic/schema.py +++ b/kpi/schema_extensions/v2/generic/schema.py @@ -73,6 +73,9 @@ GENERIC_STRING_SCHEMA = build_basic_type(OpenApiTypes.STR) +# Orval requires both type: ['string', 'null'] AND nullable: True +NULLABLE_STRING_SCHEMA = {'type': ['string', 'null'], 'nullable': True} + GENERIC_INT_SCHEMA = build_basic_type(OpenApiTypes.INT) GENERIC_OBJECT_SCHEMA = build_object_type(properties={}) @@ -81,4 +84,11 @@ GENERIC_DATETIME_SCHEMA = build_basic_type(OpenApiTypes.DATETIME) +# Orval requires both type: ['array', 'null'] AND nullable: True for nullable arrays +NULLABLE_ARRAY_SCHEMA = { + 'type': ['array', 'null'], + 'items': {'type': 'string'}, + 'nullable': True, +} + USER_URL_SCHEMA = build_url_type('api_v2:user-kpi-detail', username='bob') diff --git a/kpi/schema_extensions/v2/me/extensions.py b/kpi/schema_extensions/v2/me/extensions.py index cf695ff7f2..6625b8fd3a 100644 --- a/kpi/schema_extensions/v2/me/extensions.py +++ b/kpi/schema_extensions/v2/me/extensions.py @@ -42,14 +42,42 @@ class GitRevFieldExtension(OpenApiSerializerFieldExtension): target_class = 'kpi.schema_extensions.v2.me.fields.GitRevField' def map_serializer_field(self, auto_schema, direction): - return build_object_type( - properties={ - 'short': GENERIC_STRING_SCHEMA, - 'long': GENERIC_STRING_SCHEMA, - 'branch': GENERIC_STRING_SCHEMA, - 'tag': GENERIC_STRING_SCHEMA, - } - ) + # git_rev can be either: + # - False (when EXPOSE_GIT_REV=False and user is not superuser) + # - An object with string/boolean properties (actual git revision info) + return { + 'oneOf': [ + build_basic_type(OpenApiTypes.BOOL), + build_object_type( + properties={ + 'short': { + 'oneOf': [ + GENERIC_STRING_SCHEMA, + build_basic_type(OpenApiTypes.BOOL), + ] + }, + 'long': { + 'oneOf': [ + GENERIC_STRING_SCHEMA, + build_basic_type(OpenApiTypes.BOOL), + ] + }, + 'branch': { + 'oneOf': [ + GENERIC_STRING_SCHEMA, + build_basic_type(OpenApiTypes.BOOL), + ] + }, + 'tag': { + 'oneOf': [ + GENERIC_STRING_SCHEMA, + build_basic_type(OpenApiTypes.BOOL), + ] + }, + } + ), + ] + } class GravatarFieldExtension(OpenApiSerializerFieldExtension): diff --git a/kpi/schema_extensions/v2/me/serializers.py b/kpi/schema_extensions/v2/me/serializers.py index 8f9d05aece..5fe6bc7814 100644 --- a/kpi/schema_extensions/v2/me/serializers.py +++ b/kpi/schema_extensions/v2/me/serializers.py @@ -28,7 +28,7 @@ 'date_joined': serializers.DateTimeField(), 'projects_url': ProjectUrlField(), 'gravatar': GravatarField(), - 'last_login': serializers.DateTimeField(), + 'last_login': serializers.DateTimeField(allow_null=True), 'extra_details': ExtraDetailField(), 'git_rev': GitRevField(), 'social_accounts': SocialAccountField(), diff --git a/kpi/serializers/v2/asset.py b/kpi/serializers/v2/asset.py index d2ddbf3174..6e107855bc 100644 --- a/kpi/serializers/v2/asset.py +++ b/kpi/serializers/v2/asset.py @@ -443,8 +443,8 @@ class AssetSerializer(serializers.HyperlinkedModelSerializer): many=True, read_only=True, source='asset_export_settings' ) tag_string = serializers.CharField(required=False, allow_blank=True) - version_id = serializers.CharField(read_only=True) - version__content_hash = serializers.CharField(read_only=True) + version_id = serializers.CharField(read_only=True, allow_null=True) + version__content_hash = serializers.CharField(read_only=True, allow_null=True) has_deployment = ReadOnlyFieldWithSchemaField( schema_field=HasDeploymentField, read_only=True ) @@ -746,7 +746,7 @@ def get_data(self, obj): kwargs=kwargs, request=self.context.get('request', None)) - @extend_schema_field(OpenApiTypes.STR) + @extend_schema_field({'type': 'string', 'nullable': True}) def get_deployed_version_id(self, obj): if not obj.has_deployment: return None @@ -778,7 +778,7 @@ def get_deployment__data_download_links(self, obj): else: return {} - @extend_schema_field(OpenApiTypes.DATETIME) + @extend_schema_field({'type': 'string', 'format': 'date-time', 'nullable': True}) def get_deployment__last_submission_time(self, obj): if obj.has_deployment: return obj.deployment.last_submission_time @@ -809,7 +809,7 @@ def get_deployment__submission_count(self, obj): return None - @extend_schema_field(OpenApiTypes.STR) + @extend_schema_field({'type': 'string', 'nullable': True}) def get_deployment__uuid(self, obj): return obj.deployment.form_uuid if obj.has_deployment else None diff --git a/kpi/utils/schema_extensions/mixins.py b/kpi/utils/schema_extensions/mixins.py index be297e58b6..13aa9cf1b9 100644 --- a/kpi/utils/schema_extensions/mixins.py +++ b/kpi/utils/schema_extensions/mixins.py @@ -112,6 +112,11 @@ def _register_qual_data_schema_components(self, auto_schema): required=['status', 'error', 'uuid'], ), ], + # Tell code generators that 'status' discriminates + # between the oneOf branches + 'discriminator': { + 'propertyName': 'status', + }, } references[f'automatic_qual_{q_type}'] = ( diff --git a/kpi/views/v2/asset.py b/kpi/views/v2/asset.py index c88903ac71..bfc3beaa40 100644 --- a/kpi/views/v2/asset.py +++ b/kpi/views/v2/asset.py @@ -59,7 +59,7 @@ ) from kpi.schema_extensions.v2.assets.schema import ( ASSET_CLONE_FROM_SCHEMA, - ASSET_CONTENT_SCHEMA, + ASSET_CONTENT_REQUEST_SCHEMA, ASSET_ENABLED_SCHEMA, ASSET_FIELDS_SCHEMA, ASSET_NAME_SCHEMA, @@ -299,7 +299,9 @@ OpenApiExample( name='Updating an asset', value={ - 'content': generate_example_from_schema(ASSET_CONTENT_SCHEMA), + 'content': generate_example_from_schema( + ASSET_CONTENT_REQUEST_SCHEMA + ), 'name': generate_example_from_schema(ASSET_NAME_SCHEMA), }, request_only=True, diff --git a/orval.config.js b/orval.config.js index 0264f15434..37fe45a232 100644 --- a/orval.config.js +++ b/orval.config.js @@ -1,9 +1,9 @@ -const { operationName } = require('./jsapp/js/api/orval.operationName') +const { operationName } = require('./jsapp/js/api/orval.operationName.js') module.exports = { 'kpi-v2': { output: { - mode: 'tags', + mode: 'tags-split', workspace: './jsapp/js/api/', target: './react-query', schemas: './models', @@ -15,9 +15,13 @@ module.exports = { return generatorClients['react-query'] }, httpClient: 'fetch', - mock: false, // TODO: enable in later PRs separately. + // Generate mocks in separate .msw.ts files to avoid bundling faker/msw in production + // With mode: 'tags-split', mocks are generated separately from runtime code + mock: true, indexFiles: false, - biome: true, + // Disable built-in biome, as it is running before `afterAllFilesWrite` + // scripts - we run it manually after post-processing + biome: false, // baseUrl: 'https://api.example.com', // prepend https://api.example.com to all api calls urlEncodeParameters: true, @@ -45,8 +49,18 @@ module.exports = { hooks: { // Orval has a bug that fails to generate imports for $ref in additionalProperties. // See https://github.com/orval-labs/orval/issues/1077. - // This is a workaround. Remove it once the underlying bug is fixed. - afterAllFilesWrite: 'node scripts/orval-fix-referenced-additional-properties.js', + // Also fix TypeScript errors in MSW mock factories for types with index signatures. + // Make trailing slashes optional in MSW handlers to match both /path and /path/ + // Rename files to index.ts/msw.ts pattern for clean imports + // Run Biome last to format and organize imports after all modifications + afterAllFilesWrite: [ + 'node scripts/orval-rename-to-index.js', + 'node scripts/orval-fix-referenced-additional-properties.js', + 'node scripts/orval-fix-mock-factory-type-assertions.js', + 'node scripts/orval-make-trailing-slash-optional.js', + 'node scripts/orval-remove-mock-delays.js', + 'npx biome check --write --unsafe jsapp/js/api/react-query jsapp/js/api/models', + ], }, }, } diff --git a/scripts/generate_api.sh b/scripts/generate_api.sh index ea89a8d6fb..273937166d 100755 --- a/scripts/generate_api.sh +++ b/scripts/generate_api.sh @@ -28,6 +28,14 @@ fi echo "Enabling Stripe for schema generation…" export STRIPE_ENABLED=true echo "Stripe enabled: $STRIPE_ENABLED" + +# Override KOBOFORM_URL with canonical value for schema examples +# This ensures generated schema examples use production-like URLs regardless of environment +# To use a different URL, set SCHEMA_URL environment variable before running this script +echo "Setting KOBOFORM_URL for schema generation…" +export KOBOFORM_URL="${SCHEMA_URL:-https://kf.kobotoolbox.org}" +echo "KOBOFORM_URL: $KOBOFORM_URL" + echo "Generating v2 OpenAPI JSON schema with drf-spectacular…" run python manage.py generate_openapi_schema --file "$DESTINATION_FOLDER/schema_v2.json" --schema="api_v2" --format openapi-json echo "Generating v2 OpenAPI YAML schema with drf-spectacular…" diff --git a/scripts/orval-fix-mock-factory-type-assertions.js b/scripts/orval-fix-mock-factory-type-assertions.js new file mode 100644 index 0000000000..3aab9be041 --- /dev/null +++ b/scripts/orval-fix-mock-factory-type-assertions.js @@ -0,0 +1,128 @@ +/* eslint-disable no-console */ +/** + * Fixes TypeScript errors in MSW mock factories. + * + * Why this is needed: When Orval generates types like + * `{ _version: string } & Record`, TypeScript's type system + * sees a conflict - _version must be both a `string` AND a `SomeOtherType`, which + * is impossible. This causes the mock factory return values to fail type checking + * even though they're structurally correct at runtime. + * + * What this does: Adds explicit type assertions (`as TypeName`) to mock factory + * return statements. This tells TypeScript "trust me, this object matches the type" + * without changing runtime behavior. Safe for test mocks where we control the data. + * + * Types currently affected: + * - DataSupplementResponse (intersection with Record) + * - PatchedDataSupplementPayload (union with Record) + */ +const fs = require('fs') +const path = require('path') + +const ROOT = process.cwd() +const MODELS_DIR = path.join(ROOT, 'jsapp/js/api/models') +const REACT_QUERY_DIR = path.join(ROOT, 'jsapp/js/api/react-query') + +// Types that need fixing +const TYPE_FILES = { + 'dataSupplementResponse.ts': { + typeName: 'DataSupplementResponse', + factoryFile: 'survey-data/msw.ts', + }, + 'patchedDataSupplementPayload.ts': { + typeName: 'PatchedDataSupplementPayload', + factoryFile: 'survey-data/msw.ts', + }, +} + +function detectTypeWithVersionAndRecord(source) { + // Look for patterns like: + // export type SomeName = { _version: ... } & Record<...> + // These might span multiple lines + + if (!source.includes('export type')) return null + if (!source.includes('_version')) return null + if (!source.includes('Record<')) return null + + // Find the line with "export type" + const lines = source.split('\n') + for (let i = 0; i < lines.length; i++) { + const line = lines[i] + if (!line.includes('export type')) continue + + // Extract type name: "export type DataSupplementResponse = {" + const afterExport = line.split('export type')[1] + if (!afterExport) continue + + const typeName = afterExport.split('=')[0].trim() + if (typeName) return typeName + } + + return null +} + +let totalFixed = 0 + +for (const [modelFile, config] of Object.entries(TYPE_FILES)) { + const modelPath = path.join(MODELS_DIR, modelFile) + if (!fs.existsSync(modelPath)) { + console.log(`⊘ Skipped ${modelFile} (file not found)`) + continue + } + + const modelSource = fs.readFileSync(modelPath, 'utf8') + const detectedType = detectTypeWithVersionAndRecord(modelSource) + + if (!detectedType) { + console.log(`⊘ Skipped ${modelFile} (no problematic type pattern found)`) + continue + } + + if (detectedType !== config.typeName) { + console.log(`⚠ Warning: Expected type ${config.typeName} but found ${detectedType} in ${modelFile}`) + } + + // Now fix the mock factories + const factoryPath = path.join(REACT_QUERY_DIR, config.factoryFile) + if (!fs.existsSync(factoryPath)) { + console.log(`⊘ Skipped ${config.factoryFile} (file not found)`) + continue + } + + let factorySource = fs.readFileSync(factoryPath, 'utf8') + + // Find factories that return this type and add `as TypeName` if missing + // Turns: ): TypeName => ({ _version: ..., ...overrideResponse }) + // Into: ): TypeName => ({ _version: ..., ...overrideResponse }) as TypeName + const lines = factorySource.split('\n') + let fixCount = 0 + + for (let i = 0; i < lines.length; i++) { + const line = lines[i] + + // Skip lines that don't look like factory returns + if (!line.includes(`): ${config.typeName} =>`)) continue + if (!line.includes('_version:')) continue + if (!line.includes('...override')) continue + + // Skip if already has the type assertion + if (line.includes(` as ${config.typeName}`)) continue + + // Add the type assertion before the closing parenthesis at the end + lines[i] = line.replace(/\)\s*$/, `) as ${config.typeName}`) + fixCount++ + } + + if (fixCount > 0) { + const patchedFactory = lines.join('\n') + fs.writeFileSync(factoryPath, patchedFactory, 'utf8') + console.log(`✔ Fixed ${fixCount} mock factories for ${config.typeName} in ${config.factoryFile}`) + totalFixed += fixCount + } else { + console.log(`⊙ No fixes needed for ${config.typeName} in ${config.factoryFile}`) + } +} + +if (totalFixed > 0) { + console.log(`\n✨ Total: Fixed ${totalFixed} mock factory type assertions`) +} diff --git a/scripts/orval-fix-referenced-additional-properties.js b/scripts/orval-fix-referenced-additional-properties.js index 93d4ab4ddd..6c75fa3d67 100644 --- a/scripts/orval-fix-referenced-additional-properties.js +++ b/scripts/orval-fix-referenced-additional-properties.js @@ -46,14 +46,17 @@ function detectInterfaceWithIndex(source) { function ensureTypeImportAfterHeader(source, typeName, importPath) { const importLine = `import type { ${typeName} } from '${importPath}'` - // Already imported? + // Check if this type is already imported const hasImport = new RegExp(`\\bimport\\s+type\\s*\\{\\s*${typeName}\\s*\\}\\s+from\\s+['"]`).test(source) if (hasImport) return source + // Split the file into Orval's header comment and the rest const { header, rest } = splitHeader(source) + + // If no header exists, add import at the top if (!header) return `${importLine}\n${source}` - // Ensure one blank line after the Orval header for readability + // Insert import right after the Orval header with one blank line for readability return `${header}\n${importLine}\n${rest}` } @@ -64,14 +67,19 @@ for (const file of FILES) { const source = fs.readFileSync(filePath, 'utf8') const detected = detectInterfaceWithIndex(source) - if (!fs.existsSync(filePath)) throw new Error(`File ${file} doesn't have an interface within`) + if (!detected) { + // File already processed (converted from interface to type) + continue + } const { name, versionType, valueType, interfaceBlock } = detected const importPath = inferImportPath(valueType) let patched = ensureTypeImportAfterHeader(source, valueType, importPath) - // Note: the workaround with index signatures is partial: `|` works only for assignment and `&` works for reading. + // TypeScript index signatures behave differently with unions vs intersections: + // - Use `|` (union) for Payload types: allows assigning objects without all Record keys + // - Use `&` (intersection) for Response types: allows reading all properties safely const operator = file.includes('Payload') ? '|' : '&' const replacement = diff --git a/scripts/orval-make-trailing-slash-optional.js b/scripts/orval-make-trailing-slash-optional.js new file mode 100644 index 0000000000..2e970c7177 --- /dev/null +++ b/scripts/orval-make-trailing-slash-optional.js @@ -0,0 +1,57 @@ +/* eslint-disable no-console */ +/** + * Django REST Framework adds trailing slashes to all URLs, so Orval-generated + * MSW handlers end with '/'. But the frontend sometimes drops the slash. + * + * We fix this by appending '?' to make the slash optional in handler patterns. + * Both /api/v2/assets/123/history/actions and /actions/ will match. + */ +const fs = require('fs') +const path = require('path') + +const ROOT = process.cwd() +const REACT_QUERY_DIR = path.join(ROOT, 'jsapp/js/api/react-query') + +let totalFixed = 0 + +function processFile(filePath) { + let source = fs.readFileSync(filePath, 'utf8') + let modified = false + + // Change http.get('path/', ...) to http.get('path{/}?', ...) + // The {/}? syntax makes the trailing slash optional in path-to-regexp + const pattern = /http\.(get|post|put|patch|delete)\('(\*\/[^']+)\/'/g + + source = source.replace(pattern, (match, method, pathWithoutSlash) => { + if (pathWithoutSlash.endsWith('{/}')) { + return match + } + modified = true + return `http.${method}('${pathWithoutSlash}{/}?'` + }) + + if (modified) { + fs.writeFileSync(filePath, source, 'utf8') + totalFixed++ + } + + return modified +} + +function processDirectory(dirPath) { + const entries = fs.readdirSync(dirPath, { withFileTypes: true }) + for (const entry of entries) { + const fullPath = path.join(dirPath, entry.name) + if (entry.isDirectory()) { + processDirectory(fullPath) + } else if (entry.name.endsWith('.ts')) { + processFile(fullPath) + } + } +} + +processDirectory(REACT_QUERY_DIR) + +if (totalFixed > 0) { + console.log(`✔ Made trailing slashes optional in ${totalFixed} react-query files`) +} diff --git a/scripts/orval-remove-mock-delays.js b/scripts/orval-remove-mock-delays.js new file mode 100644 index 0000000000..c446a22bf4 --- /dev/null +++ b/scripts/orval-remove-mock-delays.js @@ -0,0 +1,74 @@ +#!/usr/bin/env node + +/** + * Post-process Orval-generated MSW handlers to remove delays. + * + * Orval generates mock handlers with `await delay(1000)` which is good for + * simulating realistic loading states but causes tests to be slow and potentially + * timeout when multiple requests are involved. + * + * This script removes the `await delay(1000)` lines from all generated handler files. + */ + +const fs = require('fs') +const path = require('path') + +const targetDir = path.join(__dirname, '../jsapp/js/api/react-query') + +function removeDelays(filePath) { + let source = fs.readFileSync(filePath, 'utf-8') + const originalSource = source + + // Remove `delay` from the MSW import statement + // Example: "import { http, delay, HttpResponse } from 'msw'" becomes "import { http, HttpResponse } from 'msw'" + source = source.replace( + /import\s+{([^}]*),\s*delay\s*([^}]*)}\s+from\s+['"]msw['"]/g, + (match, before, after) => { + // Merge the parts before and after `delay`, then clean up any double commas + const cleaned = `${before}${after}`.replace(/,\s*,/g, ',').replace(/^,|,$/g, '').trim() + // If nothing remains after removing `delay`, leave an empty import (will be cleaned up by formatter) + return cleaned ? `import { ${cleaned} } from 'msw'` : "import { } from 'msw'" + } + ) + + // Remove standalone delay import if `delay` was the only import + // Example: "import { delay } from 'msw'" becomes "" + source = source.replace(/import\s+{\s*delay\s*}\s+from\s+['"]msw['"][\s\r\n]*/g, '') + + // Remove all `await delay(...)` calls from handler bodies + // Handles both formats: + // 1. Delay on same line: "=> {await delay(1000);\n" becomes "=> {\n" + // 2. Delay on own line: " await delay(1000)\n" becomes "" + source = source.replace(/await\s+delay\(\d+\)\s*;?\s*/g, '') + + if (source !== originalSource) { + fs.writeFileSync(filePath, source, 'utf-8') + return true + } + return false +} + +function processDirectory(dir) { + let modifiedCount = 0 + const files = fs.readdirSync(dir) + + for (const file of files) { + const filePath = path.join(dir, file) + const stat = fs.statSync(filePath) + + if (stat.isDirectory()) { + modifiedCount += processDirectory(filePath) + } else if (file.endsWith('.ts') || file.endsWith('.tsx')) { + if (removeDelays(filePath)) { + modifiedCount++ + console.log(`Removed delays from: ${path.relative(process.cwd(), filePath)}`) + } + } + } + + return modifiedCount +} + +console.log('Removing delays from Orval-generated mock handlers...') +const modifiedCount = processDirectory(targetDir) +console.log(`Modified ${modifiedCount} file(s)`) diff --git a/scripts/orval-rename-to-index.js b/scripts/orval-rename-to-index.js new file mode 100755 index 0000000000..5fdac46a62 --- /dev/null +++ b/scripts/orval-rename-to-index.js @@ -0,0 +1,55 @@ +#!/usr/bin/env node + +/** + * Renames Orval-generated files to index.ts/msw.ts pattern for cleaner imports. + * + * With mode: 'tags-split', Orval creates: + * react-query/manage-projects-and-library-content/manage-projects-and-library-content.ts + * react-query/manage-projects-and-library-content/manage-projects-and-library-content.msw.ts + * + * This script renames to: + * react-query/manage-projects-and-library-content/index.ts + * react-query/manage-projects-and-library-content/msw.ts + * + * So imports can be: + * from '#/api/react-query/manage-projects-and-library-content' (runtime) + * from '#/api/react-query/manage-projects-and-library-content/msw' (mocks) + */ + +const fs = require('fs') +const path = require('path') + +const REACT_QUERY_DIR = path.join(__dirname, '../jsapp/js/api/react-query') + +function renameInDirectory(dirPath) { + const entries = fs.readdirSync(dirPath, { withFileTypes: true }) + + for (const entry of entries) { + if (entry.isDirectory()) { + const subDirPath = path.join(dirPath, entry.name) + const baseFileName = `${entry.name}.ts` + const baseMswFileName = `${entry.name}.msw.ts` + + const oldMainPath = path.join(subDirPath, baseFileName) + const oldMswPath = path.join(subDirPath, baseMswFileName) + const newMainPath = path.join(subDirPath, 'index.ts') + const newMswPath = path.join(subDirPath, 'msw.ts') + + // Rename main file if it exists + if (fs.existsSync(oldMainPath)) { + fs.renameSync(oldMainPath, newMainPath) + console.log(`✓ Renamed: ${entry.name}/${entry.name}.ts → ${entry.name}/index.ts`) + } + + // Rename .msw file if it exists + if (fs.existsSync(oldMswPath)) { + fs.renameSync(oldMswPath, newMswPath) + console.log(`✓ Renamed: ${entry.name}/${entry.name}.msw.ts → ${entry.name}/msw.ts`) + } + } + } +} + +console.log('Renaming Orval-generated files to index.ts/msw.ts pattern...') +renameInDirectory(REACT_QUERY_DIR) +console.log('Done!') diff --git a/static/openapi/schema_v2.json b/static/openapi/schema_v2.json index 0e45537b54..ef474746f3 100644 --- a/static/openapi/schema_v2.json +++ b/static/openapi/schema_v2.json @@ -21207,22 +21207,62 @@ "type": "object", "properties": { "sector": { - "type": "object" + "type": [ + "object", + "null" + ], + "properties": { + "label": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "nullable": true }, "country": { - "type": "array", + "type": [ + "array", + "null" + ], "items": { - "type": "string" - } + "type": "object", + "properties": { + "label": { + "type": "string" + }, + "value": { + "type": "string" + } + } + }, + "nullable": true }, "description": { "type": "string" }, "collects_pii": { - "type": "string" + "type": [ + "object", + "null" + ], + "properties": { + "label": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "nullable": true }, "organization": { - "type": "string" + "type": [ + "string", + "null" + ], + "nullable": true }, "country_codes": { "type": "array", @@ -21231,7 +21271,19 @@ } }, "operational_purpose": { - "type": "string" + "type": [ + "object", + "null" + ], + "properties": { + "label": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "nullable": true } } }, @@ -21241,7 +21293,39 @@ "files": { "type": "array", "items": { - "type": "string" + "type": "object", + "properties": { + "uid": { + "type": "string" + }, + "url": { + "type": "string" + }, + "asset": { + "type": "string" + }, + "user": { + "type": "string" + }, + "user__username": { + "type": "string" + }, + "file_type": { + "type": "string" + }, + "description": { + "type": "string" + }, + "date_created": { + "type": "string" + }, + "content": { + "type": "string" + }, + "metadata": { + "type": "object" + } + } }, "readOnly": true }, @@ -21279,10 +21363,73 @@ "type": "integer" }, "name_quality": { - "type": "object" + "type": "object", + "properties": { + "ok": { + "type": "integer" + }, + "bad": { + "type": "integer" + }, + "good": { + "type": "integer" + }, + "total": { + "type": "integer" + }, + "firsts": { + "type": "object", + "properties": { + "ok": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "index": { + "type": "integer" + }, + "label": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "bad": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "index": { + "type": "integer" + }, + "label": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + } + } + } }, "default_translation": { - "type": "string" + "type": [ + "string", + "null" + ], + "nullable": true + }, + "naming_conflicts": { + "type": "array", + "items": { + "type": "string" + } } }, "readOnly": true @@ -21302,11 +21449,13 @@ }, "version_id": { "type": "string", - "readOnly": true + "readOnly": true, + "nullable": true }, "version__content_hash": { "type": "string", - "readOnly": true + "readOnly": true, + "nullable": true }, "version_count": { "type": "integer", @@ -21318,6 +21467,7 @@ }, "deployed_version_id": { "type": "string", + "nullable": true, "readOnly": true }, "deployed_versions": { @@ -21327,10 +21477,18 @@ "type": "integer" }, "next": { - "type": "string" + "type": [ + "string", + "null" + ], + "nullable": true }, "previous": { - "type": "string" + "type": [ + "string", + "null" + ], + "nullable": true }, "results": { "type": "array", @@ -21356,10 +21514,23 @@ "type": "string", "format": "date-time" } - } + }, + "required": [ + "content_hash", + "date_deployed", + "date_modified", + "uid", + "url" + ] } } }, + "required": [ + "count", + "next", + "previous", + "results" + ], "readOnly": true }, "deployment__links": { @@ -21372,6 +21543,40 @@ }, "deployment__data_download_links": { "type": "object", + "properties": { + "csv_legacy": { + "type": "string" + }, + "csv": { + "type": "string" + }, + "geojson": { + "type": "string" + }, + "kml_legacy": { + "type": "string" + }, + "spss_labels": { + "type": "string" + }, + "xls_legacy": { + "type": "string" + }, + "xls": { + "type": "string" + }, + "zip_legacy": { + "type": "string" + } + }, + "required": [ + "csv", + "csv_legacy", + "kml_legacy", + "xls", + "xls_legacy", + "zip_legacy" + ], "readOnly": true }, "deployment__submission_count": { @@ -21381,6 +21586,7 @@ "deployment__last_submission_time": { "type": "string", "format": "date-time", + "nullable": true, "readOnly": true }, "deployment__encrypted": { @@ -21389,6 +21595,7 @@ }, "deployment__uuid": { "type": "string", + "nullable": true, "readOnly": true }, "deployment_status": { @@ -21403,40 +21610,184 @@ "type": "object", "properties": { "default": { - "type": "object" + "type": "object", + "properties": { + "groupDataBy": { + "type": "string" + }, + "report_type": { + "type": "string" + }, + "report_colors": { + "type": "array", + "items": { + "type": "string" + } + }, + "translationIndex": { + "type": "integer" + }, + "graphWidth": { + "type": "integer" + } + } }, "specified": { + "type": "object" + }, + "kuid_names": { + "type": "object" + } + } + }, + "report_custom": { + "type": "object" + }, + "advanced_features": { + "type": "object", + "properties": { + "transcript": { "type": "object", "properties": { - "end": { - "type": "object" + "values": { + "type": "array", + "items": { + "type": "string" + } }, - "start": { - "type": "object" + "languages": { + "type": "array", + "items": { + "type": "string" + } } } }, - "kuid_names": { + "translation": { "type": "object", "properties": { - "end": { - "type": "string" + "values": { + "type": "array", + "items": { + "type": "string" + } }, - "start": { - "type": "string" + "languages": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "qual": { + "type": "object", + "properties": { + "qual_survey": { + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "labels": { + "type": "object", + "properties": { + "_default": { + "type": "string" + } + }, + "additionalProperties": { + "type": "string" + }, + "required": [ + "_default" + ] + }, + "uuid": { + "type": "string" + }, + "options": { + "type": "object", + "properties": { + "deleted": { + "type": "boolean" + } + } + }, + "xpath": { + "type": "string" + }, + "scope": { + "type": "string" + }, + "choices": { + "type": "array", + "items": { + "type": "object", + "properties": { + "labels": { + "type": "object", + "properties": { + "_default": { + "type": "string" + } + }, + "additionalProperties": { + "type": "string" + }, + "required": [ + "_default" + ] + }, + "uuid": { + "type": "string" + }, + "options": { + "type": "object", + "properties": { + "deleted": { + "type": "boolean" + } + } + } + }, + "required": [ + "labels", + "uuid" + ] + } + } + }, + "required": [ + "labels", + "scope", + "type", + "xpath" + ] + } } } + }, + "_version": { + "type": "string" } } }, - "report_custom": { - "type": "object" - }, - "advanced_features": { - "type": "object" - }, "map_styles": { - "type": "object" + "type": "object", + "properties": { + "colorSet": { + "type": "string" + }, + "querylimit": { + "type": "string" + }, + "selectedQuestion": { + "type": "string" + } + } }, "map_custom": { "type": "object" @@ -21450,11 +21801,171 @@ "survey": { "type": "array", "items": { - "type": "object" + "type": "object", + "properties": { + "$kuid": { + "type": "string" + }, + "type": { + "type": "string" + }, + "$xpath": { + "type": "string" + }, + "$autoname": { + "type": "string" + }, + "calculation": { + "type": "string" + }, + "label": { + "type": "array", + "items": { + "type": [ + "string", + "null" + ], + "nullable": true + } + }, + "hint": { + "type": "array", + "items": { + "type": [ + "string", + "null" + ], + "nullable": true + } + }, + "name": { + "type": "string" + }, + "required": { + "type": "boolean" + }, + "appearance": { + "type": "string" + }, + "parameters": { + "type": "string" + }, + "kobo--matrix_list": { + "type": "string" + }, + "kobo--rank-constraint-message": { + "type": "string" + }, + "kobo--rank-items": { + "type": "string" + }, + "kobo--score-choices": { + "type": "string" + }, + "kobo--locking-profile": { + "type": "string" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "select_from_list_name": { + "type": "string" + }, + "body::accept": { + "type": "string" + } + }, + "additionalProperties": true, + "required": [ + "$kuid", + "type" + ] + } + }, + "choices": { + "type": "array", + "items": { + "type": "object", + "properties": { + "$autovalue": { + "type": "string" + }, + "$kuid": { + "type": "string" + }, + "label": { + "type": "array", + "items": { + "type": [ + "string", + "null" + ], + "nullable": true + } + }, + "list_name": { + "type": "string" + }, + "name": { + "type": "string" + }, + "media::image": { + "type": "array", + "items": { + "type": "string" + } + }, + "$autoname": { + "type": "string" + } + }, + "additionalProperties": true, + "required": [ + "$autovalue", + "$kuid", + "list_name", + "name" + ] } }, "settings": { - "type": "object" + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "id_string": { + "type": "string" + }, + "style": { + "type": "string" + }, + "form_id": { + "type": "string" + }, + "title": { + "type": "string" + }, + "kobo--lock_all": { + "type": "boolean" + }, + "kobo--locking-profile": { + "type": "string" + }, + "default_language": { + "type": [ + "string", + "null" + ], + "nullable": true + } + } }, "translated": { "type": "array", @@ -21465,7 +21976,25 @@ "translations": { "type": "array", "items": { - "type": "string" + "type": [ + "string", + "null" + ], + "nullable": true + } + }, + "translations_0": { + "type": [ + "string", + "null" + ], + "nullable": true + }, + "kobo--locking-profiles": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": {} } } } @@ -21481,7 +22010,11 @@ "url": { "type": "string" } - } + }, + "required": [ + "format", + "url" + ] }, "readOnly": true }, @@ -21496,7 +22029,11 @@ "url": { "type": "string" } - } + }, + "required": [ + "format", + "url" + ] }, "readOnly": true }, @@ -21506,10 +22043,81 @@ "additional_fields": { "type": "array", "items": { - "type": "string" + "type": "object", + "properties": { + "language": { + "type": "string" + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "enum": [ + "transcript", + "translation", + "qualVerification", + "qualSource", + "qualInteger", + "qualTags", + "qualText", + "qualNote", + "qualAutoKeywordCount", + "qualSelectMultiple", + "qualSelectOne" + ] + }, + "name": { + "type": "string" + }, + "dtpath": { + "type": "string" + }, + "label": { + "type": "string" + }, + "choices": { + "type": "array", + "items": { + "type": "object", + "properties": { + "uuid": { + "type": "string" + }, + "labels": { + "type": "object", + "properties": { + "_default": { + "type": "string" + } + }, + "additionalProperties": { + "type": "string" + }, + "required": [ + "_default" + ] + } + }, + "required": [ + "labels", + "uuid" + ] + } + } + }, + "required": [ + "dtpath", + "name", + "source", + "type" + ] } } }, + "required": [ + "additional_fields" + ], "readOnly": true }, "xform_link": { @@ -21548,14 +22156,116 @@ "assignable_permissions": { "type": "array", "items": { - "type": "object" + "type": "object", + "properties": { + "url": { + "type": "string" + }, + "label": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object", + "properties": { + "default": { + "type": "string" + }, + "view_submissions": { + "type": "string" + }, + "change_submissions": { + "type": "string" + }, + "delete_submissions": { + "type": "string" + }, + "validate_submissions": { + "type": "string" + } + }, + "required": [ + "default" + ] + } + ] + } + }, + "required": [ + "label", + "url" + ] }, "readOnly": true }, "permissions": { "type": "array", "items": { - "type": "string" + "type": "object", + "properties": { + "url": { + "type": "string" + }, + "user": { + "type": "string" + }, + "permission": { + "type": "string" + }, + "partial_permissions": { + "type": "array", + "items": { + "type": "object", + "properties": { + "url": { + "type": "string" + }, + "filters": { + "type": "array", + "items": { + "type": "object" + } + } + } + } + }, + "label": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "object", + "properties": { + "default": { + "type": "string" + }, + "view_submissions": { + "type": "string" + }, + "change_submissions": { + "type": "string" + }, + "delete_submissions": { + "type": "string" + }, + "validate_submissions": { + "type": "string" + } + }, + "required": [ + "default" + ] + } + ] + } + }, + "required": [ + "permission", + "url", + "user" + ] }, "readOnly": true }, @@ -21608,10 +22318,14 @@ "readOnly": true }, "access_types": { - "type": "array", + "type": [ + "array", + "null" + ], "items": { "type": "string" }, + "nullable": true, "readOnly": true }, "data_sharing": { @@ -23743,22 +24457,94 @@ "_supplementalDetails": { "oneOf": [ { - "$ref": "#/components/schemas/SupplementalDetailsManualTranscription" + "type": "object", + "description": "Manual transcription supplemental details", + "additionalProperties": { + "type": "object", + "properties": { + "manual_transcription": { + "$ref": "#/components/schemas/SupplementalDataManualTranscription" + } + }, + "required": [ + "manual_transcription" + ] + } }, { - "$ref": "#/components/schemas/SupplementalDetailsManualTranslation" + "type": "object", + "description": "Manual translation supplemental details", + "additionalProperties": { + "type": "object", + "properties": { + "manual_translation": { + "$ref": "#/components/schemas/SupplementalDataManualTranslation" + } + }, + "required": [ + "manual_translation" + ] + } }, { - "$ref": "#/components/schemas/SupplementalDetailsAutomaticTranscription" + "type": "object", + "description": "Automatic transcription supplemental details", + "additionalProperties": { + "type": "object", + "properties": { + "automatic_google_transcription": { + "$ref": "#/components/schemas/SupplementalDataAutomaticTranscription" + } + }, + "required": [ + "automatic_google_transcription" + ] + } }, { - "$ref": "#/components/schemas/SupplementalDetailsAutomaticTranslation" + "type": "object", + "description": "Automatic translation supplemental details", + "additionalProperties": { + "type": "object", + "properties": { + "automatic_google_translation": { + "$ref": "#/components/schemas/SupplementalDataAutomaticTranslation" + } + }, + "required": [ + "automatic_google_translation" + ] + } }, { - "$ref": "#/components/schemas/SupplementalDetailsManualQual" + "type": "object", + "description": "Manual qualitative supplemental details", + "additionalProperties": { + "type": "object", + "properties": { + "manual_qual": { + "$ref": "#/components/schemas/SupplementalDataManualQual" + } + }, + "required": [ + "manual_qual" + ] + } }, { - "$ref": "#/components/schemas/SupplementalDetailsAutomaticQual" + "type": "object", + "description": "Automatic qualitative supplemental details", + "additionalProperties": { + "type": "object", + "properties": { + "automatic_bedrock_qual": { + "$ref": "#/components/schemas/SupplementalDataAutomaticQual" + } + }, + "required": [ + "automatic_bedrock_qual" + ] + } } ], "nullable": true, @@ -23911,7 +24697,10 @@ "uuid" ] } - ] + ], + "discriminator": { + "propertyName": "status" + } }, "DataSupplementAutomaticQualDataSelectMultipleResponse": { "type": "object", @@ -23965,7 +24754,10 @@ "uuid" ] } - ] + ], + "discriminator": { + "propertyName": "status" + } }, "DataSupplementAutomaticQualDataSelectOneResponse": { "type": "object", @@ -24016,7 +24808,10 @@ "uuid" ] } - ] + ], + "discriminator": { + "propertyName": "status" + } }, "DataSupplementAutomaticQualDataTextResponse": { "type": "object", @@ -24066,7 +24861,10 @@ "uuid" ] } - ] + ], + "discriminator": { + "propertyName": "status" + } }, "DataSupplementManualQualDataInteger": { "type": "object", @@ -26044,7 +26842,8 @@ }, "last_login": { "type": "string", - "format": "date-time" + "format": "date-time", + "nullable": true }, "extra_details": { "type": "object", @@ -26097,21 +26896,56 @@ } }, "git_rev": { - "type": "object", - "properties": { - "short": { - "type": "string" - }, - "long": { - "type": "string" - }, - "branch": { - "type": "string" + "oneOf": [ + { + "type": "boolean" }, - "tag": { - "type": "string" + { + "type": "object", + "properties": { + "short": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "boolean" + } + ] + }, + "long": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "boolean" + } + ] + }, + "branch": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "boolean" + } + ] + }, + "tag": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "boolean" + } + ] + } + } } - } + ] }, "social_accounts": { "type": "array", @@ -32060,96 +32894,6 @@ "_uuid" ] }, - "SupplementalDetailsAutomaticQual": { - "type": "object", - "description": "Automatic qualitative supplemental details", - "additionalProperties": { - "type": "object", - "properties": { - "automatic_bedrock_qual": { - "$ref": "#/components/schemas/SupplementalDataAutomaticQual" - } - }, - "required": [ - "automatic_bedrock_qual" - ] - } - }, - "SupplementalDetailsAutomaticTranscription": { - "type": "object", - "description": "Automatic transcription supplemental details", - "additionalProperties": { - "type": "object", - "properties": { - "automatic_google_transcription": { - "$ref": "#/components/schemas/SupplementalDataAutomaticTranscription" - } - }, - "required": [ - "automatic_google_transcription" - ] - } - }, - "SupplementalDetailsAutomaticTranslation": { - "type": "object", - "description": "Automatic translation supplemental details", - "additionalProperties": { - "type": "object", - "properties": { - "automatic_google_translation": { - "$ref": "#/components/schemas/SupplementalDataAutomaticTranslation" - } - }, - "required": [ - "automatic_google_translation" - ] - } - }, - "SupplementalDetailsManualQual": { - "type": "object", - "description": "Manual qualitative supplemental details", - "additionalProperties": { - "type": "object", - "properties": { - "manual_qual": { - "$ref": "#/components/schemas/SupplementalDataManualQual" - } - }, - "required": [ - "manual_qual" - ] - } - }, - "SupplementalDetailsManualTranscription": { - "type": "object", - "description": "Manual transcription supplemental details", - "additionalProperties": { - "type": "object", - "properties": { - "manual_transcription": { - "$ref": "#/components/schemas/SupplementalDataManualTranscription" - } - }, - "required": [ - "manual_transcription" - ] - } - }, - "SupplementalDetailsManualTranslation": { - "type": "object", - "description": "Manual translation supplemental details", - "additionalProperties": { - "type": "object", - "properties": { - "manual_translation": { - "$ref": "#/components/schemas/SupplementalDataManualTranslation" - } - }, - "required": [ - "manual_translation" - ] - } - }, "TagListResponse": { "type": "object", "properties": { diff --git a/static/openapi/schema_v2.yaml b/static/openapi/schema_v2.yaml index 52791a5c63..8bf8410510 100644 --- a/static/openapi/schema_v2.yaml +++ b/static/openapi/schema_v2.yaml @@ -15204,29 +15204,85 @@ components: type: object properties: sector: - type: object + type: + - object + - 'null' + properties: + label: + type: string + value: + type: string + nullable: true country: - type: array + type: + - array + - 'null' items: - type: string + type: object + properties: + label: + type: string + value: + type: string + nullable: true description: type: string collects_pii: - type: string + type: + - object + - 'null' + properties: + label: + type: string + value: + type: string + nullable: true organization: - type: string + type: + - string + - 'null' + nullable: true country_codes: type: array items: type: string operational_purpose: - type: string + type: + - object + - 'null' + properties: + label: + type: string + value: + type: string + nullable: true asset_type: $ref: '#/components/schemas/AssetTypeEnum' files: type: array items: - type: string + type: object + properties: + uid: + type: string + url: + type: string + asset: + type: string + user: + type: string + user__username: + type: string + file_type: + type: string + description: + type: string + date_created: + type: string + content: + type: string + metadata: + type: object readOnly: true summary: type: object @@ -15253,8 +15309,49 @@ components: type: integer name_quality: type: object + properties: + ok: + type: integer + bad: + type: integer + good: + type: integer + total: + type: integer + firsts: + type: object + properties: + ok: + type: object + properties: + name: + type: string + index: + type: integer + label: + type: array + items: + type: string + bad: + type: object + properties: + name: + type: string + index: + type: integer + label: + type: array + items: + type: string default_translation: - type: string + type: + - string + - 'null' + nullable: true + naming_conflicts: + type: array + items: + type: string readOnly: true date_created: type: string @@ -15269,9 +15366,11 @@ components: version_id: type: string readOnly: true + nullable: true version__content_hash: type: string readOnly: true + nullable: true version_count: type: integer readOnly: true @@ -15280,6 +15379,7 @@ components: readOnly: true deployed_version_id: type: string + nullable: true readOnly: true deployed_versions: type: object @@ -15287,9 +15387,15 @@ components: count: type: integer next: - type: string + type: + - string + - 'null' + nullable: true previous: - type: string + type: + - string + - 'null' + nullable: true results: type: array items: @@ -15309,6 +15415,17 @@ components: date_modified: type: string format: date-time + required: + - content_hash + - date_deployed + - date_modified + - uid + - url + required: + - count + - next + - previous + - results readOnly: true deployment__links: type: object @@ -15318,6 +15435,30 @@ components: readOnly: true deployment__data_download_links: type: object + properties: + csv_legacy: + type: string + csv: + type: string + geojson: + type: string + kml_legacy: + type: string + spss_labels: + type: string + xls_legacy: + type: string + xls: + type: string + zip_legacy: + type: string + required: + - csv + - csv_legacy + - kml_legacy + - xls + - xls_legacy + - zip_legacy readOnly: true deployment__submission_count: type: integer @@ -15325,12 +15466,14 @@ components: deployment__last_submission_time: type: string format: date-time + nullable: true readOnly: true deployment__encrypted: type: boolean readOnly: true deployment__uuid: type: string + nullable: true readOnly: true deployment_status: allOf: @@ -15341,26 +15484,120 @@ components: properties: default: type: object + properties: + groupDataBy: + type: string + report_type: + type: string + report_colors: + type: array + items: + type: string + translationIndex: + type: integer + graphWidth: + type: integer specified: type: object - properties: - end: - type: object - start: - type: object kuid_names: type: object - properties: - end: - type: string - start: - type: string report_custom: type: object advanced_features: type: object + properties: + transcript: + type: object + properties: + values: + type: array + items: + type: string + languages: + type: array + items: + type: string + translation: + type: object + properties: + values: + type: array + items: + type: string + languages: + type: array + items: + type: string + qual: + type: object + properties: + qual_survey: + type: array + items: + type: object + properties: + type: + type: string + labels: + type: object + properties: + _default: + type: string + additionalProperties: + type: string + required: + - _default + uuid: + type: string + options: + type: object + properties: + deleted: + type: boolean + xpath: + type: string + scope: + type: string + choices: + type: array + items: + type: object + properties: + labels: + type: object + properties: + _default: + type: string + additionalProperties: + type: string + required: + - _default + uuid: + type: string + options: + type: object + properties: + deleted: + type: boolean + required: + - labels + - uuid + required: + - labels + - scope + - type + - xpath + _version: + type: string map_styles: type: object + properties: + colorSet: + type: string + querylimit: + type: string + selectedQuestion: + type: string map_custom: type: object content: @@ -15372,8 +15609,117 @@ components: type: array items: type: object + properties: + $kuid: + type: string + type: + type: string + $xpath: + type: string + $autoname: + type: string + calculation: + type: string + label: + type: array + items: + type: + - string + - 'null' + nullable: true + hint: + type: array + items: + type: + - string + - 'null' + nullable: true + name: + type: string + required: + type: boolean + appearance: + type: string + parameters: + type: string + kobo--matrix_list: + type: string + kobo--rank-constraint-message: + type: string + kobo--rank-items: + type: string + kobo--score-choices: + type: string + kobo--locking-profile: + type: string + tags: + type: array + items: + type: string + select_from_list_name: + type: string + body::accept: + type: string + additionalProperties: true + required: + - $kuid + - type + choices: + type: array + items: + type: object + properties: + $autovalue: + type: string + $kuid: + type: string + label: + type: array + items: + type: + - string + - 'null' + nullable: true + list_name: + type: string + name: + type: string + media::image: + type: array + items: + type: string + $autoname: + type: string + additionalProperties: true + required: + - $autovalue + - $kuid + - list_name + - name settings: type: object + properties: + name: + type: string + version: + type: string + id_string: + type: string + style: + type: string + form_id: + type: string + title: + type: string + kobo--lock_all: + type: boolean + kobo--locking-profile: + type: string + default_language: + type: + - string + - 'null' + nullable: true translated: type: array items: @@ -15381,7 +15727,20 @@ components: translations: type: array items: - type: string + type: + - string + - 'null' + nullable: true + translations_0: + type: + - string + - 'null' + nullable: true + kobo--locking-profiles: + type: array + items: + type: object + additionalProperties: {} downloads: type: array items: @@ -15391,6 +15750,9 @@ components: type: string url: type: string + required: + - format + - url readOnly: true embeds: type: array @@ -15401,6 +15763,9 @@ components: type: string url: type: string + required: + - format + - url readOnly: true analysis_form_json: type: object @@ -15408,7 +15773,58 @@ components: additional_fields: type: array items: - type: string + type: object + properties: + language: + type: string + source: + type: string + type: + type: string + enum: + - transcript + - translation + - qualVerification + - qualSource + - qualInteger + - qualTags + - qualText + - qualNote + - qualAutoKeywordCount + - qualSelectMultiple + - qualSelectOne + name: + type: string + dtpath: + type: string + label: + type: string + choices: + type: array + items: + type: object + properties: + uuid: + type: string + labels: + type: object + properties: + _default: + type: string + additionalProperties: + type: string + required: + - _default + required: + - labels + - uuid + required: + - dtpath + - name + - source + - type + required: + - additional_fields readOnly: true xform_link: type: string @@ -15440,11 +15856,73 @@ components: type: array items: type: object + properties: + url: + type: string + label: + oneOf: + - type: string + - type: object + properties: + default: + type: string + view_submissions: + type: string + change_submissions: + type: string + delete_submissions: + type: string + validate_submissions: + type: string + required: + - default + required: + - label + - url readOnly: true permissions: type: array items: - type: string + type: object + properties: + url: + type: string + user: + type: string + permission: + type: string + partial_permissions: + type: array + items: + type: object + properties: + url: + type: string + filters: + type: array + items: + type: object + label: + oneOf: + - type: string + - type: object + properties: + default: + type: string + view_submissions: + type: string + change_submissions: + type: string + delete_submissions: + type: string + validate_submissions: + type: string + required: + - default + required: + - permission + - url + - user readOnly: true effective_permissions: type: array @@ -15482,9 +15960,12 @@ components: type: string readOnly: true access_types: - type: array + type: + - array + - 'null' items: type: string + nullable: true readOnly: true data_sharing: type: object @@ -16986,12 +17467,60 @@ components: title: ' submitted by' _supplementalDetails: oneOf: - - $ref: '#/components/schemas/SupplementalDetailsManualTranscription' - - $ref: '#/components/schemas/SupplementalDetailsManualTranslation' - - $ref: '#/components/schemas/SupplementalDetailsAutomaticTranscription' - - $ref: '#/components/schemas/SupplementalDetailsAutomaticTranslation' - - $ref: '#/components/schemas/SupplementalDetailsManualQual' - - $ref: '#/components/schemas/SupplementalDetailsAutomaticQual' + - type: object + description: Manual transcription supplemental details + additionalProperties: + type: object + properties: + manual_transcription: + $ref: '#/components/schemas/SupplementalDataManualTranscription' + required: + - manual_transcription + - type: object + description: Manual translation supplemental details + additionalProperties: + type: object + properties: + manual_translation: + $ref: '#/components/schemas/SupplementalDataManualTranslation' + required: + - manual_translation + - type: object + description: Automatic transcription supplemental details + additionalProperties: + type: object + properties: + automatic_google_transcription: + $ref: '#/components/schemas/SupplementalDataAutomaticTranscription' + required: + - automatic_google_transcription + - type: object + description: Automatic translation supplemental details + additionalProperties: + type: object + properties: + automatic_google_translation: + $ref: '#/components/schemas/SupplementalDataAutomaticTranslation' + required: + - automatic_google_translation + - type: object + description: Manual qualitative supplemental details + additionalProperties: + type: object + properties: + manual_qual: + $ref: '#/components/schemas/SupplementalDataManualQual' + required: + - manual_qual + - type: object + description: Automatic qualitative supplemental details + additionalProperties: + type: object + properties: + automatic_bedrock_qual: + $ref: '#/components/schemas/SupplementalDataAutomaticQual' + required: + - automatic_bedrock_qual nullable: true description: Action-specific supplemental data attached to this submission. Structure varies by action type (transcription, translation, qual). Top-level @@ -17098,6 +17627,8 @@ components: - error - status - uuid + discriminator: + propertyName: status DataSupplementAutomaticQualDataSelectMultipleResponse: type: object additionalProperties: false @@ -17135,6 +17666,8 @@ components: - error - status - uuid + discriminator: + propertyName: status DataSupplementAutomaticQualDataSelectOneResponse: type: object additionalProperties: false @@ -17170,6 +17703,8 @@ components: - error - status - uuid + discriminator: + propertyName: status DataSupplementAutomaticQualDataTextResponse: type: object additionalProperties: false @@ -17204,6 +17739,8 @@ components: - error - status - uuid + discriminator: + propertyName: status DataSupplementManualQualDataInteger: type: object additionalProperties: false @@ -18616,6 +19153,7 @@ components: last_login: type: string format: date-time + nullable: true extra_details: type: object properties: @@ -18650,16 +19188,26 @@ components: newsletter_subscription: type: string git_rev: - type: object - properties: - short: - type: string - long: - type: string - branch: - type: string - tag: - type: string + oneOf: + - type: boolean + - type: object + properties: + short: + oneOf: + - type: string + - type: boolean + long: + oneOf: + - type: string + - type: boolean + branch: + oneOf: + - type: string + - type: boolean + tag: + oneOf: + - type: string + - type: boolean social_accounts: type: array items: @@ -22965,66 +23513,6 @@ components: - _data - _dateCreated - _uuid - SupplementalDetailsAutomaticQual: - type: object - description: Automatic qualitative supplemental details - additionalProperties: - type: object - properties: - automatic_bedrock_qual: - $ref: '#/components/schemas/SupplementalDataAutomaticQual' - required: - - automatic_bedrock_qual - SupplementalDetailsAutomaticTranscription: - type: object - description: Automatic transcription supplemental details - additionalProperties: - type: object - properties: - automatic_google_transcription: - $ref: '#/components/schemas/SupplementalDataAutomaticTranscription' - required: - - automatic_google_transcription - SupplementalDetailsAutomaticTranslation: - type: object - description: Automatic translation supplemental details - additionalProperties: - type: object - properties: - automatic_google_translation: - $ref: '#/components/schemas/SupplementalDataAutomaticTranslation' - required: - - automatic_google_translation - SupplementalDetailsManualQual: - type: object - description: Manual qualitative supplemental details - additionalProperties: - type: object - properties: - manual_qual: - $ref: '#/components/schemas/SupplementalDataManualQual' - required: - - manual_qual - SupplementalDetailsManualTranscription: - type: object - description: Manual transcription supplemental details - additionalProperties: - type: object - properties: - manual_transcription: - $ref: '#/components/schemas/SupplementalDataManualTranscription' - required: - - manual_transcription - SupplementalDetailsManualTranslation: - type: object - description: Manual translation supplemental details - additionalProperties: - type: object - properties: - manual_translation: - $ref: '#/components/schemas/SupplementalDataManualTranslation' - required: - - manual_translation TagListResponse: type: object properties: