@@ -3,19 +3,21 @@ import { BaseEvent } from '../../src/sdkRuntimeModels';
33import { expect } from 'chai' ;
44
55describe ( 'Create a batch from a base event' , ( ) => {
6- const batchValidator = new _BatchValidator ( ) ;
76 const baseEvent : BaseEvent = {
87 messageType : 4 ,
98 name : 'testEvent'
109 }
11-
10+
1211 it ( 'creates a batch with base event ' , done => {
12+ const now = new Date ( ) . getTime ( ) ;
13+ const batchValidator = new _BatchValidator ( )
14+
1315 let batch = batchValidator . returnBatch ( baseEvent ) ;
1416
1517 expect ( batch ) . to . have . property ( 'environment' ) . equal ( 'production' ) ;
1618 expect ( batch ) . to . have . property ( 'source_request_id' ) . equal ( 'mockId' ) ;
1719 expect ( batch ) . to . have . property ( 'mpid' ) . equal ( '0' ) ;
18- expect ( batch ) . to . have . property ( 'timestamp_unixtime_ms' )
20+ expect ( batch ) . to . have . property ( 'timestamp_unixtime_ms' ) . greaterThanOrEqual ( now ) ;
1921 expect ( batch ) . to . have . property ( 'mp_deviceid' ) ;
2022 expect ( batch ) . to . have . property ( 'sdk_version' )
2123 expect ( batch ) . to . have . property ( 'application_info' ) ;
@@ -47,12 +49,56 @@ describe('Create a batch from a base event', () => {
4749 batch = batchValidator . returnBatch ( baseEvent ) ;
4850 expect ( batch . events [ 0 ] . data ) . to . have . property ( 'custom_attributes' ) ;
4951 expect ( batch . events [ 0 ] . data . custom_attributes ) . to . have . property ( 'attrFoo' , 'attrBar' ) ;
50-
52+
5153 baseEvent . customFlags = { flagFoo : 'flagBar' }
5254 batch = batchValidator . returnBatch ( baseEvent ) ;
5355 expect ( batch . events [ 0 ] . data ) . to . have . property ( 'custom_flags' ) ;
5456 expect ( batch . events [ 0 ] . data . custom_flags ) . to . have . property ( 'flagFoo' , 'flagBar' ) ;
5557
5658 done ( ) ;
5759 } ) ;
60+
61+ [ undefined , null , false , true ] . forEach ( omitBatchTimestamp => {
62+ it ( `respects an omitBatchTimestamp config value of ${ omitBatchTimestamp } ` , done => {
63+ const now = new Date ( ) . getTime ( ) ;
64+ const batchValidator = new _BatchValidator ( {
65+ configOverride : { omitBatchTimestamp}
66+ } ) ;
67+
68+ const batch = batchValidator . returnBatch ( baseEvent ) ;
69+
70+ if ( omitBatchTimestamp ) {
71+ expect ( batch ) . to . have . property ( 'timestamp_unixtime_ms' , null ) ;
72+ } else {
73+ expect ( batch ) . to . have . property ( 'timestamp_unixtime_ms' ) . greaterThanOrEqual ( now ) ;
74+ }
75+
76+ done ( ) ;
77+ } ) ;
78+ } )
79+
80+ it ( `can use a batch timestamp override value` , done => {
81+ const oneDayAgo = new Date ( ) . getTime ( ) - ( 24 * 3600 * 1000 ) ;
82+ const batchValidator = new _BatchValidator ( {
83+ storeOverride : { batchTimestampUnixtimeMsOverride : oneDayAgo }
84+ } ) ;
85+ const batch = batchValidator . returnBatch ( baseEvent ) ;
86+
87+ expect ( batch ) . to . have . property ( 'timestamp_unixtime_ms' ) . greaterThanOrEqual ( oneDayAgo ) ;
88+
89+ done ( ) ;
90+ } ) ;
91+
92+ it ( `a batch timestamp override takes precedence over the sdk config` , done => {
93+ const oneDayAgo = new Date ( ) . getTime ( ) - ( 24 * 3600 * 1000 ) ;
94+ const batchValidator = new _BatchValidator ( {
95+ configOverride : { omitBatchTimestamp : true } ,
96+ storeOverride : { batchTimestampUnixtimeMsOverride : oneDayAgo } }
97+ ) ;
98+ const batch = batchValidator . returnBatch ( baseEvent ) ;
99+
100+ expect ( batch ) . to . have . property ( 'timestamp_unixtime_ms' ) . greaterThanOrEqual ( oneDayAgo ) ;
101+
102+ done ( ) ;
103+ } ) ;
58104} ) ;
0 commit comments