UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

114 lines (113 loc) 5.95 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const nock = require("nock"); const main_1 = require("../lib/main"); const util_1 = require("./util"); const dnsimple = (0, util_1.createTestClient)(); describe("webhooks", () => { describe("#listWebhooks", () => { const accountId = 1010; it("supports extra request options", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .get("/v2/1010/webhooks?foo=bar") .reply((0, util_1.readFixtureAt)("listWebhooks/success.http")); yield dnsimple.webhooks.listWebhooks(accountId, { foo: "bar" }); expect(scope.isDone()).toBeTruthy(); })); it("produces a webhook list", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/webhooks") .reply((0, util_1.readFixtureAt)("listWebhooks/success.http")); const response = yield dnsimple.webhooks.listWebhooks(accountId); const webhooks = response.data; expect(webhooks.length).toBe(2); expect(webhooks[0].id).toBe(1); })); }); describe("#listWebhooks", () => { const accountId = 1010; it("supports extra request options", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .get("/v2/1010/webhooks?foo=bar") .reply((0, util_1.readFixtureAt)("listWebhooks/success.http")); yield dnsimple.webhooks.listWebhooks(accountId, { foo: "bar" }); expect(scope.isDone()).toBeTruthy(); })); it("produces a webhook list", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/webhooks") .reply((0, util_1.readFixtureAt)("listWebhooks/success.http")); const response = yield dnsimple.webhooks.listWebhooks(accountId); const items = response.data; expect(items.length).toBe(2); expect(items[0].id).toBe(1); })); }); describe("#getWebhook", () => { const accountId = 1010; const webhookId = 1; it("produces a webhook", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/webhooks/1") .reply((0, util_1.readFixtureAt)("getWebhook/success.http")); const response = yield dnsimple.webhooks.getWebhook(accountId, webhookId); const webhook = response.data; expect(webhook.id).toBe(1); expect(webhook.url).toBe("https://webhook.test"); })); describe("when the webhook does not exist", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/webhooks/0") .reply((0, util_1.readFixtureAt)("notfound-webhook.http")); yield expect(dnsimple.webhooks.getWebhook(accountId, 0)).rejects.toThrow(main_1.NotFoundError); })); }); }); describe("#createWebhook", () => { const accountId = 1010; const attributes = { url: "https://some-site.com" }; it("builds the correct request", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .post("/v2/1010/webhooks", attributes) .reply((0, util_1.readFixtureAt)("createWebhook/created.http")); yield dnsimple.webhooks.createWebhook(accountId, attributes); expect(scope.isDone()).toBeTruthy(); })); it("produces a webhook", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .post("/v2/1010/webhooks") .reply((0, util_1.readFixtureAt)("createWebhook/created.http")); const response = yield dnsimple.webhooks.createWebhook(accountId, attributes); expect(response.data.id).toBe(1); })); }); describe("#deleteWebhook", () => { const accountId = 1010; const webhookId = 1; it("produces nothing", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .delete("/v2/1010/webhooks/1") .reply((0, util_1.readFixtureAt)("deleteWebhook/success.http")); const response = yield dnsimple.webhooks.deleteWebhook(accountId, webhookId); expect(response).toEqual({}); })); describe("when the webhook does not exist", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .delete("/v2/1010/webhooks/0") .reply((0, util_1.readFixtureAt)("notfound-webhook.http")); yield expect(dnsimple.webhooks.deleteWebhook(accountId, 0)).rejects.toThrow(main_1.NotFoundError); })); }); }); });