@@ -176,6 +176,111 @@ describe('Identify', function () {
176176 assert . deepEqual ( [ property1 , property2 , property3 , property4 , property5 ] , identify . properties ) ;
177177 } ) ;
178178
179+ it ( 'should preInsert properties' , function ( ) {
180+ var property1 = 'var value' ;
181+ var value1 = 'testValue' ;
182+
183+ var property2 = 'float value' ;
184+ var value2 = 0.123 ;
185+
186+ var property3 = 'bool value' ;
187+ var value3 = true ;
188+
189+ var property4 = 'json value' ;
190+ var value4 = { } ;
191+
192+ var property5 = 'list value' ;
193+ var value5 = [ 1 , 2 , 'test' ] ;
194+
195+ var identify = new Identify ( ) . preInsert ( property1 , value1 ) . preInsert ( property2 , value2 ) ;
196+ identify . preInsert ( property3 , value3 ) . preInsert ( property4 , value4 ) . preInsert ( property5 , value5 ) ;
197+
198+ // identify should ignore this since duplicate key
199+ identify . setOnce ( property1 , value3 ) ;
200+
201+ var expected = {
202+ $preInsert : { } ,
203+ } ;
204+ expected [ '$preInsert' ] [ property1 ] = value1 ;
205+ expected [ '$preInsert' ] [ property2 ] = value2 ;
206+ expected [ '$preInsert' ] [ property3 ] = value3 ;
207+ expected [ '$preInsert' ] [ property4 ] = value4 ;
208+ expected [ '$preInsert' ] [ property5 ] = value5 ;
209+
210+ assert . deepEqual ( expected , identify . userPropertiesOperations ) ;
211+ assert . deepEqual ( [ property1 , property2 , property3 , property4 , property5 ] , identify . properties ) ;
212+ } ) ;
213+
214+ it ( 'should postInsert properties' , function ( ) {
215+ var property1 = 'var value' ;
216+ var value1 = 'testValue' ;
217+
218+ var property2 = 'float value' ;
219+ var value2 = 0.123 ;
220+
221+ var property3 = 'bool value' ;
222+ var value3 = true ;
223+
224+ var property4 = 'json value' ;
225+ var value4 = { } ;
226+
227+ var property5 = 'list value' ;
228+ var value5 = [ 1 , 2 , 'test' ] ;
229+
230+ var identify = new Identify ( ) . postInsert ( property1 , value1 ) . postInsert ( property2 , value2 ) ;
231+ identify . postInsert ( property3 , value3 ) . postInsert ( property4 , value4 ) . postInsert ( property5 , value5 ) ;
232+
233+ // identify should ignore this since duplicate key
234+ identify . setOnce ( property1 , value3 ) ;
235+
236+ var expected = {
237+ $postInsert : { } ,
238+ } ;
239+ expected [ '$postInsert' ] [ property1 ] = value1 ;
240+ expected [ '$postInsert' ] [ property2 ] = value2 ;
241+ expected [ '$postInsert' ] [ property3 ] = value3 ;
242+ expected [ '$postInsert' ] [ property4 ] = value4 ;
243+ expected [ '$postInsert' ] [ property5 ] = value5 ;
244+
245+ assert . deepEqual ( expected , identify . userPropertiesOperations ) ;
246+ assert . deepEqual ( [ property1 , property2 , property3 , property4 , property5 ] , identify . properties ) ;
247+ } ) ;
248+
249+ it ( 'should remove properties' , function ( ) {
250+ var property1 = 'var value' ;
251+ var value1 = 'testValue' ;
252+
253+ var property2 = 'float value' ;
254+ var value2 = 0.123 ;
255+
256+ var property3 = 'bool value' ;
257+ var value3 = true ;
258+
259+ var property4 = 'json value' ;
260+ var value4 = { } ;
261+
262+ var property5 = 'list value' ;
263+ var value5 = [ 1 , 2 , 'test' ] ;
264+
265+ var identify = new Identify ( ) . remove ( property1 , value1 ) . remove ( property2 , value2 ) ;
266+ identify . remove ( property3 , value3 ) . remove ( property4 , value4 ) . remove ( property5 , value5 ) ;
267+
268+ // identify should ignore this since duplicate key
269+ identify . setOnce ( property1 , value3 ) ;
270+
271+ var expected = {
272+ $remove : { } ,
273+ } ;
274+ expected [ '$remove' ] [ property1 ] = value1 ;
275+ expected [ '$remove' ] [ property2 ] = value2 ;
276+ expected [ '$remove' ] [ property3 ] = value3 ;
277+ expected [ '$remove' ] [ property4 ] = value4 ;
278+ expected [ '$remove' ] [ property5 ] = value5 ;
279+
280+ assert . deepEqual ( expected , identify . userPropertiesOperations ) ;
281+ assert . deepEqual ( [ property1 , property2 , property3 , property4 , property5 ] , identify . properties ) ;
282+ } ) ;
283+
179284 it ( 'should allow multiple operations' , function ( ) {
180285 var property1 = 'string value' ;
181286 var value1 = 'testValue' ;
@@ -194,9 +299,20 @@ describe('Identify', function () {
194299 var property6 = 'int value' ;
195300 var value6 = 100 ;
196301
302+ var property7 = 'string value2' ;
303+ var value7 = 'testValue2' ;
304+
305+ var property8 = 'fload value2' ;
306+ var value8 = 0.456 ;
307+
308+ var property9 = 'bool value2' ;
309+ var value9 = false ;
310+
197311 var identify = new Identify ( ) . setOnce ( property1 , value1 ) . add ( property2 , value2 ) ;
198312 identify . set ( property3 , value3 ) . unset ( property4 ) . append ( property5 , value5 ) ;
199313 identify . prepend ( property6 , value6 ) ;
314+ identify . preInsert ( property7 , value7 ) . postInsert ( property8 , value8 ) ;
315+ identify . remove ( property9 , value9 ) ;
200316
201317 // identify should ignore this since duplicate key
202318 identify . set ( property4 , value3 ) ;
@@ -208,16 +324,24 @@ describe('Identify', function () {
208324 $set : { } ,
209325 $setOnce : { } ,
210326 $unset : { } ,
327+ $preInsert : { } ,
328+ $postInsert : { } ,
329+ $remove : { } ,
211330 } ;
212331 expected [ '$setOnce' ] [ property1 ] = value1 ;
213332 expected [ '$add' ] [ property2 ] = value2 ;
214333 expected [ '$set' ] [ property3 ] = value3 ;
215334 expected [ '$unset' ] [ property4 ] = '-' ;
216335 expected [ '$append' ] [ property5 ] = value5 ;
217336 expected [ '$prepend' ] [ property6 ] = value6 ;
218-
337+ expected [ '$preInsert' ] [ property7 ] = value7 ;
338+ expected [ '$postInsert' ] [ property8 ] = value8 ;
339+ expected [ '$remove' ] [ property9 ] = value9 ;
219340 assert . deepEqual ( expected , identify . userPropertiesOperations ) ;
220- assert . deepEqual ( [ property1 , property2 , property3 , property4 , property5 , property6 ] , identify . properties ) ;
341+ assert . deepEqual (
342+ [ property1 , property2 , property3 , property4 , property5 , property6 , property7 , property8 , property9 ] ,
343+ identify . properties ,
344+ ) ;
221345 } ) ;
222346
223347 it ( 'should disallow duplicate properties' , function ( ) {
0 commit comments