forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.controller.spec.ts
More file actions
62 lines (54 loc) · 1.89 KB
/
Copy pathnotifications.controller.spec.ts
File metadata and controls
62 lines (54 loc) · 1.89 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
import { Test, TestingModule } from "@nestjs/testing";
import { NotificationsController } from "./notifications.controller";
import { NotificationsService } from "./notifications.service";
import { MerchantRole } from "../common/enums/merchant-role.enum";
import { NotificationPreferencesDto } from "./dto/notification-preferences.dto";
describe("NotificationsController", () => {
let controller: NotificationsController;
let service: jest.Mocked<NotificationsService>;
const currentUser = {
id: "user-1",
merchantId: "merchant-1",
role: MerchantRole.OWNER,
publicKey: "GACN3...",
tokenVersion: 1,
isAdmin: false,
pushNotificationsEnabled: true,
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [NotificationsController],
providers: [
{
provide: NotificationsService,
useValue: {
getNotificationPreferences: jest.fn(),
},
},
],
}).compile();
controller = module.get<NotificationsController>(NotificationsController);
service = module.get(
NotificationsService,
) as jest.Mocked<NotificationsService>;
});
it("is defined", () => {
expect(controller).toBeDefined();
});
it("delegates to service passing current user's id and merchantId", async () => {
const expected: NotificationPreferencesDto = {
pushNotificationsEnabled: true,
registeredPushTokensCount: 2,
preferenceExplicit: true,
contractVersion: "1.0.0",
};
service.getNotificationPreferences.mockResolvedValue(expected);
const result = await controller.getPreferences(currentUser as any);
expect(result).toBe(expected);
expect(service.getNotificationPreferences).toHaveBeenCalledWith(
"user-1",
"merchant-1",
);
expect(service.getNotificationPreferences).toHaveBeenCalledTimes(1);
});
});