UNPKG

xero-hero

Version:

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

73 lines (64 loc) 2.41 kB
// src/accounting/invoices/__tests__/links.test.ts import { Invoice } from "xero-node"; // src/common/instance/operations.ts import { isObject } from "deep-cuts"; // src/accounting/attachments/requests.ts import { bufferToStream } from "tranquil-stream"; // src/accounting/contacts/links.ts import qs from "qs"; // src/utils/properties.ts var hasProperty = (object, property) => { if (Boolean(object) && typeof object === "object") { return property in object; } return false; }; // src/accounting/invoices/lineItems.ts import { isNil } from "deep-cuts"; // src/accounting/invoices/links.ts var getInvoiceLink = (invoice) => { return `https://invoicing.xero.com/view/${(hasProperty(invoice, "invoiceID") ? invoice.invoiceID : invoice) || "null-or-empty-invoice-id"}`; }; // src/accounting/journals/links.ts import qs2 from "qs"; // src/projects/timeEntries.ts import { roundToNearestFraction } from "deep-cuts"; // src/accounting/invoices/__tests__/links.test.ts describe("invoices/links", () => { describe("getInvoiceLink()", () => { it("returns a null indicator if passed undefined", () => { expect(getInvoiceLink()).toBe( "https://invoicing.xero.com/view/null-or-empty-invoice-id" ); }); it("returns a null indicator if passed null", () => { expect(getInvoiceLink(null)).toBe( "https://invoicing.xero.com/view/null-or-empty-invoice-id" ); }); it("returns a null indicator if passed an empty string", () => { expect(getInvoiceLink("")).toBe( "https://invoicing.xero.com/view/null-or-empty-invoice-id" ); }); it("returns the correct URL for an invoice object with an invoiceID property", () => { const invoice = new Invoice(); invoice.invoiceID = "25OR6TO4"; expect(getInvoiceLink(invoice)).toBe( "https://invoicing.xero.com/view/25OR6TO4" ); }); it("returns the correct URL for a string invoice ID", () => { expect(getInvoiceLink("kooolaid-9086-t728")).toBe( "https://invoicing.xero.com/view/kooolaid-9086-t728" ); }); it("should work with an object that matches the interface for having a invoiceID property", () => { const invoice = { invoiceID: "25OR6TO4" }; expect(getInvoiceLink(invoice)).toBe( "https://invoicing.xero.com/view/25OR6TO4" ); }); }); }); //# sourceMappingURL=links.test.mjs.map