UNPKG

xero-hero

Version:

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

128 lines (116 loc) 4.72 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/attachments/__tests__/requests.test.ts var import_node_stream = require("stream"); // node_modules/uuid/dist/esm-node/rng.js var import_crypto = __toESM(require("crypto")); var rnds8Pool = new Uint8Array(256); var poolPtr = rnds8Pool.length; function rng() { if (poolPtr > rnds8Pool.length - 16) { import_crypto.default.randomFillSync(rnds8Pool); poolPtr = 0; } return rnds8Pool.slice(poolPtr, poolPtr += 16); } // node_modules/uuid/dist/esm-node/stringify.js var byteToHex = []; for (let i = 0; i < 256; ++i) { byteToHex.push((i + 256).toString(16).slice(1)); } function unsafeStringify(arr, offset = 0) { return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]; } // node_modules/uuid/dist/esm-node/native.js var import_crypto2 = __toESM(require("crypto")); var native_default = { randomUUID: import_crypto2.default.randomUUID }; // node_modules/uuid/dist/esm-node/v4.js function v4(options, buf, offset) { if (native_default.randomUUID && !buf && !options) { return native_default.randomUUID(); } options = options || {}; const rnds = options.random || (options.rng || rng)(); rnds[6] = rnds[6] & 15 | 64; rnds[8] = rnds[8] & 63 | 128; if (buf) { offset = offset || 0; for (let i = 0; i < 16; ++i) { buf[offset + i] = rnds[i]; } return buf; } return unsafeStringify(rnds); } var v4_default = v4; // src/common/instance/operations.ts var import_deep_cuts = require("deep-cuts"); // src/accounting/attachments/requests.ts var import_tranquil_stream = require("tranquil-stream"); var createInvoiceAttachment = async (client, tenantId, { invoiceId, filename, contents }) => { return client.accountingApi.createInvoiceAttachmentByFileName( tenantId, invoiceId, filename, (0, import_tranquil_stream.bufferToStream)(contents) ); }; // 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/accounting/attachments/__tests__/requests.test.ts var getMockXeroClient = () => { return { accountingApi: { createInvoiceAttachmentByFileName: jest.fn() } }; }; describe("attachments/requests", () => { describe("createInvoiceAttachment()", () => { it("should call the createInvoiceAttachmentByFileName() method with the relevant arguments ", () => { const client = getMockXeroClient(); const tenantId = v4_default(); const invoiceId = v4_default(); const filename = "test.pdf"; const contents = Buffer.from("Test Content Here"); createInvoiceAttachment(client, tenantId, { contents, filename, invoiceId }); expect( client.accountingApi.createInvoiceAttachmentByFileName ).toHaveBeenCalledWith(tenantId, invoiceId, filename, expect.any(import_node_stream.Duplex)); }); }); }); //# sourceMappingURL=requests.test.js.map