@alertlogic/al-collector-js 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,15 +11,9 @@
11
11
  const assert = require('assert');
12
12
  const alLogFilter = require('../al_log_filter');
13
13
 
14
-
15
14
  describe('Unit Tests', function() {
16
15
  describe('Filter Messages', function() {
17
-
18
- const msgJson = [
19
- { message1: 1, text: 'test1' },
20
- { message2: 2, text: 'test12'},
21
- { messageA: "a", text: 'testa'},
22
- ];
16
+ let msgJson = [];
23
17
  const msgString = [
24
18
  'message1',
25
19
  'message2',
@@ -27,6 +21,27 @@ describe('Unit Tests', function() {
27
21
  ];
28
22
 
29
23
  before(function(){
24
+ msgJson = [
25
+ { message1: 1, text: 'test1' },
26
+ { message2: 2, text: 'test12'},
27
+ { messageA: "a", text: 'testa'},
28
+ { messageB: {
29
+ childTestMsg: 'childTest',
30
+ childTestValue: 'childValue'
31
+ }, text: 'testb'},
32
+ { messageC: {
33
+ childTestMsg: 'childTest',
34
+ childTestValue: {
35
+ messageC: "c"
36
+ }
37
+ }, text: 'testc'},
38
+ { messageD: {
39
+ childTestMsg: 'childTestD',
40
+ childTestValue: {
41
+ messageC: "c"
42
+ }
43
+ }, text: 'testd'}
44
+ ];
30
45
  });
31
46
  after(function() {
32
47
  });
@@ -48,11 +63,97 @@ describe('Unit Tests', function() {
48
63
  return done();
49
64
  });
50
65
 
51
- it('Undefined filters', function(done) {
66
+ it('Undefined filters', function (done) {
52
67
  assert.deepEqual(msgString, alLogFilter.filterRegExp(msgString, null));
53
68
  assert.deepEqual(msgJson, alLogFilter.filterJson(msgJson));
54
69
  return done();
55
70
  });
56
-
71
+
72
+ it('Should filter array based on object child property', function (done) {
73
+ assert.deepEqual([{
74
+ messageB: {
75
+ childTestMsg: 'childTest',
76
+ childTestValue: 'childValue'
77
+ },
78
+ text: 'testb'
79
+ }], alLogFilter.filterJson(msgJson, '{"messageB":{"childTestMsg":"childTest"}}'));
80
+ return done();
81
+ });
82
+
83
+ it('Should filter array based on object child of child property', function (done) {
84
+ assert.deepEqual([{
85
+ messageC: {
86
+ childTestMsg: 'childTest',
87
+ childTestValue: {
88
+ messageC: "c"
89
+ }
90
+ },
91
+ text: 'testc'
92
+ }], alLogFilter.filterJson(msgJson, '{"messageC":{"childTestMsg": "childTest","childTestValue":{"messageC":"c"}}}'));
93
+ return done();
94
+ });
95
+
96
+ it('Should filter array based on array of object with AND case', function (done) {
97
+ assert.deepEqual([{
98
+ messageB: {
99
+ childTestMsg: 'childTest',
100
+ childTestValue: 'childValue'
101
+ },
102
+ text: 'testb'
103
+ }, {
104
+ messageC: {
105
+ childTestMsg: 'childTest',
106
+ childTestValue: {
107
+ messageC: "c"
108
+ }
109
+ },
110
+ text: 'testc'
111
+ }], alLogFilter.filterJson(msgJson, '[{"messageB":{"childTestMsg":"childTest"}}, {"messageC":{"childTestMsg": "childTest","childTestValue":{"messageC":"c"}}}]'));
112
+ return done();
113
+ });
114
+
115
+ it('Should filter array based on array of object with OR case', function (done) {
116
+ assert.deepEqual([{
117
+ messageB: {
118
+ childTestMsg: 'childTest',
119
+ childTestValue: 'childValue'
120
+ },
121
+ text: 'testb'
122
+ }], alLogFilter.filterJson(msgJson, '[{"messageB":{"childTestMsg":"childTest"}}, {"messageC":{"childTestMsgT": "childTest","childTestValue":{"messageC":"c"}}}]'));
123
+ return done();
124
+ });
125
+
126
+ it('Two condition match of same object for array based filtering on array of object with OR case', function (done) {
127
+ assert.deepEqual([{
128
+ messageB: {
129
+ childTestMsg: 'childTest',
130
+ childTestValue: 'childValue'
131
+ },
132
+ text: 'testb'
133
+ }], alLogFilter.filterJson(msgJson, '[{"messageB":{"childTestMsg":"childTest"}}, {"messageB":{"childTestValue":"childValue"}}]'));
134
+ return done();
135
+ });
136
+
137
+ it('three condition match of same object for array based filtering on array of object with OR case', function (done) {
138
+ assert.deepEqual([{
139
+ messageB: {
140
+ childTestMsg: 'childTest',
141
+ childTestValue: 'childValue'
142
+ },
143
+ text: 'testb'
144
+ }], alLogFilter.filterJson(msgJson, '[{"messageB":{"childTestMsg":"childTest"}}, {"messageB":{"childTestValue":"childValue"}}, {"text": "testb"}]'));
145
+ return done();
146
+ });
147
+
148
+ it('negative case for array based filtering on array of object with OR case', function (done) {
149
+ assert.deepEqual([{
150
+ messageB: {
151
+ childTestMsg: 'childTest',
152
+ childTestValue: 'childValue'
153
+ },
154
+ text: 'testb'
155
+ }], alLogFilter.filterJson(msgJson, '[{"messageB":{"childTestMsg":"childTest"}}, {"messageB":{"childTestValue":"childValue1"}}]'));
156
+ return done();
157
+ });
57
158
  });
58
159
  });