Fixed suppression list handling of spam complaint events
refs https://github.com/TryGhost/Team/issues/2351 We were storing all suppressions with a reason of bounced, rather than spam for spam complaint events.
This commit is contained in:
parent
5749a17910
commit
939e3ce96f
@ -95,12 +95,12 @@ class MailgunEmailSuppressionList extends AbstractEmailSuppressionList {
|
||||
}
|
||||
|
||||
async init() {
|
||||
const handleEvent = async (event) => {
|
||||
const handleEvent = reason => async (event) => {
|
||||
try {
|
||||
await this.Suppression.add({
|
||||
email_address: event.email,
|
||||
email_id: event.emailId,
|
||||
reason: 'bounce',
|
||||
reason: reason,
|
||||
created_at: event.timestamp
|
||||
});
|
||||
DomainEvents.dispatch(EmailSuppressedEvent.create({
|
||||
@ -114,8 +114,8 @@ class MailgunEmailSuppressionList extends AbstractEmailSuppressionList {
|
||||
}
|
||||
}
|
||||
};
|
||||
DomainEvents.subscribe(EmailBouncedEvent, handleEvent);
|
||||
DomainEvents.subscribe(SpamComplaintEvent, handleEvent);
|
||||
DomainEvents.subscribe(EmailBouncedEvent, handleEvent('bounce'));
|
||||
DomainEvents.subscribe(SpamComplaintEvent, handleEvent('spam'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -734,7 +734,7 @@ describe('EmailEventStorage', function () {
|
||||
const emailBatch = fixtureManager.get('email_batches', 0);
|
||||
const emailId = emailBatch.email_id;
|
||||
|
||||
const emailRecipient = fixtureManager.get('email_recipients', 0);
|
||||
const emailRecipient = fixtureManager.get('email_recipients', 1);
|
||||
assert(emailRecipient.batch_id === emailBatch.id);
|
||||
const memberId = emailRecipient.member_id;
|
||||
const providerId = emailBatch.provider_id;
|
||||
@ -748,6 +748,9 @@ describe('EmailEventStorage', function () {
|
||||
const existingSpamEvent = eventsBefore.find(event => event.type === 'email_complaint_event');
|
||||
assert.equal(existingSpamEvent, null, 'This test requires a member that does not have a spam event');
|
||||
|
||||
const {body: {members: [member]}} = await agent.get(`/members/${memberId}`);
|
||||
assert.equal(member.email_suppression.suppressed, false, 'This test requires a member that does not have a suppressed email');
|
||||
|
||||
events = [{
|
||||
event: 'complained',
|
||||
recipient: emailRecipient.member_email,
|
||||
@ -779,6 +782,10 @@ describe('EmailEventStorage', function () {
|
||||
const {body: {events: eventsAfter}} = await agent.get(eventsURI);
|
||||
const spamComplaintEvent = eventsAfter.find(event => event.type === 'email_complaint_event');
|
||||
assert.equal(spamComplaintEvent.type, 'email_complaint_event');
|
||||
|
||||
const {body: {members: [memberAfter]}} = await agent.get(`/members/${memberId}`);
|
||||
assert.equal(memberAfter.email_suppression.suppressed, true, 'The member should have a suppressed email');
|
||||
assert.equal(memberAfter.email_suppression.info.reason, 'spam');
|
||||
});
|
||||
|
||||
it('Can handle unsubscribe events', async function () {
|
||||
|
Loading…
Reference in New Issue
Block a user