@hedhog/admin 0.0.39 → 0.0.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/dist/auth/auth.service.spec.d.ts +2 -0
  2. package/dist/auth/auth.service.spec.d.ts.map +1 -0
  3. package/dist/auth/auth.service.spec.js +163 -0
  4. package/dist/auth/auth.service.spec.js.map +1 -0
  5. package/dist/locale/locale.module.js +2 -2
  6. package/dist/locale/locale.module.js.map +1 -1
  7. package/dist/locale/locale.service.js +1 -1
  8. package/dist/locale/locale.service.js.map +1 -1
  9. package/dist/locale/locale.service.spec.d.ts +2 -0
  10. package/dist/locale/locale.service.spec.d.ts.map +1 -0
  11. package/dist/locale/locale.service.spec.js +171 -0
  12. package/dist/locale/locale.service.spec.js.map +1 -0
  13. package/dist/menu/menu.service.spec.d.ts +2 -0
  14. package/dist/menu/menu.service.spec.d.ts.map +1 -0
  15. package/dist/menu/menu.service.spec.js +196 -0
  16. package/dist/menu/menu.service.spec.js.map +1 -0
  17. package/dist/role/role.service.spec.d.ts +2 -0
  18. package/dist/role/role.service.spec.d.ts.map +1 -0
  19. package/dist/role/role.service.spec.js +343 -0
  20. package/dist/role/role.service.spec.js.map +1 -0
  21. package/dist/route/route.service.spec.d.ts +2 -0
  22. package/dist/route/route.service.spec.d.ts.map +1 -0
  23. package/dist/route/route.service.spec.js +235 -0
  24. package/dist/route/route.service.spec.js.map +1 -0
  25. package/dist/screen/screen.service.spec.d.ts +2 -0
  26. package/dist/screen/screen.service.spec.d.ts.map +1 -0
  27. package/dist/screen/screen.service.spec.js +242 -0
  28. package/dist/screen/screen.service.spec.js.map +1 -0
  29. package/dist/setting/settings.service.spec.d.ts +2 -0
  30. package/dist/setting/settings.service.spec.d.ts.map +1 -0
  31. package/dist/setting/settings.service.spec.js +147 -0
  32. package/dist/setting/settings.service.spec.js.map +1 -0
  33. package/dist/user/user.service.spec.d.ts +2 -0
  34. package/dist/user/user.service.spec.d.ts.map +1 -0
  35. package/dist/user/user.service.spec.js +239 -0
  36. package/dist/user/user.service.spec.js.map +1 -0
  37. package/package.json +1 -1
  38. package/src/migrations/migrate-02.ts +137 -137
@@ -0,0 +1,242 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const testing_1 = require("@nestjs/testing");
4
+ const screen_service_1 = require("./screen.service");
5
+ const prisma_1 = require("@hedhog/prisma");
6
+ const pagination_1 = require("@hedhog/pagination");
7
+ const common_1 = require("@nestjs/common");
8
+ describe('ScreenService', () => {
9
+ let service;
10
+ let prismaService;
11
+ let paginationService;
12
+ beforeEach(async () => {
13
+ const module = await testing_1.Test.createTestingModule({
14
+ providers: [
15
+ screen_service_1.ScreenService,
16
+ {
17
+ provide: prisma_1.PrismaService,
18
+ useValue: {
19
+ screens: {
20
+ create: jest.fn(),
21
+ update: jest.fn(),
22
+ deleteMany: jest.fn(),
23
+ findUnique: jest.fn(),
24
+ },
25
+ routes: {
26
+ findMany: jest.fn(),
27
+ },
28
+ role_screens: {
29
+ deleteMany: jest.fn(),
30
+ createMany: jest.fn(),
31
+ },
32
+ route_screens: {
33
+ deleteMany: jest.fn(),
34
+ createMany: jest.fn(),
35
+ },
36
+ createInsensitiveSearch: jest.fn(),
37
+ },
38
+ },
39
+ {
40
+ provide: pagination_1.PaginationService,
41
+ useValue: {
42
+ paginate: jest.fn(),
43
+ },
44
+ },
45
+ ],
46
+ }).compile();
47
+ service = module.get(screen_service_1.ScreenService);
48
+ prismaService = module.get(prisma_1.PrismaService);
49
+ paginationService = module.get(pagination_1.PaginationService);
50
+ });
51
+ it('should be defined', () => {
52
+ expect(service).toBeDefined();
53
+ });
54
+ describe('create', () => {
55
+ it('should create a screen', async () => {
56
+ const createDTO = {
57
+ name: 'Test Screen',
58
+ slug: 'test-screen',
59
+ description: 'This is a test screen',
60
+ icon: 'test-icon',
61
+ };
62
+ jest
63
+ .spyOn(prismaService.screens, 'create')
64
+ .mockResolvedValue(createDTO);
65
+ const result = await service.create(createDTO);
66
+ expect(prismaService.screens.create).toHaveBeenCalledWith({
67
+ data: createDTO,
68
+ });
69
+ expect(result).toEqual(createDTO);
70
+ });
71
+ });
72
+ describe('delete', () => {
73
+ it('should throw an error if no ids are provided', async () => {
74
+ const deleteDTO = { ids: null };
75
+ await expect(service.delete(deleteDTO)).rejects.toThrow(new common_1.BadRequestException(`You must select at least one screen to delete.`));
76
+ });
77
+ it('should delete screens by ids', async () => {
78
+ const deleteDTO = { ids: [1, 2] };
79
+ jest.spyOn(prismaService.screens, 'deleteMany').mockResolvedValue({
80
+ count: 2,
81
+ });
82
+ await service.delete(deleteDTO);
83
+ expect(prismaService.screens.deleteMany).toHaveBeenCalledWith({
84
+ where: { id: { in: deleteDTO.ids } },
85
+ });
86
+ });
87
+ });
88
+ describe('update', () => {
89
+ it('should update a screen', async () => {
90
+ const updateDTO = {
91
+ id: 1,
92
+ name: 'Updated Screen',
93
+ slug: 'updated-screen',
94
+ icon: 'update-icon',
95
+ created_at: new Date(),
96
+ updated_at: new Date(),
97
+ };
98
+ const updateInput = { id: 1, data: updateDTO };
99
+ jest.spyOn(prismaService.screens, 'update').mockResolvedValue(updateDTO);
100
+ const result = await service.update(updateInput);
101
+ expect(prismaService.screens.update).toHaveBeenCalledWith({
102
+ where: { id: updateInput.id },
103
+ data: updateInput.data,
104
+ });
105
+ expect(result).toEqual(updateDTO);
106
+ });
107
+ });
108
+ describe('get', () => {
109
+ it('should get a screen by id', async () => {
110
+ const screen = {
111
+ id: 1,
112
+ name: 'Updated Screen',
113
+ slug: 'updated-screen',
114
+ icon: 'update-icon',
115
+ created_at: new Date(),
116
+ updated_at: new Date(),
117
+ };
118
+ jest.spyOn(prismaService.screens, 'findUnique').mockResolvedValue(screen);
119
+ const result = await service.get(1);
120
+ expect(prismaService.screens.findUnique).toHaveBeenCalledWith({
121
+ where: { id: 1 },
122
+ });
123
+ expect(result).toEqual(screen);
124
+ });
125
+ });
126
+ describe('updateRoles', () => {
127
+ it('should update roles for a screen', async () => {
128
+ const screenId = 1;
129
+ const updateIdsDTO = { ids: [1, 2, 3] };
130
+ jest.spyOn(prismaService.role_screens, 'deleteMany').mockResolvedValue({
131
+ count: 1,
132
+ });
133
+ jest.spyOn(prismaService.role_screens, 'createMany').mockResolvedValue({
134
+ count: updateIdsDTO.ids.length,
135
+ });
136
+ await service.updateRoles(screenId, updateIdsDTO);
137
+ expect(prismaService.role_screens.deleteMany).toHaveBeenCalledWith({
138
+ where: { screen_id: screenId },
139
+ });
140
+ expect(prismaService.role_screens.createMany).toHaveBeenCalledWith({
141
+ data: updateIdsDTO.ids.map((roleId) => ({
142
+ screen_id: screenId,
143
+ role_id: roleId,
144
+ })),
145
+ skipDuplicates: true,
146
+ });
147
+ });
148
+ });
149
+ describe('updateRoutes', () => {
150
+ it('should delete existing route_screens and create new ones', async () => {
151
+ const screenId = 1;
152
+ const updateIdsDTO = { ids: [1, 2, 3] };
153
+ prismaService.routes.findMany = jest
154
+ .fn()
155
+ .mockResolvedValue([{ id: 1 }, { id: 2 }, { id: 3 }]);
156
+ prismaService.route_screens.deleteMany = jest.fn();
157
+ prismaService.route_screens.createMany = jest.fn();
158
+ await service.updateRoutes(screenId, updateIdsDTO);
159
+ expect(prismaService.routes.findMany).toHaveBeenCalledWith({
160
+ where: { id: { in: updateIdsDTO.ids } },
161
+ select: { id: true },
162
+ });
163
+ expect(prismaService.route_screens.deleteMany).toHaveBeenCalledWith({
164
+ where: { screen_id: screenId },
165
+ });
166
+ expect(prismaService.route_screens.createMany).toHaveBeenCalledWith({
167
+ data: updateIdsDTO.ids.map((routeId) => ({
168
+ screen_id: screenId,
169
+ route_id: routeId,
170
+ })),
171
+ skipDuplicates: true,
172
+ });
173
+ });
174
+ });
175
+ describe('listRoles', () => {
176
+ it('should call paginate method with correct parameters', async () => {
177
+ const locale = 'en';
178
+ const screenId = 1;
179
+ const paginationParams = {
180
+ page: 1,
181
+ pageSize: 10,
182
+ search: '',
183
+ sortField: '',
184
+ sortOrder: pagination_1.PageOrderDirection.Asc,
185
+ fields: '',
186
+ };
187
+ paginationService.paginate = jest.fn().mockResolvedValue({
188
+ data: [],
189
+ total: 0,
190
+ });
191
+ await service.listRoles(locale, screenId, paginationParams);
192
+ expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.roles, paginationParams, {
193
+ include: {
194
+ role_screens: {
195
+ where: {
196
+ screen_id: screenId,
197
+ },
198
+ select: {
199
+ role_id: true,
200
+ screen_id: true,
201
+ },
202
+ },
203
+ },
204
+ });
205
+ });
206
+ });
207
+ describe('listRoutes', () => {
208
+ it('should paginate the routes linked to a screen', async () => {
209
+ const paginationParams = {
210
+ page: 1,
211
+ pageSize: 10,
212
+ search: '',
213
+ sortField: '',
214
+ sortOrder: pagination_1.PageOrderDirection.Asc,
215
+ fields: '',
216
+ };
217
+ const screenId = 1;
218
+ const mockPaginationResult = {
219
+ data: [],
220
+ total: 10,
221
+ lastPage: 1,
222
+ page: 1,
223
+ prev: 0,
224
+ next: 2,
225
+ pageSize: 10,
226
+ };
227
+ jest
228
+ .spyOn(paginationService, 'paginate')
229
+ .mockResolvedValue(mockPaginationResult);
230
+ await service.listRoutes(screenId, paginationParams);
231
+ expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.routes, paginationParams, {
232
+ include: {
233
+ route_screens: {
234
+ where: { screen_id: screenId },
235
+ select: { route_id: true, screen_id: true },
236
+ },
237
+ },
238
+ });
239
+ });
240
+ });
241
+ });
242
+ //# sourceMappingURL=screen.service.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.service.spec.js","sourceRoot":"","sources":["../../src/screen/screen.service.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AACtD,qDAAiD;AACjD,2CAA+C;AAC/C,mDAI4B;AAC5B,2CAAqD;AAIrD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,OAAsB,CAAC;IAC3B,IAAI,aAA4B,CAAC;IACjC,IAAI,iBAAoC,CAAC;IAEzC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM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AI,EAAE;qBAC5C;iBACF;aACF,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=settings.service.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.service.spec.d.ts","sourceRoot":"","sources":["../../src/setting/settings.service.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const testing_1 = require("@nestjs/testing");
4
+ const settings_service_1 = require("./settings.service");
5
+ const prisma_1 = require("@hedhog/prisma");
6
+ const pagination_1 = require("@hedhog/pagination");
7
+ const common_1 = require("@nestjs/common");
8
+ describe('SettingsService', () => {
9
+ let service;
10
+ let prismaService;
11
+ let paginationService;
12
+ beforeEach(async () => {
13
+ const module = await testing_1.Test.createTestingModule({
14
+ providers: [
15
+ settings_service_1.SettingsService,
16
+ {
17
+ provide: prisma_1.PrismaService,
18
+ useValue: {
19
+ settings: {
20
+ findUnique: jest.fn(),
21
+ create: jest.fn(),
22
+ update: jest.fn(),
23
+ deleteMany: jest.fn(),
24
+ },
25
+ createInsensitiveSearch: jest.fn(),
26
+ },
27
+ },
28
+ {
29
+ provide: pagination_1.PaginationService,
30
+ useValue: {
31
+ paginate: jest.fn(),
32
+ },
33
+ },
34
+ ],
35
+ }).compile();
36
+ service = module.get(settings_service_1.SettingsService);
37
+ prismaService = module.get(prisma_1.PrismaService);
38
+ paginationService = module.get(pagination_1.PaginationService);
39
+ });
40
+ it('should be defined', () => {
41
+ expect(service).toBeDefined();
42
+ });
43
+ describe('getSettings', () => {
44
+ it('should return paginated settings', async () => {
45
+ const paginationParams = {
46
+ page: 1,
47
+ pageSize: 10,
48
+ search: '',
49
+ sortField: '',
50
+ sortOrder: pagination_1.PageOrderDirection.Asc,
51
+ fields: '',
52
+ };
53
+ const mockPaginatedData = {
54
+ data: [],
55
+ total: 10,
56
+ lastPage: 1,
57
+ page: 1,
58
+ prev: 0,
59
+ next: 2,
60
+ pageSize: 10,
61
+ };
62
+ jest.spyOn(prismaService, 'createInsensitiveSearch').mockReturnValue([]);
63
+ jest
64
+ .spyOn(paginationService, 'paginate')
65
+ .mockResolvedValue(mockPaginatedData);
66
+ const result = await service.getSettings(paginationParams);
67
+ expect(prismaService.createInsensitiveSearch).toHaveBeenCalledWith(['name'], paginationParams);
68
+ expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.settings, paginationParams, { where: { OR: [] } });
69
+ expect(result).toEqual(mockPaginatedData);
70
+ });
71
+ });
72
+ describe('get', () => {
73
+ it('should return a specific setting by ID', async () => {
74
+ const mockSetting = {
75
+ id: 1,
76
+ name: 'Test Setting',
77
+ created_at: new Date(),
78
+ updated_at: new Date(),
79
+ };
80
+ jest
81
+ .spyOn(prismaService.settings, 'findUnique')
82
+ .mockResolvedValue(mockSetting);
83
+ const result = await service.get(1);
84
+ expect(prismaService.settings.findUnique).toHaveBeenCalledWith({
85
+ where: { id: 1 },
86
+ });
87
+ expect(result).toEqual(mockSetting);
88
+ });
89
+ });
90
+ describe('create', () => {
91
+ it('should create a new setting', async () => {
92
+ const createDTO = { name: 'New Setting' };
93
+ const mockSetting = {
94
+ id: 1,
95
+ name: 'Test Setting',
96
+ created_at: new Date(),
97
+ updated_at: new Date(),
98
+ };
99
+ jest
100
+ .spyOn(prismaService.settings, 'create')
101
+ .mockResolvedValue(mockSetting);
102
+ const result = await service.create(createDTO);
103
+ expect(prismaService.settings.create).toHaveBeenCalledWith({
104
+ data: { name: createDTO.name },
105
+ });
106
+ expect(result).toEqual(mockSetting);
107
+ });
108
+ });
109
+ describe('update', () => {
110
+ it('should update an existing setting', async () => {
111
+ const updateDTO = { name: 'Updated Setting' };
112
+ const updateInput = { id: 1, data: updateDTO };
113
+ const mockSetting = {
114
+ id: 1,
115
+ name: 'Update Setting',
116
+ created_at: new Date(),
117
+ updated_at: new Date(),
118
+ };
119
+ jest
120
+ .spyOn(prismaService.settings, 'update')
121
+ .mockResolvedValue(mockSetting);
122
+ const result = await service.update(updateInput);
123
+ expect(prismaService.settings.update).toHaveBeenCalledWith({
124
+ where: { id: updateInput.id },
125
+ data: updateInput.data,
126
+ });
127
+ expect(result).toEqual(mockSetting);
128
+ });
129
+ });
130
+ describe('delete', () => {
131
+ it('should throw an error if no ids are provided', async () => {
132
+ const deleteDTO = { ids: null };
133
+ await expect(service.delete(deleteDTO)).rejects.toThrow(new common_1.BadRequestException(`You must select at least one setting to delete.`));
134
+ });
135
+ it('should delete settings by ids', async () => {
136
+ const deleteDTO = { ids: [1, 2] };
137
+ jest
138
+ .spyOn(prismaService.settings, 'deleteMany')
139
+ .mockResolvedValue({ count: 2 });
140
+ await service.delete(deleteDTO);
141
+ expect(prismaService.settings.deleteMany).toHaveBeenCalledWith({
142
+ where: { id: { in: deleteDTO.ids } },
143
+ });
144
+ });
145
+ });
146
+ });
147
+ //# sourceMappingURL=settings.service.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.service.spec.js","sourceRoot":"","sources":["../../src/setting/settings.service.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AACtD,yDAAqD;AACrD,2CAA+C;AAC/C,mDAI4B;AAC5B,2CAAqD;AAKrD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,OAAwB,CAAC;IAC7B,IAAI,aAA4B,CAAC;IACjC,IAAI,iBAAoC,CAAC;IAEzC,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC3D,SAAS,EAAE;gBACT,kCAAe;gBACf;oBACE,OAAO,EAAE,sBAAa;oBACtB,QAAQ,EAAE;wBACR,QAAQ,EAAE;4BACR,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;4BACrB,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;4BACjB,MAAM,E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AAS,CAAC,GAAG,EAAE,EAAE;aACrC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=user.service.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.service.spec.d.ts","sourceRoot":"","sources":["../../src/user/user.service.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const testing_1 = require("@nestjs/testing");
4
+ const user_service_1 = require("./user.service");
5
+ const prisma_1 = require("@hedhog/prisma");
6
+ const pagination_1 = require("@hedhog/pagination");
7
+ const common_1 = require("@nestjs/common");
8
+ const bcrypt_1 = require("bcrypt");
9
+ const user_constants_1 = require("./constants/user.constants");
10
+ jest.mock('bcrypt', () => ({
11
+ genSalt: jest.fn().mockResolvedValue('mockSalt'),
12
+ hash: jest.fn().mockResolvedValue('mockHashedPassword'),
13
+ }));
14
+ describe('UserService', () => {
15
+ let service;
16
+ let prismaService;
17
+ let paginationService;
18
+ beforeEach(async () => {
19
+ const module = await testing_1.Test.createTestingModule({
20
+ providers: [
21
+ user_service_1.UserService,
22
+ {
23
+ provide: prisma_1.PrismaService,
24
+ useValue: {
25
+ users: {
26
+ findUnique: jest.fn(),
27
+ create: jest.fn(),
28
+ update: jest.fn(),
29
+ deleteMany: jest.fn(),
30
+ },
31
+ role_users: {
32
+ deleteMany: jest.fn(),
33
+ createMany: jest.fn(),
34
+ },
35
+ createInsensitiveSearch: jest.fn(),
36
+ },
37
+ },
38
+ {
39
+ provide: pagination_1.PaginationService,
40
+ useValue: {
41
+ paginate: jest.fn(),
42
+ },
43
+ },
44
+ ],
45
+ }).compile();
46
+ service = module.get(user_service_1.UserService);
47
+ prismaService = module.get(prisma_1.PrismaService);
48
+ paginationService = module.get(pagination_1.PaginationService);
49
+ });
50
+ it('should be defined', () => {
51
+ expect(service).toBeDefined();
52
+ });
53
+ describe('listRoles', () => {
54
+ it('should return paginated roles for a specific user', async () => {
55
+ const paginationParams = {
56
+ page: 1,
57
+ pageSize: 10,
58
+ search: '',
59
+ sortField: '',
60
+ sortOrder: pagination_1.PageOrderDirection.Asc,
61
+ fields: '',
62
+ };
63
+ const mockPaginatedRoles = {
64
+ data: [],
65
+ total: 10,
66
+ lastPage: 1,
67
+ page: 1,
68
+ prev: 0,
69
+ next: 2,
70
+ pageSize: 10,
71
+ };
72
+ jest
73
+ .spyOn(paginationService, 'paginate')
74
+ .mockResolvedValue(mockPaginatedRoles);
75
+ const result = await service.listRoles(1, paginationParams);
76
+ expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.roles, paginationParams, {
77
+ include: {
78
+ role_users: {
79
+ where: { user_id: 1 },
80
+ select: { user_id: true, role_id: true },
81
+ },
82
+ },
83
+ });
84
+ expect(result).toEqual(mockPaginatedRoles);
85
+ });
86
+ });
87
+ describe('updateRoles', () => {
88
+ it('should update user roles', async () => {
89
+ const updateIdsDTO = { ids: [1, 2] };
90
+ jest
91
+ .spyOn(prismaService.role_users, 'deleteMany')
92
+ .mockResolvedValue({ count: 1 });
93
+ jest
94
+ .spyOn(prismaService.role_users, 'createMany')
95
+ .mockResolvedValue({ count: 2 });
96
+ await service.updateRoles(1, updateIdsDTO);
97
+ expect(prismaService.role_users.deleteMany).toHaveBeenCalledWith({
98
+ where: { user_id: 1 },
99
+ });
100
+ expect(prismaService.role_users.createMany).toHaveBeenCalledWith({
101
+ data: [
102
+ { user_id: 1, role_id: 1 },
103
+ { user_id: 1, role_id: 2 },
104
+ ],
105
+ skipDuplicates: true,
106
+ });
107
+ });
108
+ });
109
+ describe('getUsers', () => {
110
+ it('should return paginated users', async () => {
111
+ const paginationParams = {
112
+ page: 1,
113
+ pageSize: 10,
114
+ search: '',
115
+ sortField: '',
116
+ sortOrder: pagination_1.PageOrderDirection.Asc,
117
+ fields: '',
118
+ };
119
+ const mockPaginatedUsers = {
120
+ data: [],
121
+ total: 10,
122
+ lastPage: 1,
123
+ page: 1,
124
+ prev: 0,
125
+ next: 2,
126
+ pageSize: 10,
127
+ };
128
+ jest.spyOn(prismaService, 'createInsensitiveSearch').mockReturnValue([]);
129
+ jest
130
+ .spyOn(paginationService, 'paginate')
131
+ .mockResolvedValue(mockPaginatedUsers);
132
+ const result = await service.getUsers(paginationParams);
133
+ expect(prismaService.createInsensitiveSearch).toHaveBeenCalledWith(['name', 'email'], paginationParams);
134
+ expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.users, paginationParams, { where: { OR: [] } });
135
+ expect(result).toEqual(mockPaginatedUsers);
136
+ });
137
+ });
138
+ describe('get', () => {
139
+ it('should return a specific user by ID', async () => {
140
+ const mockUser = {
141
+ id: 1,
142
+ name: 'Test User',
143
+ email: 'user@email.com',
144
+ password: 'hashedpassword',
145
+ created_at: new Date(),
146
+ updated_at: new Date(),
147
+ multifactor_id: null,
148
+ code: null,
149
+ };
150
+ jest.spyOn(prismaService.users, 'findUnique').mockResolvedValue(mockUser);
151
+ const result = await service.get(1);
152
+ expect(prismaService.users.findUnique).toHaveBeenCalledWith({
153
+ where: { id: 1 },
154
+ });
155
+ expect(result).toEqual(mockUser);
156
+ });
157
+ });
158
+ describe('hashPassword', () => {
159
+ it('should hash the password correctly', async () => {
160
+ const password = 'plainPassword';
161
+ const result = await service.hashPassword(password);
162
+ expect(bcrypt_1.genSalt).toHaveBeenCalledWith(user_constants_1.SALT_ROUNDS);
163
+ expect(bcrypt_1.hash).toHaveBeenCalledWith(password, 'mockSalt');
164
+ expect(result).toEqual('mockHashedPassword');
165
+ });
166
+ });
167
+ describe('create', () => {
168
+ it('should create a new user with hashed password', async () => {
169
+ const createDTO = {
170
+ email: 'test@test.com',
171
+ name: 'Test User',
172
+ password: 'password123',
173
+ };
174
+ const mockUser = {
175
+ id: 1,
176
+ name: 'Test User',
177
+ email: 'user@email.com',
178
+ password: 'hashedpassword',
179
+ created_at: new Date(),
180
+ updated_at: new Date(),
181
+ multifactor_id: null,
182
+ code: null,
183
+ };
184
+ jest.spyOn(prismaService.users, 'create').mockResolvedValue(mockUser);
185
+ const result = await service.create(createDTO);
186
+ expect(prismaService.users.create).toHaveBeenCalledWith({
187
+ data: {
188
+ email: createDTO.email,
189
+ name: createDTO.name,
190
+ password: 'mockHashedPassword',
191
+ },
192
+ });
193
+ expect(result).toEqual(mockUser);
194
+ });
195
+ });
196
+ describe('update', () => {
197
+ it('should update an existing user', async () => {
198
+ const updateDTO = { name: 'Updated User' };
199
+ const updateInput = { id: 1, data: updateDTO };
200
+ const mockUser = {
201
+ id: 1,
202
+ name: 'Updated User',
203
+ email: 'user@email.com',
204
+ password: 'hashedpassword',
205
+ created_at: new Date(),
206
+ updated_at: new Date(),
207
+ multifactor_id: null,
208
+ code: null,
209
+ };
210
+ jest.spyOn(prismaService.users, 'update').mockResolvedValue(mockUser);
211
+ const result = await service.update(updateInput);
212
+ expect(prismaService.users.update).toHaveBeenCalledWith({
213
+ where: { id: updateInput.id },
214
+ data: updateInput.data,
215
+ });
216
+ expect(result).toEqual(mockUser);
217
+ });
218
+ });
219
+ describe('delete', () => {
220
+ it('should throw an error if no ids are provided', async () => {
221
+ const deleteDTO = { ids: null };
222
+ await expect(service.delete(deleteDTO)).rejects.toThrow(new common_1.BadRequestException('You must select at least one user to delete.'));
223
+ });
224
+ it('should delete users by ids', async () => {
225
+ const deleteDTO = { ids: [1, 2] };
226
+ jest
227
+ .spyOn(prismaService.users, 'deleteMany')
228
+ .mockResolvedValue({ count: 2 });
229
+ await service.delete(deleteDTO);
230
+ expect(prismaService.users.deleteMany).toHaveBeenCalledWith({
231
+ where: {
232
+ id: { in: deleteDTO.ids },
233
+ email: { not: { startsWith: 'root@' } },
234
+ },
235
+ });
236
+ });
237
+ });
238
+ });
239
+ //# sourceMappingURL=user.service.spec.js.map