mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-04-03 06:40:25 +00:00
unit tests adapted to architectural change
This commit is contained in:
parent
18b36b84ac
commit
2c3ac8d24d
17 changed files with 149 additions and 137 deletions
|
|
@ -174,7 +174,6 @@ forgeModule = ( user, oPayload, dbMod, callback ) =>
|
|||
else
|
||||
src = oPayload.data
|
||||
dynmod.compileString src, user.username, 'dummyRule', oPayload.id, oPayload.lang, null, ( cm ) =>
|
||||
console.log cm
|
||||
answ = cm.answ
|
||||
if answ.code is 200
|
||||
funcs = []
|
||||
|
|
|
|||
|
|
@ -82,9 +82,10 @@ exports.compileString = ( src, userId, ruleId, modId, lang, dbMod, cb ) =>
|
|||
src = cs.compile src
|
||||
catch err
|
||||
cb
|
||||
code: 400
|
||||
message: 'Compilation of CoffeeScript failed at line ' +
|
||||
err.location.first_line
|
||||
answ:
|
||||
code: 400
|
||||
message: 'Compilation of CoffeeScript failed at line ' +
|
||||
err.location.first_line
|
||||
return
|
||||
|
||||
@log.info "DM | Trying to fetch user specific module '#{ modId }' paramters for user '#{ userId }'"
|
||||
|
|
@ -94,7 +95,7 @@ exports.compileString = ( src, userId, ruleId, modId, lang, dbMod, cb ) =>
|
|||
try
|
||||
oDecrypted = cryptico.decrypt obj, @oPrivateRSAkey
|
||||
obj = JSON.parse oDecrypted.plaintext
|
||||
@log.warn "DM | Loaded user defined params for #{ userId }, #{ ruleId }, #{ modId }"
|
||||
@log.info "DM | Loaded user defined params for #{ userId }, #{ ruleId }, #{ modId }"
|
||||
catch err
|
||||
@log.warn "DM | Error during parsing of user defined params for #{ userId }, #{ ruleId }, #{ modId }"
|
||||
@log.warn err
|
||||
|
|
@ -107,7 +108,7 @@ fTryToLoadModule = ( userId, ruleId, modId, src, dbMod, params, cb ) =>
|
|||
if not params
|
||||
params = {}
|
||||
|
||||
answ =
|
||||
answ =
|
||||
code: 200
|
||||
message: 'Successfully compiled'
|
||||
|
||||
|
|
@ -150,24 +151,16 @@ fTryToLoadModule = ( userId, ruleId, modId, src, dbMod, params, cb ) =>
|
|||
|
||||
if dbMod
|
||||
oFuncArgs = {}
|
||||
console.log 'oFuncParams'
|
||||
console.log oFuncParams
|
||||
|
||||
for func of oFuncParams
|
||||
console.log 'fetching ' + func
|
||||
console.log typeof func
|
||||
dbMod.getUserArguments modId, func, userId, ( err, obj ) =>
|
||||
console.log err, obj
|
||||
try
|
||||
oDecrypted = cryptico.decrypt obj, @oPrivateRSAkey
|
||||
oFuncArgs[ func ] = JSON.parse oDecrypted.plaintext
|
||||
catch err
|
||||
@log.warn "DM | Error during parsing of user defined params for #{ userId }, #{ ruleId }, #{ modId }"
|
||||
@log.warn err
|
||||
|
||||
console.log 'answering compile request string'
|
||||
console.log cb
|
||||
|
||||
if obj
|
||||
try
|
||||
oDecrypted = cryptico.decrypt obj, @oPrivateRSAkey
|
||||
oFuncArgs[ func ] = JSON.parse oDecrypted.plaintext
|
||||
catch err
|
||||
@log.warn "DM | Error during parsing of user defined params for #{ userId }, #{ ruleId }, #{ modId }"
|
||||
@log.warn err
|
||||
cb
|
||||
answ: answ
|
||||
module: sandbox.exports
|
||||
|
|
|
|||
|
|
@ -154,12 +154,15 @@ updateActionModules = ( updatedRuleId ) =>
|
|||
obj.lang, # script language
|
||||
db.actionInvokers, # the DB interface
|
||||
( result ) =>
|
||||
if not result.answ is 200
|
||||
if result.answ.code is 200
|
||||
@log.info "EN | Module '#{ moduleName }' successfully loaded for userName
|
||||
'#{ userName }' in rule '#{ oMyRule.rule.id }'"
|
||||
else
|
||||
@log.error "EN | Compilation of code failed! #{ userName },
|
||||
#{ oMyRule.rule.id }, #{ moduleName }"
|
||||
#{ oMyRule.rule.id }, #{ moduleName }: #{ result.answ.message }"
|
||||
oMyRule.actions[moduleName] = result.module
|
||||
else
|
||||
@log.warn 'EN | #{ moduleName } not found for #{ oMyRule.rule.id }!'
|
||||
@log.warn "EN | #{ moduleName } not found for #{ oMyRule.rule.id }!"
|
||||
|
||||
fAddIfNewOrNotExisting action for action in oMyRule.rule.actions
|
||||
|
||||
|
|
@ -200,7 +203,7 @@ Handles retrieved events.
|
|||
processEvent = ( evt ) =>
|
||||
fSearchAndInvokeAction = ( node, arrPath, funcName, evt, depth ) =>
|
||||
if not node
|
||||
@log.error "EN | Didn't find property in user rule list: " + arrPath.join ', ' + " at depth " + depth
|
||||
@log.error "EN | Didn't find property in user rule list: " + arrPath.join( ', ' ) + " at depth " + depth
|
||||
return
|
||||
if depth is arrPath.length
|
||||
try
|
||||
|
|
@ -226,4 +229,6 @@ processEvent = ( evt ) =>
|
|||
fSearchAndInvokeAction listUserRules, [ userName, ruleName, 'actions', arr[0]], arr[1], evt, 0
|
||||
|
||||
exports.shutDown = () ->
|
||||
isRunning = false
|
||||
isRunning = false
|
||||
listUserRules = {}
|
||||
|
||||
|
|
@ -57,7 +57,6 @@ indexEvent = ( event, body, resp ) ->
|
|||
activateWebHook = ( app, name ) =>
|
||||
@log.info "HL | Webhook activated for #{ name }"
|
||||
app.post "/webhooks/#{ name }", ( req, resp ) ->
|
||||
console.log 'something is coming through'
|
||||
body = ''
|
||||
req.on 'data', ( data ) ->
|
||||
body += data
|
||||
|
|
|
|||
|
|
@ -336,7 +336,6 @@ class IndexedModules
|
|||
replyHandler "set user params in '#{ @setname }:#{ mId }:#{ userId }:function:#{ func }'"
|
||||
|
||||
getUserArguments: ( mId, funcId, userId, cb ) =>
|
||||
console.log 'calling ffunct'
|
||||
@log.info "DB | (IdxedMods) #{ @setname }.getUserArguments( #{ mId }, #{ funcId }, #{ userId } )"
|
||||
@db.get "#{ @setname }:#{ mId }:#{ userId }:function:#{ funcId }", cb
|
||||
|
||||
|
|
|
|||
|
|
@ -73,8 +73,6 @@ exports.handleEvent = ( req, resp ) ->
|
|||
#if req.session and req.session.user
|
||||
try
|
||||
obj = JSON.parse body
|
||||
console.log 'got foreign event!'
|
||||
console.log obj
|
||||
catch err
|
||||
resp.send 400, 'Badly formed event!'
|
||||
# If required event properties are present we process the event #
|
||||
|
|
|
|||
2
examples/action-invokers/aiThree.coffee
Normal file
2
examples/action-invokers/aiThree.coffee
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
exports.printUserParamToLog = ( evt ) ->
|
||||
log params.password
|
||||
|
|
@ -239,7 +239,6 @@ Components Manager
|
|||
src = oPayload.data;
|
||||
return dynmod.compileString(src, user.username, 'dummyRule', oPayload.id, oPayload.lang, null, function(cm) {
|
||||
var funcs, id, name, _ref;
|
||||
console.log(cm);
|
||||
answ = cm.answ;
|
||||
if (answ.code === 200) {
|
||||
funcs = [];
|
||||
|
|
|
|||
|
|
@ -99,8 +99,10 @@ Dynamic Modules
|
|||
} catch (_error) {
|
||||
err = _error;
|
||||
cb({
|
||||
code: 400,
|
||||
message: 'Compilation of CoffeeScript failed at line ' + err.location.first_line
|
||||
answ: {
|
||||
code: 400,
|
||||
message: 'Compilation of CoffeeScript failed at line ' + err.location.first_line
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
@ -112,7 +114,7 @@ Dynamic Modules
|
|||
try {
|
||||
oDecrypted = cryptico.decrypt(obj, _this.oPrivateRSAkey);
|
||||
obj = JSON.parse(oDecrypted.plaintext);
|
||||
_this.log.warn("DM | Loaded user defined params for " + userId + ", " + ruleId + ", " + modId);
|
||||
_this.log.info("DM | Loaded user defined params for " + userId + ", " + ruleId + ", " + modId);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
_this.log.warn("DM | Error during parsing of user defined params for " + userId + ", " + ruleId + ", " + modId);
|
||||
|
|
@ -131,11 +133,11 @@ Dynamic Modules
|
|||
var answ, err, fName, func, logFunc, msg, oFuncArgs, oFuncParams, sandbox, _ref;
|
||||
if (!params) {
|
||||
params = {};
|
||||
answ = {
|
||||
code: 200,
|
||||
message: 'Successfully compiled'
|
||||
};
|
||||
}
|
||||
answ = {
|
||||
code: 200,
|
||||
message: 'Successfully compiled'
|
||||
};
|
||||
_this.log.info("DM | Running module '" + modId + "' for user '" + userId + "'");
|
||||
logFunc = logFunction(userId, ruleId, modId);
|
||||
sandbox = {
|
||||
|
|
@ -170,27 +172,22 @@ Dynamic Modules
|
|||
}
|
||||
if (dbMod) {
|
||||
oFuncArgs = {};
|
||||
console.log('oFuncParams');
|
||||
console.log(oFuncParams);
|
||||
for (func in oFuncParams) {
|
||||
console.log('fetching ' + func);
|
||||
console.log(typeof func);
|
||||
dbMod.getUserArguments(modId, func, userId, function(err, obj) {
|
||||
var oDecrypted;
|
||||
console.log(err, obj);
|
||||
try {
|
||||
oDecrypted = cryptico.decrypt(obj, _this.oPrivateRSAkey);
|
||||
return oFuncArgs[func] = JSON.parse(oDecrypted.plaintext);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
_this.log.warn("DM | Error during parsing of user defined params for " + userId + ", " + ruleId + ", " + modId);
|
||||
return _this.log.warn(err);
|
||||
if (obj) {
|
||||
try {
|
||||
oDecrypted = cryptico.decrypt(obj, _this.oPrivateRSAkey);
|
||||
return oFuncArgs[func] = JSON.parse(oDecrypted.plaintext);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
_this.log.warn("DM | Error during parsing of user defined params for " + userId + ", " + ruleId + ", " + modId);
|
||||
return _this.log.warn(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log('answering compile request string');
|
||||
console.log(cb);
|
||||
return cb({
|
||||
answ: answ,
|
||||
module: sandbox.exports,
|
||||
|
|
|
|||
13
js/engine.js
13
js/engine.js
|
|
@ -167,13 +167,15 @@ Engine
|
|||
return db.actionInvokers.getModule(moduleName, function(err, obj) {
|
||||
if (obj) {
|
||||
return dynmod.compileString(obj.data, userName, oMyRule.rule.id, moduleName, obj.lang, db.actionInvokers, function(result) {
|
||||
if (!result.answ === 200) {
|
||||
_this.log.error("EN | Compilation of code failed! " + userName + ", " + oMyRule.rule.id + ", " + moduleName);
|
||||
if (result.answ.code === 200) {
|
||||
_this.log.info("EN | Module '" + moduleName + "' successfully loaded for userName '" + userName + "' in rule '" + oMyRule.rule.id + "'");
|
||||
} else {
|
||||
_this.log.error("EN | Compilation of code failed! " + userName + ", " + oMyRule.rule.id + ", " + moduleName + ": " + result.answ.message);
|
||||
}
|
||||
return oMyRule.actions[moduleName] = result.module;
|
||||
});
|
||||
} else {
|
||||
return _this.log.warn('EN | #{ moduleName } not found for #{ oMyRule.rule.id }!');
|
||||
return _this.log.warn("EN | " + moduleName + " not found for " + oMyRule.rule.id + "!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -253,7 +255,7 @@ Engine
|
|||
fSearchAndInvokeAction = function(node, arrPath, funcName, evt, depth) {
|
||||
var err;
|
||||
if (!node) {
|
||||
_this.log.error("EN | Didn't find property in user rule list: " + arrPath.join(', ' + " at depth " + depth));
|
||||
_this.log.error("EN | Didn't find property in user rule list: " + arrPath.join(', ') + " at depth " + depth);
|
||||
return;
|
||||
}
|
||||
if (depth === arrPath.length) {
|
||||
|
|
@ -308,7 +310,8 @@ Engine
|
|||
})(this);
|
||||
|
||||
exports.shutDown = function() {
|
||||
return isRunning = false;
|
||||
isRunning = false;
|
||||
return listUserRules = {};
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,6 @@ HTTP Listener
|
|||
_this.log.info("HL | Webhook activated for " + name);
|
||||
return app.post("/webhooks/" + name, function(req, resp) {
|
||||
var body;
|
||||
console.log('something is coming through');
|
||||
body = '';
|
||||
req.on('data', function(data) {
|
||||
return body += data;
|
||||
|
|
|
|||
|
|
@ -427,7 +427,6 @@ Persistence
|
|||
};
|
||||
|
||||
IndexedModules.prototype.getUserArguments = function(mId, funcId, userId, cb) {
|
||||
console.log('calling ffunct');
|
||||
this.log.info("DB | (IdxedMods) " + this.setname + ".getUserArguments( " + mId + ", " + funcId + ", " + userId + " )");
|
||||
return this.db.get("" + this.setname + ":" + mId + ":" + userId + ":function:" + funcId, cb);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -80,8 +80,6 @@ Request Handler
|
|||
var answ, err, obj, rand, timestamp;
|
||||
try {
|
||||
obj = JSON.parse(body);
|
||||
console.log('got foreign event!');
|
||||
console.log(obj);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
resp.send(400, 'Badly formed event!');
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@
|
|||
"aiThree": {
|
||||
"id":"aiThree",
|
||||
"lang":"CoffeeScript",
|
||||
"data":"exports.printUserParamToLog = ( evt ) ->\n\tdebug 'wow'n\tlog 'wow'\n\tlog params.password",
|
||||
"data":"exports.printUserParamToLog = () ->\n\tlog params.password",
|
||||
"public":"false",
|
||||
"params":"[\"password\"]",
|
||||
"functions":"[\"printUserParamToLog\"]",
|
||||
"functionArgs":"{\"printUserParamToLog\":[\"evt\"]}"
|
||||
"functionArgs":"{\"printUserParamToLog\":[]}"
|
||||
}
|
||||
},
|
||||
"userparams": {
|
||||
|
|
|
|||
|
|
@ -18,10 +18,11 @@ catch err
|
|||
console.log 'Error fetching standard objects file: ' + err.message
|
||||
|
||||
logger = require path.join '..', 'js', 'logging'
|
||||
log = logger.getLogger()
|
||||
# nolog: true
|
||||
log = logger.getLogger
|
||||
nolog: true
|
||||
opts =
|
||||
logger: log
|
||||
keygen: passPhrase
|
||||
|
||||
engine = require path.join '..', 'js', 'engine'
|
||||
engine opts
|
||||
|
|
@ -38,15 +39,30 @@ oUser = objects.users.userOne
|
|||
oRuleOne = objects.rules.ruleOne
|
||||
oRuleTwo = objects.rules.ruleTwo
|
||||
oRuleThree = objects.rules.ruleThree
|
||||
oEventOne = objects.events.eventOne
|
||||
oEpOne = objects.eps.epOne
|
||||
oEpTwo = objects.eps.epTwo
|
||||
oAiOne = objects.ais.aiOne
|
||||
oAiTwo = objects.ais.aiTwo
|
||||
oAiThree = objects.ais.aiThree
|
||||
|
||||
exports.setUp = ( cb ) ->
|
||||
engine.startEngine()
|
||||
cb()
|
||||
|
||||
exports.tearDown = ( cb ) ->
|
||||
engine.shutDown()
|
||||
db.deleteUser oUser.username
|
||||
db.deleteRule oRuleOne.id
|
||||
db.deleteRule oRuleTwo.id
|
||||
db.deleteRule oRuleThree.id
|
||||
db.eventPollers.deleteModule oEpOne.id
|
||||
db.eventPollers.deleteModule oEpTwo.id
|
||||
db.actionInvokers.deleteModule oAiOne.id
|
||||
db.actionInvokers.deleteModule oAiTwo.id
|
||||
db.actionInvokers.deleteModule oAiThree.id
|
||||
db.actionInvokers.deleteUserParams oAiThree.id, oUser.username
|
||||
|
||||
setTimeout cb, 100
|
||||
|
||||
exports.requestProcessing =
|
||||
|
|
@ -119,12 +135,6 @@ exports.testListener = ( test ) =>
|
|||
setTimeout fWaitForInit, 200
|
||||
|
||||
exports.moduleHandling =
|
||||
tearDown: ( cb ) ->
|
||||
db.eventPollers.deleteModule oEpOne.id
|
||||
db.eventPollers.deleteModule oEpTwo.id
|
||||
db.actionInvokers.deleteModule oAiTwo.id
|
||||
setTimeout cb, 100
|
||||
|
||||
testGetModules: ( test ) ->
|
||||
test.expect 2
|
||||
|
||||
|
|
@ -178,45 +188,87 @@ exports.moduleHandling =
|
|||
test.done()
|
||||
|
||||
|
||||
exports.testForgeRule = ( test ) ->
|
||||
test.expect 1
|
||||
exports.ruleForge =
|
||||
testUserParams: ( test ) ->
|
||||
test.expect 3
|
||||
|
||||
db.storeUser oUser
|
||||
db.actionInvokers.storeModule oUser.username, oAiThree
|
||||
db.storeUser oUser
|
||||
db.actionInvokers.storeModule oUser.username, oAiThree
|
||||
|
||||
pw = 'This password should come out cleartext'
|
||||
userparams = JSON.stringify password: pw
|
||||
oEncrypted = cryptico.encrypt userparams, strPublicKey
|
||||
pw = 'This password should come out cleartext'
|
||||
userparams = JSON.stringify password: pw
|
||||
oEncrypted = cryptico.encrypt userparams, strPublicKey
|
||||
|
||||
db.actionInvokers.storeUserParams oAiThree.id, oUser.username, oEncrypted.cipher
|
||||
db.actionInvokers.storeUserParams oAiThree.id, oUser.username, oEncrypted.cipher
|
||||
|
||||
request =
|
||||
command: 'forge_rule'
|
||||
payload: JSON.stringify oRuleThree
|
||||
request =
|
||||
command: 'forge_rule'
|
||||
payload: JSON.stringify oRuleThree
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Forging Rule returned #{ answ.code }: #{ answ.message }"
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Forging Rule returned #{ answ.code }: #{ answ.message }"
|
||||
|
||||
fWaitForPersistence = () ->
|
||||
evt = objects.events.eventReal
|
||||
evt.eventid = 'event_testid'
|
||||
db.pushEvent evt
|
||||
console.log 'pushed'
|
||||
fWaitForPersistence = () ->
|
||||
evt = objects.events.eventReal
|
||||
evt.eventid = 'event_testid'
|
||||
db.pushEvent evt
|
||||
|
||||
fWaitAgain = () ->
|
||||
console.log 'waited'
|
||||
db.getLog oUser.username, oRuleThree.id, ( err, data ) ->
|
||||
console.log data
|
||||
try
|
||||
logged = data.split( '] ' )[1]
|
||||
logged = logged.split( "\n" )[0]
|
||||
test.strictEqual logged, "{#{ oAiThree.id }} " + pw, 'Did not log the right thing'
|
||||
catch e
|
||||
test.ok false, 'Parsing log failed'
|
||||
fWaitAgain = () ->
|
||||
db.getLog oUser.username, oRuleThree.id, ( err, data ) ->
|
||||
try
|
||||
arrRows = data.split "\n"
|
||||
logged = arrRows[ 1 ].split( '] ' )[1]
|
||||
test.strictEqual logged, "{#{ oAiThree.id }} " + pw, 'Did not log the right thing'
|
||||
catch e
|
||||
test.ok false, 'Parsing log failed'
|
||||
|
||||
setTimeout test.done, 200
|
||||
request =
|
||||
command: 'delete_rule'
|
||||
payload: JSON.stringify id: oRuleThree.id
|
||||
|
||||
setTimeout fWaitAgain, 200
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Deleting Rule returned #{ answ.code }: #{ answ.message }"
|
||||
setTimeout test.done, 200
|
||||
|
||||
setTimeout fWaitForPersistence, 200
|
||||
setTimeout fWaitAgain, 200
|
||||
|
||||
setTimeout fWaitForPersistence, 200
|
||||
|
||||
|
||||
testEvent: ( test ) ->
|
||||
test.expect 3
|
||||
|
||||
db.storeUser oUser
|
||||
db.actionInvokers.storeModule oUser.username, oAiOne
|
||||
|
||||
request =
|
||||
command: 'forge_rule'
|
||||
payload: JSON.stringify oRuleOne
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Forging Rule returned #{ answ.code }: #{ answ.message }"
|
||||
|
||||
fWaitForPersistence = () ->
|
||||
db.pushEvent oEventOne
|
||||
|
||||
fWaitAgain = () ->
|
||||
db.getLog oUser.username, oRuleOne.id, ( err, data ) ->
|
||||
try
|
||||
arrRows = data.split "\n"
|
||||
logged = arrRows[ 1 ].split( '] ' )[1]
|
||||
test.strictEqual logged, "{#{ oAiOne.id }} " + oEventOne.payload.property,
|
||||
'Did not log the right thing'
|
||||
catch e
|
||||
test.ok false, 'Parsing log failed'
|
||||
|
||||
request =
|
||||
command: 'delete_rule'
|
||||
payload: JSON.stringify id: oRuleOne.id
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Deleting Rule returned #{ answ.code }: #{ answ.message }"
|
||||
setTimeout test.done, 200
|
||||
|
||||
setTimeout fWaitAgain, 200
|
||||
|
||||
setTimeout fWaitForPersistence, 200
|
||||
|
|
|
|||
|
|
@ -36,10 +36,14 @@ oUser = objects.users.userOne
|
|||
oRule = objects.rules.ruleThree
|
||||
oAi = objects.ais.aiThree
|
||||
|
||||
exports.setUp = ( cb ) ->
|
||||
engine.startEngine()
|
||||
cb()
|
||||
|
||||
exports.tearDown = ( cb ) ->
|
||||
db.storeUser oUser
|
||||
db.deleteRule oRule.id
|
||||
db.actionInvokers.deleteModule oAi.id
|
||||
engine.shutDown()
|
||||
setTimeout cb, 200
|
||||
|
||||
exports.testCompile = ( test ) ->
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ exports.ruleEvents =
|
|||
db.activateRule oRuleOne.id, oUser.username
|
||||
db.actionInvokers.storeModule oUser.username, oAiOne
|
||||
db.actionInvokers.storeModule oUser.username, oAiTwo
|
||||
|
||||
test.strictEqual listRules[oUser.username], undefined, 'Initial user object exists!?'
|
||||
|
||||
engine.internalEvent
|
||||
|
|
@ -142,36 +141,3 @@ exports.ruleEvents =
|
|||
|
||||
# setTimeout fCheckRules, 500
|
||||
|
||||
exports.engine =
|
||||
testMatchingEvent: ( test ) ->
|
||||
test.expect 1
|
||||
db.storeUser oUser
|
||||
db.storeRule oRuleOne.id, JSON.stringify oRuleOne
|
||||
db.linkRule oRuleOne.id, oUser.username
|
||||
db.activateRule oRuleOne.id, oUser.username
|
||||
db.actionInvokers.storeModule oUser.username, oAiOne
|
||||
|
||||
engine.internalEvent
|
||||
event: 'new'
|
||||
user: oUser.username
|
||||
rule: oRuleOne
|
||||
|
||||
fWaitForPersistence = () ->
|
||||
evt = objects.events.eventReal
|
||||
evt.eventid = 'event_testid'
|
||||
db.pushEvent evt
|
||||
|
||||
fWaitAgain = () ->
|
||||
db.getLog oUser.username, oRuleOne.id, ( err, data ) ->
|
||||
try
|
||||
|
||||
logged = data.split( '] ' )[1]
|
||||
logged = logged.split( "\n" )[0]
|
||||
test.strictEqual logged, "{#{ oAiOne.id }} " + evt.payload.property, 'Did not log the right thing'
|
||||
catch e
|
||||
test.ok false, 'Parsing log failed'
|
||||
test.done()
|
||||
|
||||
setTimeout fWaitAgain, 200
|
||||
|
||||
setTimeout fWaitForPersistence, 200
|
||||
|
|
|
|||
Loading…
Reference in a new issue