/
api_mail_spec.js
57 lines (46 loc) · 1.73 KB
/
api_mail_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
var testUtils = require('../../utils'),
configUtils = require('../../utils/configUtils'),
should = require('should'),
i18n = require('../../../../core/server/i18n'),
// test data
mailData = {
mail: [{
message: {
to: 'joe@example.com',
subject: 'testemail',
html: '<p>This</p>'
},
options: {}
}]
};
i18n.init();
describe('Mail API', function () {
before(testUtils.teardown);
afterEach(testUtils.teardown);
beforeEach(testUtils.setup('perms:mail', 'perms:init'));
afterEach(function () {
configUtils.restore();
});
it('returns a success', function (done) {
configUtils.set({mail: {transport: 'stub'}});
var MailAPI = require('../../../server/api/mail');
MailAPI.send(mailData, testUtils.context.internal).then(function (response) {
should.exist(response.mail);
should.exist(response.mail[0].message);
should.exist(response.mail[0].status);
response.mail[0].message.subject.should.eql('testemail');
done();
}).catch(done);
});
it('returns a boo boo', function (done) {
configUtils.set({mail: {transport: 'stub', options: {error: 'Stub made a boo boo :('}}});
var MailAPI = require('../../../server/api/mail');
MailAPI.send(mailData, testUtils.context.internal).then(function () {
done(new Error('Stub did not error'));
}).catch(function (error) {
error.message.should.startWith('Error: Stub made a boo boo :(');
error.errorType.should.eql('EmailError');
done();
}).catch(done);
});
});