This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(email): check case insensitive headers in EmailSent event (#1916)…
…, r=@philbooth, @vbudhram
- Loading branch information
1 parent
43b8fd8
commit 23593c7
Showing
2 changed files
with
97 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'use strict' | ||
|
||
const assert = require('insist') | ||
const emailHelpers = require('../../../lib/email/utils/helpers') | ||
const spyLog = require('../../mocks').spyLog | ||
|
||
|
||
describe('email utils helpers', () => { | ||
describe('getHeaderValue', () => { | ||
|
||
it('works with message.mail.headers', () => { | ||
const message = { | ||
mail: { | ||
headers: [{ | ||
name: 'content-language', | ||
value: 'en-US' | ||
}] | ||
} | ||
} | ||
|
||
const value = emailHelpers.getHeaderValue('Content-Language', message) | ||
assert.equal(value, message.mail.headers[0].value) | ||
}) | ||
|
||
|
||
it('works with message.headers', () => { | ||
const message = { | ||
headers: [{ | ||
name: 'content-language', | ||
value: 'ru' | ||
}] | ||
} | ||
|
||
const value = emailHelpers.getHeaderValue('Content-Language', message) | ||
assert.equal(value, message.headers[0].value) | ||
}) | ||
|
||
}) | ||
|
||
describe('logEmailEventSent', () => { | ||
it('should check headers case-insensitively', () => { | ||
const mockLog = spyLog() | ||
const message = { | ||
email: 'user@example.domain', | ||
template: 'verifyEmail', | ||
headers: { | ||
'cOnTeNt-LaNgUaGe': 'ru' | ||
} | ||
} | ||
emailHelpers.logEmailEventSent(mockLog, message) | ||
assert.equal(mockLog.info.callCount, 1) | ||
assert.equal(mockLog.info.args[0][0].locale, 'ru') | ||
}) | ||
|
||
}) | ||
|
||
}) |