-
Notifications
You must be signed in to change notification settings - Fork 778
/
from-data.spec.js
89 lines (80 loc) · 2.79 KB
/
from-data.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'use strict';
/**
* Dependencies
*/
const Personalization = require('../personalization');
const EmailAddress = require('../email-address');
/**
* Tests
*/
describe('Personalization', function() {
//Create new personalization before each test
let p;
beforeEach(function() {
p = new Personalization();
});
//From data
describe('fromData()', function() {
//Data
const data = {
to: 'to@example.org',
from: 'from@example.org',
cc: ['cc1@example.org', 'cc2@example.org'],
bcc: ['bcc1@example.org', 'bcc2@example.org'],
subject: 'Test',
sendAt: 1000,
headers: {test: 'Test'},
customArgs: {snake_case: 'Test', T_EST: 'Test', camelCase: 'Test'},
substitutions: {snake_case: 'Test', T_EST: 'Test', camelCase: 'Test'},
substitutionWrappers: ['[', ']'],
};
//Tests
it('should call fromData() from the constructor', () => {
p = new Personalization(data);
expect(p.to[0].email).to.equal('to@example.org');
expect(p.subject).to.equal('Test');
});
it('should throw an error for invalid input', () => {
expect(function() {
p.fromData(5);
}).to.throw(Error);
});
it('should have set all properties', () => {
p.fromData(data);
expect(p.to[0].email).to.equal('to@example.org');
expect(p.from.email).to.equal('from@example.org');
expect(p.cc[0].email).to.equal('cc1@example.org');
expect(p.cc[1].email).to.equal('cc2@example.org');
expect(p.bcc[0].email).to.equal('bcc1@example.org');
expect(p.bcc[1].email).to.equal('bcc2@example.org');
expect(p.subject).to.equal('Test');
expect(p.sendAt).to.equal(1000);
expect(p.headers.test).to.equal('Test');
expect(p.customArgs.snake_case).to.equal('Test');
expect(p.substitutions.snake_case).to.equal('Test');
expect(p.substitutionWrappers).to.have.members(['[', ']']);
});
it('should not modify the keys of substitutions and custom args', () => {
p.fromData(data);
expect(p.substitutions.T_EST).to.equal('Test');
expect(p.substitutions.camelCase).to.equal('Test');
expect(p.substitutions.snake_case).to.equal('Test');
expect(p.customArgs.T_EST).to.equal('Test');
expect(p.customArgs.camelCase).to.equal('Test');
expect(p.customArgs.snake_case).to.equal('Test');
});
});
describe('#527', function() {
it('shouldn\'t convert the headers to camel/snake case', function() {
const p = new Personalization({
to: 'test@example.com',
headers: {
'List-Unsubscribe': '<mailto:test@test.com>',
},
});
expect(p.headers['List-Unsubscribe']).to.equal('<mailto:test@test.com>');
expect(p.toJSON().headers['List-Unsubscribe']).to
.equal('<mailto:test@test.com>');
});
});
});