Initial import of verae-request-splitter from zapier monorepo
This commit is contained in:
commit
205df2d928
6 changed files with 166 additions and 0 deletions
32
test/splitRequest.test.js
Normal file
32
test/splitRequest.test.js
Normal 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/);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue