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

Create return cycle #1353

Merged
merged 17 commits into from
Oct 1, 2024
Merged

Create return cycle #1353

merged 17 commits into from
Oct 1, 2024

Conversation

robertparkinson
Copy link
Collaborator

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

As part of the work to replace the legacy system NALD we need to generate return logs. This PR creates a return cycle if one does not already exist and adds it to the return log

Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

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

I have some suggested changes from a first pass. Give me a ping if you have any questions/challeneges.

app/models/return-cycle.model.js Outdated Show resolved Hide resolved
test/support/helpers/return-cycle.helper.js Outdated Show resolved Hide resolved
Copy link
Member

@Cruikshanks Cruikshanks left a comment

Choose a reason for hiding this comment

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

Just some minor suggested changes

test/models/return-log.model.test.js Outdated Show resolved Hide resolved
@robertparkinson robertparkinson merged commit 08c3cff into main Oct 1, 2024
6 checks passed
@robertparkinson robertparkinson deleted the create-return-cycle branch October 1, 2024 09:46
Cruikshanks added a commit that referenced this pull request Oct 10, 2024
When attempting to run the acceptance tests we found most of them were now failing. After investigating we tracked it down to a [recent change made](#1353) to the `ReturnLogHelper`.

We started setting `returnCycleId` to a generated UUID. Normally, return logs have this set to the return cycle they fall within. However, if it is set (in the DB proper) the ID _must_ exist in `return.return_cycles`.

We've opted not to replicate foreign key constraints in our test DB legacy migrations because of the additional complexity they would add to our unit tests, for something we don't need to cover in them.

It wasn't being set before, because our premise for the helpers is they set _only_ what is required in order to insert a record. Any fields that are 'optional', are expected to be set within the test using the helper and passed in.

Fortunately, removing the call in the helper hasn't broken any existing tests, further highlighting we don't really need this defaulted for what we are testing. And removing the call gets the acceptance tests passing again!
Cruikshanks added a commit that referenced this pull request Oct 10, 2024
https://eaflood.atlassian.net/browse/WATER-4543

In [Create return cycle](#1353) we added a new seeder for return cycles.

They are part reference, part transactional records. When starting with a clean environment you would need to seed existing return cycles. Going forward, they are automatically created as part of creating returns logs. When we come to creating the first return log for a cycle, if the cycle record does not exist then we create it.

When we added the seeder though, the query we wrote was purely an insert. It should have been an `upsert` because seeders need to be written in such a way they can be run multiple times against the same environment (both test and 'real').

This fixes the query used to actually be an upsert.
Cruikshanks added a commit that referenced this pull request Oct 10, 2024
When attempting to run the acceptance tests we found most of them were now failing. After investigating we tracked it down to a [recent change made](#1353) to the `ReturnLogHelper`.

We started setting `returnCycleId` to a generated UUID. Normally, return logs have this set to the return cycle they fall within. However, if it is set (in the DB proper) the ID _must_ exist in `return.return_cycles`.

We've opted not to replicate foreign key constraints in our test DB legacy migrations because of the additional complexity they would add to our unit tests, for something we don't need to cover in them.

It wasn't being set before, because our premise for the helpers is they set _only_ what is required in order to insert a record. Any fields that are 'optional', are expected to be set within the test using the helper and passed in.

Fortunately, removing the call in the helper hasn't broken any existing tests, further highlighting we don't really need this defaulted for what we are testing. And removing the call gets the acceptance tests passing again!
Cruikshanks added a commit that referenced this pull request Oct 10, 2024
https://eaflood.atlassian.net/browse/WATER-4543

In [Create return cycle](#1353) we added a new seeder for return cycles.

They are part reference and part transactional records. When starting with a clean environment, you would need to seed existing return cycles. Going forward, they are automatically created as part of creating return logs. When we create the first return log for a cycle, if the cycle record does not exist, we make it.

When we added the seeder, though, the query we wrote was purely an insert. It should have been an `upsert` because seeders need to be written so they can be run multiple times against the same environment (both test and 'real').

This fixes the query used to actually be an upsert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants