UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

87 lines (86 loc) 4.59 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 util_1 = require("./util"); const dnsimple = (0, util_1.createTestClient)(); describe("collaborators", () => { describe("#listCollaborators", () => { 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/collaborators?page=1") .reply((0, util_1.readFixtureAt)("listCollaborators/success.http")); yield dnsimple.domains.listCollaborators(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/collaborators?foo=bar") .reply((0, util_1.readFixtureAt)("listCollaborators/success.http")); yield dnsimple.domains.listCollaborators(accountId, domainId, { foo: "bar", }); expect(scope.isDone()).toBeTruthy(); })); it("produces a collaborators list", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/domains/example.com/collaborators") .reply((0, util_1.readFixtureAt)("listCollaborators/success.http")); const response = yield dnsimple.domains.listCollaborators(accountId, domainId); const collaborators = response.data; expect(collaborators.length).toBe(2); expect(collaborators[0].id).toBe(100); expect(collaborators[0].domain_id).toBe(1); expect(collaborators[0].user_id).toBe(999); })); it("exposes the pagination info", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/domains/example.com/collaborators") .reply((0, util_1.readFixtureAt)("listCollaborators/success.http")); const response = yield dnsimple.domains.listCollaborators(accountId, domainId); const pagination = response.pagination; expect(pagination).not.toBe(null); expect(pagination.current_page).toBe(1); })); }); describe("#addCollaborator", () => { const accountId = 1010; const domainId = "example.com"; const collaborator = { email: "existing-user@example.com", }; it("produces a response", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .post("/v2/1010/domains/example.com/collaborators") .reply((0, util_1.readFixtureAt)("addCollaborator/success.http")); const response = yield dnsimple.domains.addCollaborator(accountId, domainId, collaborator); const data = response.data; expect(data.id).toEqual(100); expect(data.invitation).toEqual(false); })); }); describe("#removeCollaborator", () => { const accountId = 1010; const domainId = "example.com"; const collaboratorId = 100; it("produces nothing", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .delete("/v2/1010/domains/example.com/collaborators/100") .reply((0, util_1.readFixtureAt)("removeCollaborator/success.http")); const response = yield dnsimple.domains.removeCollaborator(accountId, domainId, collaboratorId); expect(response).toEqual({}); })); }); });