@@ -49,7 +49,9 @@ describe('Batching', () => {
4949 beforeEach ( ( ) => {
5050 jest . resetAllMocks ( )
5151 jest . restoreAllMocks ( )
52- jest . useFakeTimers ( )
52+ jest . useFakeTimers ( {
53+ now : new Date ( '9 Jun 1993 00:00:00Z' ) . getTime ( ) ,
54+ } )
5355 } )
5456
5557 afterEach ( ( ) => {
@@ -92,7 +94,7 @@ describe('Batching', () => {
9294 Array [
9395 "https://https://api.segment.io/b",
9496 Object {
95- "body": "{\\"batch\\":[{\\"event\\":\\"first\\"},{\\"event\\":\\"second\\"},{\\"event\\":\\"third\\"}]}",
97+ "body": "{\\"batch\\":[{\\"event\\":\\"first\\"},{\\"event\\":\\"second\\"},{\\"event\\":\\"third\\"}],\\"sentAt\\":\\"1993-06-09T00:00:00.000Z\\" }",
9698 "headers": Object {
9799 "Content-Type": "text/plain",
98100 },
@@ -150,7 +152,7 @@ describe('Batching', () => {
150152 Array [
151153 "https://https://api.segment.io/b",
152154 Object {
153- "body": "{\\"batch\\":[{\\"event\\":\\"first\\"},{\\"event\\":\\"second\\"}]}",
155+ "body": "{\\"batch\\":[{\\"event\\":\\"first\\"},{\\"event\\":\\"second\\"}],\\"sentAt\\":\\"1993-06-09T00:00:10.000Z\\" }",
154156 "headers": Object {
155157 "Content-Type": "text/plain",
156158 },
@@ -185,7 +187,7 @@ describe('Batching', () => {
185187 Array [
186188 "https://https://api.segment.io/b",
187189 Object {
188- "body": "{\\"batch\\":[{\\"event\\":\\"first\\"}]}",
190+ "body": "{\\"batch\\":[{\\"event\\":\\"first\\"}],\\"sentAt\\":\\"1993-06-09T00:00:10.000Z\\" }",
189191 "headers": Object {
190192 "Content-Type": "text/plain",
191193 },
@@ -199,7 +201,38 @@ describe('Batching', () => {
199201 Array [
200202 "https://https://api.segment.io/b",
201203 Object {
202- "body": "{\\"batch\\":[{\\"event\\":\\"second\\"}]}",
204+ "body": "{\\"batch\\":[{\\"event\\":\\"second\\"}],\\"sentAt\\":\\"1993-06-09T00:00:21.000Z\\"}",
205+ "headers": Object {
206+ "Content-Type": "text/plain",
207+ },
208+ "keepalive": false,
209+ "method": "post",
210+ },
211+ ]
212+ ` )
213+ } )
214+
215+ it ( 'removes sentAt from individual events' , async ( ) => {
216+ const { dispatch } = batch ( `https://api.segment.io` , {
217+ size : 2 ,
218+ } )
219+
220+ await dispatch ( `https://api.segment.io/v1/t` , {
221+ event : 'first' ,
222+ sentAt : new Date ( '11 Jun 1993 00:01:00Z' ) ,
223+ } )
224+
225+ await dispatch ( `https://api.segment.io/v1/t` , {
226+ event : 'second' ,
227+ sentAt : new Date ( '11 Jun 1993 00:02:00Z' ) ,
228+ } )
229+
230+ expect ( fetch ) . toHaveBeenCalledTimes ( 1 )
231+ expect ( fetch . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
232+ Array [
233+ "https://https://api.segment.io/b",
234+ Object {
235+ "body": "{\\"batch\\":[{\\"event\\":\\"first\\"},{\\"event\\":\\"second\\"}],\\"sentAt\\":\\"1993-06-09T00:00:00.000Z\\"}",
203236 "headers": Object {
204237 "Content-Type": "text/plain",
205238 },
0 commit comments