@jesseditson/dnsimple
Version:
A Node.JS client for the DNSimple API.
96 lines (95 loc) • 5.15 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 util_1 = require("./util");
const dnsimple = (0, util_1.createTestClient)();
describe("domain services", () => {
describe("#applyService", () => {
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/services?page=1")
.reply((0, util_1.readFixtureAt)("appliedServices/success.http"));
yield dnsimple.services.applyService(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/services?foo=bar")
.reply((0, util_1.readFixtureAt)("appliedServices/success.http"));
yield dnsimple.services.applyService(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/services?sort=name%3Aasc")
.reply((0, util_1.readFixtureAt)("appliedServices/success.http"));
yield dnsimple.services.applyService(accountId, domainId, {
sort: "name:asc",
});
expect(scope.isDone()).toBeTruthy();
}));
it("produces a service list", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/services")
.reply((0, util_1.readFixtureAt)("appliedServices/success.http"));
const response = yield dnsimple.services.applyService(accountId, domainId);
const services = response.data;
expect(services.length).toBe(1);
expect(services[0].name).toBe("WordPress");
}));
});
describe("#applyService.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/services?page=1")
.reply((0, util_1.readFixtureAt)("pages-1of3.http"));
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/services?page=2")
.reply((0, util_1.readFixtureAt)("pages-2of3.http"));
nock("https://api.dnsimple.com")
.get("/v2/1010/domains/example.com/services?page=3")
.reply((0, util_1.readFixtureAt)("pages-3of3.http"));
const items = yield dnsimple.services.applyService.collectAll(accountId, domainId);
expect(items.length).toBe(5);
expect(items[0].id).toBe(1);
expect(items[4].id).toBe(5);
}));
});
describe("#appliedServices", () => {
const accountId = 1010;
const domainId = "example.com";
const serviceId = "name";
it("produces nothing", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.post("/v2/1010/domains/example.com/services/name")
.reply((0, util_1.readFixtureAt)("applyService/success.http"));
const response = yield dnsimple.services.appliedServices(accountId, domainId, serviceId, {});
expect(response).toEqual({});
}));
});
describe("#unapplyService", () => {
const accountId = 1010;
const domainId = "example.com";
const serviceId = "name";
it("produces nothing", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.delete("/v2/1010/domains/example.com/services/name")
.reply((0, util_1.readFixtureAt)("unapplyService/success.http"));
const response = yield dnsimple.services.unapplyService(accountId, domainId, serviceId);
expect(response).toEqual({});
}));
});
});
;