Skip to content

Commit

Permalink
feat: support calibrate local timestamp (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: xiaoweii <xiaoweii@amazom.com>
  • Loading branch information
zhu-xiaowei and xiaoweii authored Mar 6, 2024
1 parent de64028 commit 3b6d738
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/network/NetRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class NetRequest {
platform: 'Web',
appId: configuration.appId,
event_bundle_sequence_id: bundleSequenceId.toString(),
upload_timestamp: new Date().getTime().toString(),
hashCode: eventsHash,
});
const url = `${configuration.endpoint}?${queryParams.toString()}`;
Expand Down
17 changes: 17 additions & 0 deletions test/network/NetRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,21 @@ describe('ClickstreamAnalytics test', () => {
);
expect(eventJsonHashCode).toBe(requestHashCode);
});

test('test request success with upload timestamp', async () => {
fetchMock.post('begin:https://localhost:8080/collect', {
status: 200,
body: [],
});
const mockFetch = jest.spyOn(global, 'fetch');

const result = await NetRequest.sendRequest(eventJson, context, 1);
expect(result).toBeTruthy();

const [requestUrl] = mockFetch.mock.calls[0];
const uploadTimestamp = new URL(requestUrl.toString()).searchParams.get(
'upload_timestamp'
);
expect(uploadTimestamp).not.toBeNull();
});
});

0 comments on commit 3b6d738

Please sign in to comment.