@@ -148,4 +148,106 @@ describe('LogReader', () => {
148
148
assert ( mockExtension . filter . secondCall . calledWith ( expectedArgs ) ) ;
149
149
done ( ) ;
150
150
} ) ;
151
+
152
+ it ( 'Should add timestamp if got delete event and extension is notification' , done => {
153
+ const mockExtension = {
154
+ constructor : {
155
+ name : 'NotificationQueuePopulator'
156
+ } ,
157
+ filter : sinon . spy ( ) ,
158
+ } ;
159
+ const logReaderWithExtension = new LogReader ( {
160
+ logId : 'test-log-reader' ,
161
+ zkClient : zkMock . createClient ( 'localhost:2181' ) ,
162
+ logConsumer : new MockLogConsumer ( ) ,
163
+ logger : new Logger ( 'test:logReaderWithExtension' ) ,
164
+ extensions : [ mockExtension ]
165
+ } ) ;
166
+ const record = {
167
+ db : 'example-bucket' ,
168
+ timestamp : 'YYYY-MM-DD:HH-MM-SS' ,
169
+ entry : {
170
+ type : 'delete' ,
171
+ key : 'fMexample-key' ,
172
+ }
173
+ } ;
174
+ logReaderWithExtension . _processLogEntry ( { } , record , record . entry ) ;
175
+ const expectedArgs = {
176
+ type : 'delete' ,
177
+ bucket : 'example-bucket' ,
178
+ key : 'fMexample-key' ,
179
+ value : JSON . stringify ( {
180
+ 'last-modified' : 'YYYY-MM-DD:HH-MM-SS' ,
181
+ } ) ,
182
+ logReader : logReaderWithExtension ,
183
+ } ;
184
+ assert ( mockExtension . filter . calledWith ( expectedArgs ) ) ;
185
+ done ( ) ;
186
+ } ) ;
187
+
188
+ it ( 'Should not modify entry value if already defined' , done => {
189
+ const mockExtension = {
190
+ constructor : {
191
+ name : 'NotificationQueuePopulator'
192
+ } ,
193
+ filter : sinon . spy ( ) ,
194
+ } ;
195
+ const logReaderWithExtension = new LogReader ( {
196
+ logId : 'test-log-reader' ,
197
+ zkClient : zkMock . createClient ( 'localhost:2181' ) ,
198
+ logConsumer : new MockLogConsumer ( ) ,
199
+ logger : new Logger ( 'test:logReaderWithExtension' ) ,
200
+ extensions : [ mockExtension ]
201
+ } ) ;
202
+ const record = {
203
+ db : 'example-bucket' ,
204
+ timestamp : 'timestamp-value' ,
205
+ entry : {
206
+ type : 'example-type' ,
207
+ key : 'fMexample-key' ,
208
+ value : {
209
+ 'last-modified' : 'YYYY-MM-DD:HH-MM-SS' ,
210
+ }
211
+ }
212
+ } ;
213
+ logReaderWithExtension . _processLogEntry ( { } , record , record . entry ) ;
214
+ const expectedArgs = {
215
+ type : 'example-type' ,
216
+ bucket : 'example-bucket' ,
217
+ key : 'fMexample-key' ,
218
+ value : {
219
+ 'last-modified' : 'YYYY-MM-DD:HH-MM-SS' ,
220
+ } ,
221
+ logReader : logReaderWithExtension ,
222
+ } ;
223
+ assert ( mockExtension . filter . calledWith ( expectedArgs ) ) ;
224
+ done ( ) ;
225
+ } ) ;
226
+
227
+ it ( 'Should skip filtering if value is undefined and extension not notification' , done => {
228
+ const mockExtension = {
229
+ constructor : {
230
+ name : 'ReplicationQueuePopulator'
231
+ } ,
232
+ filter : sinon . spy ( ) ,
233
+ } ;
234
+ const logReaderWithExtension = new LogReader ( {
235
+ logId : 'test-log-reader' ,
236
+ zkClient : zkMock . createClient ( 'localhost:2181' ) ,
237
+ logConsumer : new MockLogConsumer ( ) ,
238
+ logger : new Logger ( 'test:logReaderWithExtension' ) ,
239
+ extensions : [ mockExtension ]
240
+ } ) ;
241
+ const record = {
242
+ db : 'example-bucket' ,
243
+ timestamp : 'YYYY-MM-DD:HH-MM-SS' ,
244
+ entry : {
245
+ type : 'example-type' ,
246
+ key : 'fMexample-key' ,
247
+ }
248
+ } ;
249
+ logReaderWithExtension . _processLogEntry ( { } , record , record . entry ) ;
250
+ assert ( mockExtension . filter . notCalled ) ;
251
+ done ( ) ;
252
+ } ) ;
151
253
} ) ;
0 commit comments