mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The suppression count for this work is `git grep -c` over '@ts-ignore', '@ts-expect-error', 'as any', 'as unknown as', ': any' and eslint-disable. Three comments added in it matched as prose: a quoted index signature in the v1 contract, "over: any string" in the upload test and "has any meta" in the field tooltip. They say the same thing in words that do not match, so the counts read 10 `as any` and 8 `: any`, as before this work. Co-authored-by: Hanzo Dev <[email protected]>
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
/**
|
|
* Which store a document's bytes go to.
|
|
*
|
|
* The value that decides it arrives as a string from the environment, so the
|
|
* interesting cases are the wrong ones. A wrong value used to select the
|
|
* database silently, which is indistinguishable from object storage being
|
|
* configured and ignored — so every case below that is not a transport has to
|
|
* throw rather than pick one.
|
|
*
|
|
* Run: npx tsx --test packages/lib/__tests__/upload.test.ts
|
|
*/
|
|
import assert from 'node:assert/strict';
|
|
import { afterEach, describe, test } from 'node:test';
|
|
|
|
import { uploadTransport } from '../universal/upload/transport';
|
|
|
|
// The environment as the process hands it over, which may hold any string.
|
|
// ProcessEnv declares only the two transports, which the cases below are not.
|
|
const env: Record<string, string | undefined> = process.env;
|
|
|
|
const set = (value: string | undefined) => {
|
|
if (value === undefined) {
|
|
delete env.NEXT_PUBLIC_UPLOAD_TRANSPORT;
|
|
return;
|
|
}
|
|
|
|
env.NEXT_PUBLIC_UPLOAD_TRANSPORT = value;
|
|
};
|
|
|
|
afterEach(() => set(undefined));
|
|
|
|
describe('upload transport', () => {
|
|
test('unset is the database', () => {
|
|
set(undefined);
|
|
assert.equal(uploadTransport(), 'database');
|
|
|
|
set('');
|
|
assert.equal(uploadTransport(), 'database');
|
|
});
|
|
|
|
test('the two transports read as themselves', () => {
|
|
set('database');
|
|
assert.equal(uploadTransport(), 'database');
|
|
|
|
set('s3');
|
|
assert.equal(uploadTransport(), 's3');
|
|
});
|
|
|
|
test('anything else throws instead of picking a store', () => {
|
|
for (const value of ['S3', 's3 ', ' s3', 'minio', 'S3_PATH', 'true', 'bytes_64']) {
|
|
set(value);
|
|
|
|
assert.throws(
|
|
() => uploadTransport(),
|
|
(err: Error) => err.message.includes(value),
|
|
`"${value}" was accepted as a transport`,
|
|
);
|
|
}
|
|
});
|
|
});
|