mailgun/test/test.ts

42 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.',
from: 'noreply@mail.lossless.com',
subject: 'hi there. This is the subject'
});
return testSmartmail;
});
tap.test('should send a smartmail', async () => {
2019-10-28 15:07:14 +00:00
testMailgunAccount.sendSmartMail(testSmartmail, '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 () => {
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';
testMailgunAccount.sendSmartMail(result, 'sandbox@mail.git.zone');
}
2020-01-13 08:09:37 +00:00
});
2019-10-23 17:27:42 +00:00
tap.start();