UNPKG

xero-hero

Version:

Heroic utilities to simplify and enable your progress with the [xero-node](https://www.npmjs.com/package/xero-node) SDK.

111 lines (102 loc) 4.62 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); // src/common/response/__tests__/selectors.test.ts var import_xero_node = require("xero-node"); // src/common/instance/operations.ts var import_deep_cuts = require("deep-cuts"); // src/common/response/selectors.ts var getListFromResponse = (response) => { if (response.body) { const propertyName = Object.getOwnPropertyNames(response.body); for (const name of propertyName) { if (Array.isArray(response.body[name])) { return response.body[name]; } } } return void 0; }; // src/accounting/attachments/requests.ts var import_tranquil_stream = require("tranquil-stream"); // src/accounting/contacts/links.ts var import_qs = __toESM(require("qs")); // src/accounting/invoices/lineItems.ts var import_deep_cuts2 = require("deep-cuts"); // src/accounting/journals/links.ts var import_qs2 = __toESM(require("qs")); // src/projects/timeEntries.ts var import_deep_cuts3 = require("deep-cuts"); // src/common/response/__tests__/selectors.test.ts describe("common/response/selectors", () => { describe("getListFromResponse()", () => { it("should return the contacts list from a contacts response", () => { const contactsList = [new import_xero_node.Contact(), new import_xero_node.Contact(), new import_xero_node.Contact()]; const contactsBody = new import_xero_node.Contacts(); contactsBody.contacts = contactsList; expect(getListFromResponse({ body: contactsBody })).toBe(contactsList); }); it("should return the invoice list from a invoices response", () => { const invoicesList = [new import_xero_node.Invoice(), new import_xero_node.Invoice()]; const invoicesBody = new import_xero_node.Invoices(); invoicesBody.invoices = invoicesList; expect(getListFromResponse({ body: invoicesBody })).toBe(invoicesList); }); it("should return the bankTransactions from a bankTransactions response", () => { const bankTransactionsList = [ new import_xero_node.BankTransaction(), new import_xero_node.BankTransaction(), new import_xero_node.BankTransaction(), new import_xero_node.BankTransaction() ]; const bankTransactionsBody = new import_xero_node.BankTransactions(); bankTransactionsBody.bankTransactions = bankTransactionsList; expect(getListFromResponse({ body: bankTransactionsBody })).toBe( bankTransactionsList ); }); it("should play nice with an object that looks like a Xero response and has an array property on the body", () => { const itemList = [1, 2, 3, 4, 5]; const itemBody = { items: itemList }; expect(getListFromResponse({ body: itemBody })).toBe(itemList); }); it("should return undefined for responses that lack an array property", () => { const repeatingInvoices = new import_xero_node.RepeatingInvoices(); expect(getListFromResponse({ body: repeatingInvoices })).toBe(void 0); }); it("should return undefined for responses without a body", () => { expect(getListFromResponse({})).toBe(void 0); }); it("should throw an error when passed an undefined response", () => { expect(() => { return getListFromResponse(); }).toThrowError(); }); it("should throw an error when passed a null response", () => { expect(() => { return getListFromResponse(null); }).toThrowError(); }); }); }); //# sourceMappingURL=selectors.test.js.map