Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(metrics): use correct format for email service notifications
Browse files Browse the repository at this point in the history
The email service made a conscious break with the SQS notification
structure, to make the recipients array more uniform. Rather than
sometimes being an object with an `emailAddress` property and other
times being a string, it makes the items plain strings on all
notification types.

When I added code for the new notification queue to this repo, I forgot
about that and just ported the SQS logic verbatim. This fixes it to
always expect plain strings in the recipient arrays.
  • Loading branch information
philbooth committed Oct 29, 2018
1 parent 4d4e843 commit ec3ff7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
8 changes: 2 additions & 6 deletions lib/email/notifications.js
Expand Up @@ -22,10 +22,10 @@ module.exports = (log, error) => {

let addresses = [], eventType = 'bounced', isDeletionCandidate = false
if (message.bounce) {
addresses = mapBounceComplaintRecipients(message.bounce.bouncedRecipients)
addresses = message.bounce.bouncedRecipients
isDeletionCandidate = true
} else if (message.complaint) {
addresses = mapBounceComplaintRecipients(message.complaint.complainedRecipients)
addresses = message.complaint.complainedRecipients
isDeletionCandidate = true
} else if (message.delivery) {
addresses = message.delivery.recipients
Expand Down Expand Up @@ -57,7 +57,3 @@ module.exports = (log, error) => {
})
}
}

function mapBounceComplaintRecipients (recipients) {
return recipients.map(recipient => recipient.emailAddress)
}
22 changes: 6 additions & 16 deletions test/local/email/notifications.js
Expand Up @@ -71,7 +71,7 @@ describe('lib/email/notifications:', () => {
}
},
bounce: {
bouncedRecipients: [ { emailAddress: 'wibble@example.com' } ]
bouncedRecipients: [ 'wibble@example.com' ]
}
})
})
Expand Down Expand Up @@ -136,10 +136,7 @@ describe('lib/email/notifications:', () => {
}
},
complaint: {
complainedRecipients: [
{ emailAddress: 'foo@example.com' },
{ emailAddress: 'pmbooth@gmail.com' }
]
complainedRecipients: [ 'foo@example.com', 'pmbooth@gmail.com' ]
}
})
})
Expand Down Expand Up @@ -234,10 +231,7 @@ describe('lib/email/notifications:', () => {
}
},
bounce: {
bouncedRecipients: [
{ emailAddress: 'wibble@example.com' },
{ emailAddress: 'blee@example.com' }
]
bouncedRecipients: [ 'wibble@example.com', 'blee@example.com' ]
}
})
})
Expand Down Expand Up @@ -309,9 +303,7 @@ describe('lib/email/notifications:', () => {
}
},
complaint: {
complainedRecipients: [
{ emailAddress: 'foo@example.com' }
]
complainedRecipients: [ 'foo@example.com' ]
}
})
})
Expand Down Expand Up @@ -351,9 +343,7 @@ describe('lib/email/notifications:', () => {
}
},
bounce: {
bouncedRecipients: [
{ emailAddress: 'wibble@example.com' }
]
bouncedRecipients: [ 'wibble@example.com' ]
}
})
})
Expand Down Expand Up @@ -444,7 +434,7 @@ describe('lib/email/notifications:', () => {
del,
mail: {},
bounce: {
bouncedRecipients: [ { emailAddress: 'wibble@example.com' } ]
bouncedRecipients: [ 'wibble@example.com' ]
}
})
})
Expand Down

0 comments on commit ec3ff7b

Please sign in to comment.