UNPKG

1.69 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("Client - Message Statistics", () => {
10 const serverToken: string = testingKeys.get("SERVER_TOKEN");
11 const client = new postmark.ServerClient(serverToken);
12
13 function formattedDate(date: Date) {
14 return "" + date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
15 }
16
17 it("getDeliveryStatistics", async () => {
18 const stats = await client.getDeliveryStatistics();
19 expect(stats.InactiveMails).to.be.gte(0);
20 });
21
22 it("getSentCounts", async () => {
23 const stats = await client.getSentCounts();
24 expect(stats.Sent).to.be.gte(0);
25 });
26
27 it("getBounceCounts", async () => {
28 const stats = await client.getBounceCounts();
29 expect(stats.toString().length).to.be.gte(0);
30 });
31
32 it("getSpamComplaints", async () => {
33 const stats = await client.getSpamComplaintsCounts();
34 expect(stats.Days.length).to.be.gte(0);
35 });
36
37 it("getTrackedEmailCounts", async () => {
38 const stats = await client.getTrackedEmailCounts();
39 expect(stats.Tracked).to.be.gte(0);
40 });
41
42 it("getOutboundOverview", async () => {
43 const now = new Date();
44 const yesterday = new Date(now.valueOf() - (24 * 3600 * 1000));
45 const toDate = formattedDate(now);
46 const fromDate = formattedDate(yesterday);
47
48 const stats = await client.getOutboundOverview({ fromDate, toDate });
49 expect(stats.Sent).to.be.gte(0);
50 });
51});