js: importKey feedback refactor

--
* src/Keyring.js: An empty result should no longer cause an error,
  the import feedback summary has been refactored slightly
* Browsertests to reflect import feedback change
This commit is contained in:
Maximilian Krambach 2018-08-16 17:58:11 +02:00
parent d65a392670
commit 90cb4a6842
2 changed files with 32 additions and 33 deletions

View File

@ -71,10 +71,13 @@ describe('Key importing', function () {
expect(result).to.be.an('array'); expect(result).to.be.an('array');
expect(result.length).to.equal(0); expect(result.length).to.equal(0);
context.Keyring.importKey(pubKey).then(function(result){ context.Keyring.importKey(pubKey).then(function(result){
expect(result[0]).to.not.be.undefined; expect(result.Keys).to.be.an('array');
expect(result[0].key).to.be.an('object'); expect(result.Keys[0]).to.not.be.undefined;
expect(result[0].key.fingerprint).to.equal(fpr); expect(result.Keys[0].key).to.be.an('object');
expect(result[0].status).to.equal('newkey'); expect(result.Keys[0].key.fingerprint).to.equal(fpr);
expect(result.Keys[0].status).to.equal('newkey');
expect(result.summary.considered).to.equal(1);
expect(result.summary.imported).to.equal(1);
done(); done();
}); });
}); });
@ -83,15 +86,16 @@ describe('Key importing', function () {
it('Updating Key', function(done){ it('Updating Key', function(done){
context.Keyring.importKey(pubKey) context.Keyring.importKey(pubKey)
.then(function(result){ .then(function(result){
expect(result[0].key).to.not.be.undefined; expect(result.Keys[0].key).to.not.be.undefined;
expect(result[0].status).to.equal('newkey'); expect(result.Keys[0].status).to.equal('newkey');
context.Keyring.importKey(changedKey).then(function(res){ context.Keyring.importKey(changedKey).then(function(res){
expect(res[0].key).to.be.an('object'); expect(res.Keys[0].key).to.be.an('object');
expect(res[0].key.fingerprint).to.equal(fpr); expect(res.Keys[0].key.fingerprint).to.equal(fpr);
expect(res[0].status).to.equal('change'); expect(res.Keys[0].status).to.equal('change');
expect(res[0].changes.userId).to.be.true; expect(res.Keys[0].changes.userId).to.be.true;
expect(res[0].changes.subkey).to.be.false; expect(res.Keys[0].changes.subkey).to.be.false;
expect(res[0].changes.signature).to.be.true; expect(res.Keys[0].changes.signature).to.be.true;
expect(res.summary.considered).to.equal(1);
done(); done();
}); });
}); });
@ -99,9 +103,9 @@ describe('Key importing', function () {
it('Deleting Key', function(done) { it('Deleting Key', function(done) {
context.Keyring.importKey(pubKey).then(function(result){ context.Keyring.importKey(pubKey).then(function(result){
expect(result[0].key).to.be.an('object'); expect(result.Keys[0].key).to.be.an('object');
expect(result[0].key.fingerprint).to.equal(fpr); expect(result.Keys[0].key.fingerprint).to.equal(fpr);
result[0].key.delete().then(function(result){ result.Keys[0].key.delete().then(function(result){
expect(result).to.be.true; expect(result).to.be.true;
done(); done();
}); });

View File

@ -274,6 +274,17 @@ export class GPGME_Keyring {
msg.post().then(function(response){ msg.post().then(function(response){
let infos = {}; let infos = {};
let fprs = []; let fprs = [];
let summary = {};
for (let i=0; i < feedbackValues.length; i++ ){
summary[feedbackValues[i]] =
response.result[feedbackValues[i]];
}
if (!response.result.hasOwnProperty('imports') ||
response.result.imports.length === 0
){
resolve({Keys:[],summary: summary});
return;
}
for (let res=0; res<response.result.imports.length; res++){ for (let res=0; res<response.result.imports.length; res++){
let result = response.result.imports[res]; let result = response.result.imports[res];
let status = ''; let status = '';
@ -307,15 +318,7 @@ export class GPGME_Keyring {
status: infos[result[i].fingerprint].status status: infos[result[i].fingerprint].status
}); });
} }
let summary = {}; resolve({Keys:resultset,summary: summary});
for (let i=0; i < feedbackValues.length; i++ ){
summary[feedbackValues[i]] =
response[feedbackValues[i]];
}
resolve({
Keys:resultset,
summary: summary
});
}, function(error){ }, function(error){
reject(error); reject(error);
}); });
@ -327,15 +330,7 @@ export class GPGME_Keyring {
status: infos[fprs[i]].status status: infos[fprs[i]].status
}); });
} }
let summary = {}; resolve({Keys:resultset,summary:summary});
for (let i=0; i < feedbackValues.length; i++ ){
summary[feedbackValues[i]] =
response[feedbackValues[i]];
}
resolve({
Keys:resultset,
summary:summary
});
} }
}, function(error){ }, function(error){