-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathactivity.service.spec.ts
More file actions
86 lines (80 loc) · 2.36 KB
/
Copy pathactivity.service.spec.ts
File metadata and controls
86 lines (80 loc) · 2.36 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { ActivityService } from './activity.service';
describe('ActivityService', () => {
it('maps actor and group names for group activity', async () => {
const prisma = {
activity: {
findMany: jest.fn().mockResolvedValue([
{
id: 'activity-1',
groupId: 'group-1',
actorUserId: 'user-1',
type: 'expense_created',
entityId: 'expense-1',
metadata: { totalAmountCents: '1234', currency: 'USD' },
createdAt: new Date('2026-04-07T00:00:00.000Z'),
actor: { name: 'Ava' },
group: { name: 'Trip Fund' },
},
]),
},
user: {
findMany: jest.fn().mockResolvedValue([
{ id: 'user-1', name: 'Ava' },
]),
},
};
const service = new ActivityService(prisma as any);
const result = await service.getGroupActivity('group-1');
expect(prisma.activity.findMany).toHaveBeenCalledWith(
expect.objectContaining({
where: { groupId: 'group-1' },
include: {
actor: { select: { name: true } },
group: { select: { name: true } },
},
}),
);
expect(prisma.user.findMany).toHaveBeenCalledWith({
where: { id: { in: ['user-1'] } },
select: { id: true, name: true },
});
expect(result.items).toEqual([
expect.objectContaining({
actorUserId: 'user-1',
actorName: 'Ava',
groupName: 'Trip Fund',
}),
]);
});
it('keeps responses backward compatible when names are missing', async () => {
const prisma = {
activity: {
findMany: jest.fn().mockResolvedValue([
{
id: 'activity-2',
groupId: 'group-2',
actorUserId: 'user-2',
type: 'member_joined',
entityId: 'member-1',
metadata: {},
createdAt: new Date('2026-04-07T00:00:00.000Z'),
actor: null,
group: null,
},
]),
},
user: {
findMany: jest.fn().mockResolvedValue([]),
},
};
const service = new ActivityService(prisma as any);
const result = await service.getUserActivity('user-2');
expect(result.items[0]).toEqual(
expect.objectContaining({
actorUserId: 'user-2',
actorName: undefined,
groupName: undefined,
}),
);
});
});