-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.ts
36 lines (27 loc) · 1016 Bytes
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { initializeEnv } from "./helper.ts";
import type { Region } from "./types.ts";
import Mailgun from "./index.ts";
initializeEnv([
"MAILGUN_TO",
"MAILGUN_KEY",
"MAILGUN_REGION",
"MAILGUN_DOMAIN",
]);
const to = Deno.env.get("MAILGUN_TO")!;
const key = Deno.env.get("MAILGUN_KEY")!;
const domain = Deno.env.get("MAILGUN_DOMAIN")!;
const region = Deno.env.get("MAILGUN_REGION")! as Region;
const mailgun = new Mailgun({ key, region, domain });
Deno.test("check for status 200", async () => {
const text = "This is a test email";
const subject = "Testing Mailgun";
const testing = true;
const response = await mailgun.send({ to, text, from, subject, testing });
// If the Mailgun API returns a 200 OK will consider the test as passed
if (response.status !== 200) {
throw new Error(`Mailgun API returned status code ${response.status}`);
}
// Cancel the body consumption to prevent memory leaks
response.body?.cancel();
});