From a7e70a8894779e0439fad95c0736225ff4a8e465 Mon Sep 17 00:00:00 2001 From: Dave A <168838504+daveawc@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:58:26 +0000 Subject: [PATCH] Updates for generating the UI code from generated swagger docs This PR updates the code so that we can successfully generate the UI code when using auto-generated swagger documentaton. The changes are: * The `AnyValue` class now generates as `Unit`, so this has been updated * There are a number of ArrayOfOasys.... classes that are just lists of Oasys questions with different names. These have been removed to just use OasysQuestion[] --- cypress_shared/helpers/apply.ts | 17 +++++------ cypress_shared/helpers/index.ts | 28 ++++++++----------- .../riskManagementPlan.ts | 5 ++-- integration_tests/mockApis/assessments.ts | 7 ++--- server/@types/ui/index.d.ts | 14 ++-------- .../riskManagementPlan.ts | 7 ++--- 6 files changed, 27 insertions(+), 51 deletions(-) diff --git a/cypress_shared/helpers/apply.ts b/cypress_shared/helpers/apply.ts index 3c2e58799..903ee9846 100644 --- a/cypress_shared/helpers/apply.ts +++ b/cypress_shared/helpers/apply.ts @@ -1,13 +1,10 @@ import { ActiveOffence, Adjudication, - ArrayOfOASysOffenceDetailsQuestions, - ArrayOfOASysRiskManagementPlanQuestions, - ArrayOfOASysRiskOfSeriousHarmSummaryQuestions, - ArrayOfOASysRiskToSelfQuestions, - ArrayOfOASysSupportingInformationQuestions, Document, + OASysQuestion, OASysSection, + OASysSupportingInformationQuestion, Person, PersonAcctAlert, TemporaryAccommodationApplication, @@ -112,15 +109,15 @@ export default class ApplyHelper { otherOasysSections: Array = [] - roshSummaries: ArrayOfOASysRiskOfSeriousHarmSummaryQuestions = [] + roshSummaries: Array = [] - offenceDetailSummaries: ArrayOfOASysOffenceDetailsQuestions = [] + offenceDetailSummaries: Array = [] - supportingInformationSummaries: ArrayOfOASysSupportingInformationQuestions = [] + supportingInformationSummaries: Array = [] - riskManagementPlanSummaries: ArrayOfOASysRiskManagementPlanQuestions = [] + riskManagementPlanSummaries: Array = [] - riskToSelfSummaries: ArrayOfOASysRiskToSelfQuestions = [] + riskToSelfSummaries: Array = [] adjudications: Array = [] diff --git a/cypress_shared/helpers/index.ts b/cypress_shared/helpers/index.ts index ad8001a3e..1f7518eb3 100644 --- a/cypress_shared/helpers/index.ts +++ b/cypress_shared/helpers/index.ts @@ -1,32 +1,26 @@ -import { - ArrayOfOASysOffenceDetailsQuestions, - ArrayOfOASysRiskManagementPlanQuestions, - ArrayOfOASysRiskOfSeriousHarmSummaryQuestions, - ArrayOfOASysRiskToSelfQuestions, - ArrayOfOASysSupportingInformationQuestions, -} from '@approved-premises/api' +import { OASysQuestion, OASysSupportingInformationQuestion } from '@approved-premises/api' import { TableRow } from '@approved-premises/ui' import oasysDataJson from '../fixtures/oasysData.json' -const roshSummariesFromJson = (): ArrayOfOASysRiskOfSeriousHarmSummaryQuestions => { - return oasysDataJson['rosh-summary'].roshSummaries as ArrayOfOASysRiskOfSeriousHarmSummaryQuestions +const roshSummariesFromJson = (): Array => { + return oasysDataJson['rosh-summary'].roshSummaries as Array } -const offenceDetailSummariesFromJson = (): ArrayOfOASysOffenceDetailsQuestions => { - return oasysDataJson['offence-details'].offenceDetailsSummaries as ArrayOfOASysOffenceDetailsQuestions +const offenceDetailSummariesFromJson = (): Array => { + return oasysDataJson['offence-details'].offenceDetailsSummaries as Array } -const supportInformationFromJson = (): ArrayOfOASysSupportingInformationQuestions => { +const supportInformationFromJson = (): Array => { return oasysDataJson['supporting-information'] - .supportingInformationSummaries as ArrayOfOASysSupportingInformationQuestions + .supportingInformationSummaries as Array } -const riskManagementPlanFromJson = (): ArrayOfOASysRiskManagementPlanQuestions => { - return oasysDataJson['risk-management-plan'].riskManagementSummaries as ArrayOfOASysRiskManagementPlanQuestions +const riskManagementPlanFromJson = (): Array => { + return oasysDataJson['risk-management-plan'].riskManagementSummaries as Array } -const riskToSelfSummariesFromJson = (): ArrayOfOASysRiskToSelfQuestions => { - return oasysDataJson['risk-to-self'].riskToSelfSummaries as ArrayOfOASysRiskToSelfQuestions +const riskToSelfSummariesFromJson = (): Array => { + return oasysDataJson['risk-to-self'].riskToSelfSummaries as Array } const tableRowsToArrays = (tableRows: Array): Array> => { diff --git a/cypress_shared/pages/apply/assess-placement-risks-and-needs/placement-considerations/riskManagementPlan.ts b/cypress_shared/pages/apply/assess-placement-risks-and-needs/placement-considerations/riskManagementPlan.ts index 670229128..f2b6c6f75 100644 --- a/cypress_shared/pages/apply/assess-placement-risks-and-needs/placement-considerations/riskManagementPlan.ts +++ b/cypress_shared/pages/apply/assess-placement-risks-and-needs/placement-considerations/riskManagementPlan.ts @@ -1,12 +1,11 @@ -import type { TemporaryAccommodationApplication } from '@approved-premises/api' -import { ArrayOfOASysRiskManagementPlanQuestions } from '../../../../../server/@types/shared' +import type { OASysQuestion, TemporaryAccommodationApplication } from '@approved-premises/api' import paths from '../../../../../server/paths/apply' import ApplyPage from '../../applyPage' export default class RiskManagementPlanPage extends ApplyPage { constructor( application: TemporaryAccommodationApplication, - private readonly riskRiskManagementPlanSummaries: ArrayOfOASysRiskManagementPlanQuestions, + private readonly riskRiskManagementPlanSummaries: Array, private readonly oasysMissing: boolean, ) { super( diff --git a/integration_tests/mockApis/assessments.ts b/integration_tests/mockApis/assessments.ts index f2f8f8657..9af305bee 100644 --- a/integration_tests/mockApis/assessments.ts +++ b/integration_tests/mockApis/assessments.ts @@ -1,5 +1,5 @@ import type { SuperAgentRequest } from 'superagent' -import { AnyValue, Assessment, AssessmentSummary } from '../../server/@types/shared' +import { Assessment, AssessmentSummary, Unit } from '../../server/@types/shared' import api from '../../server/paths/api' import { getMatchingRequests, stubFor } from '../../wiremock' @@ -167,10 +167,7 @@ export default { jsonBody: {}, }, }), - stubUpdateAssessmentError: (args: { - assessment: Assessment - errorBody: Record - }): SuperAgentRequest => + stubUpdateAssessmentError: (args: { assessment: Assessment; errorBody: Record }): SuperAgentRequest => stubFor({ request: { method: 'PUT', diff --git a/server/@types/ui/index.d.ts b/server/@types/ui/index.d.ts index 0a1cf210e..1390c0f11 100644 --- a/server/@types/ui/index.d.ts +++ b/server/@types/ui/index.d.ts @@ -1,19 +1,16 @@ import { Adjudication, TemporaryAccommodationApplicationSummary as ApplicationSummary, - ArrayOfOASysOffenceDetailsQuestions, - ArrayOfOASysRiskManagementPlanQuestions, - ArrayOfOASysRiskOfSeriousHarmSummaryQuestions, - ArrayOfOASysRiskToSelfQuestions, - ArrayOfOASysSupportingInformationQuestions, TemporaryAccommodationAssessment as Assessment, AssessmentSortField, AssessmentStatus, BookingSearchSortField, Document, LocalAuthorityArea, + OASysQuestion, OASysSection, OASysSections, + OASysSupportingInformationQuestion, PersonAcctAlert, PersonRisks, PrisonCaseNote, @@ -261,12 +258,7 @@ export interface GroupedApplications { submitted: Array } -export type OasysImportArrays = - | ArrayOfOASysOffenceDetailsQuestions - | ArrayOfOASysRiskOfSeriousHarmSummaryQuestions - | ArrayOfOASysSupportingInformationQuestions - | ArrayOfOASysRiskToSelfQuestions - | ArrayOfOASysRiskManagementPlanQuestions +export type OasysImportArrays = Array | Array export type JourneyType = 'applications' | 'assessments' diff --git a/server/form-pages/apply/assess-placement-risks-and-needs/placement-considerations/riskManagementPlan.ts b/server/form-pages/apply/assess-placement-risks-and-needs/placement-considerations/riskManagementPlan.ts index 18f60ac78..e83095a83 100644 --- a/server/form-pages/apply/assess-placement-risks-and-needs/placement-considerations/riskManagementPlan.ts +++ b/server/form-pages/apply/assess-placement-risks-and-needs/placement-considerations/riskManagementPlan.ts @@ -1,7 +1,4 @@ -import { - TemporaryAccommodationApplication as Application, - ArrayOfOASysRiskManagementPlanQuestions, -} from '@approved-premises/api' +import { TemporaryAccommodationApplication as Application, OASysQuestion } from '@approved-premises/api' import type { DataServices, OasysPage, PersonRisksUI } from '@approved-premises/ui' import { Page } from '../../../utils/decorators' @@ -11,7 +8,7 @@ import { getOasysSections, oasysImportReponse, validateOasysEntries } from '../. export type RiskManagementPlanBody = { version: string riskManagementAnswers: Record - riskManagementSummaries: ArrayOfOASysRiskManagementPlanQuestions + riskManagementSummaries: Array oasysImported: string oasysCompleted: string }