UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

146 lines (145 loc) 7.81 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("domains", () => { describe("#listDomains", () => { const accountId = 1010; it("supports pagination", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .get("/v2/1010/domains?page=1") .reply((0, util_1.readFixtureAt)("listDomains/success.http")); yield dnsimple.domains.listDomains(accountId, { page: 1 }); expect(scope.isDone()).toBeTruthy(); })); it("supports extra request options", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .get("/v2/1010/domains?foo=bar") .reply((0, util_1.readFixtureAt)("listDomains/success.http")); yield dnsimple.domains.listDomains(accountId, { foo: "bar" }); expect(scope.isDone()).toBeTruthy(); })); it("supports sorting", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .get("/v2/1010/domains?sort=expiration%3Aasc") .reply((0, util_1.readFixtureAt)("listDomains/success.http")); yield dnsimple.domains.listDomains(accountId, { sort: "expiration:asc" }); expect(scope.isDone()).toBeTruthy(); })); it("supports filter", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .get("/v2/1010/domains?name_like=example") .reply((0, util_1.readFixtureAt)("listDomains/success.http")); yield dnsimple.domains.listDomains(accountId, { name_like: "example" }); expect(scope.isDone()).toBeTruthy(); })); it("produces a domain list", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/domains") .reply((0, util_1.readFixtureAt)("listDomains/success.http")); const response = yield dnsimple.domains.listDomains(accountId); const domains = response.data; expect(domains.length).toBe(2); expect(domains[0].name).toBe("example-alpha.com"); expect(domains[0].account_id).toBe(1385); })); it("exposes the pagination info", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/domains") .reply((0, util_1.readFixtureAt)("listDomains/success.http")); const response = yield dnsimple.domains.listDomains(accountId); const pagination = response.pagination; expect(pagination).not.toBe(null); expect(pagination.current_page).toBe(1); })); }); describe("#listDomains.collectAll", () => { const accountId = 1010; it("produces a complete list", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/domains?page=1") .reply((0, util_1.readFixtureAt)("pages-1of3.http")); nock("https://api.dnsimple.com") .get("/v2/1010/domains?page=2") .reply((0, util_1.readFixtureAt)("pages-2of3.http")); nock("https://api.dnsimple.com") .get("/v2/1010/domains?page=3") .reply((0, util_1.readFixtureAt)("pages-3of3.http")); const items = yield dnsimple.domains.listDomains.collectAll(accountId); expect(items.length).toBe(5); expect(items[0].id).toBe(1); expect(items[4].id).toBe(5); })); }); describe("#getDomain", () => { const accountId = 1385; const domainId = "example-alpha.com"; it("produces a domain", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1385/domains/example-alpha.com") .reply((0, util_1.readFixtureAt)("getDomain/success.http")); const response = yield dnsimple.domains.getDomain(accountId, domainId); const domain = response.data; expect(domain.id).toBe(181984); expect(domain.account_id).toBe(1385); expect(domain.registrant_id).toBe(2715); expect(domain.name).toBe("example-alpha.com"); expect(domain.state).toBe("registered"); expect(domain.auto_renew).toBe(false); expect(domain.private_whois).toBe(false); expect(domain.expires_on).toBe("2021-06-05"); expect(domain.expires_at).toBe("2021-06-05T02:15:00Z"); expect(domain.created_at).toBe("2020-06-04T19:15:14Z"); expect(domain.updated_at).toBe("2020-06-04T19:15:21Z"); })); describe("when the domain does not exist", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1385/domains/0") .reply((0, util_1.readFixtureAt)("notfound-domain.http")); yield expect(dnsimple.domains.getDomain(accountId, "0")).rejects.toThrow(main_1.NotFoundError); })); }); }); describe("#createDomain", () => { const accountId = 1385; const attributes = { name: "example-alpha.com" }; it("builds the correct request", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .post("/v2/1385/domains", attributes) .reply((0, util_1.readFixtureAt)("createDomain/created.http")); yield dnsimple.domains.createDomain(accountId, attributes); expect(scope.isDone()).toBeTruthy(); })); it("produces a domain", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .post("/v2/1385/domains") .reply((0, util_1.readFixtureAt)("createDomain/created.http")); const response = yield dnsimple.domains.createDomain(accountId, attributes); const domain = response.data; expect(domain.id).toBe(181985); })); }); describe("#deleteDomain", () => { const accountId = 1010; const domainId = "example.com"; it("produces nothing", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .delete("/v2/1010/domains/example.com") .reply((0, util_1.readFixtureAt)("deleteDomain/success.http")); const response = yield dnsimple.domains.deleteDomain(accountId, domainId); expect(response).toEqual({}); })); }); });