mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
Added Newsletter Events Test to Members (#19653)
refs https://linear.app/tryghost/issue/ENG-604/🐛-members-events-show-member-subscribed-to-archived-newsletter - added a tests to avoid a potential regression
This commit is contained in:
parent
612ea2f5f2
commit
58c156001c
@ -576,7 +576,7 @@ module.exports = class MemberRepository {
|
||||
.filter(newsletter => newsletter.attributes.status !== 'archived')
|
||||
.map(newsletter => newsletter.id);
|
||||
const incomingNewsletterIds = memberData.newsletters.map(newsletter => newsletter.id);
|
||||
// make sure newslettersToAdd does not contain newslettersToIgnore (archived newsletters since that creates false events)
|
||||
// make sure newslettersToAdd does not contain archived newsletters (since that creates false events)
|
||||
newslettersToAdd = _.differenceWith(_.differenceWith(incomingNewsletterIds, existingNewsletterIds), archivedNewsletters);
|
||||
newslettersToRemove = _.differenceWith(existingNewsletterIds, incomingNewsletterIds);
|
||||
}
|
||||
|
@ -143,6 +143,91 @@ describe('MemberRepository', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('newsletter subscriptions', function () {
|
||||
let Member;
|
||||
let MemberProductEvent;
|
||||
let productRepository;
|
||||
let stripeAPIService;
|
||||
let existingNewsletters;
|
||||
let MemberSubscribeEvent;
|
||||
|
||||
beforeEach(async function () {
|
||||
sinon.spy();
|
||||
existingNewsletters = [
|
||||
{
|
||||
id: 'newsletter_id_123',
|
||||
attributes: {
|
||||
status: 'active'
|
||||
},
|
||||
get: sinon.stub().withArgs('status').returns('active')
|
||||
},
|
||||
{
|
||||
id: 'newsletter_id_1234_archive',
|
||||
attributes: {
|
||||
status: 'archived'
|
||||
},
|
||||
get: sinon.stub().withArgs('status').returns('archived')
|
||||
}
|
||||
];
|
||||
|
||||
Member = {
|
||||
findOne: sinon.stub().resolves({
|
||||
get: sinon.stub().returns('member_id_123'),
|
||||
related: sinon.stub().withArgs('newsletters').returns({
|
||||
models: existingNewsletters
|
||||
}),
|
||||
toJSON: sinon.stub().returns({})
|
||||
}),
|
||||
edit: sinon.stub().resolves({
|
||||
attributes: {},
|
||||
_previousAttributes: {}
|
||||
})
|
||||
};
|
||||
|
||||
stripeAPIService = {
|
||||
configured: false
|
||||
};
|
||||
|
||||
MemberSubscribeEvent = {
|
||||
add: sinon.stub().resolves()
|
||||
};
|
||||
});
|
||||
|
||||
it('Does not create false archived newsletter events', async function () {
|
||||
const repo = new MemberRepository({
|
||||
Member,
|
||||
MemberProductEvent,
|
||||
productRepository,
|
||||
stripeAPIService,
|
||||
MemberSubscribeEventModel: MemberSubscribeEvent,
|
||||
OfferRedemption: mockOfferRedemption
|
||||
});
|
||||
|
||||
await repo.update({
|
||||
email: 'test@email.com',
|
||||
newsletters: [{
|
||||
id: 'newsletter_id_123'
|
||||
},
|
||||
{
|
||||
id: 'newsletter_id_456'
|
||||
},
|
||||
{
|
||||
id: 'newsletter_id_new'
|
||||
},
|
||||
{
|
||||
id: 'newsletter_id_1234_archive'
|
||||
}]
|
||||
},{
|
||||
transacting: {
|
||||
executionPromise: Promise.resolve()
|
||||
},
|
||||
context: {}
|
||||
});
|
||||
|
||||
MemberSubscribeEvent.add.calledTwice.should.be.true();
|
||||
});
|
||||
});
|
||||
|
||||
describe('linkSubscription', function (){
|
||||
let Member;
|
||||
let MemberPaidSubscriptionEvent;
|
||||
|
Loading…
Reference in New Issue
Block a user