@jesseditson/dnsimple
Version:
A Node.JS client for the DNSimple API.
86 lines (85 loc) • 4.5 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("services", () => {
describe("#listServices", () => {
it("supports pagination", () => __awaiter(void 0, void 0, void 0, function* () {
const scope = nock("https://api.dnsimple.com")
.get("/v2/services?page=1")
.reply((0, util_1.readFixtureAt)("listServices/success.http"));
yield dnsimple.services.listServices({ 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/services?foo=bar")
.reply((0, util_1.readFixtureAt)("listServices/success.http"));
yield dnsimple.services.listServices({ 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/services?sort=sid%3Aasc")
.reply((0, util_1.readFixtureAt)("listServices/success.http"));
yield dnsimple.services.listServices({ sort: "sid: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/services")
.reply((0, util_1.readFixtureAt)("listServices/success.http"));
const response = yield dnsimple.services.listServices();
const services = response.data;
expect(services.length).toBe(2);
expect(services[0].name).toBe("Service 1");
expect(services[0].sid).toBe("service1");
}));
it("exposes the pagination info", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/services")
.reply((0, util_1.readFixtureAt)("listServices/success.http"));
const response = yield dnsimple.services.listServices();
const pagination = response.pagination;
expect(pagination).not.toBe(null);
expect(pagination.current_page).toBe(1);
}));
});
describe("#listServices.collectAll", () => {
it("produces a complete list", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/services?page=1")
.reply((0, util_1.readFixtureAt)("pages-1of3.http"));
nock("https://api.dnsimple.com")
.get("/v2/services?page=2")
.reply((0, util_1.readFixtureAt)("pages-2of3.http"));
nock("https://api.dnsimple.com")
.get("/v2/services?page=3")
.reply((0, util_1.readFixtureAt)("pages-3of3.http"));
const items = yield dnsimple.services.listServices.collectAll();
expect(items.length).toBe(5);
expect(items[0].id).toBe(1);
expect(items[4].id).toBe(5);
}));
});
describe("#getService", () => {
const serviceId = "1";
it("produces a service", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/services/1")
.reply((0, util_1.readFixtureAt)("getService/success.http"));
const response = yield dnsimple.services.getService(serviceId);
expect(response.data.id).toBe(1);
}));
});
});
;