From 3685913bf510a14b8cb324d980217d90489e6453 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 25 Apr 2018 19:45:39 +0200 Subject: js: First testing and improvements -- * Introduced Mocha/chai as testsuite. After development build 'npm test' should run the unit tests. Functionality exclusive to Browsers/WebExtensions cannot be run this way, so some other testing is still needed. - package.json: Added required development packages - .babelrc indirect configuration for mocha. ES6 transpiling needs some babel configuration, but mocha has no setting for it. - test/mocha.opts Vonfiguration for mocha runs * Fixed errors: - Helpers.js toKeyIdArray; isLongId is now exported - Key.js Key constructor failed - Message.js will not throw an Error during construction, a new message is now created with createMessage, which can return an Error or a GPGME_Message object * Tests: - test/Helpers: exports from Helpers.js, GPGME_Error handling - test/Message: first init test with bad parameters --- lang/js/src/Key.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lang/js/src/Key.js') diff --git a/lang/js/src/Key.js b/lang/js/src/Key.js index f6fa7ae3..0b44b245 100644 --- a/lang/js/src/Key.js +++ b/lang/js/src/Key.js @@ -26,9 +26,9 @@ * */ -import {isFingerprint} from './Helpers' -import {gpgme_error} from './Errors' -import { GPGME_Message } from './Message'; +import { isFingerprint } from './Helpers' +import { gpgme_error } from './Errors' +import { createMessage } from './Message'; import { permittedOperations } from './permittedOperations'; export class GPGME_Key { @@ -39,7 +39,7 @@ export class GPGME_Key { set fingerprint(fpr){ if (isFingerprint(fpr) === true && !this._fingerprint){ - this._fingerprint = fingerprint; + this._fingerprint = fpr; } } @@ -181,9 +181,12 @@ function checkKey(fingerprint, property){ } return new Promise(function(resolve, reject){ if (!isFingerprint(fingerprint)){ - reject('KEY_INVALID'); + reject(gpgme_error('KEY_INVALID')); + } + let msg = createMessage ('keyinfo'); + if (msg instanceof Error){ + reject(gpgme_error('PARAM_WRONG')); } - let msg = new GPGME_Message('keyinfo'); msg.setParameter('fingerprint', this.fingerprint); return (this.connection.post(msg)).then(function(result){ if (result.hasOwnProperty(property)){ -- cgit v1.2.3