@@ -17,7 +17,12 @@ describe('normalize', function() {
17
17
it ( 'should merge original with normalized' , function ( ) {
18
18
msg . userId = 'user-id' ;
19
19
opts . integrations = { Segment : true } ;
20
- assert . deepEqual ( normalize ( msg , list ) , {
20
+ var normalized = normalize ( msg , list ) ;
21
+
22
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
23
+ delete normalized . messageId ;
24
+
25
+ assert . deepEqual ( normalized , {
21
26
integrations : { Segment : true } ,
22
27
userId : 'user-id' ,
23
28
context : { }
@@ -44,7 +49,12 @@ describe('normalize', function() {
44
49
opts . campaign = { name : 'campaign-name' } ;
45
50
opts . library = 'analytics-wordpress' ;
46
51
opts . traits = { trait : true } ;
47
- assert . deepEqual ( normalize ( msg , list ) , {
52
+ var normalized = normalize ( msg , list ) ;
53
+
54
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
55
+ delete normalized . messageId ;
56
+
57
+ assert . deepEqual ( normalized , {
48
58
integrations : { } ,
49
59
context : {
50
60
campaign : { name : 'campaign-name' } ,
@@ -61,7 +71,12 @@ describe('normalize', function() {
61
71
it ( 'should move to .integrations' , function ( ) {
62
72
opts . Segment = true ;
63
73
opts . KISSmetrics = false ;
64
- assert . deepEqual ( normalize ( msg , list ) , {
74
+ var normalized = normalize ( msg , list ) ;
75
+
76
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
77
+ delete normalized . messageId ;
78
+
79
+ assert . deepEqual ( normalized , {
65
80
context : { } ,
66
81
integrations : {
67
82
Segment : true ,
@@ -73,7 +88,12 @@ describe('normalize', function() {
73
88
it ( 'should match integration names' , function ( ) {
74
89
opts . segment = true ;
75
90
opts . KissMetrics = false ;
76
- assert . deepEqual ( normalize ( msg , list ) , {
91
+ var normalized = normalize ( msg , list ) ;
92
+
93
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
94
+ delete normalized . messageId ;
95
+
96
+ assert . deepEqual ( normalized , {
77
97
context : { } ,
78
98
integrations : {
79
99
segment : true ,
@@ -84,7 +104,12 @@ describe('normalize', function() {
84
104
85
105
it ( 'should move .All' , function ( ) {
86
106
opts . All = true ;
87
- assert . deepEqual ( normalize ( msg , list ) , {
107
+ var normalized = normalize ( msg , list ) ;
108
+
109
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
110
+ delete normalized . messageId ;
111
+
112
+ assert . deepEqual ( normalized , {
88
113
context : { } ,
89
114
integrations : {
90
115
All : true
@@ -94,7 +119,12 @@ describe('normalize', function() {
94
119
95
120
it ( 'should move .all' , function ( ) {
96
121
opts . all = true ;
97
- assert . deepEqual ( normalize ( msg , list ) , {
122
+ var normalized = normalize ( msg , list ) ;
123
+
124
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
125
+ delete normalized . messageId ;
126
+
127
+ assert . deepEqual ( normalized , {
98
128
context : { } ,
99
129
integrations : {
100
130
all : true
@@ -108,7 +138,12 @@ describe('normalize', function() {
108
138
opts . integrations = { } ;
109
139
opts . integrations . all = true ;
110
140
opts . integrations . Segment = true ;
111
- assert . deepEqual ( normalize ( msg , list ) , {
141
+ var normalized = normalize ( msg , list ) ;
142
+
143
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
144
+ delete normalized . messageId ;
145
+
146
+ assert . deepEqual ( normalized , {
112
147
context : { } ,
113
148
integrations : {
114
149
all : true ,
@@ -128,7 +163,12 @@ describe('normalize', function() {
128
163
it ( 'should move to .integrations' , function ( ) {
129
164
providers . Segment = true ;
130
165
providers . KISSmetrics = false ;
131
- assert . deepEqual ( normalize ( msg , list ) , {
166
+ var normalized = normalize ( msg , list ) ;
167
+
168
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
169
+ delete normalized . messageId ;
170
+
171
+ assert . deepEqual ( normalized , {
132
172
context : { } ,
133
173
integrations : {
134
174
Segment : true ,
@@ -140,7 +180,12 @@ describe('normalize', function() {
140
180
it ( 'should match integration names' , function ( ) {
141
181
providers . segment = true ;
142
182
providers . KissMetrics = false ;
143
- assert . deepEqual ( normalize ( msg , list ) , {
183
+ var normalized = normalize ( msg , list ) ;
184
+
185
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
186
+ delete normalized . messageId ;
187
+
188
+ assert . deepEqual ( normalized , {
144
189
context : { } ,
145
190
integrations : {
146
191
segment : true ,
@@ -151,7 +196,12 @@ describe('normalize', function() {
151
196
152
197
it ( 'should move .All' , function ( ) {
153
198
providers . All = true ;
154
- assert . deepEqual ( normalize ( msg , list ) , {
199
+ var normalized = normalize ( msg , list ) ;
200
+
201
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
202
+ delete normalized . messageId ;
203
+
204
+ assert . deepEqual ( normalized , {
155
205
context : { } ,
156
206
integrations : {
157
207
All : true
@@ -161,7 +211,12 @@ describe('normalize', function() {
161
211
162
212
it ( 'should move .all' , function ( ) {
163
213
providers . all = true ;
164
- assert . deepEqual ( normalize ( msg , list ) , {
214
+ var normalized = normalize ( msg , list ) ;
215
+
216
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
217
+ delete normalized . messageId ;
218
+
219
+ assert . deepEqual ( normalized , {
165
220
context : { } ,
166
221
integrations : {
167
222
all : true
@@ -175,7 +230,12 @@ describe('normalize', function() {
175
230
opts . integrations = { } ;
176
231
opts . integrations . all = true ;
177
232
opts . integrations . Segment = true ;
178
- assert . deepEqual ( normalize ( msg , list ) , {
233
+ var normalized = normalize ( msg , list ) ;
234
+
235
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
236
+ delete normalized . messageId ;
237
+
238
+ assert . deepEqual ( normalized , {
179
239
context : { } ,
180
240
integrations : {
181
241
all : true ,
@@ -187,7 +247,12 @@ describe('normalize', function() {
187
247
it ( 'should override if providers[key] is an object' , function ( ) {
188
248
providers . Segment = { } ;
189
249
opts . integrations = { Segment : true } ;
190
- assert . deepEqual ( normalize ( msg , list ) , {
250
+ var normalized = normalize ( msg , list ) ;
251
+
252
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
253
+ delete normalized . messageId ;
254
+
255
+ assert . deepEqual ( normalized , {
191
256
context : { } ,
192
257
integrations : {
193
258
Segment : { }
@@ -206,7 +271,12 @@ describe('normalize', function() {
206
271
it ( 'should move to .integrations' , function ( ) {
207
272
providers . Segment = true ;
208
273
opts . KISSmetrics = false ;
209
- assert . deepEqual ( normalize ( msg , list ) , {
274
+ var normalized = normalize ( msg , list ) ;
275
+
276
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
277
+ delete normalized . messageId ;
278
+
279
+ assert . deepEqual ( normalized , {
210
280
context : { } ,
211
281
integrations : {
212
282
Segment : true ,
@@ -218,7 +288,12 @@ describe('normalize', function() {
218
288
it ( 'should prefer options object' , function ( ) {
219
289
providers . Segment = { option : true } ;
220
290
opts . Segment = true ;
221
- assert . deepEqual ( normalize ( msg , list ) , {
291
+ var normalized = normalize ( msg , list ) ;
292
+
293
+ assert . lengthEquals ( normalized . messageId , 36 ) ;
294
+ delete normalized . messageId ;
295
+
296
+ assert . deepEqual ( normalized , {
222
297
context : { } ,
223
298
integrations : {
224
299
Segment : { option : true }
@@ -227,4 +302,13 @@ describe('normalize', function() {
227
302
} ) ;
228
303
} ) ;
229
304
} ) ;
305
+ it ( 'should properly randomize .messageId' , function ( ) {
306
+ var set = { } ;
307
+ var count = 1000 ;
308
+ for ( var i = 0 ; i < count ; i ++ ) {
309
+ var id = normalize ( msg ) . messageId ;
310
+ set [ id ] = true ;
311
+ }
312
+ assert . lengthEquals ( Object . keys ( set ) , count ) ;
313
+ } ) ;
230
314
} ) ;
0 commit comments