Skip to content

Commit

Permalink
🧪 chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Dec 11, 2024
1 parent 3997b99 commit d375d99
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 50 deletions.
84 changes: 63 additions & 21 deletions packages/tom-server/src/metrics-api/tests/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ const TODAY_USER = {
} satisfies MatrixUserInfo

const PRE_TODAY_USER = {
creation_ts: new Date().getTime() / 1000 - ONE_DAY_IN_MS - 1,
creation_ts: (new Date().getTime() - ONE_DAY_IN_MS - 1) / 1000,
last_seen_ts: new Date().getTime() - ONE_DAY_IN_MS - 1,
name: 'user2'
}

const PRE_WEEK_USER = {
creation_ts: new Date().getTime() / 1000 - ONE_WEEK_IN_MS - 1,
creation_ts: (new Date().getTime() - ONE_WEEK_IN_MS - 1) / 1000,
last_seen_ts: new Date().getTime() - ONE_WEEK_IN_MS - 1,
name: 'user3'
}

const PRE_MONTH_USER = {
creation_ts: new Date().getTime() / 1000 - ONE_MONTH_IN_MS - 1,
creation_ts: (new Date().getTime() - ONE_MONTH_IN_MS - 1) / 1000,
last_seen_ts: new Date().getTime() - ONE_MONTH_IN_MS - 1,
name: 'user4'
}
Expand Down Expand Up @@ -129,11 +129,21 @@ describe('the mectrics API controller', () => {

expect(response.status).toBe(200)
expect(response.body).toEqual({
dailyActiveUsers: [TODAY_USER],
weeklyActiveUsers: [TODAY_USER],
monthlyActiveUsers: [TODAY_USER],
weeklyNewUsers: [],
monthlyNewUsers: []
dailyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
monthlyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
]
})
})

Expand Down Expand Up @@ -167,11 +177,25 @@ describe('the mectrics API controller', () => {

expect(response.status).toBe(200)
expect(response.body).toEqual({
dailyActiveUsers: [TODAY_USER],
weeklyActiveUsers: [TODAY_USER, PRE_TODAY_USER],
monthlyActiveUsers: [TODAY_USER, PRE_TODAY_USER],
weeklyNewUsers: [],
monthlyNewUsers: []
dailyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
]
})
})

Expand Down Expand Up @@ -206,11 +230,23 @@ describe('the mectrics API controller', () => {

expect(response.status).toBe(200)
expect(response.body).toEqual({
dailyActiveUsers: [TODAY_USER],
weeklyActiveUsers: [TODAY_USER],
monthlyActiveUsers: [TODAY_USER, PRE_WEEK_USER],
weeklyNewUsers: [],
monthlyNewUsers: []
dailyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
monthlyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
]
})
})

Expand Down Expand Up @@ -247,9 +283,15 @@ describe('the mectrics API controller', () => {
expect(response.body).toEqual({
dailyActiveUsers: [],
weeklyActiveUsers: [],
monthlyActiveUsers: [PRE_WEEK_USER],
weeklyNewUsers: [],
monthlyNewUsers: []
monthlyActiveUsers: [
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
]
})
})

Expand Down
130 changes: 101 additions & 29 deletions packages/tom-server/src/metrics-api/tests/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ const TODAY_USER = {
}

const PRE_TODAY_USER = {
creation_ts: new Date().getTime() - ONE_DAY_IN_MS - 1,
creation_ts: (new Date().getTime() - ONE_DAY_IN_MS - 1) / 1000,
last_seen_ts: new Date().getTime() - ONE_DAY_IN_MS - 1,
name: 'user2'
}

const PRE_WEEK_USER = {
creation_ts: new Date().getTime() / 1000 - ONE_WEEK_IN_MS - 1,
last_seen_ts: new Date().getTime() - ONE_WEEK_IN_MS - 1,
creation_ts: (new Date().getTime() - ONE_WEEK_IN_MS - 1) / 1000,
last_seen_ts: new Date().getTime() - (ONE_WEEK_IN_MS * 1000) - 1,
name: 'user3'
}

const PRE_MONTH_USER = {
creation_ts: new Date().getTime() / 1000 - ONE_MONTH_IN_MS - 1,
creation_ts: (new Date().getTime() - ONE_MONTH_IN_MS - 1) / 1000,
last_seen_ts: new Date().getTime() - ONE_MONTH_IN_MS - 1,
name: 'user4'
}
Expand Down Expand Up @@ -103,11 +103,21 @@ describe('the Metrics API Service', () => {
const result = await metricsService.getUserActivityStats()

expect(result).toEqual({
dailyActiveUsers: [TODAY_USER],
weeklyActiveUsers: [TODAY_USER],
monthlyActiveUsers: [TODAY_USER],
weeklyNewUsers: [],
monthlyNewUsers: []
dailyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
monthlyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
]
})
})

Expand Down Expand Up @@ -155,11 +165,25 @@ describe('the Metrics API Service', () => {
const result = await metricsService.getUserActivityStats()

expect(result).toEqual({
dailyActiveUsers: [TODAY_USER],
weeklyActiveUsers: [TODAY_USER, PRE_TODAY_USER],
monthlyActiveUsers: [TODAY_USER, PRE_TODAY_USER],
weeklyNewUsers: [],
monthlyNewUsers: []
dailyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
]
})
})

Expand Down Expand Up @@ -205,11 +229,27 @@ describe('the Metrics API Service', () => {
const result = await metricsService.getUserActivityStats()

expect(result).toEqual({
dailyActiveUsers: [TODAY_USER],
weeklyActiveUsers: [TODAY_USER, PRE_TODAY_USER],
monthlyActiveUsers: [TODAY_USER, PRE_TODAY_USER, PRE_WEEK_USER],
weeklyNewUsers: [],
monthlyNewUsers: []
dailyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 },
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 },
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
]
})
})

Expand Down Expand Up @@ -263,11 +303,27 @@ describe('the Metrics API Service', () => {
const result = await metricsService.getUserActivityStats()

expect(result).toEqual({
dailyActiveUsers: [TODAY_USER],
weeklyActiveUsers: [TODAY_USER, PRE_TODAY_USER],
monthlyActiveUsers: [TODAY_USER, PRE_TODAY_USER, PRE_WEEK_USER],
weeklyNewUsers: [],
monthlyNewUsers: []
dailyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 },
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 },
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
]
})
})

Expand Down Expand Up @@ -321,11 +377,27 @@ describe('the Metrics API Service', () => {
const result = await metricsService.getUserActivityStats()

expect(result).toEqual({
dailyActiveUsers: [TODAY_USER],
weeklyActiveUsers: [TODAY_USER, PRE_TODAY_USER],
monthlyActiveUsers: [TODAY_USER, PRE_TODAY_USER, PRE_WEEK_USER],
weeklyNewUsers: [TODAY_USER, PRE_TODAY_USER],
monthlyNewUsers: [TODAY_USER, PRE_TODAY_USER, PRE_WEEK_USER]
dailyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 }
],
weeklyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyActiveUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 },
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
],
weeklyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 }
],
monthlyNewUsers: [
{ ...TODAY_USER, creation_ts: TODAY_USER.creation_ts * 1000 },
{ ...PRE_TODAY_USER, creation_ts: PRE_TODAY_USER.creation_ts * 1000 },
{ ...PRE_WEEK_USER, creation_ts: PRE_WEEK_USER.creation_ts * 1000 }
]
})
})
})
Expand Down

0 comments on commit d375d99

Please sign in to comment.