UNPKG

1.54 kBPlain TextView Raw
1import * as postmark from "../../src/index";
2
3import { expect } from "chai";
4import "mocha";
5
6import * as nconf from "nconf";
7const testingKeys = nconf.env().file({ file: __dirname + "/../../testing_keys.json" });
8
9describe("Sending", () => {
10 const serverToken: string = testingKeys.get("SERVER_API_TOKEN");
11 const client = new postmark.ServerClient(serverToken);
12
13 const fromAddress: string = testingKeys.get("SENDER_EMAIL_ADDRESS");
14 const toAddress: string = testingKeys.get("RECIPIENT_EMAIL_ADDRESS");
15
16 function messageToSend() {
17 return new postmark.Models.Message(fromAddress, "Test subject", "Test html body", undefined, toAddress);
18 }
19
20 it("sendEmail", async () => {
21 const response = await client.sendEmail(messageToSend());
22 expect(response.Message).to.equal("OK");
23 });
24
25 it("sendEmailBatch", async () => {
26 const messages = Array.from({ length: 3 }, () => messageToSend());
27 const responses = await client.sendEmailBatch(messages);
28
29 expect(responses[0].Message).to.equal("OK");
30 expect(responses.length).to.equal(3);
31 });
32
33 describe("invalid", () => {
34 it("sendEmail", () => {
35 const message = messageToSend();
36 message.HtmlBody = undefined;
37
38 return client.sendEmail(message).then((result) => {
39 throw Error(`Should not be here with result: ${result}`);
40 }).catch((error) => {
41 expect(error.name).to.equal("ApiInputError");
42 });
43 });
44 });
45});