Skip to content

Commit ca712a6

Browse files
add-send-email-tests
1 parent 86ec603 commit ca712a6

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

nodejs-smtp-email-attachments-test/test/send-named-attachments.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const fetchApi = require("isomorphic-fetch");
33
const fs = require('fs');
44

55
QUnit.module('send named attachments');
6+
QUnit.config.testTimeout = 120000;
67

78
QUnit.test('can upload attachments with names and fetch information', async assert => {
89
const apiKey = process.env.API_KEY;
@@ -13,8 +14,10 @@ QUnit.test('can upload attachments with names and fetch information', async asse
1314
if (!attachmentPath) {
1415
throw new Error("Please set PATH_TO_ATTACHMENT")
1516
}
17+
// create mailslurp instance
1618
const mailslurp = new MailSlurp({fetchApi, apiKey})
1719

20+
// create an attachment using base64 file encoding
1821
const contents = fs.readFileSync(attachmentPath, {encoding: 'base64'});
1922
const filename = 'My-Data_with-specialName.csv';
2023
const [attachmentId] = await mailslurp.uploadAttachment({
@@ -24,7 +27,30 @@ QUnit.test('can upload attachments with names and fetch information', async asse
2427
});
2528
assert.equal(!!attachmentId, true)
2629

30+
// check attachment info
2731
const attachmentInfo = await mailslurp.attachmentController.getAttachmentInfo({attachmentId})
2832
assert.equal(attachmentInfo.name, filename);
2933
assert.equal(attachmentInfo.contentType, 'text/csv');
34+
35+
// create an inbox and send attachment to it from self
36+
const inbox = await mailslurp.inboxController.createInbox({})
37+
const sent = await mailslurp.sendEmail(inbox.id, {attachments:[attachmentId], body: "test body", subject: "test subject", to:[inbox.emailAddress]})
38+
assert.equal(sent.attachments.length, 1)
39+
40+
// check sent attachment info
41+
const sentAttachmentInfo = await mailslurp.attachmentController.getAttachmentInfo({attachmentId: sent.attachments[0] })
42+
assert.equal(sentAttachmentInfo.name, filename);
43+
assert.equal(sentAttachmentInfo.contentType, 'text/csv');
44+
45+
// wait for email to arrive
46+
const email = await mailslurp.waitForNthEmail(inbox.id, 0, 30000);
47+
assert.equal(email.subject, "test subject")
48+
assert.equal(email.attachments.length, 1)
49+
50+
// get attachment
51+
const receivedAttachment = email.attachments[0];
52+
const receivedAttachmentInfo = await mailslurp.attachmentController.getAttachment({ attachmentId: receivedAttachment })
53+
54+
// assert name is preserved
55+
assert.equal(receivedAttachmentInfo.name, filename)
3056
});

0 commit comments

Comments
 (0)