-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01cada3
commit 4298496
Showing
1 changed file
with
143 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,107 @@ test.after(async (t) => { | |
server.close(t.pass); | ||
}); | ||
|
||
test('simple text message', async (t) => { | ||
test.serial('message validation fails without `from` header', async (t) => { | ||
const msg = new Message({}); | ||
const { isValid, validationError } = msg.checkValidity(); | ||
t.false(isValid); | ||
t.is(validationError, 'Message must have a `from` header'); | ||
}); | ||
|
||
test.serial( | ||
'message validation fails without `to`, `cc`, or `bcc` header', | ||
async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
}).checkValidity(); | ||
|
||
t.false(isValid); | ||
t.is( | ||
validationError, | ||
'Message must have at least one `to`, `cc`, or `bcc` header' | ||
); | ||
} | ||
); | ||
|
||
test.serial( | ||
'message validation succeeds with only `to` recipient header (string)', | ||
async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
} | ||
); | ||
|
||
test.serial( | ||
'message validation succeeds with only `to` recipient header (array)', | ||
async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
to: ['[email protected]'], | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
} | ||
); | ||
|
||
test.serial( | ||
'message validation succeeds with only `cc` recipient header (string)', | ||
async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
cc: '[email protected]', | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
} | ||
); | ||
|
||
test.serial( | ||
'message validation succeeds with only `cc` recipient header (array)', | ||
async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
cc: ['[email protected]'], | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
} | ||
); | ||
|
||
test.serial( | ||
'message validation succeeds with only `bcc` recipient header (string)', | ||
async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
bcc: '[email protected]', | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
} | ||
); | ||
|
||
test.serial( | ||
'message validation succeeds with only `bcc` recipient header (array)', | ||
async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
bcc: ['[email protected]'], | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
} | ||
); | ||
|
||
test.serial('simple text message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -98,7 +198,7 @@ test('simple text message', async (t) => { | |
t.is(mail.messageId, '<' + msg['message-id'] + '>'); | ||
}); | ||
|
||
test('null text message', async (t) => { | ||
test.serial('null text message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -111,7 +211,7 @@ test('null text message', async (t) => { | |
t.is(mail.text, '\n\n\n'); | ||
}); | ||
|
||
test('empty text message', async (t) => { | ||
test.serial('empty text message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -124,7 +224,7 @@ test('empty text message', async (t) => { | |
t.is(mail.text, '\n\n\n'); | ||
}); | ||
|
||
test('simple unicode text message', async (t) => { | ||
test.serial('simple unicode text message', async (t) => { | ||
const msg = { | ||
subject: 'this ✓ is a test ✓ TEXT message from emailjs', | ||
from: 'zelda✓ <[email protected]>', | ||
|
@@ -139,45 +239,7 @@ test('simple unicode text message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('very large text message', async (t) => { | ||
// thanks to jart+loberstech for this one! | ||
const msg = { | ||
subject: 'this is a test TEXT message from emailjs', | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
text: textFixture, | ||
}; | ||
|
||
const mail = await send(msg); | ||
t.is(mail.text, msg.text.replace(/\r/g, '') + '\n\n\n'); | ||
t.is(mail.subject, msg.subject); | ||
t.is(mail.from?.text, msg.from); | ||
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('very large text data message', async (t) => { | ||
const text = '<html><body><pre>' + textFixture + '</pre></body></html>'; | ||
|
||
const msg = { | ||
subject: 'this is a test TEXT+DATA message from emailjs', | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
text: 'hello friend if you are seeing this, you can not view html emails. it is attached inline.', | ||
attachment: { | ||
data: text, | ||
alternative: true, | ||
}, | ||
}; | ||
|
||
const mail = await send(msg); | ||
t.is(mail.html, text.replace(/\r/g, '')); | ||
t.is(mail.text, msg.text + '\n'); | ||
t.is(mail.subject, msg.subject); | ||
t.is(mail.from?.text, msg.from); | ||
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('html data message', async (t) => { | ||
test.serial('html data message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT+HTML+DATA message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -196,7 +258,7 @@ test('html data message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('html file message', async (t) => { | ||
test.serial('html file message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT+HTML+FILE message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -215,7 +277,7 @@ test('html file message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('html with image embed message', async (t) => { | ||
test.serial('html with image embed message', async (t) => { | ||
const htmlFixture2Url = new URL('attachments/smtp2.html', import.meta.url); | ||
const imageFixtureUrl = new URL('attachments/smtp.gif', import.meta.url); | ||
const msg = { | ||
|
@@ -248,7 +310,7 @@ test('html with image embed message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('html data and attachment message', async (t) => { | ||
test.serial('html data and attachment message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT+HTML+FILE message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -270,7 +332,7 @@ test('html data and attachment message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('attachment message', async (t) => { | ||
test.serial('attachment message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT+ATTACHMENT message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -291,7 +353,7 @@ test('attachment message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('attachment sent with unicode filename message', async (t) => { | ||
test.serial('attachment sent with unicode filename message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT+ATTACHMENT message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -313,7 +375,7 @@ test('attachment sent with unicode filename message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('attachments message', async (t) => { | ||
test.serial('attachments message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT+2+ATTACHMENTS message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -342,7 +404,7 @@ test('attachments message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('streams message', async (t) => { | ||
test.serial('streams message', async (t) => { | ||
const msg = { | ||
subject: 'this is a test TEXT+2+STREAMED+ATTACHMENTS message from emailjs', | ||
from: '[email protected]', | ||
|
@@ -375,81 +437,40 @@ test('streams message', async (t) => { | |
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('message validation fails without `from` header', async (t) => { | ||
const msg = new Message({}); | ||
const { isValid, validationError } = msg.checkValidity(); | ||
t.false(isValid); | ||
t.is(validationError, 'Message must have a `from` header'); | ||
}); | ||
|
||
test('message validation fails without `to`, `cc`, or `bcc` header', async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
}).checkValidity(); | ||
|
||
t.false(isValid); | ||
t.is( | ||
validationError, | ||
'Message must have at least one `to`, `cc`, or `bcc` header' | ||
); | ||
}); | ||
|
||
test('message validation succeeds with only `to` recipient header (string)', async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
}); | ||
|
||
test('message validation succeeds with only `to` recipient header (array)', async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
to: ['[email protected]'], | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
}); | ||
|
||
test('message validation succeeds with only `cc` recipient header (string)', async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
cc: '[email protected]', | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
}); | ||
|
||
test('message validation succeeds with only `cc` recipient header (array)', async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
cc: ['[email protected]'], | ||
}).checkValidity(); | ||
test.serial('very large text message', async (t) => { | ||
// thanks to jart+loberstech for this one! | ||
const msg = { | ||
subject: 'this is a test TEXT message from emailjs', | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
text: textFixture, | ||
}; | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
const mail = await send(msg); | ||
t.is(mail.text, msg.text.replace(/\r/g, '') + '\n\n\n'); | ||
t.is(mail.subject, msg.subject); | ||
t.is(mail.from?.text, msg.from); | ||
t.is(mail.to?.text, msg.to); | ||
}); | ||
|
||
test('message validation succeeds with only `bcc` recipient header (string)', async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
bcc: '[email protected]', | ||
}).checkValidity(); | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
}); | ||
test.serial('very large text data message', async (t) => { | ||
const text = '<html><body><pre>' + textFixture + '</pre></body></html>'; | ||
|
||
test('message validation succeeds with only `bcc` recipient header (array)', async (t) => { | ||
const { isValid, validationError } = new Message({ | ||
from: '[email protected]', | ||
bcc: ['[email protected]'], | ||
}).checkValidity(); | ||
const msg = { | ||
subject: 'this is a test TEXT+DATA message from emailjs', | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
text: 'hello friend if you are seeing this, you can not view html emails. it is attached inline.', | ||
attachment: { | ||
data: text, | ||
alternative: true, | ||
}, | ||
}; | ||
|
||
t.true(isValid); | ||
t.is(validationError, undefined); | ||
const mail = await send(msg); | ||
t.is(mail.html, text.replace(/\r/g, '')); | ||
t.is(mail.text, msg.text + '\n'); | ||
t.is(mail.subject, msg.subject); | ||
t.is(mail.from?.text, msg.from); | ||
t.is(mail.to?.text, msg.to); | ||
}); |