-
Notifications
You must be signed in to change notification settings - Fork 0
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 service #400
Conversation
1b48d9b
to
55c81f8
Compare
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 previously added migrations to recreate the CRM_V2 tables `addresses`, `companies` and `invoice_account_addresses` in our test DB. But to keep things simple we normally don't bother with constraints as unless we really need them, we prefer to avoid using them. Well, in the [new Billing Account change address service](#400) we're adding we do! 🤦 We depend on the constraints to raise [ON CONFLICT errors](https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT) for our logic to work. So, in order to test our new service we need to add the missing constraints to our migrations. We're doing that change separately because [Add new Billing Account change address service](#400) is already pretty big 😬.
Just need PR #404 to be merged then the tests should pass and this will be ready to go. |
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. This change is the final part of the backend logic! In this change we add the `ChangeAddressService`. It will be responsible for orchestrating the change address process; letting the [Charging Module API](https://github.com/DEFRA/sroc-charging-module-api) know about the change and updating our own DB. It then needs to generate a response the [water-abstraction-ui](https://github.com/DEFRA/water-abstraction-ui) will understand so it can complete the journey for the user. We're making those changes in [Send change address requests to system in future](DEFRA/water-abstraction-ui#2423).
This works and has been tested locally. But we're still sorting out the documentation and need to add tests for it.
This hooks up the service to the controller. The only bit remaining is to update its tests.
Hopefully this all makes sense and is of value to others.
The tests highlighted some mistakes we had made in the implementation.
cf14f99
to
cff2bd0
Compare
https://eaflood.atlassian.net/browse/WATER-4092 We are migrating the change billing account address functionality from the legacy code to this project. In our test DB, we previously added migrations to recreate the CRM_V2 tables `addresses`, `companies` and `invoice_account_addresses`. But to keep things simple we usually don't bother with constraints as unless we really need them, we prefer to avoid using them. Well, in the [new Billing Account change address service](#400) we're adding we do! 🤦 We depend on the constraints to raise [ON CONFLICT errors](https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT) for our logic to work. So, in order to test our new service we need to add the missing constraints to our migrations. We're doing that change separately because [Add new Billing Account change address service](#400) is already pretty big 😬. --- When we did apply the constraints it highlighted we had a flaw in our model tests. The top-level `beforeEach()` should only have been cleaning the DB. The model tests also had to be updated to deal with creating 2 invoice address records using the same default data; we can't have multiple records with the same start date and invoice account ID.
Now changeaddressservice is used in the controller the test can be expanded.
@Jozzey @Beckyrose200 @StuAA78 This is a big one and I've broken out as much as I could into other PR's. So, if you need me to walk through it before you review do let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't have time for a full review but on a first pass it all looks good! Just a few minor comments 😁
* @param {module:AddressModel} address the new address to be persisted (expected to be populated) | ||
* @param {module:CompanyModel} company the new agent company to be persisted (not expected to be populated) | ||
* @param {module:ContactModel} contact the new contact to be persisted (not expected to be populated) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a little figuring out to realise that when we say "expected to be populated" and "not expected to be populated", it's because agentCompany
and contact
are optional when calling the service but we always transform the day we receive (empty or not) into companyInstance
and contactInstance
. A little note in the comments to note why those two may not be populated might be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added extra comments. Hopefully that helps.
@@ -0,0 +1,424 @@ | |||
'use strict' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a general point, all of our tests call ChangeAddressService.go()
with agentCompany
and contact
. Presumably some of these tests are passing in empty values but is it worth having at least one test that doesn't pass these in, just to confirm/document the defaulting of these to empty objects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test and it made me think about what the service returns. So, also helped me clean things up a bit. Thank you!
Co-authored-by: Stuart Adair <43574728+StuAA78@users.noreply.github.com>
Based on feedback these extra comments try to explain why we talk about address, company and contact being 'populated' or not.
Feedback in the PR suggested we have an explicit test that covers the service handling a null agent company and contact. After implementing the test we realised the response from the service was 'dirty' and confusing. If you passed in a null `agentCompany` you would expect to get a null `agentCompany` out. So, we also took this opportunity to clean up the response from the service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from what I can tell, added a few comments :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://eaflood.atlassian.net/browse/WATER-4092
We are migrating the change billing account address functionality from the legacy code to this project. This change is the final part of the backend logic!
In this change, we add the
ChangeAddressService
. It will be responsible for orchestrating the change address process; letting the Charging Module API know about the change and updating our own DB.It then needs to generate a response that the water-abstraction-ui will understand so it can complete the journey for the user. We're making those changes in Send change address requests to system in future.