-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
Report subscription failures #7207
Report subscription failures #7207
Conversation
engines/order_management/spec/services/order_management/subscriptions/summary_spec.rb
Outdated
Show resolved
Hide resolved
it "records an error " do | ||
expect(job).to receive(:record_subscription_issue) | ||
expect(job).to_not receive(:place_order) | ||
job.send(:place_proxy_order, proxy_order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird, I tried to execute this test and I get "NoMethodError: undefined method `place_proxy_order' for #SubscriptionPlacementJob:0x000055d45d802fa0"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
besides, something is wrong if need to unit test a private method. IMO this is a clear symptom that the existing design doesn't allow for proper testing and should be improved.
I offer myself ☝️ if you think I can be of any help getting this sorted out. |
15d21e2
to
5c94095
Compare
Thanks for the review @sauloperez. I made a couple changes that are marginal improvements, but agree that there's quite a bit that could still be improved about subscriptions. I didn't change the spec that tests the private method, however; we test other private methods in the same spec file, was my thinking with that, and to call What do you think about these changes? Would you want to proceed with the PR, or wait until we can do some more refactoring on subscriptions? I don't know where that would fit in a priority list. |
5c94095
to
61a3931
Compare
IMO given we've introduced a new feature (yes, rather small but still a new feature) it's on us to adequate the underlying OOP design to better fit this new requirement so we keep things changeable. It's part of the job and the more we neglect it that it'll get overtime. In any case, this is not fixing the specific user error on #7063 but improves the experience if this were to happen again, right? so we're not rushing. So, there are various code smells that lead me to think that we need to extract a class and move there the private methods that we're testing. A simple case of Extract Class. As a result, tests will probably require less setup and become easier to read, which is always good. The code smells that come to mind are:
For the record, I used reek and churn to assess the situation. |
@@ -56,6 +56,15 @@ module Subscriptions | |||
end | |||
end | |||
|
|||
describe "record_subscription_issue" do | |||
let(:subscription) { double(:subscription, id: 101) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should rely on an RSpec's verifying double such as https://relishapp.com/rspec/rspec-mocks/docs/verifying-doubles/using-an-instance-double to avoid the double drifting away from Susbcription's interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth it if the only method being used is #id
?
@@ -81,6 +90,21 @@ module Subscriptions | |||
summary.instance_variable_set(:@success_ids, success_ids) | |||
expect(summary.issue_count).to be 2 # 7 & 9 | |||
end | |||
|
|||
context "when there are also subscription issues" do | |||
let(:subscription) { double(:subscription, id: 101) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here as well
|
||
context "when there are also subscription issues" do | ||
let(:subscription) { double(:subscription, id: 101) } | ||
let(:order) { double(:order, id: 1) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the same happens with the order. We must ensure we don't diverge from Spree::Order
's public API.
Sorry for the wall of text, but I wanted to stress the need to improve subs. I'm sorry you're paying the price 😅 I have an attempt halfway through at #7281. What do you think? |
I think we can move forward with this while we finish off #7281. Then that'll be just a refactoring which will ease reviews. |
Codecov Report
@@ Coverage Diff @@
## master #7207 +/- ##
=========================================
Coverage ? 89.69%
=========================================
Files ? 648
Lines ? 18857
Branches ? 0
=========================================
Hits ? 16913
Misses ? 1944
Partials ? 0 Continue to review full report at Codecov.
|
Hey @andrewpbrett , Not sure what to test here. I looked at the original issue, which seems to relate to situations where: Looking at your code:
I tried to reproduce the bug with the hints from the issue, but wasn't really successful. Did a brief sanity check, around:
While I think these are valid tests, it probably would be interesting to test the changes this PR introduces on the email. We'd need to reproduce the bug for this. What do you think? Other than this, I guess we can merge. |
What about:
Maybe worth a try... |
@filipefurtad0 - yes, if you manually set the price to nil on a variant in a subscription, you should see an example of the changes in the emails that go out. That was what I did as a dev-test; I think what you already did (making sure there weren't any big changes to existing behavior) was a good general test and we could probably go ahead and merge with just that. But if you did want to see it in action, manually setting a price to nil should do it. |
Ok, I was not aware you've tested this scenario before, I just gave it a try on staging-UK. I just made these changes on the relevant variant: Before staging this PR - Running the placement job command: After staging this PR - Running the placement job command: this seems to point to the code introduced, on The order confirmation email does not arrive, in this case. Any thoughts on this? |
Something strange is going on here. When I look at the trace for the bugsnag triggered after this PR is staged, I see this code:
But this PR has those lines as:
I double checked the notifications channel and I don't see this PR as being deployed to the UK - maybe there was an error deploying it? |
Thanks @andrewpbrett , I've tried it again - now the deploy appears on the logs - and repeated the procedure. Changing the price to This error is new, I can't find it on Slack nor on bugsnag (the code is also new, so that's ok I think). It seems to break subs as well (when compared to the case before staging) - no emails arrive in this case. We should perhaps consider that this does not seem reproduce what was reported on issue #7063 (NaN), namely on the UI. The price for that item appears in So maybe it is
Ok, I've tried this as well, with: and now it does look like #7063 🎉 What's interesting is that, despite seeing the NaN on the screen, the subscription runs as normal, at least in testing, in which one places and confirms the jobs manually... all 6 emails arrive, everything seemingly normal, despite the NaN and having this in the DB:
So - long story short - this PR seems to introduce no regression. It's difficult to check the change in the email, but I guess we are good to merge? I'll probably have yet another look during release testing. |
Thanks again @filipefurtad0. I'm going to merge since we also have some work coming that builds on it in #7281 that should improve things further. |
What? Why?
Addresses #7063
See #7063 (comment)
What should we test?
We're not sure how this is actually happening in production... one way to get to this branch of the code, though, is by trying to place an order for a subscription that contains a variant with a nil price should report the failure in the summary email.
I think this might be dev-test or no-test, actually.
Release notes
Fixed a bug where some subscriptions that failed to create orders would not appear in the summary email.
Changelog Category: User facing changes
Dependencies
Documentation updates