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 (65 loc) • 2.7 kB
JavaScript
// src/accounting/journals/__tests__/links.test.ts
import { ManualJournal } 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/journals/links.ts
import qs2 from "qs";
var getManualJournalLink = (manualJournal) => {
return `https://go.xero.com/Journal/View.aspx?${qs2.stringify({
invoiceID: (hasProperty(manualJournal, "manualJournalID") ? manualJournal.manualJournalID : manualJournal) || "null-or-empty-manual-journal-id"
})}`;
};
// src/projects/timeEntries.ts
import { roundToNearestFraction } from "deep-cuts";
// src/accounting/journals/__tests__/links.test.ts
describe("journals/links", () => {
describe("getManualJournalLink()", () => {
it("returns a null indicator if passed undefined", () => {
expect(getManualJournalLink()).toBe(
"https://go.xero.com/Journal/View.aspx?invoiceID=null-or-empty-manual-journal-id"
);
});
it("returns a null indicator if passed null", () => {
expect(getManualJournalLink(null)).toBe(
"https://go.xero.com/Journal/View.aspx?invoiceID=null-or-empty-manual-journal-id"
);
});
it("returns a null indicator if passed an empty string", () => {
expect(getManualJournalLink("")).toBe(
"https://go.xero.com/Journal/View.aspx?invoiceID=null-or-empty-manual-journal-id"
);
});
it("returns the correct URL for a manual journal object with an manualJournalID property", () => {
const manualJournal = new ManualJournal();
manualJournal.manualJournalID = "25OR6TO4";
expect(getManualJournalLink(manualJournal)).toBe(
"https://go.xero.com/Journal/View.aspx?invoiceID=25OR6TO4"
);
});
it("returns the correct URL for a string manual journal ID", () => {
expect(getManualJournalLink("sdfhj-47629-sjdgdd")).toBe(
"https://go.xero.com/Journal/View.aspx?invoiceID=sdfhj-47629-sjdgdd"
);
});
it("should work with an object that matches the interface for having a manualJournalID property", () => {
const manualJournal = { manualJournalID: "25OR6TO4" };
expect(getManualJournalLink(manualJournal)).toBe(
"https://go.xero.com/Journal/View.aspx?invoiceID=25OR6TO4"
);
});
});
});
//# sourceMappingURL=links.test.mjs.map