Skip to content

Commit d3b517e

Browse files
committed
test(analytics): update tests to use timestamp and validate payload
Refactored tests to replace workspaceId with timestamp and introduced stricter validation using `expect.objectContaining`. Ensures improved test coverage for event and pageview handling with additional payload and timestamp checks.
1 parent 5d87d46 commit d3b517e

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

packages/twenty-server/src/engine/core-modules/analytics/services/analytics.service.spec.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('AnalyticsService', () => {
4646
};
4747
const commonProperties = {
4848
version: '1',
49-
workspaceId: new Date().toISOString(),
49+
timestamp: new Date().getTime().toString(),
5050
};
5151

5252
it('should create a valid context object', () => {
@@ -67,10 +67,14 @@ describe('AnalyticsService', () => {
6767

6868
await context.sendEvent(testEvent);
6969

70-
expect(insertSpy).toHaveBeenCalledWith({
71-
...testEvent,
72-
...commonProperties,
73-
});
70+
expect(insertSpy).toHaveBeenCalledWith(
71+
expect.objectContaining({
72+
...testEvent,
73+
...mockUserIdAndWorkspaceId,
74+
timestamp: expect.any(String),
75+
payload: {},
76+
}),
77+
);
7478
});
7579

7680
it('should call sendPageview with merged properties', async () => {
@@ -91,10 +95,14 @@ describe('AnalyticsService', () => {
9195

9296
await context.sendPageview(testPageview);
9397

94-
expect(insertSpy).toHaveBeenCalledWith({
95-
...testPageview,
96-
...commonProperties,
97-
});
98+
expect(insertSpy).toHaveBeenCalledWith(
99+
expect.objectContaining({
100+
...testPageview,
101+
...commonProperties,
102+
...mockUserIdAndWorkspaceId,
103+
timestamp: expect.any(String),
104+
}),
105+
);
98106
});
99107

100108
it('should return success when analytics are disabled', async () => {
@@ -122,7 +130,13 @@ describe('AnalyticsService', () => {
122130

123131
await context.sendEvent(testEvent);
124132

125-
expect(insertSpy).toHaveBeenCalledWith(testEvent);
133+
expect(insertSpy).toHaveBeenCalledWith(
134+
expect.objectContaining({
135+
...testEvent,
136+
timestamp: expect.any(String),
137+
payload: {},
138+
}),
139+
);
126140
});
127141
});
128142
});

0 commit comments

Comments
 (0)