UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

242 lines (241 loc) 13.7 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("zones", () => { describe("#activateDns", () => { const accountId = 1010; it("produces a zone", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .put("/v2/1010/zones/example.com/activation") .reply((0, util_1.readFixtureAt)("activateZoneService/success.http")); const response = yield dnsimple.zones.activateDns(accountId, "example.com"); const zone = response.data; expect(zone.id).toBe(1); expect(zone.account_id).toBe(1010); expect(zone.name).toBe("example.com"); expect(zone.reverse).toBe(false); expect(zone.created_at).toBe("2015-04-23T07:40:03Z"); expect(zone.updated_at).toBe("2015-04-23T07:40:03Z"); })); }); describe("#deactivateDns", () => { const accountId = 1010; it("produces a zone", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .delete("/v2/1010/zones/example.com/activation") .reply((0, util_1.readFixtureAt)("deactivateZoneService/success.http")); const response = yield dnsimple.zones.deactivateDns(accountId, "example.com"); const zone = response.data; expect(zone.id).toBe(1); expect(zone.account_id).toBe(1010); expect(zone.name).toBe("example.com"); expect(zone.reverse).toBe(false); expect(zone.created_at).toBe("2015-04-23T07:40:03Z"); expect(zone.updated_at).toBe("2015-04-23T07:40:03Z"); })); }); describe("#listZones", () => { const accountId = 1010; it("supports pagination", () => __awaiter(void 0, void 0, void 0, function* () { const scope = nock("https://api.dnsimple.com") .get("/v2/1010/zones?page=1") .reply((0, util_1.readFixtureAt)("listZones/success.http")); yield dnsimple.zones.listZones(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/zones?foo=bar") .reply((0, util_1.readFixtureAt)("listZones/success.http")); yield dnsimple.zones.listZones(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/zones?sort=name%3Aasc") .reply((0, util_1.readFixtureAt)("listZones/success.http")); yield dnsimple.zones.listZones(accountId, { sort: "name: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/zones?name_like=example") .reply((0, util_1.readFixtureAt)("listZones/success.http")); yield dnsimple.zones.listZones(accountId, { name_like: "example" }); expect(scope.isDone()).toBeTruthy(); })); it("produces a zone list", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones") .reply((0, util_1.readFixtureAt)("listZones/success.http")); const response = yield dnsimple.zones.listZones(accountId); const zones = response.data; expect(zones.length).toBe(2); expect(zones[0].name).toBe("example-alpha.com"); expect(zones[0].account_id).toBe(1010); })); it("exposes the pagination info", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones") .reply((0, util_1.readFixtureAt)("listZones/success.http")); const response = yield dnsimple.zones.listZones(accountId); const pagination = response.pagination; expect(pagination).not.toBe(null); expect(pagination.current_page).toBe(1); })); }); describe("#listZones.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/zones?page=1") .reply((0, util_1.readFixtureAt)("pages-1of3.http")); nock("https://api.dnsimple.com") .get("/v2/1010/zones?page=2") .reply((0, util_1.readFixtureAt)("pages-2of3.http")); nock("https://api.dnsimple.com") .get("/v2/1010/zones?page=3") .reply((0, util_1.readFixtureAt)("pages-3of3.http")); const items = yield dnsimple.zones.listZones.collectAll(accountId); expect(items.length).toBe(5); expect(items[0].id).toBe(1); expect(items[4].id).toBe(5); })); }); describe("#getZone", () => { const accountId = 1010; it("produces a zone", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example-alpha.com") .reply((0, util_1.readFixtureAt)("getZone/success.http")); const response = yield dnsimple.zones.getZone(accountId, "example-alpha.com"); const zone = response.data; expect(zone.id).toBe(1); expect(zone.account_id).toBe(1010); expect(zone.name).toBe("example-alpha.com"); expect(zone.reverse).toBe(false); expect(zone.secondary).toBe(false); expect(zone.last_transferred_at).toBe(null); expect(zone.active).toBe(true); expect(zone.created_at).toBe("2015-04-23T07:40:03Z"); expect(zone.updated_at).toBe("2015-04-23T07:40:03Z"); })); describe("when the zone does not exist", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com") .reply((0, util_1.readFixtureAt)("notfound-zone.http")); yield expect(dnsimple.zones.getZone(accountId, "example.com")).rejects.toThrow(main_1.NotFoundError); })); }); }); describe("#getZoneFile", () => { const accountId = 1010; it("produces a zone file", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example-alpha.com/file") .reply((0, util_1.readFixtureAt)("getZoneFile/success.http")); const response = yield dnsimple.zones.getZoneFile(accountId, "example-alpha.com"); expect(response.data).not.toBe(null); })); describe("when the zone file does not exist", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com/file") .reply((0, util_1.readFixtureAt)("notfound-zone.http")); yield expect(dnsimple.zones.getZoneFile(accountId, "example.com")).rejects.toThrow(main_1.NotFoundError); })); }); }); describe("#checkZoneDistribution", () => { const accountId = 1010; it("returns true when the zone is fully distributed", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example-alpha.com/distribution") .reply((0, util_1.readFixtureAt)("checkZoneDistribution/success.http")); const response = yield dnsimple.zones.checkZoneDistribution(accountId, "example-alpha.com"); expect(response.data).not.toBe(null); })); describe("when the zone is not fully distributed", () => { it("returns false", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com/distribution") .reply((0, util_1.readFixtureAt)("checkZoneDistribution/failure.http")); const response = yield dnsimple.zones.checkZoneDistribution(accountId, "example.com"); expect(response.data.distributed).toBeFalsy(); })); }); describe("returns an error when the server was not able to complete the check", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com/distribution") .reply((0, util_1.readFixtureAt)("checkZoneDistribution/error.http")); yield expect(dnsimple.zones.checkZoneDistribution(accountId, "example.com")).rejects.toThrow(); })); }); describe("when the zone does not exist", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com/distribution") .reply((0, util_1.readFixtureAt)("notfound-zone.http")); yield expect(dnsimple.zones.checkZoneDistribution(accountId, "example.com")).rejects.toThrow(main_1.NotFoundError); })); }); }); describe("#checkZoneRecordDistribution", () => { const accountId = 1010; const recordId = 1; it("returns true when the zone record is fully distributed", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example-alpha.com/records/1/distribution") .reply((0, util_1.readFixtureAt)("checkZoneRecordDistribution/success.http")); const response = yield dnsimple.zones.checkZoneRecordDistribution(accountId, "example-alpha.com", recordId); expect(response.data).not.toBe(null); })); describe("when the zone record is not fully distributed", () => { it("returns false", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com/records/1/distribution") .reply((0, util_1.readFixtureAt)("checkZoneRecordDistribution/failure.http")); const response = yield dnsimple.zones.checkZoneRecordDistribution(accountId, "example.com", recordId); expect(response.data.distributed).toBeFalsy(); })); }); describe("returns an error when the server was not able to complete the check", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com/records/1/distribution") .reply((0, util_1.readFixtureAt)("checkZoneRecordDistribution/error.http")); yield expect(dnsimple.zones.checkZoneRecordDistribution(accountId, "example.com", recordId)).rejects.toThrow(); })); }); describe("when the zone does not exist", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com/records/1/distribution") .reply((0, util_1.readFixtureAt)("notfound-zone.http")); yield expect(dnsimple.zones.checkZoneRecordDistribution(accountId, "example.com", recordId)).rejects.toThrow(main_1.NotFoundError); })); }); describe("when the zone record does not exist", () => { it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/zones/example.com/records/1/distribution") .reply((0, util_1.readFixtureAt)("notfound-record.http")); yield expect(dnsimple.zones.checkZoneRecordDistribution(accountId, "example.com", recordId)).rejects.toThrow(main_1.NotFoundError); })); }); }); });