UNPKG

@jesseditson/dnsimple

Version:

A Node.JS client for the DNSimple API.

113 lines (112 loc) 5.13 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 main_1 = require("../lib/main"); const util_1 = require("./util"); const dnsimple = (0, util_1.createTestClient)(); describe("billing", () => { describe("#listCharges", () => { const accountId = 1010; it("produces a charges list", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/billing/charges") .reply((0, util_1.readFixtureAt)("listCharges/success.http")); const response = yield dnsimple.billing.listCharges(accountId); const certificates = response.data; expect(certificates).toEqual([ { invoiced_at: "2023-08-17T05:53:36Z", total_amount: "14.50", balance_amount: "0.00", reference: "1-2", state: "collected", items: [ { description: "Register bubble-registered.com", amount: "14.50", product_id: 1, product_type: "domain-registration", product_reference: "bubble-registered.com", }, ], }, { invoiced_at: "2023-08-17T05:57:53Z", total_amount: "14.50", balance_amount: "0.00", reference: "2-2", state: "refunded", items: [ { description: "Register example.com", amount: "14.50", product_id: 2, product_type: "domain-registration", product_reference: "example.com", }, ], }, { invoiced_at: "2023-10-24T07:49:05Z", total_amount: "1099999.99", balance_amount: "0.00", reference: "4-2", state: "collected", items: [ { description: "Test Line Item 1", amount: "99999.99", product_id: null, product_type: "manual", product_reference: null, }, { description: "Test Line Item 2", amount: "1000000.00", product_id: null, product_type: "manual", product_reference: null, }, ], }, ]); })); it("throws an error on bad filter", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/billing/charges") .reply((0, util_1.readFixtureAt)("listCharges/fail-400-bad-filter.http")); try { yield dnsimple.billing.listCharges(accountId); } catch (error) { expect(error).toBeInstanceOf(main_1.ClientError); const clientError = error; expect(clientError.status).toBe(400); expect(clientError.data.message).toBe("Invalid date format must be ISO8601 (YYYY-MM-DD)"); } })); it("throws an error on missing scope", () => __awaiter(void 0, void 0, void 0, function* () { nock("https://api.dnsimple.com") .get("/v2/1010/billing/charges") .reply((0, util_1.readFixtureAt)("listCharges/fail-403.http")); try { yield dnsimple.billing.listCharges(accountId); } catch (error) { expect(error).toBeInstanceOf(main_1.ClientError); const clientError = error; expect(clientError.status).toBe(403); expect(clientError.data.message).toBe("Permission Denied. Required Scope: billing:*:read"); } })); }); });