Skip to content

Commit 86ec603

Browse files
add-csv-names-test
1 parent b697ca0 commit 86ec603

File tree

6 files changed

+231
-0
lines changed

6 files changed

+231
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-include ../.env
2+
3+
.PHONY: test
4+
5+
node_modules:
6+
npm install
7+
8+
test: node_modules
9+
API_KEY=$(API_KEY) PATH_TO_ATTACHMENT=$(PWD)/My-Data_with-specialName.csv npm t
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"LatD", "LatM", "LatS", "NS", "LonD", "LonM", "LonS", "EW", "City", "State"
2+
41, 5, 59, "N", 80, 39, 0, "W", "Youngstown", OH
3+
42, 52, 48, "N", 97, 23, 23, "W", "Yankton", SD
4+
46, 35, 59, "N", 120, 30, 36, "W", "Yakima", WA

nodejs-smtp-email-attachments-test/package-lock.json

Lines changed: 169 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "nodejs-smtp-email-attachments-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "qunit"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"isomorphic-fetch": "^3.0.0",
14+
"mailslurp-client": "^15.4.5",
15+
"qunit": "^2.17.2"
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const MailSlurp = require("mailslurp-client").MailSlurp;
2+
const fetchApi = require("isomorphic-fetch");
3+
const fs = require('fs');
4+
5+
QUnit.module('send named attachments');
6+
7+
QUnit.test('can upload attachments with names and fetch information', async assert => {
8+
const apiKey = process.env.API_KEY;
9+
if (!apiKey) {
10+
throw new Error("Please set API_KEY environment variable")
11+
}
12+
const attachmentPath = process.env.PATH_TO_ATTACHMENT;
13+
if (!attachmentPath) {
14+
throw new Error("Please set PATH_TO_ATTACHMENT")
15+
}
16+
const mailslurp = new MailSlurp({fetchApi, apiKey})
17+
18+
const contents = fs.readFileSync(attachmentPath, {encoding: 'base64'});
19+
const filename = 'My-Data_with-specialName.csv';
20+
const [attachmentId] = await mailslurp.uploadAttachment({
21+
base64Contents: contents,
22+
contentType: 'text/csv',
23+
filename
24+
});
25+
assert.equal(!!attachmentId, true)
26+
27+
const attachmentInfo = await mailslurp.attachmentController.getAttachmentInfo({attachmentId})
28+
assert.equal(attachmentInfo.name, filename);
29+
assert.equal(attachmentInfo.contentType, 'text/csv');
30+
});

0 commit comments

Comments
 (0)