@hedhog/admin 0.11.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/{hedhog.yaml → bkp.hedhog.yaml} +1012 -814
  2. package/dist/auth/consts/body.js +23 -23
  3. package/package.json +43 -43
  4. package/src/admin.module.ts +37 -37
  5. package/src/auth/auth.controller.ts +72 -72
  6. package/src/auth/auth.module.ts +39 -39
  7. package/src/auth/auth.service.spec.ts +196 -196
  8. package/src/auth/auth.service.ts +234 -234
  9. package/src/auth/consts/body.ts +26 -26
  10. package/src/auth/consts/subject.ts +1 -1
  11. package/src/auth/dto/forget.dto.ts +6 -6
  12. package/src/auth/dto/login.dto.ts +15 -15
  13. package/src/auth/dto/otp.dto.ts +11 -11
  14. package/src/auth/dto/reset.dto.ts +14 -14
  15. package/src/auth/enums/multifactor-type.enum.ts +4 -4
  16. package/src/auth/guards/auth.guard.ts +50 -50
  17. package/src/auth/types/user.type.ts +8 -8
  18. package/src/dto/delete.dto.ts +8 -8
  19. package/src/dto/update-ids.dto.ts +9 -9
  20. package/src/index.ts +20 -20
  21. package/src/menu/dto/create.dto.ts +25 -25
  22. package/src/menu/dto/order.dto.ts +8 -8
  23. package/src/menu/dto/update.dto.ts +19 -19
  24. package/src/menu/menu.controller.ts +105 -105
  25. package/src/menu/menu.module.ts +18 -18
  26. package/src/menu/menu.service.spec.ts +247 -247
  27. package/src/menu/menu.service.ts +263 -263
  28. package/src/role/dto/create.dto.ts +7 -7
  29. package/src/role/dto/update.dto.ts +4 -4
  30. package/src/role/guards/role.guard.ts +123 -123
  31. package/src/role/role.controller.ts +126 -126
  32. package/src/role/role.module.ts +28 -28
  33. package/src/role/role.service.spec.ts +417 -417
  34. package/src/role/role.service.ts +289 -289
  35. package/src/route/dto/create.dto.ts +13 -13
  36. package/src/route/dto/update.dto.ts +15 -15
  37. package/src/route/route.controller.ts +91 -91
  38. package/src/route/route.module.ts +18 -18
  39. package/src/route/route.service.spec.ts +300 -300
  40. package/src/route/route.service.ts +164 -164
  41. package/src/screen/dto/create.dto.ts +11 -11
  42. package/src/screen/dto/update.dto.ts +19 -19
  43. package/src/screen/screen.controller.ts +93 -93
  44. package/src/screen/screen.module.ts +18 -18
  45. package/src/screen/screen.service.spec.ts +298 -298
  46. package/src/screen/screen.service.ts +179 -179
  47. package/src/types/http-method.ts +8 -8
  48. package/src/user/constants/user.constants.ts +1 -1
  49. package/src/user/dto/create.dto.ts +24 -24
  50. package/src/user/dto/update.dto.ts +41 -41
  51. package/src/user/user.controller.ts +75 -75
  52. package/src/user/user.module.ts +18 -18
  53. package/src/user/user.service.spec.ts +294 -294
  54. package/src/user/user.service.ts +129 -129
@@ -1,417 +1,417 @@
1
- /*
2
- describe('RoleService', () => {
3
- let roleService: RoleService;
4
- let prismaService: PrismaService;
5
- let paginationService: PaginationService;
6
-
7
- beforeEach(async () => {
8
- const module: TestingModule = await Test.createTestingModule({
9
- providers: [
10
- RoleService,
11
- {
12
- provide: PrismaService,
13
- useValue: {
14
- role {
15
- create: jest.fn(),
16
- update: jest.fn(),
17
- findUnique: jest.fn(),
18
- deleteMany: jest.fn(),
19
- findMany: jest.fn(),
20
- },
21
- role_user: {
22
- deleteMany: jest.fn(),
23
- createMany: jest.fn(),
24
- },
25
- role_menu: {
26
- deleteMany: jest.fn(),
27
- createMany: jest.fn(),
28
- },
29
- role_screen: {
30
- deleteMany: jest.fn(),
31
- createMany: jest.fn(),
32
- },
33
- role_route: {
34
- deleteMany: jest.fn(),
35
- createMany: jest.fn(),
36
- },
37
- },
38
- },
39
- {
40
- provide: PaginationService,
41
- useValue: {
42
- paginate: jest.fn(),
43
- },
44
- },
45
- ],
46
- }).compile();
47
-
48
- roleService = module.get<RoleService>(RoleService);
49
- prismaService = module.get<PrismaService>(PrismaService);
50
- paginationService = module.get<PaginationService>(PaginationService);
51
- });
52
- /*
53
- describe('create', () => {
54
- it('should create a new role', async () => {
55
- const dto: CreateDTO = {
56
- name: 'Admin',
57
- description: 'Administrator role',
58
- };
59
- const result = {
60
- id: 1,
61
- ...dto,
62
- created_at: new Date(),
63
- updated_at: new Date(),
64
- };
65
-
66
- jest.spyOn(prismaService.role, 'create').mockResolvedValue(result);
67
-
68
- expect(await roleService.create(dto)).toEqual(result);
69
- });
70
- });
71
- */
72
- // describe('update', () => {
73
- // it('should update an existing role', async () => {
74
- // const dto: UpdateDTO = {
75
- // name: 'Admin',
76
- // description: 'Updated description',
77
- // };
78
- // const result = {
79
- // id: 1,
80
- // ...dto,
81
- // created_at: new Date(),
82
- // updated_at: new Date(),
83
- // };
84
-
85
- // jest.spyOn(prismaService.role, 'update').mockResolvedValue(result);
86
-
87
- // expect(await roleService.update({ id: 1, data: dto })).toEqual(result);
88
- // });
89
- // });
90
- /*
91
- describe('delete', () => {
92
- it('should delete role', async () => {
93
- const dto: DeleteDTO = { ids: [1, 2] };
94
- jest
95
- .spyOn(prismaService.role, 'deleteMany')
96
- .mockResolvedValue({ count: 2 });
97
-
98
- await roleService.delete(dto);
99
- expect(prismaService.role.deleteMany).toHaveBeenCalledWith({
100
- where: {
101
- id: { in: dto.ids },
102
- },
103
- });
104
- });
105
-
106
- it('should throw BadRequestException if no ids are provided', async () => {
107
- const dto: DeleteDTO = { ids: null };
108
- await expect(roleService.delete(dto)).rejects.toThrow(
109
- BadRequestException,
110
- );
111
- });
112
- });
113
-
114
- describe('updateUsers', () => {
115
- it('should update user for a role', async () => {
116
- const roleId = 1;
117
- const data: UpdateIdsDTO = { ids: [1, 2] };
118
-
119
- jest
120
- .spyOn(prismaService.role_user, 'deleteMany')
121
- .mockResolvedValue({ count: 2 });
122
- jest
123
- .spyOn(prismaService.role_user, 'createMany')
124
- .mockResolvedValue({ count: 2 });
125
-
126
- await roleService.updateUsers(roleId, data);
127
-
128
- expect(prismaService.role_user.deleteMany).toHaveBeenCalledWith({
129
- where: { role_id: roleId },
130
- });
131
-
132
- expect(prismaService.role_user.createMany).toHaveBeenCalledWith({
133
- data: data.ids.map((userId) => ({
134
- role_id: roleId,
135
- user_id: userId,
136
- })),
137
- skipDuplicates: true,
138
- });
139
- });
140
- });
141
-
142
- describe('updateScreens', () => {
143
- it('should update screens for a role', async () => {
144
- const roleId = 1;
145
- const data: UpdateIdsDTO = { ids: [1, 2] };
146
-
147
- jest
148
- .spyOn(prismaService.role_screen, 'deleteMany')
149
- .mockResolvedValue({ count: 2 });
150
- jest
151
- .spyOn(prismaService.role_screen, 'createMany')
152
- .mockResolvedValue({ count: 2 });
153
-
154
- await roleService.updateScreens(roleId, data);
155
-
156
- expect(prismaService.role_screen.deleteMany).toHaveBeenCalledWith({
157
- where: { role_id: roleId },
158
- });
159
-
160
- expect(prismaService.role_screen.createMany).toHaveBeenCalledWith({
161
- data: data.ids.map((screenId) => ({
162
- role_id: roleId,
163
- screen_id: screenId,
164
- })),
165
- skipDuplicates: true,
166
- });
167
- });
168
- });
169
-
170
- describe('updateRoutes', () => {
171
- it('should update route for a role', async () => {
172
- const roleId = 1;
173
- const data: UpdateIdsDTO = { ids: [1, 2] };
174
-
175
- jest
176
- .spyOn(prismaService.role_route, 'deleteMany')
177
- .mockResolvedValue({ count: 2 });
178
- jest
179
- .spyOn(prismaService.role_route, 'createMany')
180
- .mockResolvedValue({ count: 2 });
181
-
182
- await roleService.updateRoutes(roleId, data);
183
-
184
- expect(prismaService.role_route.deleteMany).toHaveBeenCalledWith({
185
- where: { role_id: roleId },
186
- });
187
-
188
- expect(prismaService.role_route.createMany).toHaveBeenCalledWith({
189
- data: data.ids.map((routeId) => ({
190
- role_id: roleId,
191
- route_id: routeId,
192
- })),
193
- skipDuplicates: true,
194
- });
195
- });
196
- });
197
-
198
- describe('updateMenus', () => {
199
- it('should update menu for a role', async () => {
200
- const roleId = 1;
201
- const data: UpdateIdsDTO = { ids: [1, 2] };
202
-
203
- jest
204
- .spyOn(prismaService.role_menu, 'deleteMany')
205
- .mockResolvedValue({ count: 2 });
206
- jest
207
- .spyOn(prismaService.role_menu, 'createMany')
208
- .mockResolvedValue({ count: 2 });
209
-
210
- await roleService.updateMenus(roleId, data);
211
-
212
- expect(prismaService.role_menu.deleteMany).toHaveBeenCalledWith({
213
- where: { role_id: roleId },
214
- });
215
-
216
- expect(prismaService.role_menu.createMany).toHaveBeenCalledWith({
217
- data: data.ids.map((menuId) => ({
218
- role_id: roleId,
219
- menu_id: menuId,
220
- })),
221
- skipDuplicates: true,
222
- });
223
- });
224
- });
225
-
226
- describe('listUsers', () => {
227
- it('should list user associated with a role', async () => {
228
- const roleId = 1;
229
- const paginationParams: PaginationDTO = {
230
- page: 1,
231
- pageSize: 10,
232
- search: '',
233
- sortField: '',
234
- sortOrder: PageOrderDirection.Asc,
235
- fields: '',
236
- };
237
- const mockPaginationResult = {
238
- data: [],
239
- total: 10,
240
- lastPage: 1,
241
- page: 1,
242
- prev: 0,
243
- next: 2,
244
- pageSize: 10,
245
- };
246
-
247
- jest
248
- .spyOn(paginationService, 'paginate')
249
- .mockResolvedValue(mockPaginationResult);
250
-
251
- await roleService.listUsers(roleId, paginationParams);
252
-
253
- expect(paginationService.paginate).toHaveBeenCalledWith(
254
- prismaService.user,
255
- paginationParams,
256
- {
257
- include: {
258
- role_user: {
259
- where: { role_id: roleId },
260
- select: { user_id: true, role_id: true },
261
- },
262
- },
263
- },
264
- );
265
- });
266
- });
267
-
268
- describe('listMenus', () => {
269
- it('should list menu associated with a role', async () => {
270
- const locale = 'en';
271
- const roleId = 1;
272
- const paginationParams: PaginationDTO = {
273
- page: 1,
274
- pageSize: 10,
275
- search: '',
276
- sortField: '',
277
- sortOrder: PageOrderDirection.Asc,
278
- fields: '',
279
- };
280
- const mockPaginationResult = {
281
- data: [],
282
- total: 10,
283
- lastPage: 1,
284
- page: 1,
285
- prev: 0,
286
- next: 2,
287
- pageSize: 10,
288
- };
289
-
290
- jest
291
- .spyOn(paginationService, 'paginate')
292
- .mockResolvedValue(mockPaginationResult);
293
-
294
- await roleService.listMenus(locale, roleId, paginationParams);
295
-
296
- expect(paginationService.paginate).toHaveBeenCalledWith(
297
- prismaService.menu,
298
- paginationParams,
299
- {
300
- include: {
301
- menu_locale: {
302
- where: { locale: { code: locale } },
303
- select: { name: true },
304
- },
305
- role_menu: {
306
- where: { role_id: roleId },
307
- select: { menu_id: true, role_id: true },
308
- },
309
- },
310
- },
311
- 'menu_locale',
312
- );
313
- });
314
- });
315
-
316
- describe('listRoutes', () => {
317
- it('should list route associated with a role', async () => {
318
- const roleId = 1;
319
- const paginationParams: PaginationDTO = {
320
- page: 1,
321
- pageSize: 10,
322
- search: '',
323
- sortField: '',
324
- sortOrder: PageOrderDirection.Asc,
325
- fields: '',
326
- };
327
- const mockPaginationResult = {
328
- data: [],
329
- total: 10,
330
- lastPage: 1,
331
- page: 1,
332
- prev: 0,
333
- next: 2,
334
- pageSize: 10,
335
- };
336
-
337
- jest
338
- .spyOn(paginationService, 'paginate')
339
- .mockResolvedValue(mockPaginationResult);
340
-
341
- await roleService.listRoutes(roleId, paginationParams);
342
-
343
- expect(paginationService.paginate).toHaveBeenCalledWith(
344
- prismaService.route,
345
- paginationParams,
346
- {
347
- include: {
348
- role_route: {
349
- where: { role_id: roleId },
350
- select: { route_id: true, role_id: true },
351
- },
352
- },
353
- },
354
- );
355
- });
356
- });
357
-
358
- describe('listScreens', () => {
359
- it('should list screens associated with a role', async () => {
360
- const locale = 'en';
361
- const roleId = 1;
362
- const paginationParams: PaginationDTO = {
363
- page: 1,
364
- pageSize: 10,
365
- search: '',
366
- sortField: '',
367
- sortOrder: PageOrderDirection.Asc,
368
- fields: '',
369
- };
370
- const mockPaginationResult = {
371
- data: [],
372
- total: 10,
373
- lastPage: 1,
374
- page: 1,
375
- prev: 0,
376
- next: 2,
377
- pageSize: 10,
378
- };
379
-
380
- jest
381
- .spyOn(paginationService, 'paginate')
382
- .mockResolvedValue(mockPaginationResult);
383
-
384
- await roleService.listScreens(locale, roleId, paginationParams);
385
-
386
- expect(paginationService.paginate).toHaveBeenCalledWith(
387
- prismaService.screens,
388
- paginationParams,
389
- {
390
- include: {
391
- screen_locale: {
392
- where: { locale: { code: locale } },
393
- select: { name: true },
394
- },
395
- role_screen: {
396
- where: { role_id: roleId },
397
- select: { screen_id: true, role_id: true },
398
- },
399
- },
400
- },
401
- 'screen_locale',
402
- );
403
- });
404
- });
405
-
406
- describe('get', () => {
407
- it('should get a specific role by ID', async () => {
408
- const roleId = 1;
409
- const result = { id: roleId, name: 'Admin', description: 'Admin role' };
410
-
411
- jest.spyOn(prismaService.role, 'findUnique').mockResolvedValue(result);
412
-
413
- expect(await roleService.get('en', roleId)).toEqual(result);
414
- });
415
- });
416
- });
417
- */
1
+ /*
2
+ describe('RoleService', () => {
3
+ let roleService: RoleService;
4
+ let prismaService: PrismaService;
5
+ let paginationService: PaginationService;
6
+
7
+ beforeEach(async () => {
8
+ const module: TestingModule = await Test.createTestingModule({
9
+ providers: [
10
+ RoleService,
11
+ {
12
+ provide: PrismaService,
13
+ useValue: {
14
+ role {
15
+ create: jest.fn(),
16
+ update: jest.fn(),
17
+ findUnique: jest.fn(),
18
+ deleteMany: jest.fn(),
19
+ findMany: jest.fn(),
20
+ },
21
+ role_user: {
22
+ deleteMany: jest.fn(),
23
+ createMany: jest.fn(),
24
+ },
25
+ role_menu: {
26
+ deleteMany: jest.fn(),
27
+ createMany: jest.fn(),
28
+ },
29
+ role_screen: {
30
+ deleteMany: jest.fn(),
31
+ createMany: jest.fn(),
32
+ },
33
+ role_route: {
34
+ deleteMany: jest.fn(),
35
+ createMany: jest.fn(),
36
+ },
37
+ },
38
+ },
39
+ {
40
+ provide: PaginationService,
41
+ useValue: {
42
+ paginate: jest.fn(),
43
+ },
44
+ },
45
+ ],
46
+ }).compile();
47
+
48
+ roleService = module.get<RoleService>(RoleService);
49
+ prismaService = module.get<PrismaService>(PrismaService);
50
+ paginationService = module.get<PaginationService>(PaginationService);
51
+ });
52
+ /*
53
+ describe('create', () => {
54
+ it('should create a new role', async () => {
55
+ const dto: CreateDTO = {
56
+ name: 'Admin',
57
+ description: 'Administrator role',
58
+ };
59
+ const result = {
60
+ id: 1,
61
+ ...dto,
62
+ created_at: new Date(),
63
+ updated_at: new Date(),
64
+ };
65
+
66
+ jest.spyOn(prismaService.role, 'create').mockResolvedValue(result);
67
+
68
+ expect(await roleService.create(dto)).toEqual(result);
69
+ });
70
+ });
71
+ */
72
+ // describe('update', () => {
73
+ // it('should update an existing role', async () => {
74
+ // const dto: UpdateDTO = {
75
+ // name: 'Admin',
76
+ // description: 'Updated description',
77
+ // };
78
+ // const result = {
79
+ // id: 1,
80
+ // ...dto,
81
+ // created_at: new Date(),
82
+ // updated_at: new Date(),
83
+ // };
84
+
85
+ // jest.spyOn(prismaService.role, 'update').mockResolvedValue(result);
86
+
87
+ // expect(await roleService.update({ id: 1, data: dto })).toEqual(result);
88
+ // });
89
+ // });
90
+ /*
91
+ describe('delete', () => {
92
+ it('should delete role', async () => {
93
+ const dto: DeleteDTO = { ids: [1, 2] };
94
+ jest
95
+ .spyOn(prismaService.role, 'deleteMany')
96
+ .mockResolvedValue({ count: 2 });
97
+
98
+ await roleService.delete(dto);
99
+ expect(prismaService.role.deleteMany).toHaveBeenCalledWith({
100
+ where: {
101
+ id: { in: dto.ids },
102
+ },
103
+ });
104
+ });
105
+
106
+ it('should throw BadRequestException if no ids are provided', async () => {
107
+ const dto: DeleteDTO = { ids: null };
108
+ await expect(roleService.delete(dto)).rejects.toThrow(
109
+ BadRequestException,
110
+ );
111
+ });
112
+ });
113
+
114
+ describe('updateUsers', () => {
115
+ it('should update user for a role', async () => {
116
+ const roleId = 1;
117
+ const data: UpdateIdsDTO = { ids: [1, 2] };
118
+
119
+ jest
120
+ .spyOn(prismaService.role_user, 'deleteMany')
121
+ .mockResolvedValue({ count: 2 });
122
+ jest
123
+ .spyOn(prismaService.role_user, 'createMany')
124
+ .mockResolvedValue({ count: 2 });
125
+
126
+ await roleService.updateUsers(roleId, data);
127
+
128
+ expect(prismaService.role_user.deleteMany).toHaveBeenCalledWith({
129
+ where: { role_id: roleId },
130
+ });
131
+
132
+ expect(prismaService.role_user.createMany).toHaveBeenCalledWith({
133
+ data: data.ids.map((userId) => ({
134
+ role_id: roleId,
135
+ user_id: userId,
136
+ })),
137
+ skipDuplicates: true,
138
+ });
139
+ });
140
+ });
141
+
142
+ describe('updateScreens', () => {
143
+ it('should update screens for a role', async () => {
144
+ const roleId = 1;
145
+ const data: UpdateIdsDTO = { ids: [1, 2] };
146
+
147
+ jest
148
+ .spyOn(prismaService.role_screen, 'deleteMany')
149
+ .mockResolvedValue({ count: 2 });
150
+ jest
151
+ .spyOn(prismaService.role_screen, 'createMany')
152
+ .mockResolvedValue({ count: 2 });
153
+
154
+ await roleService.updateScreens(roleId, data);
155
+
156
+ expect(prismaService.role_screen.deleteMany).toHaveBeenCalledWith({
157
+ where: { role_id: roleId },
158
+ });
159
+
160
+ expect(prismaService.role_screen.createMany).toHaveBeenCalledWith({
161
+ data: data.ids.map((screenId) => ({
162
+ role_id: roleId,
163
+ screen_id: screenId,
164
+ })),
165
+ skipDuplicates: true,
166
+ });
167
+ });
168
+ });
169
+
170
+ describe('updateRoutes', () => {
171
+ it('should update route for a role', async () => {
172
+ const roleId = 1;
173
+ const data: UpdateIdsDTO = { ids: [1, 2] };
174
+
175
+ jest
176
+ .spyOn(prismaService.role_route, 'deleteMany')
177
+ .mockResolvedValue({ count: 2 });
178
+ jest
179
+ .spyOn(prismaService.role_route, 'createMany')
180
+ .mockResolvedValue({ count: 2 });
181
+
182
+ await roleService.updateRoutes(roleId, data);
183
+
184
+ expect(prismaService.role_route.deleteMany).toHaveBeenCalledWith({
185
+ where: { role_id: roleId },
186
+ });
187
+
188
+ expect(prismaService.role_route.createMany).toHaveBeenCalledWith({
189
+ data: data.ids.map((routeId) => ({
190
+ role_id: roleId,
191
+ route_id: routeId,
192
+ })),
193
+ skipDuplicates: true,
194
+ });
195
+ });
196
+ });
197
+
198
+ describe('updateMenus', () => {
199
+ it('should update menu for a role', async () => {
200
+ const roleId = 1;
201
+ const data: UpdateIdsDTO = { ids: [1, 2] };
202
+
203
+ jest
204
+ .spyOn(prismaService.role_menu, 'deleteMany')
205
+ .mockResolvedValue({ count: 2 });
206
+ jest
207
+ .spyOn(prismaService.role_menu, 'createMany')
208
+ .mockResolvedValue({ count: 2 });
209
+
210
+ await roleService.updateMenus(roleId, data);
211
+
212
+ expect(prismaService.role_menu.deleteMany).toHaveBeenCalledWith({
213
+ where: { role_id: roleId },
214
+ });
215
+
216
+ expect(prismaService.role_menu.createMany).toHaveBeenCalledWith({
217
+ data: data.ids.map((menuId) => ({
218
+ role_id: roleId,
219
+ menu_id: menuId,
220
+ })),
221
+ skipDuplicates: true,
222
+ });
223
+ });
224
+ });
225
+
226
+ describe('listUsers', () => {
227
+ it('should list user associated with a role', async () => {
228
+ const roleId = 1;
229
+ const paginationParams: PaginationDTO = {
230
+ page: 1,
231
+ pageSize: 10,
232
+ search: '',
233
+ sortField: '',
234
+ sortOrder: PageOrderDirection.Asc,
235
+ fields: '',
236
+ };
237
+ const mockPaginationResult = {
238
+ data: [],
239
+ total: 10,
240
+ lastPage: 1,
241
+ page: 1,
242
+ prev: 0,
243
+ next: 2,
244
+ pageSize: 10,
245
+ };
246
+
247
+ jest
248
+ .spyOn(paginationService, 'paginate')
249
+ .mockResolvedValue(mockPaginationResult);
250
+
251
+ await roleService.listUsers(roleId, paginationParams);
252
+
253
+ expect(paginationService.paginate).toHaveBeenCalledWith(
254
+ prismaService.user,
255
+ paginationParams,
256
+ {
257
+ include: {
258
+ role_user: {
259
+ where: { role_id: roleId },
260
+ select: { user_id: true, role_id: true },
261
+ },
262
+ },
263
+ },
264
+ );
265
+ });
266
+ });
267
+
268
+ describe('listMenus', () => {
269
+ it('should list menu associated with a role', async () => {
270
+ const locale = 'en';
271
+ const roleId = 1;
272
+ const paginationParams: PaginationDTO = {
273
+ page: 1,
274
+ pageSize: 10,
275
+ search: '',
276
+ sortField: '',
277
+ sortOrder: PageOrderDirection.Asc,
278
+ fields: '',
279
+ };
280
+ const mockPaginationResult = {
281
+ data: [],
282
+ total: 10,
283
+ lastPage: 1,
284
+ page: 1,
285
+ prev: 0,
286
+ next: 2,
287
+ pageSize: 10,
288
+ };
289
+
290
+ jest
291
+ .spyOn(paginationService, 'paginate')
292
+ .mockResolvedValue(mockPaginationResult);
293
+
294
+ await roleService.listMenus(locale, roleId, paginationParams);
295
+
296
+ expect(paginationService.paginate).toHaveBeenCalledWith(
297
+ prismaService.menu,
298
+ paginationParams,
299
+ {
300
+ include: {
301
+ menu_locale: {
302
+ where: { locale: { code: locale } },
303
+ select: { name: true },
304
+ },
305
+ role_menu: {
306
+ where: { role_id: roleId },
307
+ select: { menu_id: true, role_id: true },
308
+ },
309
+ },
310
+ },
311
+ 'menu_locale',
312
+ );
313
+ });
314
+ });
315
+
316
+ describe('listRoutes', () => {
317
+ it('should list route associated with a role', async () => {
318
+ const roleId = 1;
319
+ const paginationParams: PaginationDTO = {
320
+ page: 1,
321
+ pageSize: 10,
322
+ search: '',
323
+ sortField: '',
324
+ sortOrder: PageOrderDirection.Asc,
325
+ fields: '',
326
+ };
327
+ const mockPaginationResult = {
328
+ data: [],
329
+ total: 10,
330
+ lastPage: 1,
331
+ page: 1,
332
+ prev: 0,
333
+ next: 2,
334
+ pageSize: 10,
335
+ };
336
+
337
+ jest
338
+ .spyOn(paginationService, 'paginate')
339
+ .mockResolvedValue(mockPaginationResult);
340
+
341
+ await roleService.listRoutes(roleId, paginationParams);
342
+
343
+ expect(paginationService.paginate).toHaveBeenCalledWith(
344
+ prismaService.route,
345
+ paginationParams,
346
+ {
347
+ include: {
348
+ role_route: {
349
+ where: { role_id: roleId },
350
+ select: { route_id: true, role_id: true },
351
+ },
352
+ },
353
+ },
354
+ );
355
+ });
356
+ });
357
+
358
+ describe('listScreens', () => {
359
+ it('should list screens associated with a role', async () => {
360
+ const locale = 'en';
361
+ const roleId = 1;
362
+ const paginationParams: PaginationDTO = {
363
+ page: 1,
364
+ pageSize: 10,
365
+ search: '',
366
+ sortField: '',
367
+ sortOrder: PageOrderDirection.Asc,
368
+ fields: '',
369
+ };
370
+ const mockPaginationResult = {
371
+ data: [],
372
+ total: 10,
373
+ lastPage: 1,
374
+ page: 1,
375
+ prev: 0,
376
+ next: 2,
377
+ pageSize: 10,
378
+ };
379
+
380
+ jest
381
+ .spyOn(paginationService, 'paginate')
382
+ .mockResolvedValue(mockPaginationResult);
383
+
384
+ await roleService.listScreens(locale, roleId, paginationParams);
385
+
386
+ expect(paginationService.paginate).toHaveBeenCalledWith(
387
+ prismaService.screens,
388
+ paginationParams,
389
+ {
390
+ include: {
391
+ screen_locale: {
392
+ where: { locale: { code: locale } },
393
+ select: { name: true },
394
+ },
395
+ role_screen: {
396
+ where: { role_id: roleId },
397
+ select: { screen_id: true, role_id: true },
398
+ },
399
+ },
400
+ },
401
+ 'screen_locale',
402
+ );
403
+ });
404
+ });
405
+
406
+ describe('get', () => {
407
+ it('should get a specific role by ID', async () => {
408
+ const roleId = 1;
409
+ const result = { id: roleId, name: 'Admin', description: 'Admin role' };
410
+
411
+ jest.spyOn(prismaService.role, 'findUnique').mockResolvedValue(result);
412
+
413
+ expect(await roleService.get('en', roleId)).toEqual(result);
414
+ });
415
+ });
416
+ });
417
+ */