forked from MettaChain/PropChain-BackEnd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail-digest.service.spec.ts
More file actions
54 lines (48 loc) · 1.53 KB
/
Copy pathemail-digest.service.spec.ts
File metadata and controls
54 lines (48 loc) · 1.53 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
jest.mock('@prisma/client', () => ({
...jest.requireActual('@prisma/client'),
DigestFrequency: {
DAILY: 'DAILY',
WEEKLY: 'WEEKLY',
},
}));
import { EmailDigestService } from './email-digest.service';
import { PrismaService } from '../database/prisma.service';
import { EmailService } from '../email/email.service';
import { ConfigService } from '@nestjs/config';
interface MockPrisma {
digestPreference: {
upsert: jest.Mock;
findUnique: jest.Mock;
};
}
describe('EmailDigestService', () => {
let service: EmailDigestService;
let prisma: MockPrisma;
beforeEach(() => {
prisma = {
digestPreference: {
upsert: jest.fn().mockResolvedValue({
userId: 'u1',
enabled: true,
frequency: 'DAILY',
unsubscribeToken: 'tok',
}),
findUnique: jest.fn().mockResolvedValue(null),
},
};
emailService = { sendEmail: jest.fn().mockResolvedValue(undefined) };
configService = { get: jest.fn().mockReturnValue('https://api.propchain.example/api') };
service = new EmailDigestService(
prisma as unknown as PrismaService,
emailService as unknown as EmailService,
configService as unknown as ConfigService,
);
});
it('getOrCreatePreference creates preference for new user', async () => {
const result = await service.getOrCreatePreference('u1');
expect(prisma.digestPreference.upsert).toHaveBeenCalledWith(
expect.objectContaining({ where: { userId: 'u1' } }),
);
expect(result.userId).toBe('u1');
});
});