more frontend tests and some factoring based on them

This commit is contained in:
Danny Coates 2018-02-24 11:24:12 -08:00
parent 78728ce4ca
commit d6c0489fa3
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
6 changed files with 153 additions and 107 deletions

View file

@ -16,11 +16,28 @@ describe('API', function() {
const encrypted = await keychain.encryptFile(plaintext);
const meta = await keychain.encryptMetadata(metadata);
const verifierB64 = await keychain.authKeyB64();
const up = api.uploadFile(encrypted, meta, verifierB64, keychain);
const p = function() {};
const up = api.uploadFile(encrypted, 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 encrypted = await keychain.encryptFile(plaintext);
const meta = await keychain.encryptMetadata(metadata);
const verifierB64 = await keychain.authKeyB64();
const p = function() {};
const up = api.uploadFile(encrypted, meta, verifierB64, keychain, p);
up.cancel();
try {
await up.result;
assert.fail('not cancelled');
} catch (e) {
assert.equal(e.message, '0');
}
});
});
});

View file

@ -87,6 +87,53 @@ describe('Upload / Download flow', function() {
assert.equal(fr.fileInfo.name, blob.name);
});
it('can cancel the upload', async function() {
const fs = new FileSender(blob);
const up = fs.upload();
fs.cancel(); // before encrypting
try {
await up;
assert.fail('not cancelled');
} catch (e) {
assert.equal(e.message, '0');
}
fs.reset();
fs.once('encrypting', () => fs.cancel());
try {
await fs.upload();
assert.fail('not cancelled');
} catch (e) {
assert.equal(e.message, '0');
}
fs.reset();
fs.once('progress', () => fs.cancel());
try {
await fs.upload();
assert.fail('not cancelled');
} catch (e) {
assert.equal(e.message, '0');
}
});
it('can cancel the download', async function() {
const fs = new FileSender(blob);
const file = await fs.upload();
const fr = new FileReceiver({
secretKey: file.toJSON().secretKey,
id: file.id,
nonce: file.keychain.nonce,
requiresPassword: false
});
await fr.getMetadata();
fr.once('progress', () => fr.cancel());
try {
await fr.download(noSave);
assert.fail('not cancelled');
} catch (e) {
assert.equal(e.message, '0');
}
});
it('can allow multiple downloads', async function() {
const fs = new FileSender(blob);
const file = await fs.upload();