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