Initial import of verae-request-splitter from zapier monorepo

This commit is contained in:
George Lambert 2026-09-11 12:58:42 -04:00
commit 969f01e01d
5 changed files with 134 additions and 0 deletions

32
test/splitRequest.test.js Normal file
View file

@ -0,0 +1,32 @@
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { splitRequest, sha256Hex } from '../src/splitRequest.js';
describe('splitRequest', () => {
it('hash-only has no archive puts', () => {
const out = splitRequest({ data: 'hello' });
assert.equal(out.chain.sha256, sha256Hex('hello'));
assert.equal(out.archivePuts.length, 0);
assert.equal(out.includeAttached, false);
});
it('splits public metadata and two files onto archive puts', () => {
const out = splitRequest({
data: 'hello',
publicMetadata: { title: 't' },
files: [
{ path: 'a.txt', data: 'A' },
{ path: 'b.txt', data: 'B' },
],
includeAttached: true,
});
assert.equal(out.archivePuts.length, 3);
assert.equal(out.archivePuts.filter((p) => p.kind === 'file').length, 2);
assert.equal(out.includeAttached, true);
assert.equal(out.chain.sha256, sha256Hex('hello'));
});
it('throws without data or sha256', () => {
assert.throws(() => splitRequest({}), /data or sha256/);
});
});