98 lines
2.2 KiB
JavaScript
98 lines
2.2 KiB
JavaScript
|
|
import assert from 'node:assert/strict';
|
||
|
|
import {
|
||
|
|
BrowserProductClient,
|
||
|
|
requireValue
|
||
|
|
} from '../src/transport.ts';
|
||
|
|
|
||
|
|
const baseUrl = process.argv[2];
|
||
|
|
if (baseUrl === undefined) {
|
||
|
|
throw new Error('missing integration base URL');
|
||
|
|
}
|
||
|
|
|
||
|
|
const client = new BrowserProductClient(globalThis.fetch.bind(globalThis), baseUrl);
|
||
|
|
const csrf = 'a'.repeat(43);
|
||
|
|
const path = 'folder/문서 a.txt';
|
||
|
|
const operationId = 'operation-1';
|
||
|
|
|
||
|
|
const session = requireValue(await client.session({}));
|
||
|
|
assert.deepEqual(session, {
|
||
|
|
user_id: 'user-1',
|
||
|
|
display: 'User',
|
||
|
|
csrf
|
||
|
|
});
|
||
|
|
|
||
|
|
const browse = requireValue(
|
||
|
|
await client.browse({
|
||
|
|
root: 'shared',
|
||
|
|
prefix: path,
|
||
|
|
q: 'needle',
|
||
|
|
continuation: 'next-page'
|
||
|
|
})
|
||
|
|
);
|
||
|
|
assert.equal(browse.entries[0].path, path);
|
||
|
|
assert.equal(browse.continuation, 'next-page');
|
||
|
|
assert.equal(browse.partial, true);
|
||
|
|
|
||
|
|
const download = requireValue(
|
||
|
|
await client.download({ root: 'shared', path })
|
||
|
|
);
|
||
|
|
assert.equal(await new Response(download.body).text(), 'abc');
|
||
|
|
assert.equal(download.contentDisposition, 'attachment; filename="file.txt"');
|
||
|
|
assert.equal(download.xContentTypeOptions, 'nosniff');
|
||
|
|
assert.equal(download.contentSecurityPolicy, "default-src 'none'");
|
||
|
|
assert.equal(download.contentLength, 3);
|
||
|
|
|
||
|
|
const upload = requireValue(
|
||
|
|
await client.upload({
|
||
|
|
root: 'personal',
|
||
|
|
path,
|
||
|
|
operationId,
|
||
|
|
declaredSize: 3,
|
||
|
|
contentSha256: 'b'.repeat(64),
|
||
|
|
csrfToken: csrf,
|
||
|
|
body: new Blob(['abc'])
|
||
|
|
})
|
||
|
|
);
|
||
|
|
assert.equal(upload.operation_id, operationId);
|
||
|
|
assert.equal(upload.result, 'succeeded');
|
||
|
|
|
||
|
|
const deletion = requireValue(
|
||
|
|
await client.delete({
|
||
|
|
body: {
|
||
|
|
root: 'shared',
|
||
|
|
path,
|
||
|
|
operation_id: operationId,
|
||
|
|
csrf
|
||
|
|
}
|
||
|
|
})
|
||
|
|
);
|
||
|
|
assert.equal(deletion.operation_id, operationId);
|
||
|
|
assert.equal(deletion.result, 'succeeded');
|
||
|
|
|
||
|
|
const plan = requireValue(
|
||
|
|
await client.deletePlan({
|
||
|
|
root: 'shared',
|
||
|
|
path,
|
||
|
|
continuation: 'next-page'
|
||
|
|
})
|
||
|
|
);
|
||
|
|
assert.deepEqual(plan.paths, [path]);
|
||
|
|
assert.equal(plan.continuation, 'next-page');
|
||
|
|
|
||
|
|
const batch = requireValue(
|
||
|
|
await client.deleteBatch({
|
||
|
|
body: {
|
||
|
|
root: 'shared',
|
||
|
|
csrf,
|
||
|
|
items: [{ path, operation_id: operationId }]
|
||
|
|
}
|
||
|
|
})
|
||
|
|
);
|
||
|
|
assert.deepEqual(batch.results, [
|
||
|
|
{
|
||
|
|
path,
|
||
|
|
operation_id: operationId,
|
||
|
|
result: 'succeeded',
|
||
|
|
error: null
|
||
|
|
}
|
||
|
|
]);
|