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

Refactor, unit tests & add NewBillingBatchService #236

Merged
merged 15 commits into from
May 22, 2023

Conversation

Cruikshanks
Copy link
Member

@Cruikshanks Cruikshanks commented May 21, 2023

https://eaflood.atlassian.net/browse/WATER-3977
https://eaflood.atlassian.net/browse/WATER-3984

This is a follow on from Refactor start of processing a supp. billing batch. In there we needed to refactor the ProcessBillingBatchService to not mix processing a given billing period and the overall billing batch. So, we created ProcessBillingPeriodService and split the functionality between the 2.

But we parked writing any unit tests for our new ProcessBillingBatchService till this PR, else the change would have been massive. Only we hit an issue when we started writing them.

ProcessBillingBatchService in its new form was determining the billing periods, initiating the billing batch record, and generating a response back to the client all whilst kicking off the process for each billing period and handling any errors thrown. It was also responsible for finalising the bill run.

A bit much! The final issue was that background processing was not awaited. This made it a nightmare to try and test all this behaviour.

We realised we needed to get the 'processing' bit in its own service if only to make it testable. So, this change adds a new NewBillingBatchService (yes - we really need to sit down and firm up our naming conventions!)

This is now what is called when kicking off a new billing batch. It deals with determining the billing periods, initiating the billing batch, and generating the response for the client. Essentially, it manages everything to do with a new bill run. It also kicks off ProcessBillingBatchService in the background, which is now solely focused on processing a billing batch; generating the data, handling errors, updating the billing batch status, and finalising it.

With this in place, it meant we could also write some unit tests!

I just can't get this to work properly at the moment.
We really want to test what the ProcessBillingBatchService service _was_ doing in it's `_process()` method. But the way we have designed this is to kick off the processing whilst still returning a response to the client.

This made it extremely painful to test. Then inspiration hit; if we move what `_process()` is doing to its own service we can then test that as normal!

Key thing is that new service really needed to keep the name `ProcessBillingBatchService`! So, we introduce a new service that will be called from the controller, will do all the work of determining the billing periods and creating the initial billing batch record. It will also kick of our ProcessBillingBatchService whilst sending a response back to the controller.
Have it call our new service.
@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label May 21, 2023
@Cruikshanks Cruikshanks self-assigned this May 21, 2023
@Cruikshanks Cruikshanks marked this pull request as ready for review May 21, 2023 09:05
@Cruikshanks Cruikshanks requested review from Jozzey and StuAA78 May 21, 2023 09:05
Copy link
Contributor

@StuAA78 StuAA78 left a comment

Choose a reason for hiding this comment

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

Great stuff 😁 Just a couple of small tweaks I've spotted we could make that might neaten things up a little.

Cruikshanks and others added 2 commits May 22, 2023 10:10
Co-authored-by: Stuart Adair <43574728+StuAA78@users.noreply.github.com>
Co-authored-by: Stuart Adair <43574728+StuAA78@users.noreply.github.com>
@Cruikshanks Cruikshanks requested a review from StuAA78 May 22, 2023 09:27
Cruikshanks and others added 4 commits May 22, 2023 10:53
Co-authored-by: Stuart Adair <43574728+StuAA78@users.noreply.github.com>
In review it was agreed it is more expected that a service returns true if something is done, and false if it isn't.
@Cruikshanks Cruikshanks merged commit c1f491a into main May 22, 2023
@Cruikshanks Cruikshanks deleted the refactor-finalise-to-process-service branch May 22, 2023 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants