UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

44 lines (43 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readFixtureAt = exports.createTestClient = void 0; const fs_1 = require("fs"); const main_1 = require("../lib/main"); function hasJsonContent(lines) { for (let line of lines) { const [key, value] = line.split(/:\s/); if (key.toLowerCase() === "content-type" && value.includes("application/json")) return true; } return false; } function parseStatusCode(lines) { return parseInt(lines[0].split(/\s+/)[1], 10); } function parseBody(lines) { const separatorLineIndex = lines.findIndex((line) => line.trim() === ""); const rawBody = lines .slice(separatorLineIndex + 1) .join("\n") .trim(); if (hasJsonContent(lines) && rawBody !== "") return JSON.parse(rawBody); return rawBody; } function createTestClient() { var _a; return new main_1.DNSimple({ accessToken: (_a = process.env["TOKEN"]) !== null && _a !== void 0 ? _a : "bogus", }); } exports.createTestClient = createTestClient; function readFixtureAt(path) { const data = (0, fs_1.readFileSync)(`${__dirname}/fixtures.http/${path}`, "utf-8"); const lines = data.split(/\r?\n/); const statusCode = parseStatusCode(lines); if (statusCode === 204) return () => [204, ""]; return () => [statusCode, parseBody(lines)]; } exports.readFixtureAt = readFixtureAt;