-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathservice.test.ts
More file actions
50 lines (45 loc) · 1.37 KB
/
Copy pathservice.test.ts
File metadata and controls
50 lines (45 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { describe, expect, it } from 'vitest'
import type { GitHubEventDetail } from '@/features/github/types'
import { selectDistinctRecentActivity } from '@/server/github/service'
function createActivity(
id: string,
repository: string,
timestamp: string
): GitHubEventDetail {
return {
id,
type: 'commit',
title: 'updated code',
description: 'latest change',
url: `https://github.com/${repository}`,
repository,
timestamp,
isPrivate: false
}
}
describe('selectDistinctRecentActivity', () => {
it('returns the latest event for each repository in recency order', () => {
const events = [
createActivity('1', 'owner/app-a', '2026-04-08T12:00:00.000Z'),
createActivity('2', 'owner/app-a', '2026-04-08T11:00:00.000Z'),
createActivity('3', 'owner/app-b', '2026-04-08T10:00:00.000Z'),
createActivity('4', 'owner/app-c', '2026-04-08T09:00:00.000Z')
]
expect(selectDistinctRecentActivity(events, 3)).toEqual([
events[0],
events[2],
events[3]
])
})
it('respects the requested limit after de-duplicating repositories', () => {
const events = [
createActivity('1', 'owner/app-a', '2026-04-08T12:00:00.000Z'),
createActivity('2', 'owner/app-b', '2026-04-08T11:00:00.000Z'),
createActivity('3', 'owner/app-c', '2026-04-08T10:00:00.000Z')
]
expect(selectDistinctRecentActivity(events, 2)).toEqual([
events[0],
events[1]
])
})
})