1 | import * as postmark from "../../src/index";
|
2 |
|
3 | import { expect } from "chai";
|
4 | import "mocha";
|
5 |
|
6 | import * as nconf from "nconf";
|
7 | import {Suppression, Suppressions, SuppressionStatuses} from "../../src/client/models";
|
8 | const testingKeys = nconf.env().file({ file: __dirname + "/../../testing_keys.json" });
|
9 |
|
10 | describe("Client - Suppressions", () => {
|
11 | const serverToken: string = testingKeys.get("SERVER_TOKEN");
|
12 | const client = new postmark.ServerClient(serverToken);
|
13 | const suppression_email_domain:string = 'supression.example.com';
|
14 |
|
15 | async function cleanup() {
|
16 | const suppressions: Suppressions = await client.getSuppressions('outbound');
|
17 | suppressions.Suppressions.forEach( async (suppression: Suppression) => {
|
18 | if (suppression.EmailAddress.includes(suppression_email_domain)) {
|
19 | await client.deleteSuppressions('outbound', { Suppressions: [ { EmailAddress: suppression.EmailAddress} ] });
|
20 | }
|
21 | });
|
22 | }
|
23 |
|
24 | before(cleanup);
|
25 | after(cleanup);
|
26 |
|
27 | it("createSuppression", async () => {
|
28 | const emailAddress = `nothing+create@${suppression_email_domain}`;
|
29 | const suppression: SuppressionStatuses = await client.createSuppressions('outbound', {
|
30 | Suppressions: [ { EmailAddress: emailAddress} ]
|
31 | });
|
32 |
|
33 | expect(suppression.Suppressions.length).to.eq(1);
|
34 | });
|
35 |
|
36 | it("getSuppressions", async () => {
|
37 | const emailAddress = `nothing+list@${suppression_email_domain}`;
|
38 | await client.createSuppressions('outbound', {
|
39 | Suppressions: [ { EmailAddress: emailAddress} ]
|
40 | });
|
41 |
|
42 |
|
43 | const suppressions: Suppressions = await client.getSuppressions('outbound');
|
44 | expect(suppressions.Suppressions.length).to.be.gte(1);
|
45 | });
|
46 |
|
47 | it("deleteSuppression", async () => {
|
48 | const emailAddress = `nothing+delete@${suppression_email_domain}`;
|
49 | const suppression: SuppressionStatuses = await client.deleteSuppressions('outbound', {
|
50 | Suppressions: [ { EmailAddress: emailAddress} ]
|
51 | });
|
52 |
|
53 | expect(suppression.Suppressions.length).to.eq(1);
|
54 | });
|
55 | });
|