2019-10-23 17:27:42 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
2019-10-28 14:55:04 +00:00
|
|
|
import { Qenv } from '@pushrocks/qenv';
|
|
|
|
import * as smartmail from '@pushrocks/smartmail';
|
|
|
|
|
|
|
|
const testQenv = new Qenv('./', './.nogit');
|
|
|
|
|
2019-10-23 17:27:42 +00:00
|
|
|
import * as mailgun from '../ts/index';
|
2020-01-21 10:04:28 +00:00
|
|
|
import { IMailgunMessage } from '../ts/index';
|
2019-10-23 17:27:42 +00:00
|
|
|
|
2019-10-28 14:55:04 +00:00
|
|
|
let testMailgunAccount: mailgun.MailgunAccount;
|
2020-01-21 10:04:28 +00:00
|
|
|
let testSmartmail: smartmail.Smartmail<IMailgunMessage>;
|
2019-10-28 14:55:04 +00:00
|
|
|
|
2020-01-21 10:04:28 +00:00
|
|
|
tap.test('should create a mailgun account', async () => {
|
2019-10-28 14:55:04 +00:00
|
|
|
testMailgunAccount = new mailgun.MailgunAccount(testQenv.getEnvVarOnDemand('MAILGUN_API_TOKEN'));
|
2020-08-13 00:32:05 +00:00
|
|
|
testMailgunAccount.addSmtpCredentials(testQenv.getEnvVarOnDemand('MAILGUN_SMTP_CREDENTIALS'));
|
2019-10-28 14:55:04 +00:00
|
|
|
expect(testMailgunAccount).to.be.instanceOf(mailgun.MailgunAccount);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should create a smartmail', async () => {
|
|
|
|
testSmartmail = new smartmail.Smartmail({
|
|
|
|
body: 'hi there. This is the body.',
|
2020-04-26 23:24:03 +00:00
|
|
|
from: 'Lossless GmbH <noreply@mail.lossless.com>',
|
|
|
|
subject: 'TestMessage from @mojoio/mailgun test'
|
2019-10-28 14:55:04 +00:00
|
|
|
});
|
2020-08-13 00:32:05 +00:00
|
|
|
expect(testSmartmail).to.be.instanceOf(smartmail.Smartmail);
|
2019-10-28 14:55:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should send a smartmail', async () => {
|
2020-04-26 23:24:03 +00:00
|
|
|
await testMailgunAccount.sendSmartMail(testSmartmail, 'Sandbox Team <sandbox@mail.git.zone>');
|
2019-10-23 17:27:42 +00:00
|
|
|
});
|
|
|
|
|
2020-08-11 14:47:25 +00:00
|
|
|
tap.test('should send a smartmail with empty body', async () => {
|
|
|
|
const emptyBodySmartmail = new smartmail.Smartmail<IMailgunMessage>({
|
|
|
|
body: '',
|
2020-08-13 00:32:05 +00:00
|
|
|
from: 'Lossless GmbH <noreply@mail.lossless.one>',
|
2020-08-11 14:47:25 +00:00
|
|
|
subject: 'A message with no body from @mojoio/mailgun test'
|
|
|
|
});
|
|
|
|
await testMailgunAccount.sendSmartMail(emptyBodySmartmail, 'Sandbox Team <sandbox@mail.git.zone>');
|
|
|
|
});
|
|
|
|
|
2020-01-13 08:09:37 +00:00
|
|
|
tap.test('should retrieve a mail using a retrieval url', async () => {
|
2020-06-18 22:00:00 +00:00
|
|
|
const result = await testMailgunAccount.retrieveSmartMailFromMessageUrl(
|
|
|
|
'https://sw.api.mailgun.net/v3/domains/mail.lossless.one/messages/AgMFnnnAKC8xp_dDa79LyoxhloxtaVmnRA=='
|
|
|
|
);
|
2020-01-21 10:04:28 +00:00
|
|
|
if (result) {
|
|
|
|
result.options.subject = 'hi there. This is a testmail with attachment';
|
|
|
|
result.options.from = 'noreply@mail.lossless.com';
|
2020-04-26 23:24:03 +00:00
|
|
|
await testMailgunAccount.sendSmartMail(result, 'Sandbox Team <sandbox@mail.git.zone>');
|
2020-01-21 10:04:28 +00:00
|
|
|
}
|
2020-01-13 08:09:37 +00:00
|
|
|
});
|
|
|
|
|
2019-10-23 17:27:42 +00:00
|
|
|
tap.start();
|