refs https://github.com/TryGhost/Ghost/pull/14488
**Bug:**
When creating a new offer, sometimes no discount object is created in Stripe (only in MySQL). This issue causes tests to fail in https://github.com/TryGhost/Ghost/pull/14488
**Cause:**
When creating an offer with the OffersAPI, we create a new transaction to save the offer and check for uniqueness. Inside that transaction, we dispatch an OfferCreatedEvent event before the transaction is committed to the database.
When listening for this event in the `members-payments` package, we create the discount object in Stripe and save the stripe_coupon_id to the newly created offer. But because (in most cases) the offer doesn't yet exist in the database, that listener fails without warning and exits early.
**Solution:**
Creating a discount in Stripe should only happen after we succesfully committed the offer to the database. If we don't wait for the commit, the offer often (by chance) won't exist in the database, so the coupon won't be created inside Stripe. The solution is to wait for the transaction to succeed/be committed before dispatching the event.
refs https://github.com/TryGhost/Team/issues/1519
- Removed offer metadata again from offer (added in one of the previous commits)
- Added `getByStripeCouponId` method in offer repository (required to find an offer based on the stripe_coupon_id)
- Match discounts from Stripe based on the stripe_coupon_id instead of metadata
refs https://github.com/TryGhost/Toolbox/issues/203
- without `--all`, c8 ignores files that should be included in the
coverage score but aren't used in tests
- this means we have artificially high scores in places where this isn't
used
- this commit adds `--all` where previously missing
- where this fails `--check-coverage`, that has been removed for now
refs: 23b383bedf
- @tryghost/error constructors take an object, not a string - the expectation is that message, context & help should all be set
- This does the bare minimum and just ensures message is set correctly
refs: 3a1c51672c
- @babel/eslint-parser was added to enable support for static members on classes but this causes other problems as it fails on eslint ugprades etc
- a better solution is to set ecmaVersion to 2022, as our default is 2018 which does not support static, yet 2022 does
refs https://github.com/TryGhost/Team/issues/1236
We want to be able to use the OfferName as the name property for a
Stripe Coupon - which has a maximum character length of 40.
no-issue
When attempting to read a non-existent offer we were running into issues
with calling toJSON() on `null`. This updates the handling to explicitly
return null - so that the controller can correctly throw a NotFoundError
refs https://github.com/TryGhost/Team/issues/1163
This allows users to not provide a title for an Offer. We store the lack
of a title as `NULL` in the DB, but we will always provide a string to
the API so that the title can safely be used in HTML.
refs https://github.com/TryGhost/Team/issues/1166
Since we removed the creation of coupons from the Offers module, we must
emit events so that the Payments module can handle creating Coupons when
Offers are created.
We also export the events from the module so that they can be listened
to by the Payments module.
We also export other internals of the module so that the types can be
used.
refs https://github.com/TryGhost/Team/issues/1166
This will be handled by a payments module instead. In order to
disconnect Stripe we must delete all Stripe related data, which means an
Offer doesn't inherently have a stripe coupon id. Instead we can use a
payments service which will get/create the coupon for us when we need
it.
refs linear.app/tryghost/issue/CORE-74/improve-the-test-situation
- this commit adds the codecov GitHub Action into CI so we can upload
coverage reports
- the coverage files need to be in XML for them to work with
codecov, so this commit also adds cobertura (XML) as a reporter
no-issue
Because we were checking for truthyness rather than existence when
updating properties on an Offer - it was impossible to set the
description to a blank string, as this is falsy.