@hedhog/admin 0.0.38 → 0.0.40
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/auth/auth.service.spec.d.ts +2 -0
- package/dist/auth/auth.service.spec.d.ts.map +1 -0
- package/dist/auth/auth.service.spec.js +163 -0
- package/dist/auth/auth.service.spec.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/locale/locale.module.js +2 -2
- package/dist/locale/locale.module.js.map +1 -1
- package/dist/locale/locale.service.js +1 -1
- package/dist/locale/locale.service.js.map +1 -1
- package/dist/locale/locale.service.spec.d.ts +2 -0
- package/dist/locale/locale.service.spec.d.ts.map +1 -0
- package/dist/locale/locale.service.spec.js +171 -0
- package/dist/locale/locale.service.spec.js.map +1 -0
- package/dist/menu/menu.service.spec.d.ts +2 -0
- package/dist/menu/menu.service.spec.d.ts.map +1 -0
- package/dist/menu/menu.service.spec.js +196 -0
- package/dist/menu/menu.service.spec.js.map +1 -0
- package/dist/role/role.service.spec.d.ts +2 -0
- package/dist/role/role.service.spec.d.ts.map +1 -0
- package/dist/role/role.service.spec.js +343 -0
- package/dist/role/role.service.spec.js.map +1 -0
- package/dist/route/route.service.spec.d.ts +2 -0
- package/dist/route/route.service.spec.d.ts.map +1 -0
- package/dist/route/route.service.spec.js +235 -0
- package/dist/route/route.service.spec.js.map +1 -0
- package/dist/screen/screen.service.spec.d.ts +2 -0
- package/dist/screen/screen.service.spec.d.ts.map +1 -0
- package/dist/screen/screen.service.spec.js +242 -0
- package/dist/screen/screen.service.spec.js.map +1 -0
- package/dist/setting/settings.service.spec.d.ts +2 -0
- package/dist/setting/settings.service.spec.d.ts.map +1 -0
- package/dist/setting/settings.service.spec.js +147 -0
- package/dist/setting/settings.service.spec.js.map +1 -0
- package/dist/user/user.service.spec.d.ts +2 -0
- package/dist/user/user.service.spec.d.ts.map +1 -0
- package/dist/user/user.service.spec.js +239 -0
- package/dist/user/user.service.spec.js.map +1 -0
- package/package.json +1 -1
- package/src/migrations/migrate-01.ts +1 -6
- package/src/migrations/migrate-02.ts +137 -137
@@ -0,0 +1,235 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const testing_1 = require("@nestjs/testing");
|
4
|
+
const pagination_1 = require("@hedhog/pagination");
|
5
|
+
const prisma_1 = require("@hedhog/prisma");
|
6
|
+
const route_service_1 = require("./route.service");
|
7
|
+
describe('RouteService', () => {
|
8
|
+
let service;
|
9
|
+
let prismaService;
|
10
|
+
let paginationService;
|
11
|
+
const mockPrismaService = {
|
12
|
+
routes: {
|
13
|
+
findUnique: jest.fn(),
|
14
|
+
create: jest.fn(),
|
15
|
+
update: jest.fn(),
|
16
|
+
deleteMany: jest.fn(),
|
17
|
+
},
|
18
|
+
role_routes: {
|
19
|
+
deleteMany: jest.fn(),
|
20
|
+
createMany: jest.fn(),
|
21
|
+
},
|
22
|
+
route_screens: {
|
23
|
+
deleteMany: jest.fn(),
|
24
|
+
createMany: jest.fn(),
|
25
|
+
},
|
26
|
+
createInsensitiveSearch: jest.fn(),
|
27
|
+
};
|
28
|
+
const mockPaginationService = {
|
29
|
+
paginate: jest.fn(),
|
30
|
+
};
|
31
|
+
beforeEach(async () => {
|
32
|
+
const module = await testing_1.Test.createTestingModule({
|
33
|
+
providers: [
|
34
|
+
route_service_1.RouteService,
|
35
|
+
{ provide: prisma_1.PrismaService, useValue: mockPrismaService },
|
36
|
+
{ provide: pagination_1.PaginationService, useValue: mockPaginationService },
|
37
|
+
],
|
38
|
+
}).compile();
|
39
|
+
service = module.get(route_service_1.RouteService);
|
40
|
+
prismaService = module.get(prisma_1.PrismaService);
|
41
|
+
paginationService = module.get(pagination_1.PaginationService);
|
42
|
+
});
|
43
|
+
it('should be defined', () => {
|
44
|
+
expect(service).toBeDefined();
|
45
|
+
});
|
46
|
+
describe('getRoutes', () => {
|
47
|
+
it('should paginate routes', async () => {
|
48
|
+
const paginationParams = {
|
49
|
+
page: 1,
|
50
|
+
pageSize: 10,
|
51
|
+
search: '',
|
52
|
+
sortField: '',
|
53
|
+
sortOrder: pagination_1.PageOrderDirection.Asc,
|
54
|
+
fields: '',
|
55
|
+
};
|
56
|
+
const result = { data: [], total: 0 };
|
57
|
+
mockPrismaService.createInsensitiveSearch.mockReturnValue([]);
|
58
|
+
mockPaginationService.paginate.mockResolvedValue(result);
|
59
|
+
const res = await service.getRoutes(paginationParams);
|
60
|
+
expect(mockPrismaService.createInsensitiveSearch).toHaveBeenCalledWith(['url', 'method'], paginationParams);
|
61
|
+
expect(mockPaginationService.paginate).toHaveBeenCalledWith(mockPrismaService.routes, paginationParams, { where: { OR: [] } });
|
62
|
+
expect(res).toEqual(result);
|
63
|
+
});
|
64
|
+
});
|
65
|
+
describe('getRouteById', () => {
|
66
|
+
it('should return a route by ID', async () => {
|
67
|
+
const routeId = 1;
|
68
|
+
const route = { id: routeId, url: '/test', method: 'GET' };
|
69
|
+
mockPrismaService.routes.findUnique.mockResolvedValue(route);
|
70
|
+
const res = await service.getRouteById(routeId);
|
71
|
+
expect(mockPrismaService.routes.findUnique).toHaveBeenCalledWith({
|
72
|
+
where: { id: routeId },
|
73
|
+
});
|
74
|
+
expect(res).toEqual(route);
|
75
|
+
});
|
76
|
+
});
|
77
|
+
describe('create', () => {
|
78
|
+
it('should create a new route', async () => {
|
79
|
+
const createDto = { url: '/test', method: 'GET' };
|
80
|
+
const route = Object.assign({ id: 1 }, createDto);
|
81
|
+
mockPrismaService.routes.create.mockResolvedValue(route);
|
82
|
+
const res = await service.create(createDto);
|
83
|
+
expect(mockPrismaService.routes.create).toHaveBeenCalledWith({
|
84
|
+
data: createDto,
|
85
|
+
});
|
86
|
+
expect(res).toEqual(route);
|
87
|
+
});
|
88
|
+
});
|
89
|
+
describe('update', () => {
|
90
|
+
it('should update a route', async () => {
|
91
|
+
const updateDto = { url: '/updated', method: 'POST' };
|
92
|
+
const routeId = 1;
|
93
|
+
const updatedRoute = Object.assign({ id: routeId }, updateDto);
|
94
|
+
mockPrismaService.routes.update.mockResolvedValue(updatedRoute);
|
95
|
+
const res = await service.update({ id: routeId, data: updateDto });
|
96
|
+
expect(mockPrismaService.routes.update).toHaveBeenCalledWith({
|
97
|
+
where: { id: routeId },
|
98
|
+
data: updateDto,
|
99
|
+
});
|
100
|
+
expect(res).toEqual(updatedRoute);
|
101
|
+
});
|
102
|
+
});
|
103
|
+
describe('delete', () => {
|
104
|
+
it('should delete routes by ids', async () => {
|
105
|
+
const deleteDto = { ids: [1, 2] };
|
106
|
+
const result = { count: 2 };
|
107
|
+
mockPrismaService.routes.deleteMany.mockResolvedValue(result);
|
108
|
+
const res = await service.delete(deleteDto);
|
109
|
+
expect(mockPrismaService.routes.deleteMany).toHaveBeenCalledWith({
|
110
|
+
where: { id: { in: deleteDto.ids } },
|
111
|
+
});
|
112
|
+
expect(res).toEqual(result);
|
113
|
+
});
|
114
|
+
});
|
115
|
+
describe('updateRoles', () => {
|
116
|
+
it('should update roles for a route', async () => {
|
117
|
+
const routeId = 1;
|
118
|
+
const updateIdsDto = { ids: [1, 2] };
|
119
|
+
const result = { count: 2 };
|
120
|
+
mockPrismaService.role_routes.deleteMany.mockResolvedValue({});
|
121
|
+
mockPrismaService.role_routes.createMany.mockResolvedValue(result);
|
122
|
+
const res = await service.updateRoles(routeId, updateIdsDto);
|
123
|
+
expect(mockPrismaService.role_routes.deleteMany).toHaveBeenCalledWith({
|
124
|
+
where: { route_id: routeId },
|
125
|
+
});
|
126
|
+
expect(mockPrismaService.role_routes.createMany).toHaveBeenCalledWith({
|
127
|
+
data: updateIdsDto.ids.map((roleId) => ({
|
128
|
+
role_id: roleId,
|
129
|
+
route_id: routeId,
|
130
|
+
})),
|
131
|
+
skipDuplicates: true,
|
132
|
+
});
|
133
|
+
expect(res).toEqual(result);
|
134
|
+
});
|
135
|
+
});
|
136
|
+
describe('updateScreens', () => {
|
137
|
+
it('should update screens for a route', async () => {
|
138
|
+
const routeId = 1;
|
139
|
+
const updateIdsDto = { ids: [1, 2] };
|
140
|
+
const result = { count: 2 };
|
141
|
+
mockPrismaService.route_screens.deleteMany.mockResolvedValue({});
|
142
|
+
mockPrismaService.route_screens.createMany.mockResolvedValue(result);
|
143
|
+
const res = await service.updateScreens(routeId, updateIdsDto);
|
144
|
+
expect(mockPrismaService.route_screens.deleteMany).toHaveBeenCalledWith({
|
145
|
+
where: { route_id: routeId },
|
146
|
+
});
|
147
|
+
expect(mockPrismaService.route_screens.createMany).toHaveBeenCalledWith({
|
148
|
+
data: updateIdsDto.ids.map((screenId) => ({
|
149
|
+
screen_id: screenId,
|
150
|
+
route_id: routeId,
|
151
|
+
})),
|
152
|
+
skipDuplicates: true,
|
153
|
+
});
|
154
|
+
expect(res).toEqual(result);
|
155
|
+
});
|
156
|
+
});
|
157
|
+
describe('listRoles', () => {
|
158
|
+
it('should call paginate method with correct parameters', async () => {
|
159
|
+
const locale = 'en';
|
160
|
+
const routeId = 1;
|
161
|
+
const paginationParams = {
|
162
|
+
page: 1,
|
163
|
+
pageSize: 10,
|
164
|
+
search: '',
|
165
|
+
sortField: '',
|
166
|
+
sortOrder: pagination_1.PageOrderDirection.Asc,
|
167
|
+
fields: '',
|
168
|
+
};
|
169
|
+
paginationService.paginate = jest.fn().mockResolvedValue({
|
170
|
+
data: [],
|
171
|
+
total: 0,
|
172
|
+
});
|
173
|
+
await service.listRoles(locale, routeId, paginationParams);
|
174
|
+
expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.roles, paginationParams, {
|
175
|
+
include: {
|
176
|
+
role_translations: {
|
177
|
+
where: {
|
178
|
+
locales: { code: locale },
|
179
|
+
},
|
180
|
+
select: {
|
181
|
+
name: true,
|
182
|
+
description: true,
|
183
|
+
},
|
184
|
+
},
|
185
|
+
role_routes: {
|
186
|
+
where: { route_id: routeId },
|
187
|
+
select: {
|
188
|
+
route_id: true,
|
189
|
+
role_id: true,
|
190
|
+
},
|
191
|
+
},
|
192
|
+
},
|
193
|
+
}, 'role_translations');
|
194
|
+
});
|
195
|
+
});
|
196
|
+
describe('listScreens', () => {
|
197
|
+
it('should call paginate method with correct parameters', async () => {
|
198
|
+
const locale = 'en';
|
199
|
+
const routeId = 1;
|
200
|
+
const paginationParams = {
|
201
|
+
page: 1,
|
202
|
+
pageSize: 10,
|
203
|
+
search: '',
|
204
|
+
sortField: '',
|
205
|
+
sortOrder: pagination_1.PageOrderDirection.Asc,
|
206
|
+
fields: '',
|
207
|
+
};
|
208
|
+
paginationService.paginate = jest.fn().mockResolvedValue({
|
209
|
+
data: [],
|
210
|
+
total: 0,
|
211
|
+
});
|
212
|
+
await service.listScreens(locale, routeId, paginationParams);
|
213
|
+
expect(paginationService.paginate).toHaveBeenCalledWith(prismaService.screens, paginationParams, {
|
214
|
+
include: {
|
215
|
+
screen_translations: {
|
216
|
+
where: {
|
217
|
+
locales: { code: locale },
|
218
|
+
},
|
219
|
+
select: {
|
220
|
+
name: true,
|
221
|
+
},
|
222
|
+
},
|
223
|
+
route_screens: {
|
224
|
+
where: { route_id: routeId },
|
225
|
+
select: {
|
226
|
+
route_id: true,
|
227
|
+
screen_id: true,
|
228
|
+
},
|
229
|
+
},
|
230
|
+
},
|
231
|
+
}, 'screen_translations');
|
232
|
+
});
|
233
|
+
});
|
234
|
+
});
|
235
|
+
//# sourceMappingURL=route.service.spec.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"route.service.spec.js","sourceRoot":"","sources":["../../src/route/route.service.spec.ts"],"names":[],"mappings":";;AAAA,6CAAsD;AACtD,mDAI4B;AAC5B,2CAA+C;AAC/C,mDAA+C;AAM/C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,OAAqB,CAAC;IAC1B,IAAI,aAA4B,CAAC;IACjC,IAAI,iBAAoC,CAAC;IAEzC,MAAM,iBAAiB,GAAG;QACxB,MAAM,EAAE;YACN,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;YACrB,MAAM,EAAE,IA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C,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;YAE7D,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CACrD,aAAa,CAAC,OAAO,EACrB,gBAAgB,EAChB;gBACE,OAAO,EAAE;oBACP,mBAAmB,EAAE;wBACnB,KAAK,EAAE;4BACL,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;yBAC1B;wBACD,MAAM,EAAE;4BACN,IAAI,EAAE,IAAI;yBACX;qBACF;oBACD,aAAa,EAAE;wBACb,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE;wBAC5B,MAAM,EAAE;4BACN,QAAQ,EAAE,IAAI;4BACd,SAAS,EAAE,IAAI;yBAChB;qBACF;iBACF;aACF,EACD,qBAAqB,CACtB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"screen.service.spec.d.ts","sourceRoot":"","sources":["../../src/screen/screen.service.spec.ts"],"names":[],"mappings":""}
|
@@ -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,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC3D,SAAS,EAAE;gBACT,8BAAa;gBACb;oBACE,OAAO,EAAE,sBAAa;oBACtB,QAAQ,EAAE;wBACR,OAAO,EAAE;4BACP,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;4BACjB,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;4BACjB,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;4BACrB,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;yBACtB;wBACD,MAAM,EAAE;4BACN,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;yBACpB;wBACD,YAAY,EAAE;4BACZ,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;4BACrB,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;yBACtB;wBACD,aAAa,EAAE;4BACb,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;4BACrB,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;yBACtB;wBACD,uBAAuB,EAAE,IAAI,CA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gBACR,KAAK,EAAE,EAAE;gBACT,QAAQ,EAAE,CAAC;gBACX,IAAI,EAAE,CAAC;gBACP,IAAI,EAAE,CAAC;gBACP,IAAI,EAAE,CAAC;gBACP,QAAQ,EAAE,EAAE;aACb,CAAC;YAEF,IAAI;iBACD,KAAK,CAAC,iBAAiB,EAAE,UAAU,CAAC;iBACpC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;YAE3C,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;YAErD,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,oBAAoB,CACrD,aAAa,CAAC,MAAM,EACpB,gBAAgB,EAChB;gBACE,OAAO,EAAE;oBACP,aAAa,EAAE;wBACb,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE;wBAC9B,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;qBAC5C;iBACF;aACF,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -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
|