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

Move getting the licence holder to the model #683

Merged
merged 7 commits into from
Jan 24, 2024

Conversation

Cruikshanks
Copy link
Member

https://eaflood.atlassian.net/browse/WATER-4188
https://eaflood.atlassian.net/browse/WATER-4328

Much like in Move licence end date logic to model we have another two tickets that need to identify the licence holder for a licence. We've already figured out how to do that in Add licence ref. and holder to rtn. req. session.

But that implementation was specific to return requirements and unlike myContact.$name() and myLicence.$ends() to determine the licence holder you need to have pulled through a series of related models.

So, for the same reasons we want to move this piece of logic to the model to make it easier to reuse. However, there will be differences in implementation.

This change adds the logic to the model and then refactors InitiateReturnRequirementSessionService to demonstrate how to use it.

https://eaflood.atlassian.net/browse/WATER-4188
https://eaflood.atlassian.net/browse/WATER-4328

Much like in [Move licence end date logic to model](#681) we have another two tickets that need to identify the licence holder for a licence. We've already figured out how to do that in [Add licence ref. and holder to rtn. req. session](#639).

But that implementation was specific to return requirements and unlike `myContact.$name()` and `myLicence.$ends()` to determine the licence holder you need to have pulled through a series of related models.

So, for the same reasons we want to move this piece of logic to the model to make it easier to reuse. However, their will be differences in implementation.

This change adds the logic to the model and then refactors `InitiateReturnRequirementSessionService` to demonstrate how to use it.
@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Jan 23, 2024
@Cruikshanks Cruikshanks self-assigned this Jan 23, 2024
The first step to make this reusable is to make the query needed to fetch the additional records reusable.

Thankfully, Objection.js has the concept of [modifiers](https://vincit.github.io/objection.js/recipes/modifiers.html), reusable query components we can chain to queries we build.

We also tweak `InitiateReturnRequirementSessionService` to use the modifier and prove the query still works thanks to the unit tests still passing.
Again, because of the existing tests for `InitiateReturnRequirementSessionService` we can move the functionality to the model, update the service and confirm everything still works as expected.
We want the custom instance method tested within the model tests. Because these instance methods rely on the right data being available in the instance we also end up testing the modifier. This was the approach we took on [sroc-charging-module-api](https://github.com/DEFRA/sroc-charging-module-api); we add modifiers because numerous things depend on them and they are better tested through those things.
Because we cover the edge case for the query in our model tests we don't need to cover them in the `InitiateReturnRequirementSessionService` tests. So, we can simplify things there.
On review realised we didn't have test coverage for `$licenceHolder()` being called on an instance that has not been created with the `licenceDocument` and related properties instantiated.

That flagged we'd forgotten the optional chaining! So, we fix that as well.
@Cruikshanks Cruikshanks marked this pull request as ready for review January 23, 2024 18:51
Copy link
Contributor

@Beckyrose200 Beckyrose200 left a comment

Choose a reason for hiding this comment

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

@Cruikshanks Cruikshanks merged commit 31fe625 into main Jan 24, 2024
6 checks passed
@Cruikshanks Cruikshanks deleted the move-licence-holder-logic-to-licence branch January 24, 2024 09:37
robertparkinson pushed a commit that referenced this pull request Jan 24, 2024
https://eaflood.atlassian.net/browse/WATER-4188
https://eaflood.atlassian.net/browse/WATER-4328

Much like in [Move licence end date logic to model](#681) we have another two tickets that need to identify the licence holder for a licence. We've already figured out how to do that in [Add licence ref. and holder to rtn. req. session](#639).

But that implementation was specific to return requirements and unlike `myContact.$name()` and `myLicence.$ends()` to determine the licence holder you need to have pulled through a series of related models.

So, for the same reasons we want to move this piece of logic to the model to make it easier to reuse. However, there will be differences in implementation.

This change adds the logic to the model and then refactors `InitiateReturnRequirementSessionService` to demonstrate how to use it.
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