xero-hero
Version:
Heroic utilities to simplify and enable your progress with the [xero-node](https://www.npmjs.com/package/xero-node) SDK.
104 lines (93 loc) • 3.36 kB
JavaScript
// src/accounting/attachments/__tests__/requests.test.ts
import { Duplex } from "stream";
// node_modules/uuid/dist/esm-node/rng.js
import crypto from "crypto";
var rnds8Pool = new Uint8Array(256);
var poolPtr = rnds8Pool.length;
function rng() {
if (poolPtr > rnds8Pool.length - 16) {
crypto.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
import crypto2 from "crypto";
var native_default = {
randomUUID: crypto2.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
import { isObject } from "deep-cuts";
// src/accounting/attachments/requests.ts
import { bufferToStream } from "tranquil-stream";
var createInvoiceAttachment = async (client, tenantId, { invoiceId, filename, contents }) => {
return client.accountingApi.createInvoiceAttachmentByFileName(
tenantId,
invoiceId,
filename,
bufferToStream(contents)
);
};
// src/accounting/contacts/links.ts
import qs from "qs";
// 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/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(Duplex));
});
});
});
//# sourceMappingURL=requests.test.mjs.map