Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APS-884: Future Manager creates out-of-service bed record from "v2 manage" #1964

Merged
merged 12 commits into from
Jul 8, 2024

Conversation

edavey
Copy link
Contributor

@edavey edavey commented Jul 3, 2024

This PR implements the "Future manager creates an out-of-service bed record" and incorporates:

  • APS-953: validate presence of OOSB "notes"
  • APS-956: obtain "reasons" from new CAS1 reference data endpoint
  • APS-910: redirect on success to v2 bed page with improved flash notification

server/data/cas1ReferenceDataClient.test.ts Dismissed Show dismissed Hide dismissed
@edavey edavey force-pushed the APS-884-create-oosb branch 4 times, most recently from 1928f95 to 784f588 Compare July 4, 2024 17:45
@edavey edavey marked this pull request as ready for review July 4, 2024 17:46
@edavey edavey requested review from patrickjfl and richpjames July 4, 2024 17:46
@edavey edavey changed the title APS-884: Create out of service bed record APS-884: Manager creates out of service bed record from "v2 manage" Jul 4, 2024
@edavey edavey changed the title APS-884: Manager creates out of service bed record from "v2 manage" APS-884: Future Manager creates out-of-service bed record from "v2 manage" Jul 4, 2024
@edavey edavey force-pushed the APS-884-create-oosb branch from 784f588 to 14336a1 Compare July 4, 2024 17:53
server/i18n/en/errors.json Outdated Show resolved Hide resolved
server/utils/bedUtils.test.ts Outdated Show resolved Hide resolved
e2e/pages/manage/v2MarkBedAsOutOfServicePage.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@richpjames richpjames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the int tests are passing :)

@edavey edavey force-pushed the APS-884-create-oosb branch from 14336a1 to a8e58ed Compare July 8, 2024 09:59
We rename OutOfService date fields:

- outOfServiceFrom -> startDate
- outOfServiceTo -> endDate

to line up with the actual fields implemented at the API, see
[OpenAPI spec][].

---

This commit includes a change to the `errors.json` translation file
which converts field and error keys sent by the API to human error
messages which map to form fields in the DOM -- to which we need to
apply error styling.

The system of "translating" validation errors messages sent from
the API works like this ([see validation error code in the API][]):

1. FROM THE ENTITY LAYER

For validation errors raised from the entity level, by virtue of
a field being non-nullable, the `propertyName` is automatically
used as the field key e.g.

```
data: {
  "title": "Bad Request",
  "status": 400,
  "detail": "There is a problem with your request",
  "invalid-params": [
    {
      "propertyName": "$.endDate",
      "errorType": "empty"
    },
  ]
}
```

2. FROM THE SERVICE LAYER

PROBLEM: HOW TO DISTINGUISH BETWEEN `foo.notes` and `bar.notes`?

Where we have custom validations which are not set at the db level
we can set a bespoke `propertyName` -- but this won't allow us to
have consistent and unique propertyNames e.g. for 3 entities which
all have a `notes` property

 - `LostBedNotes`
 - `OutOfServiceBedNotes`
 - `AnOtherEntityNotes`

[OpenAPI spec]:
https://approved-premises-api-dev.hmpps.service.justice.gov.uk/swagger-ui/index.html?urls.primaryName=CAS1%20API#/out-of-service%20beds/post_premises__premisesId__out_of_service_beds

[validation error code in the API]:
https://github.com/ministryofjustice/hmpps-approved-premises-api/blob/79ed9528719e6829cbac5ecd2a46ce3e21390e72/src/main/kotlin/uk/gov/justice/digital/hmpps/approvedpremisesapi/results/ValidatableActionResult.kt#L6-L27
@edavey edavey force-pushed the APS-884-create-oosb branch from a8e58ed to 3fa2be1 Compare July 8, 2024 16:34
@edavey edavey force-pushed the APS-884-create-oosb branch from 3fa2be1 to a044fe6 Compare July 8, 2024 16:52
edavey added 2 commits July 8, 2024 18:19
We start a new `/e2e/tests/v2Manage.spec` file to compartmentalise these
user journeys, starting with:

> Future manager marks a bed as out of service in the V2 Manage area
>
>   Given I am signed in as a future manager
>   And I am on the list of premises page
>
>   When choose to view the detail of a particular premises
>   Then I should see the premises page
>
>   When I choose to manage its beds
>   And I pick a particular bed to manage
>   Then I see the V2 Bed page
>   And I should be able to mark a bed as out of service
>
>   When I fill in and submit the v2 Manage out-of-service-bed form
>   Then I am redirected back to the V2 bed page
>   And I see the success message on the 'history' pane of the bed page

The differences in v2/v1 behaviour are achieved with:

- a new `v2BedLink()` 'Manage (bed)' link used on the premises' bed list to
  link to the new v2 bed page

- a new `v2BedActions()` widget which offers FUTURE_MANAGER the
  link to the new v2 "create out of service bed" form from the v2
  bed page

Also: the "Future manager creates V2 OOSB record" was duplicated in
both:

1. `integration_tests/tests/v2Manage/beds.cy.ts` and
2. `integration_tests/tests/v2Manage/outOfServiceBeds.cy.ts`

We delete [1].
This tidy up is unrelated to the PR so feel free to move or drop.
@edavey edavey force-pushed the APS-884-create-oosb branch from a044fe6 to 4f95a15 Compare July 8, 2024 17:19
@edavey edavey merged commit 873207d into main Jul 8, 2024
7 checks passed
@edavey edavey deleted the APS-884-create-oosb branch July 8, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants