UNPKG

xero-hero

Version:

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

77 lines (68 loc) 2.57 kB
// src/accounting/contacts/__tests__/links.test.ts import { Contact } 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/contacts/links.ts var getContactLink = (contact) => { return `https://go.xero.com/Contacts/View.aspx?${qs.stringify({ contactID: (hasProperty(contact, "contactID") ? contact.contactID : contact) || "null-or-empty-contact-id" })}`; }; // src/accounting/invoices/lineItems.ts import { isNil } from "deep-cuts"; // src/accounting/journals/links.ts import qs2 from "qs"; // src/projects/timeEntries.ts import { roundToNearestFraction } from "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 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.mjs.map