fox-send/test/frontend/tests/api-tests.js

63 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2018-08-07 22:40:17 +00:00
/* global DEFAULTS */
2018-02-21 04:31:27 +00:00
import assert from 'assert';
2018-07-26 05:26:11 +00:00
import Archive from '../../../app/archive';
2018-02-21 04:31:27 +00:00
import * as api from '../../../app/api';
import Keychain from '../../../app/keychain';
const encoder = new TextEncoder();
2018-07-26 05:26:11 +00:00
const plaintext = new Archive([new Blob([encoder.encode('hello world!')])]);
2018-02-21 04:31:27 +00:00
const metadata = {
name: 'test.txt',
type: 'text/plain'
};
describe('API', function() {
2018-06-21 00:05:33 +00:00
describe('websocket upload', function() {
2018-02-21 04:31:27 +00:00
it('returns file info on success', async function() {
const keychain = new Keychain();
2018-07-26 05:26:11 +00:00
const enc = await keychain.encryptStream(plaintext.stream);
2018-02-21 04:31:27 +00:00
const meta = await keychain.encryptMetadata(metadata);
const verifierB64 = await keychain.authKeyB64();
const p = function() {};
2018-08-08 18:07:09 +00:00
const up = api.uploadWs(
enc,
meta,
verifierB64,
2018-08-07 22:40:17 +00:00
DEFAULTS.EXPIRE_SECONDS,
2018-08-31 21:20:15 +00:00
1,
2018-08-07 22:40:17 +00:00
null,
p
2018-08-08 18:07:09 +00:00
);
2018-06-21 00:05:33 +00:00
2018-02-21 04:31:27 +00:00
const result = await up.result;
assert.ok(result.url);
assert.ok(result.id);
2018-07-06 22:49:50 +00:00
assert.ok(result.ownerToken);
2018-02-21 04:31:27 +00:00
});
it('can be cancelled', async function() {
const keychain = new Keychain();
2018-07-26 05:26:11 +00:00
const enc = await keychain.encryptStream(plaintext.stream);
const meta = await keychain.encryptMetadata(metadata);
const verifierB64 = await keychain.authKeyB64();
const p = function() {};
2018-08-08 18:07:09 +00:00
const up = api.uploadWs(
enc,
meta,
verifierB64,
2018-08-07 22:40:17 +00:00
DEFAULTS.EXPIRE_SECONDS,
null,
p
2018-08-08 18:07:09 +00:00
);
up.cancel();
try {
await up.result;
assert.fail('not cancelled');
} catch (e) {
assert.equal(e.message, '0');
}
});
2018-02-21 04:31:27 +00:00
});
});