Fixed Tier events being created when Posts are edited

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

- due to an misbehavior in our model layer, when `tiers` is set on a Post, it'll
  trigger a save of the Tier, and this produces an extra event in the
  `actions` table
- mapping the Tier(s) to just the ID prevents bookshelf-relations from
  editing the Tier and thus prevents the extra event
- also fixed tests which were implicitly assuming supplying a slug to a
  post would create the product
This commit is contained in:
Daniel Lockyer 2022-09-05 16:14:12 +01:00
parent a27342c8ae
commit 79368f565f
No known key found for this signature in database
GPG Key ID: D21186F0B47295AD
3 changed files with 12 additions and 2 deletions

View File

@ -794,6 +794,12 @@ Post = ghostBookshelf.Model.extend({
});
}
if (this.get('tiers')) {
this.set('tiers', this.get('tiers').map(t => ({
id: t.id
})));
}
return sequence(ops);
},

View File

@ -72,11 +72,13 @@ describe('e2e {{#get}} helper', function () {
published_at: new Date() // here to ensure sorting is not modified
});
const defaultTier = await models.Product.findOne({slug: 'default-product'});
basicTierPost = await createPost({
slug: 'tiers-post',
visibility: 'tiers',
tiers: [{
slug: 'default-product'
id: defaultTier.get('id')
}],
published_at: new Date() // here to ensure sorting is not modified
});

View File

@ -54,11 +54,13 @@ describe('e2e {{#next_post}} helper', function () {
published_at: new Date(2020, 0, 3) // here to ensure sorting is not modified
});
const defaultTier = await models.Product.findOne({slug: 'default-product'});
basicTierPost = await createPost({
slug: 'tiers-post',
visibility: 'tiers',
tiers: [{
slug: 'default-product'
id: defaultTier.get('id')
}],
published_at: new Date(2020, 0, 4) // here to ensure sorting is not modified
});