@blackcode_sa/metaestetics-api 1.10.0 → 1.11.1
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.
- package/dist/admin/index.d.mts +337 -319
- package/dist/admin/index.d.ts +337 -319
- package/dist/admin/index.js +98 -79
- package/dist/admin/index.mjs +98 -79
- package/dist/backoffice/index.d.mts +284 -67
- package/dist/backoffice/index.d.ts +284 -67
- package/dist/backoffice/index.js +114 -6
- package/dist/backoffice/index.mjs +112 -6
- package/dist/index.d.mts +3145 -3065
- package/dist/index.d.ts +3145 -3065
- package/dist/index.js +460 -141
- package/dist/index.mjs +463 -143
- package/package.json +3 -1
- package/src/admin/booking/booking.admin.ts +2 -0
- package/src/admin/booking/booking.calculator.ts +121 -117
- package/src/admin/booking/booking.types.ts +3 -0
- package/src/backoffice/expo-safe/index.ts +2 -0
- package/src/backoffice/services/README.md +40 -0
- package/src/backoffice/services/constants.service.ts +268 -0
- package/src/backoffice/services/technology.service.ts +122 -10
- package/src/backoffice/types/admin-constants.types.ts +69 -0
- package/src/backoffice/types/index.ts +1 -0
- package/src/backoffice/types/product.types.ts +3 -1
- package/src/backoffice/types/technology.types.ts +4 -4
- package/src/backoffice/validations/schemas.ts +35 -9
- package/src/services/appointment/appointment.service.ts +0 -5
- package/src/services/appointment/utils/appointment.utils.ts +124 -113
- package/src/services/clinic/clinic.service.ts +163 -82
- package/src/services/procedure/procedure.service.ts +435 -234
- package/src/types/appointment/index.ts +9 -3
- package/src/types/clinic/index.ts +3 -6
- package/src/types/patient/medical-info.types.ts +3 -3
- package/src/types/procedure/index.ts +20 -17
- package/src/validations/appointment.schema.ts +2 -0
- package/src/validations/clinic.schema.ts +3 -6
- package/src/validations/patient/medical-info.schema.ts +7 -2
- package/src/validations/procedure.schema.ts +8 -10
- package/src/backoffice/services/__tests__/brand.service.test.ts +0 -196
- package/src/backoffice/services/__tests__/category.service.test.ts +0 -201
- package/src/backoffice/services/__tests__/product.service.test.ts +0 -358
- package/src/backoffice/services/__tests__/requirement.service.test.ts +0 -226
- package/src/backoffice/services/__tests__/subcategory.service.test.ts +0 -181
- package/src/backoffice/services/__tests__/technology.service.test.ts +0 -1097
|
@@ -1,1097 +0,0 @@
|
|
|
1
|
-
import { TechnologyService } from "../technology.service";
|
|
2
|
-
import { Technology } from "../../types/technology.types";
|
|
3
|
-
import {
|
|
4
|
-
collection,
|
|
5
|
-
doc,
|
|
6
|
-
getDoc,
|
|
7
|
-
getDocs,
|
|
8
|
-
addDoc,
|
|
9
|
-
updateDoc,
|
|
10
|
-
query,
|
|
11
|
-
where,
|
|
12
|
-
arrayUnion,
|
|
13
|
-
arrayRemove,
|
|
14
|
-
} from "firebase/firestore";
|
|
15
|
-
import { DEFAULT_CERTIFICATION_REQUIREMENT } from "../../../backoffice/constants/certification.constants";
|
|
16
|
-
import { ProductService } from "../product.service";
|
|
17
|
-
import { Product } from "../../types/product.types";
|
|
18
|
-
import { RequirementType, TimeUnit } from "../../types/requirement.types";
|
|
19
|
-
import {
|
|
20
|
-
CertificationLevel,
|
|
21
|
-
CertificationSpecialty,
|
|
22
|
-
} from "../../types/static/certification.types";
|
|
23
|
-
import { BlockingCondition } from "../../types/static/blocking-condition.types";
|
|
24
|
-
import { Contraindication } from "../../types/static/contraindication.types";
|
|
25
|
-
import { TreatmentBenefit } from "../../types/static/treatment-benefit.types";
|
|
26
|
-
import { collectionGroup } from "firebase/firestore";
|
|
27
|
-
|
|
28
|
-
jest.mock("firebase/firestore");
|
|
29
|
-
jest.mock("../../../config/firebase", () => ({
|
|
30
|
-
getFirebaseInstance: jest.fn().mockResolvedValue({
|
|
31
|
-
db: {},
|
|
32
|
-
auth: {},
|
|
33
|
-
}),
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
// Konstante za kolekcije
|
|
37
|
-
const CATEGORIES_COLLECTION = "backoffice_categories";
|
|
38
|
-
const SUBCATEGORIES_COLLECTION = "subcategories";
|
|
39
|
-
const TECHNOLOGIES_COLLECTION = "technologies";
|
|
40
|
-
const PRODUCTS_COLLECTION = "products";
|
|
41
|
-
const BRANDS_COLLECTION = "backoffice_brands";
|
|
42
|
-
|
|
43
|
-
// Mock baze podataka
|
|
44
|
-
const mockDb = {} as any;
|
|
45
|
-
|
|
46
|
-
describe("TechnologyService", () => {
|
|
47
|
-
let service: TechnologyService;
|
|
48
|
-
const CATEGORY_ID = "test-category-id";
|
|
49
|
-
const SUBCATEGORY_ID = "test-subcategory-id";
|
|
50
|
-
|
|
51
|
-
const mockTechnology: Omit<Technology, "id" | "createdAt" | "updatedAt"> = {
|
|
52
|
-
name: "Test Technology",
|
|
53
|
-
description: "Test Description",
|
|
54
|
-
subcategoryId: SUBCATEGORY_ID,
|
|
55
|
-
isActive: true,
|
|
56
|
-
requirements: {
|
|
57
|
-
pre: [],
|
|
58
|
-
post: [],
|
|
59
|
-
},
|
|
60
|
-
blockingConditions: [],
|
|
61
|
-
contraindications: [],
|
|
62
|
-
benefits: [],
|
|
63
|
-
certificationRequirement: DEFAULT_CERTIFICATION_REQUIREMENT,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
jest.clearAllMocks();
|
|
68
|
-
service = new TechnologyService();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe("create", () => {
|
|
72
|
-
it("treba da kreira novu tehnologiju", async () => {
|
|
73
|
-
const mockDocRef = { id: "test-id" };
|
|
74
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
75
|
-
(addDoc as jest.Mock).mockResolvedValue(mockDocRef);
|
|
76
|
-
|
|
77
|
-
const result = await service.create(
|
|
78
|
-
CATEGORY_ID,
|
|
79
|
-
SUBCATEGORY_ID,
|
|
80
|
-
mockTechnology
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
expect(collection).toHaveBeenCalledWith(
|
|
84
|
-
mockDb,
|
|
85
|
-
CATEGORIES_COLLECTION,
|
|
86
|
-
CATEGORY_ID,
|
|
87
|
-
SUBCATEGORIES_COLLECTION,
|
|
88
|
-
SUBCATEGORY_ID,
|
|
89
|
-
TECHNOLOGIES_COLLECTION
|
|
90
|
-
);
|
|
91
|
-
expect(addDoc).toHaveBeenCalledWith(
|
|
92
|
-
"technologies-collection",
|
|
93
|
-
expect.objectContaining({
|
|
94
|
-
...mockTechnology,
|
|
95
|
-
createdAt: expect.any(Date),
|
|
96
|
-
updatedAt: expect.any(Date),
|
|
97
|
-
})
|
|
98
|
-
);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("getAllBySubcategoryId", () => {
|
|
103
|
-
it("treba da vrati sve aktivne tehnologije za podkategoriju", async () => {
|
|
104
|
-
const mockDocs = [
|
|
105
|
-
{
|
|
106
|
-
id: "tech-1",
|
|
107
|
-
data: () => ({
|
|
108
|
-
...mockTechnology,
|
|
109
|
-
createdAt: new Date(),
|
|
110
|
-
updatedAt: new Date(),
|
|
111
|
-
}),
|
|
112
|
-
},
|
|
113
|
-
];
|
|
114
|
-
|
|
115
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
116
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
117
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
118
|
-
(getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
|
|
119
|
-
|
|
120
|
-
const results = await service.getAllBySubcategoryId(
|
|
121
|
-
CATEGORY_ID,
|
|
122
|
-
SUBCATEGORY_ID
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
expect(collection).toHaveBeenCalledWith(
|
|
126
|
-
mockDb,
|
|
127
|
-
CATEGORIES_COLLECTION,
|
|
128
|
-
CATEGORY_ID,
|
|
129
|
-
SUBCATEGORIES_COLLECTION,
|
|
130
|
-
SUBCATEGORY_ID,
|
|
131
|
-
TECHNOLOGIES_COLLECTION
|
|
132
|
-
);
|
|
133
|
-
expect(query).toHaveBeenCalledWith(
|
|
134
|
-
"technologies-collection",
|
|
135
|
-
"where-clause"
|
|
136
|
-
);
|
|
137
|
-
expect(where).toHaveBeenCalledWith("isActive", "==", true);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("update", () => {
|
|
142
|
-
it("treba da ažurira postojeću tehnologiju", async () => {
|
|
143
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
144
|
-
const updateData = { name: "Updated Technology" };
|
|
145
|
-
|
|
146
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
147
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
148
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
149
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
150
|
-
exists: () => true,
|
|
151
|
-
id: TECHNOLOGY_ID,
|
|
152
|
-
data: () => ({
|
|
153
|
-
...mockTechnology,
|
|
154
|
-
...updateData,
|
|
155
|
-
createdAt: new Date(),
|
|
156
|
-
updatedAt: new Date(),
|
|
157
|
-
}),
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
await service.update(
|
|
161
|
-
CATEGORY_ID,
|
|
162
|
-
SUBCATEGORY_ID,
|
|
163
|
-
TECHNOLOGY_ID,
|
|
164
|
-
updateData
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
expect(collection).toHaveBeenCalledWith(
|
|
168
|
-
mockDb,
|
|
169
|
-
CATEGORIES_COLLECTION,
|
|
170
|
-
CATEGORY_ID,
|
|
171
|
-
SUBCATEGORIES_COLLECTION,
|
|
172
|
-
SUBCATEGORY_ID,
|
|
173
|
-
TECHNOLOGIES_COLLECTION
|
|
174
|
-
);
|
|
175
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
176
|
-
"doc-ref",
|
|
177
|
-
expect.objectContaining({
|
|
178
|
-
...updateData,
|
|
179
|
-
updatedAt: expect.any(Date),
|
|
180
|
-
})
|
|
181
|
-
);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
describe("addRequirement", () => {
|
|
186
|
-
it("treba da doda novi zahtev tehnologiji", async () => {
|
|
187
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
188
|
-
const mockRequirement = {
|
|
189
|
-
id: "req-1",
|
|
190
|
-
type: RequirementType.PRE,
|
|
191
|
-
name: "Test Requirement",
|
|
192
|
-
description: "Test Description",
|
|
193
|
-
timeframe: {
|
|
194
|
-
duration: 2,
|
|
195
|
-
unit: TimeUnit.HOURS,
|
|
196
|
-
notifyAt: [1, 2],
|
|
197
|
-
},
|
|
198
|
-
importance: "high" as const,
|
|
199
|
-
isActive: true,
|
|
200
|
-
createdAt: new Date(),
|
|
201
|
-
updatedAt: new Date(),
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
205
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
206
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
207
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
208
|
-
exists: () => true,
|
|
209
|
-
id: TECHNOLOGY_ID,
|
|
210
|
-
data: () => ({
|
|
211
|
-
...mockTechnology,
|
|
212
|
-
requirements: {
|
|
213
|
-
pre: [mockRequirement],
|
|
214
|
-
post: [],
|
|
215
|
-
},
|
|
216
|
-
createdAt: new Date(),
|
|
217
|
-
updatedAt: new Date(),
|
|
218
|
-
}),
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const result = await service.addRequirement(
|
|
222
|
-
CATEGORY_ID,
|
|
223
|
-
SUBCATEGORY_ID,
|
|
224
|
-
TECHNOLOGY_ID,
|
|
225
|
-
mockRequirement
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
229
|
-
"doc-ref",
|
|
230
|
-
expect.objectContaining({
|
|
231
|
-
[`requirements.${
|
|
232
|
-
mockRequirement.type === RequirementType.PRE ? "pre" : "post"
|
|
233
|
-
}`]: arrayUnion(mockRequirement),
|
|
234
|
-
updatedAt: expect.any(Date),
|
|
235
|
-
})
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
if (result) {
|
|
239
|
-
expect(result.requirements.pre).toContainEqual(mockRequirement);
|
|
240
|
-
} else {
|
|
241
|
-
fail("Technology should exist");
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
describe("removeRequirement", () => {
|
|
247
|
-
it("treba da ukloni zahtev iz tehnologije", async () => {
|
|
248
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
249
|
-
const mockRequirement = {
|
|
250
|
-
id: "req-1",
|
|
251
|
-
type: RequirementType.PRE,
|
|
252
|
-
name: "Test Requirement",
|
|
253
|
-
description: "Test Description",
|
|
254
|
-
timeframe: {
|
|
255
|
-
duration: 2,
|
|
256
|
-
unit: TimeUnit.HOURS,
|
|
257
|
-
notifyAt: [1, 2],
|
|
258
|
-
},
|
|
259
|
-
importance: "high" as const,
|
|
260
|
-
isActive: true,
|
|
261
|
-
createdAt: new Date(),
|
|
262
|
-
updatedAt: new Date(),
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
266
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
267
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
268
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
269
|
-
exists: () => true,
|
|
270
|
-
id: TECHNOLOGY_ID,
|
|
271
|
-
data: () => ({
|
|
272
|
-
...mockTechnology,
|
|
273
|
-
requirements: {
|
|
274
|
-
pre: [],
|
|
275
|
-
post: [],
|
|
276
|
-
},
|
|
277
|
-
createdAt: new Date(),
|
|
278
|
-
updatedAt: new Date(),
|
|
279
|
-
}),
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
await service.removeRequirement(
|
|
283
|
-
CATEGORY_ID,
|
|
284
|
-
SUBCATEGORY_ID,
|
|
285
|
-
TECHNOLOGY_ID,
|
|
286
|
-
mockRequirement
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
290
|
-
"doc-ref",
|
|
291
|
-
expect.objectContaining({
|
|
292
|
-
"requirements.pre": expect.not.arrayContaining([mockRequirement]),
|
|
293
|
-
updatedAt: expect.any(Date),
|
|
294
|
-
})
|
|
295
|
-
);
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
describe("getRequirements", () => {
|
|
300
|
-
it("treba da vrati sve zahteve za tehnologiju", async () => {
|
|
301
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
302
|
-
const mockRequirements = {
|
|
303
|
-
pre: [
|
|
304
|
-
{
|
|
305
|
-
id: "req-1",
|
|
306
|
-
type: RequirementType.PRE,
|
|
307
|
-
name: "Pre Requirement",
|
|
308
|
-
},
|
|
309
|
-
],
|
|
310
|
-
post: [
|
|
311
|
-
{
|
|
312
|
-
id: "req-2",
|
|
313
|
-
type: RequirementType.POST,
|
|
314
|
-
name: "Post Requirement",
|
|
315
|
-
},
|
|
316
|
-
],
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
320
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
321
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
322
|
-
exists: () => true,
|
|
323
|
-
id: TECHNOLOGY_ID,
|
|
324
|
-
data: () => ({
|
|
325
|
-
...mockTechnology,
|
|
326
|
-
requirements: mockRequirements,
|
|
327
|
-
createdAt: new Date(),
|
|
328
|
-
updatedAt: new Date(),
|
|
329
|
-
}),
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
const result = await service.getRequirements(
|
|
333
|
-
CATEGORY_ID,
|
|
334
|
-
SUBCATEGORY_ID,
|
|
335
|
-
TECHNOLOGY_ID
|
|
336
|
-
);
|
|
337
|
-
|
|
338
|
-
expect(result).toHaveLength(2);
|
|
339
|
-
expect(result).toEqual([
|
|
340
|
-
...mockRequirements.pre,
|
|
341
|
-
...mockRequirements.post,
|
|
342
|
-
]);
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
it("treba da vrati zahteve filtirane po tipu", async () => {
|
|
346
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
347
|
-
const mockRequirements = {
|
|
348
|
-
pre: [
|
|
349
|
-
{
|
|
350
|
-
id: "req-1",
|
|
351
|
-
type: RequirementType.PRE,
|
|
352
|
-
name: "Pre Requirement",
|
|
353
|
-
},
|
|
354
|
-
],
|
|
355
|
-
post: [
|
|
356
|
-
{
|
|
357
|
-
id: "req-2",
|
|
358
|
-
type: RequirementType.POST,
|
|
359
|
-
name: "Post Requirement",
|
|
360
|
-
},
|
|
361
|
-
],
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
365
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
366
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
367
|
-
exists: () => true,
|
|
368
|
-
id: TECHNOLOGY_ID,
|
|
369
|
-
data: () => ({
|
|
370
|
-
...mockTechnology,
|
|
371
|
-
requirements: mockRequirements,
|
|
372
|
-
createdAt: new Date(),
|
|
373
|
-
updatedAt: new Date(),
|
|
374
|
-
}),
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
const result = await service.getRequirements(
|
|
378
|
-
CATEGORY_ID,
|
|
379
|
-
SUBCATEGORY_ID,
|
|
380
|
-
TECHNOLOGY_ID,
|
|
381
|
-
RequirementType.PRE
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
expect(result).toHaveLength(1);
|
|
385
|
-
expect(result).toEqual(mockRequirements.pre);
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
describe("getBlockingConditions", () => {
|
|
390
|
-
it("treba da vrati sve blokirajuće uslove za tehnologiju", async () => {
|
|
391
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
392
|
-
const mockBlockingConditions = [
|
|
393
|
-
BlockingCondition.PREGNANCY,
|
|
394
|
-
BlockingCondition.BREASTFEEDING,
|
|
395
|
-
];
|
|
396
|
-
|
|
397
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
398
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
399
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
400
|
-
exists: () => true,
|
|
401
|
-
id: TECHNOLOGY_ID,
|
|
402
|
-
data: () => ({
|
|
403
|
-
...mockTechnology,
|
|
404
|
-
blockingConditions: mockBlockingConditions,
|
|
405
|
-
createdAt: new Date(),
|
|
406
|
-
updatedAt: new Date(),
|
|
407
|
-
}),
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
const result = await service.getBlockingConditions(
|
|
411
|
-
CATEGORY_ID,
|
|
412
|
-
SUBCATEGORY_ID,
|
|
413
|
-
TECHNOLOGY_ID
|
|
414
|
-
);
|
|
415
|
-
|
|
416
|
-
expect(result).toEqual(mockBlockingConditions);
|
|
417
|
-
});
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
describe("getContraindications", () => {
|
|
421
|
-
it("treba da vrati sve kontraindikacije za tehnologiju", async () => {
|
|
422
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
423
|
-
const mockContraindications = [
|
|
424
|
-
Contraindication.SENSITIVE_SKIN,
|
|
425
|
-
Contraindication.RECENT_TANNING,
|
|
426
|
-
];
|
|
427
|
-
|
|
428
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
429
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
430
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
431
|
-
exists: () => true,
|
|
432
|
-
id: TECHNOLOGY_ID,
|
|
433
|
-
data: () => ({
|
|
434
|
-
...mockTechnology,
|
|
435
|
-
contraindications: mockContraindications,
|
|
436
|
-
createdAt: new Date(),
|
|
437
|
-
updatedAt: new Date(),
|
|
438
|
-
}),
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
const result = await service.getContraindications(
|
|
442
|
-
CATEGORY_ID,
|
|
443
|
-
SUBCATEGORY_ID,
|
|
444
|
-
TECHNOLOGY_ID
|
|
445
|
-
);
|
|
446
|
-
|
|
447
|
-
expect(result).toEqual(mockContraindications);
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
describe("getBenefits", () => {
|
|
452
|
-
it("treba da vrati sve benefite za tehnologiju", async () => {
|
|
453
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
454
|
-
const mockBenefits = [
|
|
455
|
-
TreatmentBenefit.WRINKLE_REDUCTION,
|
|
456
|
-
TreatmentBenefit.SKIN_TIGHTENING,
|
|
457
|
-
];
|
|
458
|
-
|
|
459
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
460
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
461
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
462
|
-
exists: () => true,
|
|
463
|
-
id: TECHNOLOGY_ID,
|
|
464
|
-
data: () => ({
|
|
465
|
-
...mockTechnology,
|
|
466
|
-
benefits: mockBenefits,
|
|
467
|
-
createdAt: new Date(),
|
|
468
|
-
updatedAt: new Date(),
|
|
469
|
-
}),
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
const result = await service.getBenefits(
|
|
473
|
-
CATEGORY_ID,
|
|
474
|
-
SUBCATEGORY_ID,
|
|
475
|
-
TECHNOLOGY_ID
|
|
476
|
-
);
|
|
477
|
-
|
|
478
|
-
expect(result).toEqual(mockBenefits);
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
describe("updateCertificationRequirement", () => {
|
|
483
|
-
it("treba da ažurira zahteve sertifikacije za tehnologiju", async () => {
|
|
484
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
485
|
-
const newCertificationRequirement = {
|
|
486
|
-
minimumLevel: CertificationLevel.SPECIALIST,
|
|
487
|
-
requiredSpecialties: [
|
|
488
|
-
CertificationSpecialty.LASER,
|
|
489
|
-
CertificationSpecialty.INJECTABLES,
|
|
490
|
-
],
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
494
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
495
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
496
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
497
|
-
exists: () => true,
|
|
498
|
-
id: TECHNOLOGY_ID,
|
|
499
|
-
data: () => ({
|
|
500
|
-
...mockTechnology,
|
|
501
|
-
certificationRequirement: newCertificationRequirement,
|
|
502
|
-
createdAt: new Date(),
|
|
503
|
-
updatedAt: new Date(),
|
|
504
|
-
}),
|
|
505
|
-
});
|
|
506
|
-
|
|
507
|
-
const result = await service.updateCertificationRequirement(
|
|
508
|
-
CATEGORY_ID,
|
|
509
|
-
SUBCATEGORY_ID,
|
|
510
|
-
TECHNOLOGY_ID,
|
|
511
|
-
newCertificationRequirement
|
|
512
|
-
);
|
|
513
|
-
|
|
514
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
515
|
-
"doc-ref",
|
|
516
|
-
expect.objectContaining({
|
|
517
|
-
certificationRequirement: newCertificationRequirement,
|
|
518
|
-
updatedAt: expect.any(Date),
|
|
519
|
-
})
|
|
520
|
-
);
|
|
521
|
-
|
|
522
|
-
if (result) {
|
|
523
|
-
expect(result.certificationRequirement).toEqual(
|
|
524
|
-
newCertificationRequirement
|
|
525
|
-
);
|
|
526
|
-
} else {
|
|
527
|
-
fail("Technology should exist");
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
describe("getCertificationRequirement", () => {
|
|
533
|
-
it("treba da vrati zahteve sertifikacije za tehnologiju", async () => {
|
|
534
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
535
|
-
|
|
536
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
537
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
538
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
539
|
-
exists: () => true,
|
|
540
|
-
id: TECHNOLOGY_ID,
|
|
541
|
-
data: () => ({
|
|
542
|
-
...mockTechnology,
|
|
543
|
-
createdAt: new Date(),
|
|
544
|
-
updatedAt: new Date(),
|
|
545
|
-
}),
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
const result = await service.getCertificationRequirement(
|
|
549
|
-
CATEGORY_ID,
|
|
550
|
-
SUBCATEGORY_ID,
|
|
551
|
-
TECHNOLOGY_ID
|
|
552
|
-
);
|
|
553
|
-
|
|
554
|
-
expect(result).toEqual(DEFAULT_CERTIFICATION_REQUIREMENT);
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
it("treba da vrati null ako tehnologija ne postoji", async () => {
|
|
558
|
-
const TECHNOLOGY_ID = "non-existent-id";
|
|
559
|
-
|
|
560
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
561
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
562
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
563
|
-
exists: () => false,
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
const result = await service.getCertificationRequirement(
|
|
567
|
-
CATEGORY_ID,
|
|
568
|
-
SUBCATEGORY_ID,
|
|
569
|
-
TECHNOLOGY_ID
|
|
570
|
-
);
|
|
571
|
-
|
|
572
|
-
expect(result).toBeNull();
|
|
573
|
-
});
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
describe("delete", () => {
|
|
577
|
-
it("treba da izvrši soft delete tehnologije", async () => {
|
|
578
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
579
|
-
|
|
580
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
581
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
582
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
583
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
584
|
-
exists: () => true,
|
|
585
|
-
id: TECHNOLOGY_ID,
|
|
586
|
-
data: () => ({
|
|
587
|
-
...mockTechnology,
|
|
588
|
-
isActive: false,
|
|
589
|
-
createdAt: new Date(),
|
|
590
|
-
updatedAt: new Date(),
|
|
591
|
-
}),
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
await service.delete(CATEGORY_ID, SUBCATEGORY_ID, TECHNOLOGY_ID);
|
|
595
|
-
|
|
596
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
597
|
-
"doc-ref",
|
|
598
|
-
expect.objectContaining({
|
|
599
|
-
isActive: false,
|
|
600
|
-
updatedAt: expect.any(Date),
|
|
601
|
-
})
|
|
602
|
-
);
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
|
|
606
|
-
describe("getById", () => {
|
|
607
|
-
it("treba da vrati tehnologiju po ID-u", async () => {
|
|
608
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
609
|
-
|
|
610
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
611
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
612
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
613
|
-
exists: () => true,
|
|
614
|
-
id: TECHNOLOGY_ID,
|
|
615
|
-
data: () => ({
|
|
616
|
-
...mockTechnology,
|
|
617
|
-
createdAt: new Date(),
|
|
618
|
-
updatedAt: new Date(),
|
|
619
|
-
}),
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
const result = await service.getById(
|
|
623
|
-
CATEGORY_ID,
|
|
624
|
-
SUBCATEGORY_ID,
|
|
625
|
-
TECHNOLOGY_ID
|
|
626
|
-
);
|
|
627
|
-
|
|
628
|
-
expect(result).toBeDefined();
|
|
629
|
-
expect(result?.id).toBe(TECHNOLOGY_ID);
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
it("treba da vrati null ako tehnologija ne postoji", async () => {
|
|
633
|
-
const TECHNOLOGY_ID = "non-existent-id";
|
|
634
|
-
|
|
635
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
636
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
637
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
638
|
-
exists: () => false,
|
|
639
|
-
});
|
|
640
|
-
|
|
641
|
-
const result = await service.getById(
|
|
642
|
-
CATEGORY_ID,
|
|
643
|
-
SUBCATEGORY_ID,
|
|
644
|
-
TECHNOLOGY_ID
|
|
645
|
-
);
|
|
646
|
-
|
|
647
|
-
expect(result).toBeNull();
|
|
648
|
-
});
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
describe("updateRequirement", () => {
|
|
652
|
-
it("treba da ažurira postojeći zahtev", async () => {
|
|
653
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
654
|
-
const baseRequirement = {
|
|
655
|
-
id: "req-1",
|
|
656
|
-
type: RequirementType.PRE,
|
|
657
|
-
name: "Test Requirement",
|
|
658
|
-
description: "Test Description",
|
|
659
|
-
timeframe: {
|
|
660
|
-
duration: 2,
|
|
661
|
-
unit: TimeUnit.HOURS,
|
|
662
|
-
notifyAt: [1, 2],
|
|
663
|
-
},
|
|
664
|
-
importance: "high" as const,
|
|
665
|
-
isActive: true,
|
|
666
|
-
createdAt: new Date(),
|
|
667
|
-
updatedAt: new Date(),
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
const oldRequirement = {
|
|
671
|
-
...baseRequirement,
|
|
672
|
-
name: "Old Name",
|
|
673
|
-
};
|
|
674
|
-
const newRequirement = {
|
|
675
|
-
...baseRequirement,
|
|
676
|
-
name: "New Name",
|
|
677
|
-
};
|
|
678
|
-
|
|
679
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
680
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
681
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
682
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
683
|
-
exists: () => true,
|
|
684
|
-
id: TECHNOLOGY_ID,
|
|
685
|
-
data: () => ({
|
|
686
|
-
...mockTechnology,
|
|
687
|
-
requirements: {
|
|
688
|
-
pre: [newRequirement],
|
|
689
|
-
post: [],
|
|
690
|
-
},
|
|
691
|
-
createdAt: new Date(),
|
|
692
|
-
updatedAt: new Date(),
|
|
693
|
-
}),
|
|
694
|
-
});
|
|
695
|
-
|
|
696
|
-
const result = await service.updateRequirement(
|
|
697
|
-
CATEGORY_ID,
|
|
698
|
-
SUBCATEGORY_ID,
|
|
699
|
-
TECHNOLOGY_ID,
|
|
700
|
-
oldRequirement,
|
|
701
|
-
newRequirement
|
|
702
|
-
);
|
|
703
|
-
|
|
704
|
-
expect(updateDoc).toHaveBeenCalledTimes(2); // Jednom za remove, jednom za add
|
|
705
|
-
if (result) {
|
|
706
|
-
expect(result.requirements.pre).toContainEqual(newRequirement);
|
|
707
|
-
expect(result.requirements.pre).not.toContainEqual(oldRequirement);
|
|
708
|
-
} else {
|
|
709
|
-
fail("Technology should exist");
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
describe("addBlockingCondition", () => {
|
|
715
|
-
it("treba da doda blokirajući uslov tehnologiji", async () => {
|
|
716
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
717
|
-
const condition = BlockingCondition.PREGNANCY;
|
|
718
|
-
|
|
719
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
720
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
721
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
722
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
723
|
-
exists: () => true,
|
|
724
|
-
id: TECHNOLOGY_ID,
|
|
725
|
-
data: () => ({
|
|
726
|
-
...mockTechnology,
|
|
727
|
-
blockingConditions: [condition],
|
|
728
|
-
createdAt: new Date(),
|
|
729
|
-
updatedAt: new Date(),
|
|
730
|
-
}),
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
const result = await service.addBlockingCondition(
|
|
734
|
-
CATEGORY_ID,
|
|
735
|
-
SUBCATEGORY_ID,
|
|
736
|
-
TECHNOLOGY_ID,
|
|
737
|
-
condition
|
|
738
|
-
);
|
|
739
|
-
|
|
740
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
741
|
-
"doc-ref",
|
|
742
|
-
expect.objectContaining({
|
|
743
|
-
blockingConditions: arrayUnion(condition),
|
|
744
|
-
updatedAt: expect.any(Date),
|
|
745
|
-
})
|
|
746
|
-
);
|
|
747
|
-
if (result) {
|
|
748
|
-
expect(result.blockingConditions).toContain(condition);
|
|
749
|
-
} else {
|
|
750
|
-
fail("Technology should exist");
|
|
751
|
-
}
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
|
|
755
|
-
describe("removeBlockingCondition", () => {
|
|
756
|
-
it("treba da ukloni blokirajući uslov iz tehnologije", async () => {
|
|
757
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
758
|
-
const condition = BlockingCondition.PREGNANCY;
|
|
759
|
-
|
|
760
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
761
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
762
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
763
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
764
|
-
exists: () => true,
|
|
765
|
-
id: TECHNOLOGY_ID,
|
|
766
|
-
data: () => ({
|
|
767
|
-
...mockTechnology,
|
|
768
|
-
blockingConditions: [],
|
|
769
|
-
createdAt: new Date(),
|
|
770
|
-
updatedAt: new Date(),
|
|
771
|
-
}),
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
const result = await service.removeBlockingCondition(
|
|
775
|
-
CATEGORY_ID,
|
|
776
|
-
SUBCATEGORY_ID,
|
|
777
|
-
TECHNOLOGY_ID,
|
|
778
|
-
condition
|
|
779
|
-
);
|
|
780
|
-
|
|
781
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
782
|
-
"doc-ref",
|
|
783
|
-
expect.objectContaining({
|
|
784
|
-
blockingConditions: arrayRemove(condition),
|
|
785
|
-
updatedAt: expect.any(Date),
|
|
786
|
-
})
|
|
787
|
-
);
|
|
788
|
-
if (result) {
|
|
789
|
-
expect(result.blockingConditions).not.toContain(condition);
|
|
790
|
-
} else {
|
|
791
|
-
fail("Technology should exist");
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
describe("addContraindication", () => {
|
|
797
|
-
it("treba da doda kontraindikaciju tehnologiji", async () => {
|
|
798
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
799
|
-
const contraindication = Contraindication.SENSITIVE_SKIN;
|
|
800
|
-
|
|
801
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
802
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
803
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
804
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
805
|
-
exists: () => true,
|
|
806
|
-
id: TECHNOLOGY_ID,
|
|
807
|
-
data: () => ({
|
|
808
|
-
...mockTechnology,
|
|
809
|
-
contraindications: [contraindication],
|
|
810
|
-
createdAt: new Date(),
|
|
811
|
-
updatedAt: new Date(),
|
|
812
|
-
}),
|
|
813
|
-
});
|
|
814
|
-
|
|
815
|
-
const result = await service.addContraindication(
|
|
816
|
-
CATEGORY_ID,
|
|
817
|
-
SUBCATEGORY_ID,
|
|
818
|
-
TECHNOLOGY_ID,
|
|
819
|
-
contraindication
|
|
820
|
-
);
|
|
821
|
-
|
|
822
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
823
|
-
"doc-ref",
|
|
824
|
-
expect.objectContaining({
|
|
825
|
-
contraindications: arrayUnion(contraindication),
|
|
826
|
-
updatedAt: expect.any(Date),
|
|
827
|
-
})
|
|
828
|
-
);
|
|
829
|
-
if (result) {
|
|
830
|
-
expect(result.contraindications).toContain(contraindication);
|
|
831
|
-
} else {
|
|
832
|
-
fail("Technology should exist");
|
|
833
|
-
}
|
|
834
|
-
});
|
|
835
|
-
});
|
|
836
|
-
|
|
837
|
-
describe("removeContraindication", () => {
|
|
838
|
-
it("treba da ukloni kontraindikaciju iz tehnologije", async () => {
|
|
839
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
840
|
-
const contraindication = Contraindication.SENSITIVE_SKIN;
|
|
841
|
-
|
|
842
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
843
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
844
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
845
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
846
|
-
exists: () => true,
|
|
847
|
-
id: TECHNOLOGY_ID,
|
|
848
|
-
data: () => ({
|
|
849
|
-
...mockTechnology,
|
|
850
|
-
contraindications: [],
|
|
851
|
-
createdAt: new Date(),
|
|
852
|
-
updatedAt: new Date(),
|
|
853
|
-
}),
|
|
854
|
-
});
|
|
855
|
-
|
|
856
|
-
const result = await service.removeContraindication(
|
|
857
|
-
CATEGORY_ID,
|
|
858
|
-
SUBCATEGORY_ID,
|
|
859
|
-
TECHNOLOGY_ID,
|
|
860
|
-
contraindication
|
|
861
|
-
);
|
|
862
|
-
|
|
863
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
864
|
-
"doc-ref",
|
|
865
|
-
expect.objectContaining({
|
|
866
|
-
contraindications: arrayRemove(contraindication),
|
|
867
|
-
updatedAt: expect.any(Date),
|
|
868
|
-
})
|
|
869
|
-
);
|
|
870
|
-
if (result) {
|
|
871
|
-
expect(result.contraindications).not.toContain(contraindication);
|
|
872
|
-
} else {
|
|
873
|
-
fail("Technology should exist");
|
|
874
|
-
}
|
|
875
|
-
});
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
describe("addBenefit", () => {
|
|
879
|
-
it("treba da doda benefit tehnologiji", async () => {
|
|
880
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
881
|
-
const benefit = TreatmentBenefit.WRINKLE_REDUCTION;
|
|
882
|
-
|
|
883
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
884
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
885
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
886
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
887
|
-
exists: () => true,
|
|
888
|
-
id: TECHNOLOGY_ID,
|
|
889
|
-
data: () => ({
|
|
890
|
-
...mockTechnology,
|
|
891
|
-
benefits: [benefit],
|
|
892
|
-
createdAt: new Date(),
|
|
893
|
-
updatedAt: new Date(),
|
|
894
|
-
}),
|
|
895
|
-
});
|
|
896
|
-
|
|
897
|
-
const result = await service.addBenefit(
|
|
898
|
-
CATEGORY_ID,
|
|
899
|
-
SUBCATEGORY_ID,
|
|
900
|
-
TECHNOLOGY_ID,
|
|
901
|
-
benefit
|
|
902
|
-
);
|
|
903
|
-
|
|
904
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
905
|
-
"doc-ref",
|
|
906
|
-
expect.objectContaining({
|
|
907
|
-
benefits: arrayUnion(benefit),
|
|
908
|
-
updatedAt: expect.any(Date),
|
|
909
|
-
})
|
|
910
|
-
);
|
|
911
|
-
if (result) {
|
|
912
|
-
expect(result.benefits).toContain(benefit);
|
|
913
|
-
} else {
|
|
914
|
-
fail("Technology should exist");
|
|
915
|
-
}
|
|
916
|
-
});
|
|
917
|
-
});
|
|
918
|
-
|
|
919
|
-
describe("removeBenefit", () => {
|
|
920
|
-
it("treba da ukloni benefit iz tehnologije", async () => {
|
|
921
|
-
const TECHNOLOGY_ID = "test-tech-id";
|
|
922
|
-
const benefit = TreatmentBenefit.WRINKLE_REDUCTION;
|
|
923
|
-
|
|
924
|
-
(collection as jest.Mock).mockReturnValue("technologies-collection");
|
|
925
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
926
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
927
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
928
|
-
exists: () => true,
|
|
929
|
-
id: TECHNOLOGY_ID,
|
|
930
|
-
data: () => ({
|
|
931
|
-
...mockTechnology,
|
|
932
|
-
benefits: [],
|
|
933
|
-
createdAt: new Date(),
|
|
934
|
-
updatedAt: new Date(),
|
|
935
|
-
}),
|
|
936
|
-
});
|
|
937
|
-
|
|
938
|
-
const result = await service.removeBenefit(
|
|
939
|
-
CATEGORY_ID,
|
|
940
|
-
SUBCATEGORY_ID,
|
|
941
|
-
TECHNOLOGY_ID,
|
|
942
|
-
benefit
|
|
943
|
-
);
|
|
944
|
-
|
|
945
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
946
|
-
"doc-ref",
|
|
947
|
-
expect.objectContaining({
|
|
948
|
-
benefits: arrayRemove(benefit),
|
|
949
|
-
updatedAt: expect.any(Date),
|
|
950
|
-
})
|
|
951
|
-
);
|
|
952
|
-
if (result) {
|
|
953
|
-
expect(result.benefits).not.toContain(benefit);
|
|
954
|
-
} else {
|
|
955
|
-
fail("Technology should exist");
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
});
|
|
959
|
-
});
|
|
960
|
-
|
|
961
|
-
describe("ProductService", () => {
|
|
962
|
-
let service: ProductService;
|
|
963
|
-
const CATEGORY_ID = "test-category-id";
|
|
964
|
-
const SUBCATEGORY_ID = "test-subcategory-id";
|
|
965
|
-
const TECHNOLOGY_ID = "test-technology-id";
|
|
966
|
-
const BRAND_ID = "test-brand-id";
|
|
967
|
-
|
|
968
|
-
const mockProduct: Omit<
|
|
969
|
-
Product,
|
|
970
|
-
"id" | "createdAt" | "updatedAt" | "brandId" | "technologyId"
|
|
971
|
-
> = {
|
|
972
|
-
name: "Test Product",
|
|
973
|
-
description: "Test Description",
|
|
974
|
-
isActive: true,
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
beforeEach(() => {
|
|
978
|
-
jest.clearAllMocks();
|
|
979
|
-
service = new ProductService();
|
|
980
|
-
});
|
|
981
|
-
|
|
982
|
-
describe("create", () => {
|
|
983
|
-
it("treba da kreira novi proizvod u obe kolekcije", async () => {
|
|
984
|
-
const mockDocRef = { id: "test-id" };
|
|
985
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
986
|
-
(addDoc as jest.Mock).mockResolvedValue(mockDocRef);
|
|
987
|
-
|
|
988
|
-
const result = await service.create(
|
|
989
|
-
CATEGORY_ID,
|
|
990
|
-
SUBCATEGORY_ID,
|
|
991
|
-
TECHNOLOGY_ID,
|
|
992
|
-
BRAND_ID,
|
|
993
|
-
mockProduct
|
|
994
|
-
);
|
|
995
|
-
|
|
996
|
-
// Provera kreiranja u technology kolekciji
|
|
997
|
-
expect(collection).toHaveBeenCalledWith(
|
|
998
|
-
mockDb,
|
|
999
|
-
CATEGORIES_COLLECTION,
|
|
1000
|
-
CATEGORY_ID,
|
|
1001
|
-
SUBCATEGORIES_COLLECTION,
|
|
1002
|
-
SUBCATEGORY_ID,
|
|
1003
|
-
TECHNOLOGIES_COLLECTION,
|
|
1004
|
-
TECHNOLOGY_ID,
|
|
1005
|
-
PRODUCTS_COLLECTION
|
|
1006
|
-
);
|
|
1007
|
-
|
|
1008
|
-
// Provera kreiranja u brand kolekciji
|
|
1009
|
-
expect(collection).toHaveBeenCalledWith(
|
|
1010
|
-
mockDb,
|
|
1011
|
-
BRANDS_COLLECTION,
|
|
1012
|
-
BRAND_ID,
|
|
1013
|
-
PRODUCTS_COLLECTION
|
|
1014
|
-
);
|
|
1015
|
-
|
|
1016
|
-
expect(addDoc).toHaveBeenCalledTimes(2);
|
|
1017
|
-
});
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
|
-
describe("getAllByTechnology", () => {
|
|
1021
|
-
it("treba da vrati sve aktivne proizvode za tehnologiju", async () => {
|
|
1022
|
-
const mockDocs = [
|
|
1023
|
-
{
|
|
1024
|
-
id: "prod-1",
|
|
1025
|
-
data: () => ({
|
|
1026
|
-
...mockProduct,
|
|
1027
|
-
brandId: BRAND_ID,
|
|
1028
|
-
technologyId: TECHNOLOGY_ID,
|
|
1029
|
-
createdAt: new Date(),
|
|
1030
|
-
updatedAt: new Date(),
|
|
1031
|
-
}),
|
|
1032
|
-
},
|
|
1033
|
-
];
|
|
1034
|
-
|
|
1035
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
1036
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
1037
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
1038
|
-
(getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
|
|
1039
|
-
|
|
1040
|
-
const results = await service.getAllByTechnology(
|
|
1041
|
-
CATEGORY_ID,
|
|
1042
|
-
SUBCATEGORY_ID,
|
|
1043
|
-
TECHNOLOGY_ID
|
|
1044
|
-
);
|
|
1045
|
-
|
|
1046
|
-
expect(collection).toHaveBeenCalledWith(
|
|
1047
|
-
mockDb,
|
|
1048
|
-
CATEGORIES_COLLECTION,
|
|
1049
|
-
CATEGORY_ID,
|
|
1050
|
-
SUBCATEGORIES_COLLECTION,
|
|
1051
|
-
SUBCATEGORY_ID,
|
|
1052
|
-
TECHNOLOGIES_COLLECTION,
|
|
1053
|
-
TECHNOLOGY_ID,
|
|
1054
|
-
PRODUCTS_COLLECTION
|
|
1055
|
-
);
|
|
1056
|
-
expect(query).toHaveBeenCalledWith("collection-ref", "where-clause");
|
|
1057
|
-
expect(where).toHaveBeenCalledWith("isActive", "==", true);
|
|
1058
|
-
});
|
|
1059
|
-
});
|
|
1060
|
-
|
|
1061
|
-
describe("getAllByBrand", () => {
|
|
1062
|
-
it("treba da vrati sve aktivne proizvode za brend", async () => {
|
|
1063
|
-
const mockDocs = [
|
|
1064
|
-
{
|
|
1065
|
-
id: "prod-1",
|
|
1066
|
-
data: () => ({
|
|
1067
|
-
...mockProduct,
|
|
1068
|
-
brandId: BRAND_ID,
|
|
1069
|
-
technologyId: TECHNOLOGY_ID,
|
|
1070
|
-
categoryId: CATEGORY_ID,
|
|
1071
|
-
subcategoryId: SUBCATEGORY_ID,
|
|
1072
|
-
createdAt: new Date(),
|
|
1073
|
-
updatedAt: new Date(),
|
|
1074
|
-
}),
|
|
1075
|
-
},
|
|
1076
|
-
];
|
|
1077
|
-
|
|
1078
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
1079
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
1080
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
1081
|
-
(getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
|
|
1082
|
-
|
|
1083
|
-
const results = await service.getAllByBrand(BRAND_ID);
|
|
1084
|
-
|
|
1085
|
-
expect(collection).toHaveBeenCalledWith(
|
|
1086
|
-
mockDb,
|
|
1087
|
-
BRANDS_COLLECTION,
|
|
1088
|
-
BRAND_ID,
|
|
1089
|
-
PRODUCTS_COLLECTION
|
|
1090
|
-
);
|
|
1091
|
-
expect(query).toHaveBeenCalledWith("collection-ref", "where-clause");
|
|
1092
|
-
expect(where).toHaveBeenCalledWith("isActive", "==", true);
|
|
1093
|
-
});
|
|
1094
|
-
});
|
|
1095
|
-
|
|
1096
|
-
// Nastavak u sledećem delu...
|
|
1097
|
-
});
|