fix(metrics): fix the data on email sent events

https://github.com/mozilla/fxa-auth-server/pull/2139
r=rfk
This commit is contained in:
Phil Booth 2017-09-25 08:11:43 +01:00 коммит произвёл GitHub
Родитель 5990da6aae
Коммит 4f6f367f5e
3 изменённых файлов: 22 добавлений и 15 удалений

Просмотреть файл

@ -75,10 +75,10 @@ function logEmailEventSent(log, message) {
const emailEventInfo = {
op: 'emailEvent',
template: message.template,
type: 'sent'
type: 'sent',
flow_id: message.flowId
}
emailEventInfo['flow_id'] = getHeaderValue('X-Flow-Id', message)
emailEventInfo.locale = getHeaderValue('Content-Language', message)
const addrs = [message.email].concat(message.ccEmails || [])
@ -112,11 +112,12 @@ function logAmplitudeEvent (log, message, eventInfo) {
query: {},
payload: {}
}, {
device_id: getHeaderValue('X-Device-Id', message),
device_id: message.deviceId || getHeaderValue('X-Device-Id', message),
email_domain: eventInfo.domain,
service: getHeaderValue('X-Service-Id', message),
uid: getHeaderValue('X-Uid', message)
service: message.service || getHeaderValue('X-Service-Id', message),
uid: message.uid || getHeaderValue('X-Uid', message)
}, {
flowBeginTime: message.flowBeginTime || getHeaderValue('X-Flow-Begin-Time', message),
flow_id: eventInfo.flow_id,
time: Date.now()
})

Просмотреть файл

@ -87,12 +87,13 @@ describe('email utils helpers', () => {
ccEmails: [ 'bar@example.com', 'baz@example.com' ],
template: 'verifyEmail',
headers: [
{ name: 'Content-Language', value: 'aaa' },
{ name: 'X-Device-Id', value: 'bbb' },
{ name: 'X-Flow-Id', value: 'ccc' },
{ name: 'X-Service-Id', value: 'ddd' },
{ name: 'X-Uid', value: 'eee' }
]
{ name: 'Content-Language', value: 'aaa' }
],
deviceId: 'bbb',
flowBeginTime: 42,
flowId: 'ccc',
service: 'ddd',
uid: 'eee'
})
assert.equal(amplitude.callCount, 1)
const args = amplitude.args[0]
@ -118,6 +119,7 @@ describe('email utils helpers', () => {
uid: 'eee'
})
assert.equal(args[3].flow_id, 'ccc')
assert.equal(args[3].flowBeginTime, 42)
assert.ok(args[3].time > Date.now() - 1000)
})
@ -128,6 +130,7 @@ describe('email utils helpers', () => {
headers: [
{ name: 'Content-Language', value: 'a' },
{ name: 'X-Device-Id', value: 'b' },
{ name: 'X-Flow-Begin-Time', value: 1 },
{ name: 'X-Flow-Id', value: 'c' },
{ name: 'X-Service-Id', value: 'd' },
{ name: 'X-Template-Name', value: 'verifyLoginEmail' },
@ -158,6 +161,7 @@ describe('email utils helpers', () => {
uid: 'e'
})
assert.equal(args[3].flow_id, 'c')
assert.equal(args[3].flowBeginTime, 1)
})
describe('logErrorIfHeadersAreWeirdOrMissing', () => {

Просмотреть файл

@ -122,6 +122,10 @@ describe(
})
})
afterEach(() => {
mockLog.info.reset()
})
messageTypes.forEach(
function (type) {
var message = {
@ -631,10 +635,9 @@ describe(
it(
'logs emailEvent on send',
function () {
mockLog.info.reset()
var message = {
email: 'test@restmail.net',
flowId: 'wibble',
subject: 'subject',
template: 'verifyLoginEmail',
uid: 'foo'
@ -646,6 +649,7 @@ describe(
const emailEventLog = mockLog.info.getCalls()[2]
assert.equal(emailEventLog.args[0].op, 'emailEvent', 'logs emailEvent')
assert.equal(emailEventLog.args[0].domain, 'other', 'logs domain')
assert.equal(emailEventLog.args[0].flow_id, 'wibble', 'logs flow id')
assert.equal(emailEventLog.args[0].template, 'verifyLoginEmail', 'logs correct template')
assert.equal(emailEventLog.args[0].type, 'sent', 'logs correct type')
})
@ -655,8 +659,6 @@ describe(
it(
'rejects sendMail status',
function () {
mailer.mailer.sendMail.reset()
var message = {
email: 'test@restmail.net',
subject: 'subject',