UNPKG

xero-hero

Version:

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

101 lines (91 loc) 3.84 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/accounting/contacts/__tests__/links.test.ts var import_xero_node = require("xero-node"); // src/common/instance/operations.ts var import_deep_cuts = require("deep-cuts"); // src/accounting/attachments/requests.ts var import_tranquil_stream = require("tranquil-stream"); // src/accounting/contacts/links.ts var import_qs = __toESM(require("qs")); // src/utils/properties.ts var hasProperty = (object, property) => { if (Boolean(object) && typeof object === "object") { return property in object; } return false; }; // src/accounting/contacts/links.ts var getContactLink = (contact) => { return `https://go.xero.com/Contacts/View.aspx?${import_qs.default.stringify({ contactID: (hasProperty(contact, "contactID") ? contact.contactID : contact) || "null-or-empty-contact-id" })}`; }; // 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/accounting/contacts/__tests__/links.test.ts describe("contacts/links", () => { describe("getContactLink()", () => { it("returns a null indicator if passed undefined", () => { expect(getContactLink()).toBe( "https://go.xero.com/Contacts/View.aspx?contactID=null-or-empty-contact-id" ); }); it("returns a null indicator if passed null", () => { expect(getContactLink(null)).toBe( "https://go.xero.com/Contacts/View.aspx?contactID=null-or-empty-contact-id" ); }); it("returns a null indicator if passed an empty string", () => { expect(getContactLink("")).toBe( "https://go.xero.com/Contacts/View.aspx?contactID=null-or-empty-contact-id" ); }); it("returns the correct URL for an contact object with an contactID property", () => { const contact = new import_xero_node.Contact(); contact.contactID = "25OR6TO4"; expect(getContactLink(contact)).toBe( "https://go.xero.com/Contacts/View.aspx?contactID=25OR6TO4" ); }); it("returns the correct URL for a string invoice ID", () => { expect(getContactLink("kooolaid-9086-t728")).toBe( "https://go.xero.com/Contacts/View.aspx?contactID=kooolaid-9086-t728" ); }); it("should work with an object that matches the interface for having a contactID property", () => { const contact = { contactID: "25OR6TO4" }; expect(getContactLink(contact)).toBe( "https://go.xero.com/Contacts/View.aspx?contactID=25OR6TO4" ); }); }); }); //# sourceMappingURL=links.test.js.map