mailgun/test/test.ts

43 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

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'));
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
});
return testSmartmail;
});
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-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();