@jesseditson/dnsimple
Version:
A Node.JS client for the DNSimple API.
202 lines (201 loc) • 11.3 kB
JavaScript
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("zone records", () => {
describe("#listZoneRecords", () => {
const accountId = 1010;
const zoneId = "example.com";
it("supports pagination", () => __awaiter(void 0, void 0, void 0, function* () {
const scope = nock("https://api.dnsimple.com")
.get("/v2/1010/zones/example.com/records?page=1")
.reply((0, util_1.readFixtureAt)("listZoneRecords/success.http"));
yield dnsimple.zones.listZoneRecords(accountId, zoneId, { 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/example.com/records?foo=bar")
.reply((0, util_1.readFixtureAt)("listZoneRecords/success.http"));
yield dnsimple.zones.listZoneRecords(accountId, zoneId, { 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/example.com/records?sort=name%3Aasc")
.reply((0, util_1.readFixtureAt)("listZoneRecords/success.http"));
yield dnsimple.zones.listZoneRecords(accountId, zoneId, {
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/example.com/records?name_like=example")
.reply((0, util_1.readFixtureAt)("listZoneRecords/success.http"));
yield dnsimple.zones.listZoneRecords(accountId, zoneId, {
name_like: "example",
});
expect(scope.isDone()).toBeTruthy();
}));
it("produces a record list", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/zones/example.com/records")
.reply((0, util_1.readFixtureAt)("listZoneRecords/success.http"));
const response = yield dnsimple.zones.listZoneRecords(accountId, zoneId);
const records = response.data;
expect(records.length).toBe(5);
expect(records[0].id).toBe(1);
expect(records[0].zone_id).toBe(zoneId);
expect(records[0].name).toBe("");
expect(records[0].content).toBe("ns1.dnsimple.com admin.dnsimple.com 1458642070 86400 7200 604800 300");
expect(records[0].ttl).toBe(3600);
expect(records[0].priority).toBe(null);
expect(records[0].type).toBe("SOA");
expect(records[0].system_record).toBe(true);
expect(records[0].created_at).toBe("2016-03-22T10:20:53Z");
expect(records[0].updated_at).toBe("2016-10-05T09:26:38Z");
}));
it("exposes the pagination info", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get(`/v2/1010/zones/${zoneId}/records`)
.reply((0, util_1.readFixtureAt)("listZoneRecords/success.http"));
const response = yield dnsimple.zones.listZoneRecords(accountId, zoneId);
const pagination = response.pagination;
expect(pagination).not.toBe(null);
expect(pagination.current_page).toBe(1);
}));
});
describe("#listZoneRecords.collectAll", () => {
const accountId = 1010;
const zoneId = "example.com";
it("produces a complete list", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/zones/example.com/records?page=1")
.reply((0, util_1.readFixtureAt)("pages-1of3.http"));
nock("https://api.dnsimple.com")
.get("/v2/1010/zones/example.com/records?page=2")
.reply((0, util_1.readFixtureAt)("pages-2of3.http"));
nock("https://api.dnsimple.com")
.get("/v2/1010/zones/example.com/records?page=3")
.reply((0, util_1.readFixtureAt)("pages-3of3.http"));
const items = yield dnsimple.zones.listZoneRecords.collectAll(accountId, zoneId);
expect(items.length).toBe(5);
expect(items[0].id).toBe(1);
expect(items[4].id).toBe(5);
}));
});
describe("#getZoneRecord", () => {
const accountId = 1010;
const zoneId = "example.com";
it("produces a record", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/zones/example.com/records/64784")
.reply((0, util_1.readFixtureAt)("getZoneRecord/success.http"));
const response = yield dnsimple.zones.getZoneRecord(accountId, zoneId, 64784);
const record = response.data;
expect(record.id).toBe(5);
expect(record.regions.length).toBe(2);
expect(record.regions[0]).toBe("SV1");
expect(record.regions[1]).toBe("IAD");
}));
describe("when the 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/0")
.reply((0, util_1.readFixtureAt)("notfound-record.http"));
yield expect(dnsimple.zones.getZoneRecord(accountId, zoneId, 0)).rejects.toThrow(main_1.NotFoundError);
}));
});
});
describe("#createZoneRecord", () => {
const accountId = 1010;
const zoneId = "example.com";
const attributes = {
name: "",
type: "A",
ttl: 3600,
content: "1.2.3.4",
};
it("builds the correct request", () => __awaiter(void 0, void 0, void 0, function* () {
const scope = nock("https://api.dnsimple.com")
.post("/v2/1010/zones/example.com/records", attributes)
.reply((0, util_1.readFixtureAt)("createZoneRecord/created.http"));
yield dnsimple.zones.createZoneRecord(accountId, zoneId, attributes);
expect(scope.isDone()).toBeTruthy();
}));
it("produces a record", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.post("/v2/1010/zones/example.com/records", attributes)
.reply((0, util_1.readFixtureAt)("createZoneRecord/created.http"));
const response = yield dnsimple.zones.createZoneRecord(accountId, zoneId, attributes);
expect(response.data.id).toBe(1);
}));
});
describe("#updateZoneRecord", () => {
const accountId = 1010;
const zoneId = "example.com";
const recordId = 64784;
const attributes = { content: "127.0.0.1" };
it("builds the correct request", () => __awaiter(void 0, void 0, void 0, function* () {
const scope = nock("https://api.dnsimple.com")
.patch("/v2/1010/zones/example.com/records/" + recordId, attributes)
.reply((0, util_1.readFixtureAt)("updateZoneRecord/success.http"));
yield dnsimple.zones.updateZoneRecord(accountId, zoneId, recordId, attributes);
expect(scope.isDone()).toBeTruthy();
}));
it("produces a record", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.patch("/v2/1010/zones/example.com/records/" + recordId, attributes)
.reply((0, util_1.readFixtureAt)("updateZoneRecord/success.http"));
const response = yield dnsimple.zones.updateZoneRecord(accountId, zoneId, recordId, attributes);
expect(response.data.id).toEqual(5);
}));
describe("when the record does not exist", () => {
it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.patch("/v2/1010/zones/example.com/records/" + recordId, attributes)
.reply((0, util_1.readFixtureAt)("notfound-record.http"));
yield expect(dnsimple.zones.updateZoneRecord(accountId, zoneId, recordId, attributes)).rejects.toThrow(main_1.NotFoundError);
}));
});
describe("#deleteZoneRecord", () => {
const accountId = 1010;
const zoneId = "example.com";
const recordId = 64784;
it("builds the correct request", () => __awaiter(void 0, void 0, void 0, function* () {
const scope = nock("https://api.dnsimple.com")
.delete("/v2/1010/zones/example.com/records/" + recordId)
.reply((0, util_1.readFixtureAt)("deleteZoneRecord/success.http"));
yield dnsimple.zones.deleteZoneRecord(accountId, zoneId, recordId);
expect(scope.isDone()).toBeTruthy();
}));
it("produces nothing", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.delete("/v2/1010/zones/example.com/records/" + recordId)
.reply((0, util_1.readFixtureAt)("deleteZoneRecord/success.http"));
const response = yield dnsimple.zones.deleteZoneRecord(accountId, zoneId, recordId);
expect(response).toEqual({});
}));
describe("when the record does not exist", () => {
it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.delete("/v2/1010/zones/example.com/records/" + recordId)
.reply((0, util_1.readFixtureAt)("notfound-record.http"));
yield expect(dnsimple.zones.deleteZoneRecord(accountId, zoneId, recordId)).rejects.toThrow(main_1.NotFoundError);
}));
});
});
});
});
;