mirror of
https://gitlab.com/timvisee/send.git
synced 2024-11-15 07:32:48 +01:00
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
import assert from 'assert';
|
|
import * as api from '../../../app/api';
|
|
import Keychain from '../../../app/keychain';
|
|
|
|
const encoder = new TextEncoder();
|
|
const plaintext = new Blob([encoder.encode('hello world!')]);
|
|
const metadata = {
|
|
name: 'test.txt',
|
|
type: 'text/plain'
|
|
};
|
|
|
|
describe('API', function() {
|
|
describe('websocket upload', function() {
|
|
it('returns file info on success', async function() {
|
|
const keychain = new Keychain();
|
|
const enc = await keychain.encryptStream(plaintext);
|
|
const meta = await keychain.encryptMetadata(metadata);
|
|
const verifierB64 = await keychain.authKeyB64();
|
|
const p = function() {};
|
|
const up = await api.uploadWs(
|
|
enc.stream,
|
|
enc.streamInfo,
|
|
meta,
|
|
verifierB64,
|
|
keychain,
|
|
p
|
|
);
|
|
|
|
const result = await up.result;
|
|
assert.ok(result.url);
|
|
assert.ok(result.id);
|
|
assert.ok(result.ownerToken);
|
|
});
|
|
|
|
it('can be cancelled', async function() {
|
|
const keychain = new Keychain();
|
|
const enc = await keychain.encryptStream(plaintext);
|
|
const meta = await keychain.encryptMetadata(metadata);
|
|
const verifierB64 = await keychain.authKeyB64();
|
|
const p = function() {};
|
|
const up = await api.uploadWs(
|
|
enc.stream,
|
|
enc.streamInfo,
|
|
meta,
|
|
verifierB64,
|
|
keychain,
|
|
p
|
|
);
|
|
up.cancel();
|
|
try {
|
|
await up.result;
|
|
assert.fail('not cancelled');
|
|
} catch (e) {
|
|
assert.equal(e.message, '0');
|
|
}
|
|
});
|
|
});
|
|
});
|