Browse files

Add test on message filtering

  • Loading branch information...
1 parent 88d375c commit 37dd3d214bd09818bb4a6206d6655fa739d34217 Bertrand Paquet committed Oct 14, 2012
Showing with 32 additions and 1 deletion.
  1. +3 −0 lib/filters/filter_compute_field.js
  2. +8 −1 test/test_25_filter_compute_field.js
  3. +21 −0 test/test_26_message_filtering.js
View
3 lib/filters/filter_compute_field.js
@@ -21,6 +21,9 @@ FilterComputeField.prototype.afterLoadConfig = function(callback) {
FilterComputeField.prototype.process = function(data) {
var value = this.replaceByFields(data, this.value);
if (value) {
+ if (!data['@fields']) {
+ data['@fields'] = {};
+ }
data['@fields'][this.field_name] = value;
}
return data;
View
9 test/test_25_filter_compute_field.js
@@ -4,7 +4,14 @@ var vows = require('vows'),
filter_helper = require('./filter_helper');
vows.describe('Filter compute field ').addBatch({
- 'normal': filter_helper.create('compute_field', 'titi?value=ab#{bouh}', [
+ 'normal': filter_helper.create('compute_field', 'titi?value=ab', [
+ {'@message': 'toto'},
+ {'@message': 'toto', '@fields': {'bouh': 'tata'}},
+ ], [
+ {'@message': 'toto', '@fields': {'titi': 'ab'}},
+ {'@message': 'toto', '@fields': {'bouh': 'tata', 'titi': 'ab'}},
+ ]),
+ 'with value': filter_helper.create('compute_field', 'titi?value=ab#{bouh}', [
{'@message': 'toto'},
{'@message': 'toto', '@fields': {'bouh': 'tata'}},
{'@message': 'toto', '@fields': {'bouh': 42}},
View
21 test/test_26_message_filtering.js
@@ -0,0 +1,21 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ os = require('os'),
+ filter_helper = require('./filter_helper');
+
+vows.describe('Message filtering ').addBatch({
+ 'nothing': filter_helper.create('compute_field', 'titi?value=a', [
+ {'@message': 'toto'},
+ ], [
+ {'@message': 'toto', '@fields': {'titi': 'a'}},
+ ]),
+ 'only type': filter_helper.create('compute_field', 'titi?value=a&only_type=z', [
+ {'@message': 'toto'},
+ {'@message': 'toto', '@type': 'tata'},
+ {'@message': 'toto', '@type': 'z'},
+ ], [
+ {'@message': 'toto'},
+ {'@message': 'toto', '@type': 'tata'},
+ {'@message': 'toto', '@type': 'z', '@fields': {'titi': 'a'}},
+ ]),
+}).export(module);

0 comments on commit 37dd3d2

Please sign in to comment.