1 | import * as postmark from "../../src/index";
|
2 |
|
3 | import { expect } from "chai";
|
4 | import "mocha";
|
5 |
|
6 | import * as nconf from "nconf";
|
7 | const testingKeys = nconf.env().file({ file: __dirname + "/../../testing_keys.json" });
|
8 |
|
9 | describe("Client - Webhooks", () => {
|
10 | const serverToken: string = testingKeys.get("SERVER_TOKEN");
|
11 | const client = new postmark.ServerClient(serverToken);
|
12 |
|
13 | function webhookToCreate() {
|
14 | return new postmark.Models.CreateWebhookRequest(
|
15 | 'https://example.com',
|
16 | { Open: { Enabled: true } }
|
17 | );
|
18 | }
|
19 |
|
20 | async function cleanup() {
|
21 | const webhooks = await client.getWebhooks();
|
22 |
|
23 | for (const webhook of webhooks.Webhooks) {
|
24 | await client.deleteWebhook(webhook.ID)
|
25 | }
|
26 | }
|
27 |
|
28 | before(cleanup);
|
29 | after(cleanup);
|
30 |
|
31 | it("getWebhooks", async () => {
|
32 | const result = await client.getWebhooks();
|
33 | expect(result.Webhooks.length).to.above(-1);
|
34 | });
|
35 |
|
36 | it("getWebhook", async () => {
|
37 | const webhook = await client.createWebhook(webhookToCreate());
|
38 | const result = await client.getWebhook(webhook.ID);
|
39 | expect(result.ID).to.above(-1);
|
40 | });
|
41 |
|
42 | it("createWebhook", async () => {
|
43 | const webhook = await client.createWebhook(webhookToCreate());
|
44 | expect(webhook.ID).to.above(-1);
|
45 | });
|
46 |
|
47 | it("editWebhook", async () => {
|
48 | const webhook = await client.createWebhook(webhookToCreate());
|
49 | const result = await client.editWebhook(webhook.ID, { Triggers: { SpamComplaint: { Enabled:true } } } );
|
50 | expect(result.Triggers.SpamComplaint.Enabled).to.equal(true);
|
51 | });
|
52 |
|
53 | it("deleteWebhook", async () => {
|
54 | const webhook = await client.createWebhook(webhookToCreate());
|
55 | const result = await client.deleteWebhook(webhook.ID);
|
56 | expect(result.Message.length).to.above(0);
|
57 | });
|
58 | });
|