mirror of https://github.com/eleith/emailjs.git
test: add validation units
This commit is contained in:
parent
5841918d7d
commit
615de80130
|
@ -122,8 +122,12 @@ test('client accepts array sender', async (t) => {
|
|||
});
|
||||
msg.header.from = [msg.header.from as string];
|
||||
|
||||
const { isValid } = msg.checkValidity();
|
||||
t.true(isValid);
|
||||
const message = await client.sendAsync(msg);
|
||||
t.is(message.text, msg.text);
|
||||
t.deepEqual(message.header.from, ['zelda@gmail.com']);
|
||||
t.is(message.header.to, 'gannon1@gmail.com');
|
||||
t.is(message.header.cc, undefined);
|
||||
t.is(message.header.bcc, undefined);
|
||||
});
|
||||
|
||||
test('client rejects message without `from` header', async (t) => {
|
||||
|
|
|
@ -380,6 +380,21 @@ test('text + two attachments message (streams)', async (t) => {
|
|||
t.is(mail.to?.text, msg.to);
|
||||
});
|
||||
|
||||
test('message validation succeeds when `from` header is an array', async (t) => {
|
||||
const msg = new Message({
|
||||
from: ['zelda@gmail.com'],
|
||||
to: 'gannon1@gmail.com',
|
||||
});
|
||||
|
||||
t.false(Array.isArray(msg.header.from));
|
||||
|
||||
msg.header.from = [msg.header.from as string];
|
||||
const { isValid } = msg.checkValidity();
|
||||
|
||||
t.true(Array.isArray(msg.header.from));
|
||||
t.true(isValid);
|
||||
});
|
||||
|
||||
test('message validation fails without `from` header', async (t) => {
|
||||
const msg = new Message({});
|
||||
const { isValid, validationError } = msg.checkValidity();
|
||||
|
|
Loading…
Reference in New Issue