Refactor/481476 refactor after lists #481
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor - Service method abstraction
A huge amount of code in the Service methods is a carbon copy. To avoid repetition am suggesting a functional abstraction, where we pass through a callback, and allow the abstraction to handle starting a new session, surfacing errors, logging etc. Appreciate that not everyone is a fan of a functional approach, so can always come up with a more OOP approach (which may reduce complexity at least in the usage). I believe functional makes more sense though in this service as there isn't any OOP. Also understand that this commit may be scrapped.
Positives - will save time in writing simple service methods.
Negatives - does add slightly more complexity
Why is this needed?
The main reasoning behind the abstraction is for every service method we need to:
With the abstraction we know that 2 and 3 are working as expected, so for most tests we only need to check that the abstraction is being called correctly. We need a couple of "integration" tests to check the whole process, but it basically hugely simplify the whole test process, as for the majority of the tests we don't need to test 2/3 and we don't need the mongo mock in the test suite.
On writing the service methods it was very time consuming doing all the above, especially as we have pulled out the services into multiple files (due to SonarLint issues).