mailgun/test/test.ts

62 lines
2.2 KiB
TypeScript
Raw 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');
2022-08-07 14:31:56 +00:00
import * as mailgun from '../ts/index.js';
import { IMailgunMessage } from '../ts/index.js';
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 () => {
2022-08-07 14:31:56 +00:00
testMailgunAccount = new mailgun.MailgunAccount({
apiToken: testQenv.getEnvVarOnDemand('MAILGUN_API_TOKEN'),
region: 'eu'
});
await testMailgunAccount.addSmtpCredentials(testQenv.getEnvVarOnDemand('MAILGUN_SMTP_CREDENTIALS'));
expect(testMailgunAccount).toBeInstanceOf(mailgun.MailgunAccount);
2019-10-28 14:55:04 +00:00
});
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>',
2020-08-13 01:37:26 +00:00
subject: 'TestMessage from @mojoio/mailgun test',
2019-10-28 14:55:04 +00:00
});
2022-08-07 14:31:56 +00:00
expect(testSmartmail).toBeInstanceOf(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-13 01:37:26 +00:00
subject: 'A message with no body from @mojoio/mailgun test',
2020-08-11 14:47:25 +00:00
});
2020-08-13 01:37:26 +00:00
await testMailgunAccount.sendSmartMail(
emptyBodySmartmail,
'Sandbox Team <sandbox@mail.git.zone>'
);
2020-08-11 14:47:25 +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=='
);
2022-08-07 14:31:56 +00:00
console.log(result);
// TODO handle empty body
if (false) {
2020-01-21 10:04:28 +00:00
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();