test: add validation units

This commit is contained in:
Zack Schuster 2022-05-11 16:39:49 -07:00
parent 5841918d7d
commit 615de80130
2 changed files with 21 additions and 2 deletions

View File

@ -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) => {

View File

@ -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();