@jesseditson/dnsimple
Version:
A Node.JS client for the DNSimple API.
143 lines (142 loc) • 8.19 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("domains", () => {
describe("#listDelegationSignerRecords", () => {
const accountId = 1010;
const domainId = "example.com";
it("supports pagination", () => __awaiter(void 0, void 0, void 0, function* () {
const scope = nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/ds_records?page=1")
.reply((0, util_1.readFixtureAt)("listDelegationSignerRecords/success.http"));
yield dnsimple.domains.listDelegationSignerRecords(accountId, domainId, {
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/example.com/ds_records?foo=bar")
.reply((0, util_1.readFixtureAt)("listDelegationSignerRecords/success.http"));
yield dnsimple.domains.listDelegationSignerRecords(accountId, domainId, {
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/example.com/ds_records?sort=created_at%3Aasc")
.reply((0, util_1.readFixtureAt)("listDelegationSignerRecords/success.http"));
yield dnsimple.domains.listDelegationSignerRecords(accountId, domainId, {
sort: "created_at:asc",
});
expect(scope.isDone()).toBeTruthy();
}));
it("produces an delegation signer records list", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/ds_records")
.reply((0, util_1.readFixtureAt)("listDelegationSignerRecords/success.http"));
const response = yield dnsimple.domains.listDelegationSignerRecords(accountId, domainId);
expect(response.data.length).toBe(1);
}));
it("exposes the pagination info", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/ds_records")
.reply((0, util_1.readFixtureAt)("listDelegationSignerRecords/success.http"));
const response = yield dnsimple.domains.listDelegationSignerRecords(accountId, domainId);
const pagination = response.pagination;
expect(pagination).not.toBe(null);
expect(pagination.current_page).toBe(1);
}));
});
describe("#listDelegationSignerRecords.collectAll", () => {
const accountId = 1010;
const domainId = "example.com";
it("produces a complete list", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/ds_records?page=1")
.reply((0, util_1.readFixtureAt)("pages-1of3.http"));
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/ds_records?page=2")
.reply((0, util_1.readFixtureAt)("pages-2of3.http"));
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/ds_records?page=3")
.reply((0, util_1.readFixtureAt)("pages-3of3.http"));
const items = yield dnsimple.domains.listDelegationSignerRecords.collectAll(accountId, domainId);
expect(items.length).toBe(5);
expect(items[0].id).toBe(1);
expect(items[4].id).toBe(5);
}));
});
describe("#getDelegationSignerRecord", () => {
const accountId = 1010;
const domainId = "example.com";
const dsRecordId = 1;
it("produces a delegation signer record", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/ds_records/1")
.reply((0, util_1.readFixtureAt)("getDelegationSignerRecord/success.http"));
const response = yield dnsimple.domains.getDelegationSignerRecord(accountId, domainId, dsRecordId);
const dsRecord = response.data;
expect(dsRecord.id).toBe(24);
expect(dsRecord.algorithm).toBe("8");
expect(dsRecord.digest).toBe("C1F6E04A5A61FBF65BF9DC8294C363CF11C89E802D926BDAB79C55D27BEFA94F");
expect(dsRecord.digest_type).toBe("2");
expect(dsRecord.keytag).toBe("44620");
expect(dsRecord.public_key).toBe(null);
expect(dsRecord.created_at).toBe("2017-03-03T13:49:58Z");
expect(dsRecord.updated_at).toBe("2017-03-03T13:49:58Z");
}));
describe("when the delegation signer record does not exist", () => {
it("produces an error", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/ds_records/0")
.reply((0, util_1.readFixtureAt)("notfound-delegationSignerRecord.http"));
yield expect(dnsimple.domains.getDelegationSignerRecord(accountId, domainId, 0)).rejects.toThrow(main_1.NotFoundError);
}));
});
});
describe("#createDelegationSignerRecord", () => {
const accountId = 1010;
const domainId = "example.com";
const attributes = { algorithm: "8" };
it("builds the correct request", () => __awaiter(void 0, void 0, void 0, function* () {
const scope = nock("https://api.dnsimple.com")
.post("/v2/1010/domains/example.com/ds_records", attributes)
.reply((0, util_1.readFixtureAt)("createDelegationSignerRecord/created.http"));
yield dnsimple.domains.createDelegationSignerRecord(accountId, domainId, attributes);
expect(scope.isDone()).toBeTruthy();
}));
it("produces a delegation signer record", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.post("/v2/1010/domains/example.com/ds_records")
.reply((0, util_1.readFixtureAt)("createDelegationSignerRecord/created.http"));
const response = yield dnsimple.domains.createDelegationSignerRecord(accountId, domainId, attributes);
expect(response.data.id).toBe(2);
}));
});
describe("#deleteDelegationSignerRecord", () => {
const accountId = 1010;
const domainId = "example.com";
const dsRecordId = 1;
it("produces nothing", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.delete("/v2/1010/domains/example.com/ds_records/1")
.reply((0, util_1.readFixtureAt)("deleteDelegationSignerRecord/success.http"));
const response = yield dnsimple.domains.deleteDelegationSignerRecord(accountId, domainId, dsRecordId);
expect(response).toEqual({});
}));
});
});
;