Skip to content

🐛 Fixed removing comped subscriptions for members with active subs#15332

Merged
SimonBackx merged 5 commits into
TryGhost:mainfrom
SimonBackx:fixed-removing-complimentary-subscriptions
Aug 30, 2022
Merged

🐛 Fixed removing comped subscriptions for members with active subs#15332
SimonBackx merged 5 commits into
TryGhost:mainfrom
SimonBackx:fixed-removing-complimentary-subscriptions

Conversation

@SimonBackx
Copy link
Copy Markdown
Contributor

@SimonBackx SimonBackx commented Aug 30, 2022

fixes https://github.com/TryGhost/Team/issues/1859

Problem:
When for some reason a member has an active subscription (or legacy comped subscription) for product A, and a comped subscription for product B. You cannot remove comped subscription B.

Fixed by:
Updating the API to allow more flexible product changes on members.

  • Allow the removal of (comped) products on a member, as long as that product doesn't have a related subscription
  • (still) allow the addition of comped products to a member, as long as that member doesn't have other active subscriptions. This matches the existing behaviour, but now this is only checked for added products.
  • Includes tests for these edge cases

…subscriptions

refs https://github.com/TryGhost/Team/issues/1859

Problem:
When for some reason a member has an active subscription (or legacy comped subscription) for product A, and a comped subscription for product B. You cannot remove comped subscription B.

Fixed by:
Updating the API to allow more flexible product changes on members.
- Allow the removal of (comped) products on a member, as long as that product doesn't have a related subscription
- Allow the addition of comped products to a member, as long as that member doesn't have other active subscriptions
- Includes tests for these edge cases
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 30, 2022

Codecov Report

Merging #15332 (2b14d1c) into main (fcd6360) will increase coverage by 5.76%.
The diff coverage is 4.76%.

@@            Coverage Diff             @@
##             main   #15332      +/-   ##
==========================================
+ Coverage   52.75%   58.51%   +5.76%     
==========================================
  Files        1399      767     -632     
  Lines       89896    64101   -25795     
  Branches    10216     5642    -4574     
==========================================
- Hits        47422    37509    -9913     
+ Misses      42423    26541   -15882     
  Partials       51       51              
Impacted Files Coverage Δ
ghost/members-api/lib/repositories/member.js 12.99% <4.76%> (-0.16%) ⬇️
ghost/core/core/server/services/mega/template.js 99.92% <0.00%> (-0.08%) ⬇️
ghost/admin/app/controllers/members/import.js
ghost/admin/app/components/gh-file-upload.js
ghost/admin/app/components/gh-skip-link.js
ghost/admin/app/helpers/gh-price-amount.js
ghost/admin/app/components/gh-navitem-url-input.js
ghost/admin/app/adapters/theme.js
...admin/app/controllers/settings/integrations/amp.js
ghost/admin/app/services/upgrade-status.js
... and 625 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@SimonBackx SimonBackx requested a review from allouis August 30, 2022 11:21
@SimonBackx SimonBackx marked this pull request as ready for review August 30, 2022 11:21
Copy link
Copy Markdown
Collaborator

@allouis allouis left a comment

Choose a reason for hiding this comment

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

Couple comments but otherwise 👍

it('Cannot add complimentary subscriptions to a member with an active subscription', async function () {
if (!memberWithPaidSubscription) {
// Previous test failed
this.skip();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an interesting pattern, have you seen this used elsewhere in the tests?

I'm not against it, as it is frustrating when a single test failing causes a cascade of later ones failing.

Ultimately that's because we have tests depending on some global state outside of the test, which IMO is not good.

We could fix this by making sure each test does the setup that it needs, but that adds overhead.

Using this pattern at least makes the coupling explicit 🤔 Though what would happen if we removed the previous test, it would render this test useless right?

I'd be interested in your thoughts either way on this, and if you think it's a good idea - let's talk with Hannah about sharing/using this pattern going forwards

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I introduced this pattern a couple of months ago in the same file. I didn't really think a lot about it when writing these additional tests. I don't think this pattern is ideal, but it was an effort to prevent having to repeat all the Stripe mocking in every test. But moving that repeated part to the top might be a better solution... 🤔 Or we could build the models manually without mocking Stripe...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gonna move this to a tech debt issue and clean up the whole test file in one go 🧹

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@SimonBackx what was the outcome of the cleanup? If the memberWithPaidSubscription is used in a group of test, like it seems to be done here, probably best would be grouping such tests into a "describe" and having a memberWithPaidSubscription be set up through fixtures? 🤔

Comment thread ghost/core/test/e2e-api/admin/members.test.js Outdated
Comment thread ghost/core/test/e2e-api/admin/members.test.js Outdated
Comment thread ghost/core/test/e2e-api/admin/members.test.js Outdated
@SimonBackx SimonBackx merged commit e7786ca into TryGhost:main Aug 30, 2022
@SimonBackx SimonBackx deleted the fixed-removing-complimentary-subscriptions branch August 30, 2022 15:36
daniellockyer pushed a commit that referenced this pull request Aug 30, 2022
…15332)

fixes https://github.com/TryGhost/Team/issues/1859

**Problem:**
When for some reason a member has an active subscription (or legacy comped subscription) for product A, and a comped subscription for product B. You cannot remove comped subscription B.

**Fixed by:**
Updating the API to allow more flexible product changes on members.
- Allow the removal of (comped) products on a member, as long as that product doesn't have a related subscription
- (still) allow the addition of comped products to a member, as long as that member doesn't have other active subscriptions. This matches the existing behaviour, but now this is only checked for added products.
- Includes tests for these edge cases
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.

3 participants