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

Improve spec for Spree::Order#finalize! #12662

Merged
merged 5 commits into from
Jul 15, 2024

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Jul 11, 2024

What? Why?

I was looking at existing specs around stock allocation when an order is completed. And I stumbled across some ineffective specs of the Order model which I fixed here.

What should we test?

  • Specs only.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

mkllnk added 5 commits July 11, 2024 15:42
This is more realistic and robust. Don't mock the class under test (even
though `touch` is actually provided by Active Record).
The spec was asserting on all shipments of the order but there were one.
In consequence, the spec didn't assert anything. Now I set up a shipment
that is asserted on. I'm stil not sure how useful this spec is though.
The next test case wasn't asserting anything as well. The referenced
method `decrease_stock_for_variant` doesn't actually exist.
It's more realistic this way.
@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Jul 11, 2024
@mkllnk mkllnk self-assigned this Jul 11, 2024
@mkllnk mkllnk marked this pull request as ready for review July 11, 2024 07:24
Comment on lines -232 to -235
order.shipments.each do |shipment|
expect(shipment).to receive(:update!)
expect(shipment).to receive(:finalize!)
end
Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the typo in the commit message. order.shipments was empty.

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice find ! It's interesting to find out another way that spec can fail to test anything. Are shipments actually used in OFN ?

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great improvements 💯

order.reload
}.to change {
order.completed_at
}.from(nil)
Copy link
Member

Choose a reason for hiding this comment

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

Nice way to test this. I probably would have gone down the unnecessary task of freezing time and checking it changed to the current time..

@dacook dacook merged commit a66fec0 into openfoodfoundation:master Jul 15, 2024
53 checks passed
@mkllnk mkllnk deleted the order-finalise-spec branch August 2, 2024 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants