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

Add new billing account change address validator #383

Merged
merged 5 commits into from
Aug 29, 2023

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-4092

We use validators to 'validate' incoming payloads. This new validator will be used to check the content of a request to our new /billing-accounts/{id}/change-address endpoint.

Though the journey in the UI starts with clicking a Change address button during the process you can also change the company and contact linked to the billing account as well.

This is why we need to cater for all 3 possibly being sent in the payload.

The Joi schema we've compiled comes from what we found is currently being used in the legacy code (water-abstraction-service/src/modules/invoice-accounts/routes.js).

@Cruikshanks Cruikshanks added the enhancement New feature or request label Aug 25, 2023
@Cruikshanks Cruikshanks self-assigned this Aug 25, 2023
@Cruikshanks Cruikshanks force-pushed the add-change-address-validator branch 3 times, most recently from cf933e3 to 9544512 Compare August 25, 2023 14:03
https://eaflood.atlassian.net/browse/WATER-4092

We use validators to 'validate' incoming payloads. This new validator will be used to check the content of a request to our new `/billing-accounts/{id}/change-address` endpoint.

Though the journey in the UI starts with clicking a **Change address** button during the process you can also change the company and contact linked to the billing account as well.

This is why we need to cater for all 3 possibly being sent in the payload.

The [Joi](https://joi.dev/) schema we've compiled comes from what we found is currently being used in the legacy code (`water-abstraction-service/src/modules/invoice-accounts/routes.js`).
@Cruikshanks Cruikshanks force-pushed the add-change-address-validator branch from 9544512 to 3f71f8c Compare August 29, 2023 10:56
Cruikshanks added a commit that referenced this pull request Aug 29, 2023
https://eaflood.atlassian.net/browse/WATER-4092

WATER-4092 will require us to add a new 'validator'. These are the modules that contain [Joi](https://joi.dev/) schemas we use to check inbound request payloads.

Whilst working on [Add new billing account change address validator](#383) we spotted a few things we wanted to change on the existing validator. As we only have the one, now seemed a good time to make the changes.

- fix the test filename (we'd omitted `.test`)
- move it out of the `/bill-runs` folder

On that last one, similar to [Refactor controllers out of folders](#368) if we find we have lots of validators in the future we'll likely move them into folders. But right now it feels pre-emptive.
These lists are used when validating the address, contact and company data used when changing a billing account's address.
The invalid tests just focus on those that involve checking a value is in one of our static lookups. Those checks in the schema depend on another area of our code so it felt worth while including tests for them.

We have a test to show that `address:` is a required property. Beyond that it felt like we'd just be testing Joi which is why every possible invalid data scenario is not covered.
TBH 50/50 on whether this improves things or not. We hope it makes the schemas for the individual properties easy to see and understand so we're going for it.

There is an argument though that seeing the whole schema in one place makes it easier to see what Joi is doing. ¯\_(ツ)_/¯
@Cruikshanks Cruikshanks force-pushed the add-change-address-validator branch from 4b89656 to 7f121f3 Compare August 29, 2023 11:25
@Cruikshanks Cruikshanks marked this pull request as ready for review August 29, 2023 11:29
Cruikshanks added a commit that referenced this pull request Aug 29, 2023
https://eaflood.atlassian.net/browse/WATER-4092

WATER-4092 will require us to add a new 'validator'. These modules contain [Joi](https://joi.dev/) schemas we use to check inbound request payloads.

Whilst working on [Add new billing account change address validator](#383) we spotted a few things we wanted to change on the existing validator. As we only have one, now seemed a good time to make the changes.

- fix the test filename (we'd omitted `.test`)
- move it out of the `/bill-runs` folder

On that last one, similar to [Refactor controllers out of folders](#368) if we find we have lots of validators in the future we'll likely move them into folders. But right now it feels pre-emptive.
@Cruikshanks Cruikshanks merged commit 9f7e07c into main Aug 29, 2023
@Cruikshanks Cruikshanks deleted the add-change-address-validator branch August 29, 2023 13:20
Cruikshanks added a commit that referenced this pull request Aug 31, 2023
https://eaflood.atlassian.net/browse/WATER-4092

We are working on migrating the change billing account address functionality from the legacy code to this project.

We've previously added a new endpoint and controller that the UI will start using instead of the legacy one. But it is only a dummy, just returning a `201` in response to requests.

This change adds the [new change address validator](#383) to the controller. It will mean the controller can validate the incoming requests and handle errors resulting from invalid data.

A future final step will add in a new `ChangeAddressService`.
Cruikshanks added a commit that referenced this pull request Sep 1, 2023
https://eaflood.atlassian.net/browse/WATER-4092

We are working on migrating the change billing account address functionality from the legacy code to this project.

We've previously added a new endpoint and controller that the UI will start using instead of the legacy one. But it is only a dummy, just returning a `201` in response to requests.

This change adds the [new change address validator](#383) to the controller. It will mean the controller can validate the incoming requests and handle errors resulting from invalid data.

A future final step will add in a new `ChangeAddressService`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants