@@ -3,6 +3,7 @@ const fetchApi = require("isomorphic-fetch");
33const fs = require ( 'fs' ) ;
44
55QUnit . module ( 'send named attachments' ) ;
6+ QUnit . config . testTimeout = 120000 ;
67
78QUnit . 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