forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush-notifications.controller.spec.ts
More file actions
126 lines (101 loc) · 3.74 KB
/
Copy pathpush-notifications.controller.spec.ts
File metadata and controls
126 lines (101 loc) · 3.74 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { Test, TestingModule } from '@nestjs/testing';
import { PushNotificationsController } from './push-notifications.controller';
import { PushNotificationsService } from './push-notifications.service';
import { DeviceRegistration } from './entities/device-registration.entity';
import { NotificationPreference } from './entities/notification-preference.entity';
import { RegisterDeviceDto } from './dto/register-device.dto';
import { UpdatePreferencesDto } from './dto/update-preferences.dto';
import { NotificationEventType } from './entities/notification-preference.entity';
describe('PushNotificationsController', () => {
let controller: PushNotificationsController;
let service: PushNotificationsService;
const mockService = {
registerDevice: jest.fn(),
unregisterDevice: jest.fn(),
getDevices: jest.fn(),
updatePreferences: jest.fn(),
getPreferences: jest.fn(),
sendNotification: jest.fn(),
sendTestNotification: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [PushNotificationsController],
providers: [
{
provide: PushNotificationsService,
useValue: mockService,
},
],
}).compile();
controller = module.get<PushNotificationsController>(PushNotificationsController);
service = module.get<PushNotificationsService>(PushNotificationsService);
});
afterEach(() => {
jest.clearAllMocks();
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
describe('registerDevice', () => {
it('should register a device', async () => {
const dto = {
userId: 'user1',
deviceToken: 'token123',
platform: 'android',
deviceName: 'Pixel 6',
} as any;
const req = { user: { walletAddress: 'user1' } };
await controller.registerDevice(dto, req);
expect(mockService.registerDevice).toHaveBeenCalledWith(dto);
});
});
describe('unregisterDevice', () => {
it('should unregister a device', async () => {
const deviceId = 'uuid';
const req = { user: { walletAddress: 'user1' } };
await controller.unregisterDevice(deviceId, req);
expect(mockService.unregisterDevice).toHaveBeenCalledWith(deviceId, 'user1');
});
});
describe('getDevices', () => {
it('should get devices for user', async () => {
const req = { user: { walletAddress: 'user1' } };
await controller.getDevices(req);
expect(mockService.getDevices).toHaveBeenCalledWith('user1');
});
});
describe('updatePreferences', () => {
it('should update preferences', async () => {
const dto = {
userId: 'user1',
preferences: [],
} as any;
const req = { user: { walletAddress: 'user1' } };
await controller.updatePreferences(dto, req);
expect(mockService.updatePreferences).toHaveBeenCalledWith(dto);
});
});
describe('getPreferences', () => {
it('should get preferences for user', async () => {
const req = { user: { walletAddress: 'user1' } };
await controller.getPreferences(req);
expect(mockService.getPreferences).toHaveBeenCalledWith('user1');
});
});
describe('sendTestNotification', () => {
it('should send a test notification', async () => {
const body = {
title: 'Test',
message: 'Message'
};
const req = { user: { walletAddress: 'user1' } };
await controller.sendTestNotification(body, req);
expect(mockService.sendTestNotification).toHaveBeenCalledWith(
'user1',
'Test',
'Message'
);
});
});
});