1
|
|
|
import chai, { expect } from 'chai' |
2
|
|
|
import chaiHttp from 'chai-http' |
3
|
|
|
import xmldoc from 'xmldoc' |
4
|
|
|
import fs from 'fs' |
5
|
|
|
import server from './server' |
6
|
|
|
|
7
|
|
|
chai.use(chaiHttp) |
8
|
|
|
|
9
|
|
|
// describe('Runtime arguments', () => { |
10
|
|
|
// it('should clean the output directory when called with --clean', (done) => { |
11
|
|
|
// process.argv = ['--clean'] |
12
|
|
|
// chai.request(server) |
13
|
|
|
// }) |
14
|
|
|
// }) |
15
|
|
|
|
16
|
|
|
describe('/POST email', () => { |
17
|
|
|
const toAddress = '[email protected]' |
18
|
|
|
const ccAddress = '[email protected]' |
19
|
|
|
const bccAddress = '[email protected]' |
20
|
|
|
const replyToAddress = '[email protected]' |
21
|
|
|
const htmlEmail = '<p>HTML Email</p>' |
22
|
|
|
const textEmail = 'Text Email' |
23
|
|
|
const emailSubject = 'Email Subject 😊' |
24
|
|
|
const fromEmail = '[email protected]' |
25
|
|
|
it('should succeed if email has all params', (done) => { |
26
|
|
|
chai.request(server) |
27
|
|
|
.post('/') |
28
|
|
|
.send({ |
29
|
|
|
Action: 'SendEmail', |
30
|
|
|
'Destination.ToAddresses.member.1': toAddress, |
31
|
|
|
'Message.Body.Html.Data': htmlEmail, |
32
|
|
|
'Message.Body.Text.Data': textEmail, |
33
|
|
|
'Message.Subject.Data': emailSubject, |
34
|
|
|
'Destination.CcAddresses.member.1': ccAddress, |
35
|
|
|
'Destination.BccAddresses.member.1': bccAddress, |
36
|
|
|
'ReplyToAddresses.member.1': replyToAddress, |
37
|
|
|
Source: fromEmail, |
38
|
|
|
}) |
39
|
|
|
.end((err, res) => { |
40
|
|
|
expect(res).to.have.status(200) |
41
|
|
|
const response = new xmldoc.XmlDocument(res.text) |
42
|
|
|
const path = response.valueWithPath('SendEmailResult.MessageId') |
43
|
|
|
expect(fs.readFileSync(path, 'utf8')).to.eq(htmlEmail) |
44
|
|
|
expect(fs.readFileSync(path.replace('body.html', 'body.txt'), 'utf8')).to.eq(textEmail) |
45
|
|
|
expect(fs.readFileSync(path.replace('body.html', 'headers.txt'), 'utf8')).to.eq(`Subject: ${emailSubject}\nTo Address: ${toAddress}\nCc Address: ${ccAddress}\nBcc Address: ${bccAddress}\nReply To Address: ${replyToAddress}\nSource: ${fromEmail}`) |
46
|
|
|
done() |
47
|
|
|
}) |
48
|
|
|
}) |
49
|
|
|
it('should fail if one param is not sent', (done) => { |
50
|
|
|
chai.request(server) |
51
|
|
|
.post('/') |
52
|
|
|
.send({ |
53
|
|
|
Action: 'SendEmail', |
54
|
|
|
'Message.Body.Html.Data': htmlEmail, |
55
|
|
|
'Message.Body.Text.Data': textEmail, |
56
|
|
|
'Message.Subject.Data': emailSubject, |
57
|
|
|
Source: fromEmail, |
58
|
|
|
}) |
59
|
|
|
.end((err, res) => { |
60
|
|
|
expect(res).to.have.status(500) |
61
|
|
|
const response = new xmldoc.XmlDocument(res.text) |
62
|
|
|
expect(response.valueWithPath('Code')).to.eq('MessageRejected') |
63
|
|
|
expect(response.valueWithPath('Message')).to.eq('One or more required fields was not sent') |
64
|
|
|
done() |
65
|
|
|
}) |
66
|
|
|
}) |
67
|
|
|
}) |