@blackcode_sa/metaestetics-api 1.11.3 → 1.12.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 +378 -334
- package/dist/admin/index.d.ts +378 -334
- package/dist/backoffice/index.d.mts +1198 -430
- package/dist/backoffice/index.d.ts +1198 -430
- package/dist/backoffice/index.js +1128 -245
- package/dist/backoffice/index.mjs +1119 -209
- package/dist/index.d.mts +4478 -4031
- package/dist/index.d.ts +4478 -4031
- package/dist/index.js +1974 -757
- package/dist/index.mjs +1735 -490
- package/package.json +1 -1
- package/src/backoffice/expo-safe/index.ts +4 -0
- package/src/backoffice/services/README.md +40 -0
- package/src/backoffice/services/brand.service.ts +85 -6
- package/src/backoffice/services/category.service.ts +92 -10
- package/src/backoffice/services/constants.service.ts +308 -0
- package/src/backoffice/services/documentation-template.service.ts +56 -2
- package/src/backoffice/services/index.ts +1 -0
- package/src/backoffice/services/product.service.ts +126 -5
- package/src/backoffice/services/requirement.service.ts +13 -0
- package/src/backoffice/services/subcategory.service.ts +184 -13
- package/src/backoffice/services/technology.service.ts +344 -129
- package/src/backoffice/types/admin-constants.types.ts +69 -0
- package/src/backoffice/types/brand.types.ts +1 -0
- package/src/backoffice/types/index.ts +2 -0
- package/src/backoffice/types/procedure-product.types.ts +38 -0
- package/src/backoffice/types/product.types.ts +31 -4
- package/src/backoffice/types/static/contraindication.types.ts +1 -0
- package/src/backoffice/types/static/treatment-benefit.types.ts +1 -0
- package/src/backoffice/types/technology.types.ts +113 -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/base.service.ts +10 -3
- package/src/services/documentation-templates/documentation-template.service.ts +116 -0
- package/src/services/media/media.service.ts +2 -2
- package/src/services/practitioner/practitioner.service.ts +201 -83
- package/src/services/procedure/README.md +76 -1
- package/src/services/procedure/procedure.service.ts +538 -235
- package/src/types/appointment/index.ts +2 -3
- package/src/types/clinic/index.ts +1 -6
- package/src/types/patient/medical-info.types.ts +3 -3
- package/src/types/procedure/index.ts +39 -20
- package/src/validations/clinic.schema.ts +1 -6
- package/src/validations/patient/medical-info.schema.ts +7 -2
- package/src/validations/procedure-product.schema.ts +41 -0
- package/src/validations/procedure.schema.ts +59 -8
- 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,201 +0,0 @@
|
|
|
1
|
-
import { CategoryService } from "../category.service";
|
|
2
|
-
import { Category } from "../../types/category.types";
|
|
3
|
-
import { ProcedureFamily } from "../../types/static/procedure-family.types";
|
|
4
|
-
import {
|
|
5
|
-
collection,
|
|
6
|
-
doc,
|
|
7
|
-
getDoc,
|
|
8
|
-
getDocs,
|
|
9
|
-
addDoc,
|
|
10
|
-
updateDoc,
|
|
11
|
-
query,
|
|
12
|
-
where,
|
|
13
|
-
} from "firebase/firestore";
|
|
14
|
-
|
|
15
|
-
// Mock Firebase
|
|
16
|
-
jest.mock("firebase/firestore");
|
|
17
|
-
jest.mock("../../../config/firebase", () => ({
|
|
18
|
-
getFirebaseInstance: jest.fn().mockResolvedValue({
|
|
19
|
-
db: {},
|
|
20
|
-
auth: {},
|
|
21
|
-
}),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
const COLLECTION = "backoffice_categories";
|
|
25
|
-
|
|
26
|
-
describe("CategoryService", () => {
|
|
27
|
-
let service: CategoryService;
|
|
28
|
-
|
|
29
|
-
const mockCategory: Omit<Category, "id" | "createdAt" | "updatedAt"> = {
|
|
30
|
-
name: "Test Category",
|
|
31
|
-
description: "Test Description",
|
|
32
|
-
family: ProcedureFamily.AESTHETICS,
|
|
33
|
-
isActive: true,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
jest.clearAllMocks();
|
|
38
|
-
service = new CategoryService();
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("create", () => {
|
|
42
|
-
it("treba da kreira novu kategoriju", async () => {
|
|
43
|
-
const mockDocRef = { id: "test-id" };
|
|
44
|
-
(collection as jest.Mock).mockReturnValue("categories-collection");
|
|
45
|
-
(addDoc as jest.Mock).mockResolvedValue(mockDocRef);
|
|
46
|
-
|
|
47
|
-
const result = await service.create(mockCategory);
|
|
48
|
-
|
|
49
|
-
expect(collection).toHaveBeenCalledWith({}, COLLECTION);
|
|
50
|
-
expect(addDoc).toHaveBeenCalledWith(
|
|
51
|
-
"categories-collection",
|
|
52
|
-
expect.objectContaining({
|
|
53
|
-
...mockCategory,
|
|
54
|
-
createdAt: expect.any(Date),
|
|
55
|
-
updatedAt: expect.any(Date),
|
|
56
|
-
})
|
|
57
|
-
);
|
|
58
|
-
expect(result).toEqual({
|
|
59
|
-
id: "test-id",
|
|
60
|
-
...mockCategory,
|
|
61
|
-
createdAt: expect.any(Date),
|
|
62
|
-
updatedAt: expect.any(Date),
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe("getAll", () => {
|
|
68
|
-
it("treba da vrati sve aktivne kategorije", async () => {
|
|
69
|
-
const mockDocs = [
|
|
70
|
-
{
|
|
71
|
-
id: "cat-1",
|
|
72
|
-
data: () => ({
|
|
73
|
-
...mockCategory,
|
|
74
|
-
createdAt: new Date(),
|
|
75
|
-
updatedAt: new Date(),
|
|
76
|
-
}),
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
id: "cat-2",
|
|
80
|
-
data: () => ({
|
|
81
|
-
...mockCategory,
|
|
82
|
-
name: "Test Category 2",
|
|
83
|
-
createdAt: new Date(),
|
|
84
|
-
updatedAt: new Date(),
|
|
85
|
-
}),
|
|
86
|
-
},
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
(collection as jest.Mock).mockReturnValue("categories-collection");
|
|
90
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
91
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
92
|
-
(getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
|
|
93
|
-
|
|
94
|
-
const results = await service.getAll();
|
|
95
|
-
|
|
96
|
-
expect(collection).toHaveBeenCalledWith({}, COLLECTION);
|
|
97
|
-
expect(query).toHaveBeenCalledWith(
|
|
98
|
-
"categories-collection",
|
|
99
|
-
"where-clause"
|
|
100
|
-
);
|
|
101
|
-
expect(where).toHaveBeenCalledWith("isActive", "==", true);
|
|
102
|
-
expect(results).toHaveLength(2);
|
|
103
|
-
expect(results[0]).toEqual({
|
|
104
|
-
id: "cat-1",
|
|
105
|
-
...mockCategory,
|
|
106
|
-
createdAt: expect.any(Date),
|
|
107
|
-
updatedAt: expect.any(Date),
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe("getAllByFamily", () => {
|
|
113
|
-
it("treba da vrati sve kategorije za određenu familiju", async () => {
|
|
114
|
-
const mockDocs = [
|
|
115
|
-
{
|
|
116
|
-
id: "cat-1",
|
|
117
|
-
data: () => ({
|
|
118
|
-
...mockCategory,
|
|
119
|
-
family: ProcedureFamily.AESTHETICS,
|
|
120
|
-
createdAt: new Date(),
|
|
121
|
-
updatedAt: new Date(),
|
|
122
|
-
}),
|
|
123
|
-
},
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
(collection as jest.Mock).mockReturnValue("categories-collection");
|
|
127
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
128
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
129
|
-
(getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
|
|
130
|
-
|
|
131
|
-
const results = await service.getAllByFamily(ProcedureFamily.AESTHETICS);
|
|
132
|
-
|
|
133
|
-
expect(query).toHaveBeenCalledWith(
|
|
134
|
-
"categories-collection",
|
|
135
|
-
"where-clause",
|
|
136
|
-
"where-clause"
|
|
137
|
-
);
|
|
138
|
-
expect(where).toHaveBeenCalledWith(
|
|
139
|
-
"family",
|
|
140
|
-
"==",
|
|
141
|
-
ProcedureFamily.AESTHETICS
|
|
142
|
-
);
|
|
143
|
-
expect(where).toHaveBeenCalledWith("isActive", "==", true);
|
|
144
|
-
expect(results).toHaveLength(1);
|
|
145
|
-
expect(results[0].family).toBe(ProcedureFamily.AESTHETICS);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe("update", () => {
|
|
150
|
-
it("treba da ažurira postojeću kategoriju", async () => {
|
|
151
|
-
const updateData = { name: "Updated Category" };
|
|
152
|
-
|
|
153
|
-
(collection as jest.Mock).mockReturnValue("categories-collection");
|
|
154
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
155
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
156
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
157
|
-
exists: () => true,
|
|
158
|
-
id: "test-id",
|
|
159
|
-
data: () => ({
|
|
160
|
-
...mockCategory,
|
|
161
|
-
...updateData,
|
|
162
|
-
createdAt: new Date(),
|
|
163
|
-
updatedAt: new Date(),
|
|
164
|
-
}),
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
const result = await service.update("test-id", updateData);
|
|
168
|
-
|
|
169
|
-
expect(collection).toHaveBeenCalledWith({}, COLLECTION);
|
|
170
|
-
expect(doc).toHaveBeenCalledWith("categories-collection", "test-id");
|
|
171
|
-
expect(updateDoc).toHaveBeenCalledWith("doc-ref", {
|
|
172
|
-
...updateData,
|
|
173
|
-
updatedAt: expect.any(Date),
|
|
174
|
-
});
|
|
175
|
-
expect(result).toEqual({
|
|
176
|
-
id: "test-id",
|
|
177
|
-
...mockCategory,
|
|
178
|
-
...updateData,
|
|
179
|
-
createdAt: expect.any(Date),
|
|
180
|
-
updatedAt: expect.any(Date),
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
describe("delete", () => {
|
|
186
|
-
it("treba da izvrši soft delete kategorije", async () => {
|
|
187
|
-
(collection as jest.Mock).mockReturnValue("categories-collection");
|
|
188
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
189
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
190
|
-
|
|
191
|
-
await service.delete("test-id");
|
|
192
|
-
|
|
193
|
-
expect(collection).toHaveBeenCalledWith({}, COLLECTION);
|
|
194
|
-
expect(doc).toHaveBeenCalledWith("categories-collection", "test-id");
|
|
195
|
-
expect(updateDoc).toHaveBeenCalledWith("doc-ref", {
|
|
196
|
-
isActive: false,
|
|
197
|
-
updatedAt: expect.any(Date),
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
});
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import { ProductService } from "../product.service";
|
|
2
|
-
import { Product } from "../../types/product.types";
|
|
3
|
-
import {
|
|
4
|
-
collection,
|
|
5
|
-
doc,
|
|
6
|
-
getDoc,
|
|
7
|
-
getDocs,
|
|
8
|
-
addDoc,
|
|
9
|
-
updateDoc,
|
|
10
|
-
query,
|
|
11
|
-
where,
|
|
12
|
-
collectionGroup,
|
|
13
|
-
} from "firebase/firestore";
|
|
14
|
-
|
|
15
|
-
jest.mock("firebase/firestore");
|
|
16
|
-
jest.mock("../../../config/firebase", () => ({
|
|
17
|
-
getFirebaseInstance: jest.fn().mockResolvedValue({
|
|
18
|
-
db: {},
|
|
19
|
-
auth: {},
|
|
20
|
-
}),
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
// Konstante za kolekcije
|
|
24
|
-
const CATEGORIES_COLLECTION = "backoffice_categories";
|
|
25
|
-
const SUBCATEGORIES_COLLECTION = "subcategories";
|
|
26
|
-
const TECHNOLOGIES_COLLECTION = "technologies";
|
|
27
|
-
const PRODUCTS_COLLECTION = "products";
|
|
28
|
-
const BRANDS_COLLECTION = "backoffice_brands";
|
|
29
|
-
|
|
30
|
-
// Mock baze podataka
|
|
31
|
-
const mockDb = {} as any;
|
|
32
|
-
|
|
33
|
-
describe("ProductService", () => {
|
|
34
|
-
let service: ProductService;
|
|
35
|
-
const CATEGORY_ID = "test-category-id";
|
|
36
|
-
const SUBCATEGORY_ID = "test-subcategory-id";
|
|
37
|
-
const TECHNOLOGY_ID = "test-technology-id";
|
|
38
|
-
const BRAND_ID = "test-brand-id";
|
|
39
|
-
|
|
40
|
-
const mockProduct: Omit<Product, "id" | "createdAt" | "updatedAt"> = {
|
|
41
|
-
name: "Test Product",
|
|
42
|
-
description: "Test Description",
|
|
43
|
-
brandId: BRAND_ID,
|
|
44
|
-
technologyId: TECHNOLOGY_ID,
|
|
45
|
-
isActive: true,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
jest.clearAllMocks();
|
|
50
|
-
service = new ProductService();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("create", () => {
|
|
54
|
-
it("treba da kreira novi proizvod u obe kolekcije", async () => {
|
|
55
|
-
const mockDocRef = { id: "test-id" };
|
|
56
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
57
|
-
(addDoc as jest.Mock).mockResolvedValue(mockDocRef);
|
|
58
|
-
|
|
59
|
-
const result = await service.create(
|
|
60
|
-
CATEGORY_ID,
|
|
61
|
-
SUBCATEGORY_ID,
|
|
62
|
-
TECHNOLOGY_ID,
|
|
63
|
-
BRAND_ID,
|
|
64
|
-
mockProduct
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
expect(collection).toHaveBeenCalledWith(
|
|
68
|
-
mockDb,
|
|
69
|
-
CATEGORIES_COLLECTION,
|
|
70
|
-
CATEGORY_ID,
|
|
71
|
-
SUBCATEGORIES_COLLECTION,
|
|
72
|
-
SUBCATEGORY_ID,
|
|
73
|
-
TECHNOLOGIES_COLLECTION,
|
|
74
|
-
TECHNOLOGY_ID,
|
|
75
|
-
PRODUCTS_COLLECTION
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
expect(collection).toHaveBeenCalledWith(
|
|
79
|
-
mockDb,
|
|
80
|
-
BRANDS_COLLECTION,
|
|
81
|
-
BRAND_ID,
|
|
82
|
-
PRODUCTS_COLLECTION
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
expect(addDoc).toHaveBeenCalledTimes(2);
|
|
86
|
-
expect(result).toEqual(
|
|
87
|
-
expect.objectContaining({
|
|
88
|
-
id: mockDocRef.id,
|
|
89
|
-
...mockProduct,
|
|
90
|
-
createdAt: expect.any(Date),
|
|
91
|
-
updatedAt: expect.any(Date),
|
|
92
|
-
})
|
|
93
|
-
);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("update", () => {
|
|
98
|
-
it("treba da ažurira proizvod u obe kolekcije", async () => {
|
|
99
|
-
const PRODUCT_ID = "test-product-id";
|
|
100
|
-
const updateData = { name: "Updated Product" };
|
|
101
|
-
|
|
102
|
-
// Mock za technology kolekciju
|
|
103
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
104
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
105
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
106
|
-
|
|
107
|
-
// Mock za brand kolekciju (collectionGroup query)
|
|
108
|
-
(collectionGroup as jest.Mock).mockReturnValue("collection-group-ref");
|
|
109
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
110
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
111
|
-
(getDocs as jest.Mock).mockResolvedValue({
|
|
112
|
-
docs: [
|
|
113
|
-
{
|
|
114
|
-
ref: "brand-doc-ref",
|
|
115
|
-
id: PRODUCT_ID,
|
|
116
|
-
data: () => ({
|
|
117
|
-
...mockProduct,
|
|
118
|
-
...updateData,
|
|
119
|
-
createdAt: new Date(),
|
|
120
|
-
updatedAt: new Date(),
|
|
121
|
-
}),
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Mock za getById
|
|
127
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
128
|
-
exists: () => true,
|
|
129
|
-
id: PRODUCT_ID,
|
|
130
|
-
data: () => ({
|
|
131
|
-
...mockProduct,
|
|
132
|
-
...updateData,
|
|
133
|
-
createdAt: new Date(),
|
|
134
|
-
updatedAt: new Date(),
|
|
135
|
-
}),
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const result = await service.update(
|
|
139
|
-
CATEGORY_ID,
|
|
140
|
-
SUBCATEGORY_ID,
|
|
141
|
-
TECHNOLOGY_ID,
|
|
142
|
-
PRODUCT_ID,
|
|
143
|
-
updateData
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
// Provera poziva za technology kolekciju
|
|
147
|
-
expect(collection).toHaveBeenCalledWith(
|
|
148
|
-
mockDb,
|
|
149
|
-
CATEGORIES_COLLECTION,
|
|
150
|
-
CATEGORY_ID,
|
|
151
|
-
SUBCATEGORIES_COLLECTION,
|
|
152
|
-
SUBCATEGORY_ID,
|
|
153
|
-
TECHNOLOGIES_COLLECTION,
|
|
154
|
-
TECHNOLOGY_ID,
|
|
155
|
-
PRODUCTS_COLLECTION
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
// Provera poziva za brand kolekciju
|
|
159
|
-
expect(collectionGroup).toHaveBeenCalledWith(mockDb, PRODUCTS_COLLECTION);
|
|
160
|
-
expect(query).toHaveBeenCalledWith(
|
|
161
|
-
"collection-group-ref",
|
|
162
|
-
"where-clause"
|
|
163
|
-
);
|
|
164
|
-
expect(where).toHaveBeenCalledWith("id", "==", PRODUCT_ID);
|
|
165
|
-
|
|
166
|
-
expect(updateDoc).toHaveBeenCalledTimes(2);
|
|
167
|
-
expect(result).toEqual(
|
|
168
|
-
expect.objectContaining({
|
|
169
|
-
id: PRODUCT_ID,
|
|
170
|
-
...mockProduct,
|
|
171
|
-
...updateData,
|
|
172
|
-
updatedAt: expect.any(Date),
|
|
173
|
-
})
|
|
174
|
-
);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe("delete", () => {
|
|
179
|
-
it("treba da izvrši soft delete proizvoda u obe kolekcije", async () => {
|
|
180
|
-
const PRODUCT_ID = "test-product-id";
|
|
181
|
-
|
|
182
|
-
// Mock za technology kolekciju
|
|
183
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
184
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
185
|
-
(updateDoc as jest.Mock).mockResolvedValue(undefined);
|
|
186
|
-
|
|
187
|
-
// Mock za brand kolekciju (collectionGroup query)
|
|
188
|
-
(collectionGroup as jest.Mock).mockReturnValue("collection-group-ref");
|
|
189
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
190
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
191
|
-
(getDocs as jest.Mock).mockResolvedValue({
|
|
192
|
-
docs: [
|
|
193
|
-
{
|
|
194
|
-
ref: "brand-doc-ref",
|
|
195
|
-
id: PRODUCT_ID,
|
|
196
|
-
data: () => ({
|
|
197
|
-
...mockProduct,
|
|
198
|
-
isActive: false,
|
|
199
|
-
createdAt: new Date(),
|
|
200
|
-
updatedAt: new Date(),
|
|
201
|
-
}),
|
|
202
|
-
},
|
|
203
|
-
],
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// Mock za getById
|
|
207
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
208
|
-
exists: () => true,
|
|
209
|
-
id: PRODUCT_ID,
|
|
210
|
-
data: () => ({
|
|
211
|
-
...mockProduct,
|
|
212
|
-
isActive: false,
|
|
213
|
-
createdAt: new Date(),
|
|
214
|
-
updatedAt: new Date(),
|
|
215
|
-
}),
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
await service.delete(
|
|
219
|
-
CATEGORY_ID,
|
|
220
|
-
SUBCATEGORY_ID,
|
|
221
|
-
TECHNOLOGY_ID,
|
|
222
|
-
PRODUCT_ID
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
// Provera poziva za technology kolekciju
|
|
226
|
-
expect(collection).toHaveBeenCalledWith(
|
|
227
|
-
mockDb,
|
|
228
|
-
CATEGORIES_COLLECTION,
|
|
229
|
-
CATEGORY_ID,
|
|
230
|
-
SUBCATEGORIES_COLLECTION,
|
|
231
|
-
SUBCATEGORY_ID,
|
|
232
|
-
TECHNOLOGIES_COLLECTION,
|
|
233
|
-
TECHNOLOGY_ID,
|
|
234
|
-
PRODUCTS_COLLECTION
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
// Provera poziva za brand kolekciju
|
|
238
|
-
expect(collectionGroup).toHaveBeenCalledWith(mockDb, PRODUCTS_COLLECTION);
|
|
239
|
-
expect(query).toHaveBeenCalledWith(
|
|
240
|
-
"collection-group-ref",
|
|
241
|
-
"where-clause"
|
|
242
|
-
);
|
|
243
|
-
expect(where).toHaveBeenCalledWith("id", "==", PRODUCT_ID);
|
|
244
|
-
|
|
245
|
-
expect(updateDoc).toHaveBeenCalledTimes(2);
|
|
246
|
-
expect(updateDoc).toHaveBeenCalledWith(
|
|
247
|
-
"doc-ref",
|
|
248
|
-
expect.objectContaining({
|
|
249
|
-
isActive: false,
|
|
250
|
-
updatedAt: expect.any(Date),
|
|
251
|
-
})
|
|
252
|
-
);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
describe("getById", () => {
|
|
257
|
-
it("treba da vrati proizvod po ID-u", async () => {
|
|
258
|
-
const PRODUCT_ID = "test-product-id";
|
|
259
|
-
|
|
260
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
261
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
262
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
263
|
-
exists: () => true,
|
|
264
|
-
id: PRODUCT_ID,
|
|
265
|
-
data: () => ({
|
|
266
|
-
...mockProduct,
|
|
267
|
-
createdAt: new Date(),
|
|
268
|
-
updatedAt: new Date(),
|
|
269
|
-
}),
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
const result = await service.getById(
|
|
273
|
-
CATEGORY_ID,
|
|
274
|
-
SUBCATEGORY_ID,
|
|
275
|
-
TECHNOLOGY_ID,
|
|
276
|
-
PRODUCT_ID
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
expect(result).toBeDefined();
|
|
280
|
-
expect(result?.id).toBe(PRODUCT_ID);
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
it("treba da vrati null ako proizvod ne postoji", async () => {
|
|
284
|
-
const PRODUCT_ID = "non-existent-id";
|
|
285
|
-
|
|
286
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
287
|
-
(doc as jest.Mock).mockReturnValue("doc-ref");
|
|
288
|
-
(getDoc as jest.Mock).mockResolvedValue({
|
|
289
|
-
exists: () => false,
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
const result = await service.getById(
|
|
293
|
-
CATEGORY_ID,
|
|
294
|
-
SUBCATEGORY_ID,
|
|
295
|
-
TECHNOLOGY_ID,
|
|
296
|
-
PRODUCT_ID
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
expect(result).toBeNull();
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
describe("getAllByTechnology", () => {
|
|
304
|
-
it("treba da vrati sve aktivne proizvode za tehnologiju", async () => {
|
|
305
|
-
const mockDocs = [
|
|
306
|
-
{
|
|
307
|
-
id: "prod-1",
|
|
308
|
-
data: () => ({
|
|
309
|
-
...mockProduct,
|
|
310
|
-
createdAt: new Date(),
|
|
311
|
-
updatedAt: new Date(),
|
|
312
|
-
}),
|
|
313
|
-
},
|
|
314
|
-
];
|
|
315
|
-
|
|
316
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
317
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
318
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
319
|
-
(getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
|
|
320
|
-
|
|
321
|
-
const results = await service.getAllByTechnology(
|
|
322
|
-
CATEGORY_ID,
|
|
323
|
-
SUBCATEGORY_ID,
|
|
324
|
-
TECHNOLOGY_ID
|
|
325
|
-
);
|
|
326
|
-
|
|
327
|
-
expect(query).toHaveBeenCalledWith("collection-ref", "where-clause");
|
|
328
|
-
expect(where).toHaveBeenCalledWith("isActive", "==", true);
|
|
329
|
-
expect(results).toHaveLength(1);
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
describe("getAllByBrand", () => {
|
|
334
|
-
it("treba da vrati sve aktivne proizvode za brend", async () => {
|
|
335
|
-
const mockDocs = [
|
|
336
|
-
{
|
|
337
|
-
id: "prod-1",
|
|
338
|
-
data: () => ({
|
|
339
|
-
...mockProduct,
|
|
340
|
-
createdAt: new Date(),
|
|
341
|
-
updatedAt: new Date(),
|
|
342
|
-
}),
|
|
343
|
-
},
|
|
344
|
-
];
|
|
345
|
-
|
|
346
|
-
(collection as jest.Mock).mockReturnValue("collection-ref");
|
|
347
|
-
(query as jest.Mock).mockReturnValue("filtered-query");
|
|
348
|
-
(where as jest.Mock).mockReturnValue("where-clause");
|
|
349
|
-
(getDocs as jest.Mock).mockResolvedValue({ docs: mockDocs });
|
|
350
|
-
|
|
351
|
-
const results = await service.getAllByBrand(BRAND_ID);
|
|
352
|
-
|
|
353
|
-
expect(query).toHaveBeenCalledWith("collection-ref", "where-clause");
|
|
354
|
-
expect(where).toHaveBeenCalledWith("isActive", "==", true);
|
|
355
|
-
expect(results).toHaveLength(1);
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
});
|