@jesseditson/dnsimple
Version:
A Node.JS client for the DNSimple API.
56 lines (55 loc) • 2.99 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("response handling", () => {
describe("a 400 error", () => {
it("includes the error message from the server", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.post("/v2/validation-error", {})
.reply((0, util_1.readFixtureAt)("validation-error.http"));
try {
yield dnsimple.request("POST", "/validation-error", {}, {});
}
catch (error) {
expect(error).toBeInstanceOf(main_1.ClientError);
expect(error.data.errors.email).toEqual(expect.arrayContaining(["can't be blank"]));
}
}));
});
describe("a 200 response with malformed json", () => {
it("produces a JSON parse error", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/success-with-malformed-json")
.reply((0, util_1.readFixtureAt)("success-with-malformed-json.http"));
yield expect(dnsimple.request("GET", "/success-with-malformed-json", null, {})).rejects.toThrow(SyntaxError);
}));
});
describe("an error response with HTML content", () => {
it("produces a JSON parse error", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/badgateway")
.reply((0, util_1.readFixtureAt)("badgateway.http"));
yield expect(dnsimple.request("GET", "/badgateway", null, {})).rejects.toThrow(SyntaxError);
}));
});
describe("a 405 error", () => {
it("results in a rejected promise", () => __awaiter(void 0, void 0, void 0, function* () {
nock("https://api.dnsimple.com")
.get("/v2/method-not-allowed")
.reply((0, util_1.readFixtureAt)("method-not-allowed.http"));
yield expect(dnsimple.request("GET", "/method-not-allowed", null, {})).rejects.toThrow(main_1.MethodNotAllowedError);
}));
});
});
;