aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/Message.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-04-25 17:45:39 +0000
committerMaximilian Krambach <[email protected]>2018-04-25 17:45:39 +0000
commit3685913bf510a14b8cb324d980217d90489e6453 (patch)
treeeb1acbdee90bf747f2dfbd4c9a61ed83d41c2b8f /lang/js/src/Message.js
parentjs: Configuration and Error handling (diff)
downloadgpgme-3685913bf510a14b8cb324d980217d90489e6453.tar.gz
gpgme-3685913bf510a14b8cb324d980217d90489e6453.zip
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
Diffstat (limited to '')
-rw-r--r--lang/js/src/Message.js47
1 files changed, 23 insertions, 24 deletions
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js
index 06ac8db2..4d242277 100644
--- a/lang/js/src/Message.js
+++ b/lang/js/src/Message.js
@@ -19,13 +19,34 @@
*/
import { permittedOperations } from './permittedOperations'
import { gpgme_error } from './Errors'
-export class GPGME_Message {
+
+export function createMessage(operation){
+ if (typeof(operation) !== 'string'){
+ return gpgme_error('PARAM_WRONG');
+ }
+ if (permittedOperations.hasOwnProperty(operation)){
+ return new GPGME_Message(operation);
+ } else {
+ return gpgme_error('MSG_WRONG_OP');
+ }
+}
+
+/**
+ * Prepares a communication request. It checks operations and parameters in
+ * ./permittedOperations.
+ * @param {String} operation
+ */
+class GPGME_Message {
//TODO getter
constructor(operation){
- setOperation(this, operation);
+ this.operation = operation;
}
+ set operation (op){
+
+
+ }
get operation(){
return this._msg.op;
}
@@ -41,9 +62,6 @@ export class GPGME_Message {
if (!param || typeof(param) !== 'string'){
return gpgme_error('PARAM_WRONG');
}
- if (!this._msg || !this._msg.op){
- return gpgme_error('MSG_OP_PENDING');
- }
let po = permittedOperations[this._msg.op];
if (!po){
return gpgme_error('MSG_WRONG_OP');
@@ -90,22 +108,3 @@ export class GPGME_Message {
}
}
-
-/**
- * Defines the operation this message will have
- * @param {String} operation Must be defined in permittedOperations
- * TODO: move to constructor?
- */
-function setOperation (scope, operation){
- if (!operation || typeof(operation) !== 'string'){
- return gpgme_error('PARAM_WRONG');
- }
- if (permittedOperations.hasOwnProperty(operation)){
- if (!scope._msg){
- scope._msg = {};
- }
- scope._msg.op = operation;
- } else {
- return gpgme_error('MSG_WRONG_OP');
- }
-} \ No newline at end of file