Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('deliver.send()', async () => {
const deliver = email(smtpConfig);
const token = '123.123.123';
const user = { name: 'John', email: 'john@doe.com' };
const req = { hostname: 'a-domain.com', protocol: 'http' };
await deliver.send(user, token, req);
expect(emailjs.__spy.connect).toHaveBeenCalledWith({
host: 'smtp.domain.com',
password: 'secure',
port: '465',
ssl: true,
user: 'user@domain.com'
});
expect(emailjs.__spy.send.mock.calls[0][0]).toEqual({
from: 'from@domain.com',
subject: 'Token for a-domain.com!',
text:
'Hello!\nAccess your account here: http://a-domain.com/?token=123.123.123',
to: 'john@doe.com'
});
});
...smtpConfig
});
const token = '123.123.123';
const user = { name: 'John', email: 'john@doe.com' };
const req = { hostname: 'a-domain.com', protocol: 'http' };
await deliver.send(user, token, req);
expect(emailjs.__spy.connect).toHaveBeenCalledWith({
host: 'smtp.domain.com',
password: 'secure',
port: '465',
ssl: true,
user: 'user@domain.com'
});
expect(emailjs.__spy.send.mock.calls[0][0]).toEqual({
from: 'from@domain.com',
subject: 'Token for a-domain.com!',
text:
'Hello!\nAccess your account here: http://a-domain.com/?acceptToken=123.123.123',
to: 'john@doe.com'
});
expect(deliver.tokenField).toBe('acceptToken');
});