@smess/networking 1.0.28 → 1.0.30
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/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/services/customer.service.js +1 -1
- package/dist/services/storefront.cart.service.d.ts +73 -0
- package/dist/services/storefront.cart.service.js +167 -0
- package/dist/services/storefront.cart.service.test.d.ts +1 -0
- package/dist/services/storefront.cart.service.test.js +211 -0
- package/dist/services/storefront.checkout.service.d.ts +62 -0
- package/dist/services/storefront.checkout.service.js +75 -0
- package/dist/services/storefront.checkout.service.test.d.ts +1 -0
- package/dist/services/storefront.checkout.service.test.js +158 -0
- package/dist/services/storefront.customer.metadata.service.d.ts +91 -0
- package/dist/services/storefront.customer.metadata.service.js +225 -0
- package/dist/services/storefront.customer.metadata.service.test.d.ts +1 -0
- package/dist/services/storefront.customer.metadata.service.test.js +271 -0
- package/dist/services/storefront.order.service.d.ts +45 -0
- package/dist/services/storefront.order.service.js +99 -0
- package/dist/services/storefront.order.service.test.d.ts +1 -0
- package/dist/services/storefront.order.service.test.js +158 -0
- package/dist/services/storefront.product.service.d.ts +52 -0
- package/dist/services/storefront.product.service.js +75 -0
- package/dist/services/storefront.product.service.test.d.ts +1 -0
- package/dist/services/storefront.product.service.test.js +120 -0
- package/dist/services/storefront.store.service.d.ts +52 -0
- package/dist/services/storefront.store.service.js +140 -0
- package/dist/services/storefront.store.service.test.d.ts +1 -0
- package/dist/services/storefront.store.service.test.js +90 -0
- package/dist/src/core/axios.d.ts +51 -0
- package/dist/src/core/axios.js +65 -0
- package/dist/src/core/axios.observable.d.ts +11 -0
- package/dist/src/core/axios.observable.js +58 -0
- package/dist/src/core/base.provider.advanced.test.d.ts +1 -0
- package/dist/src/core/base.provider.advanced.test.js +29 -0
- package/dist/src/core/base.provider.d.ts +15 -0
- package/dist/src/core/base.provider.js +13 -0
- package/dist/src/core/base.provider.test.d.ts +1 -0
- package/dist/src/core/base.provider.test.js +36 -0
- package/dist/src/core/base.service.wrapper.advanced.test.d.ts +1 -0
- package/dist/src/core/base.service.wrapper.advanced.test.js +39 -0
- package/dist/src/core/base.service.wrapper.d.ts +7 -0
- package/dist/src/core/base.service.wrapper.js +11 -0
- package/dist/src/core/base.service.wrapper.test.d.ts +1 -0
- package/dist/src/core/base.service.wrapper.test.js +25 -0
- package/dist/src/core/rx.http.service.d.ts +51 -0
- package/dist/src/core/rx.http.service.js +65 -0
- package/dist/src/index.d.ts +25 -0
- package/dist/src/index.js +29 -0
- package/dist/src/services/auth.service.d.ts +65 -0
- package/dist/src/services/auth.service.js +197 -0
- package/dist/src/services/auth.service.test.d.ts +1 -0
- package/dist/src/services/auth.service.test.js +334 -0
- package/dist/src/services/cache.service.d.ts +31 -0
- package/dist/src/services/cache.service.js +77 -0
- package/dist/src/services/cache.service.test.d.ts +1 -0
- package/dist/src/services/cache.service.test.js +88 -0
- package/dist/src/services/customer.service.d.ts +199 -0
- package/dist/src/services/customer.service.js +114 -0
- package/dist/src/services/customer.service.test.d.ts +1 -0
- package/dist/src/services/customer.service.test.js +430 -0
- package/dist/src/services/employee.service.d.ts +73 -0
- package/dist/src/services/employee.service.js +74 -0
- package/dist/src/services/employee.service.test.d.ts +1 -0
- package/dist/src/services/employee.service.test.js +127 -0
- package/dist/src/services/logger.service.d.ts +31 -0
- package/dist/src/services/logger.service.js +93 -0
- package/dist/src/services/logger.service.test.d.ts +1 -0
- package/dist/src/services/logger.service.test.js +31 -0
- package/dist/src/services/order.service.d.ts +73 -0
- package/dist/src/services/order.service.js +97 -0
- package/dist/src/services/order.service.test.d.ts +1 -0
- package/dist/src/services/order.service.test.js +163 -0
- package/dist/src/services/product.service.d.ts +21 -0
- package/dist/src/services/product.service.js +42 -0
- package/dist/src/services/product.service.test.d.ts +1 -0
- package/dist/src/services/product.service.test.js +61 -0
- package/dist/src/services/smess.service.d.ts +36 -0
- package/dist/src/services/smess.service.js +128 -0
- package/dist/src/services/smess.service.test.d.ts +1 -0
- package/dist/src/services/smess.service.test.js +103 -0
- package/dist/src/services/store.cart.service.d.ts +158 -0
- package/dist/src/services/store.cart.service.js +177 -0
- package/dist/src/services/store.cart.service.test.d.ts +1 -0
- package/dist/src/services/store.cart.service.test.js +394 -0
- package/dist/src/services/store.product.service.d.ts +124 -0
- package/dist/src/services/store.product.service.js +102 -0
- package/dist/src/services/store.product.service.test.d.ts +1 -0
- package/dist/src/services/store.product.service.test.js +319 -0
- package/dist/src/services/store.service.d.ts +79 -0
- package/dist/src/services/store.service.js +235 -0
- package/dist/src/services/store.service.test.d.ts +1 -0
- package/dist/src/services/store.service.test.js +274 -0
- package/dist/src/services/storefront.cart.service.d.ts +73 -0
- package/dist/src/services/storefront.cart.service.js +167 -0
- package/dist/src/services/storefront.cart.service.test.d.ts +1 -0
- package/dist/src/services/storefront.cart.service.test.js +211 -0
- package/dist/src/services/storefront.checkout.service.d.ts +62 -0
- package/dist/src/services/storefront.checkout.service.js +75 -0
- package/dist/src/services/storefront.checkout.service.test.d.ts +1 -0
- package/dist/src/services/storefront.checkout.service.test.js +158 -0
- package/dist/src/services/storefront.customer.metadata.service.d.ts +91 -0
- package/dist/src/services/storefront.customer.metadata.service.js +225 -0
- package/dist/src/services/storefront.customer.metadata.service.test.d.ts +1 -0
- package/dist/src/services/storefront.customer.metadata.service.test.js +271 -0
- package/dist/src/services/storefront.order.service.d.ts +45 -0
- package/dist/src/services/storefront.order.service.js +99 -0
- package/dist/src/services/storefront.order.service.test.d.ts +1 -0
- package/dist/src/services/storefront.order.service.test.js +158 -0
- package/dist/src/services/storefront.product.service.d.ts +52 -0
- package/dist/src/services/storefront.product.service.js +75 -0
- package/dist/src/services/storefront.product.service.test.d.ts +1 -0
- package/dist/src/services/storefront.product.service.test.js +120 -0
- package/dist/src/services/storefront.store.service.d.ts +52 -0
- package/dist/src/services/storefront.store.service.js +140 -0
- package/dist/src/services/storefront.store.service.test.d.ts +1 -0
- package/dist/src/services/storefront.store.service.test.js +90 -0
- package/dist/src/services/user.service.d.ts +16 -0
- package/dist/src/services/user.service.js +37 -0
- package/dist/src/services/user.service.test.d.ts +1 -0
- package/dist/src/services/user.service.test.js +52 -0
- package/dist/src/services/utils/withAuthReset.d.ts +3 -0
- package/dist/src/services/utils/withAuthReset.js +8 -0
- package/dist/src/types/types.d.ts +93 -0
- package/dist/src/types/types.js +82 -0
- package/dist/src/types/types.test.d.ts +1 -0
- package/dist/src/types/types.test.js +25 -0
- package/dist/src/utils/cache-import.d.ts +3 -0
- package/dist/src/utils/cache-import.js +2 -0
- package/dist/src/utils/networking-import.d.ts +4 -0
- package/dist/src/utils/networking-import.js +3 -0
- package/dist/src/utils/rxjs-import.d.ts +5 -0
- package/dist/src/utils/rxjs-import.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { CustomerService, } from "./customer.service";
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel, } from "../types/types";
|
|
3
|
+
import { of, BehaviorSubject } from "rxjs";
|
|
4
|
+
describe("CustomerService", () => {
|
|
5
|
+
const config = {
|
|
6
|
+
baseUrl: "https://api.example.com",
|
|
7
|
+
isProd: false,
|
|
8
|
+
clientId: "test-client-id",
|
|
9
|
+
apiKey: "test-api-key",
|
|
10
|
+
};
|
|
11
|
+
let service;
|
|
12
|
+
let $authToken;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
$authToken = new BehaviorSubject(null);
|
|
15
|
+
service = new CustomerService(config, $authToken);
|
|
16
|
+
});
|
|
17
|
+
it("register success", async () => {
|
|
18
|
+
const payload = {
|
|
19
|
+
email: "test@example.com",
|
|
20
|
+
password: "pass",
|
|
21
|
+
};
|
|
22
|
+
const response = {
|
|
23
|
+
data: { id: 1, email: "test@example.com" },
|
|
24
|
+
};
|
|
25
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
26
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
27
|
+
});
|
|
28
|
+
const result = await service.register(payload).toPromise();
|
|
29
|
+
expect(result?.hasSuccess).toBe(true);
|
|
30
|
+
expect(result?.response).toEqual(response);
|
|
31
|
+
});
|
|
32
|
+
it("register error", async () => {
|
|
33
|
+
const payload = {
|
|
34
|
+
email: "test@example.com",
|
|
35
|
+
password: "pass",
|
|
36
|
+
};
|
|
37
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
38
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
39
|
+
});
|
|
40
|
+
const result = await service.register(payload).toPromise();
|
|
41
|
+
expect(result?.hasFailed).toBe(true);
|
|
42
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
43
|
+
});
|
|
44
|
+
it("getProfile success", async () => {
|
|
45
|
+
const response = {
|
|
46
|
+
data: { id: 1, email: "test@example.com" },
|
|
47
|
+
};
|
|
48
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
49
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
50
|
+
});
|
|
51
|
+
const result = await service.getProfile().toPromise();
|
|
52
|
+
expect(result?.hasSuccess).toBe(true);
|
|
53
|
+
expect(result?.response).toEqual(response);
|
|
54
|
+
});
|
|
55
|
+
it("getProfile error", async () => {
|
|
56
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
57
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
58
|
+
});
|
|
59
|
+
const result = await service.getProfile().toPromise();
|
|
60
|
+
expect(result?.hasFailed).toBe(true);
|
|
61
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
62
|
+
});
|
|
63
|
+
it("updateProfile success", async () => {
|
|
64
|
+
const payload = {
|
|
65
|
+
name: "Test",
|
|
66
|
+
address: "123 Main St",
|
|
67
|
+
postal_code: "12345",
|
|
68
|
+
city: "City",
|
|
69
|
+
state: null,
|
|
70
|
+
country: null,
|
|
71
|
+
contact_email: null,
|
|
72
|
+
phone_number: null,
|
|
73
|
+
};
|
|
74
|
+
const response = { data: { id: 1, name: "Test" } };
|
|
75
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
76
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
77
|
+
});
|
|
78
|
+
const result = await service.updateProfile(payload).toPromise();
|
|
79
|
+
expect(result?.hasSuccess).toBe(true);
|
|
80
|
+
expect(result?.response).toEqual(response);
|
|
81
|
+
});
|
|
82
|
+
it("updateProfile error", async () => {
|
|
83
|
+
const payload = {
|
|
84
|
+
name: "Test",
|
|
85
|
+
address: "123 Main St",
|
|
86
|
+
postal_code: "12345",
|
|
87
|
+
city: "City",
|
|
88
|
+
state: null,
|
|
89
|
+
country: null,
|
|
90
|
+
contact_email: null,
|
|
91
|
+
phone_number: null,
|
|
92
|
+
};
|
|
93
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
94
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
95
|
+
});
|
|
96
|
+
const result = await service.updateProfile(payload).toPromise();
|
|
97
|
+
expect(result?.hasFailed).toBe(true);
|
|
98
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
99
|
+
});
|
|
100
|
+
it("getCartCollection success", async () => {
|
|
101
|
+
const cartItem = {
|
|
102
|
+
id: "45bfb315-bc60-11f0-90ea-0242ac120004",
|
|
103
|
+
productId: "352235aa-a6bc-11f0-a3ef-0242ac120004",
|
|
104
|
+
productName: "GARAM MASALA 100G",
|
|
105
|
+
quantity: 2,
|
|
106
|
+
unit: "piece",
|
|
107
|
+
unitPrice: 1.55,
|
|
108
|
+
subtotal: 3.1,
|
|
109
|
+
total: 3.1,
|
|
110
|
+
picture: "https://s3.smeservices.cloud/grandparismarche-fr/2025-04/3276650136216.png",
|
|
111
|
+
};
|
|
112
|
+
const cartSummary = {
|
|
113
|
+
cartId: "45acc017-bc60-11f0-90ea-0242ac120004",
|
|
114
|
+
reference: "ORD-A121C9-220935",
|
|
115
|
+
dateCreated: "2025-11-08 05:03:32",
|
|
116
|
+
dateModified: "2025-11-08 16:08:55",
|
|
117
|
+
discountTotal: 0,
|
|
118
|
+
discountTax: 0,
|
|
119
|
+
shippingTotal: 0,
|
|
120
|
+
shippingTax: 0,
|
|
121
|
+
cartTax: 0,
|
|
122
|
+
total: 13.95,
|
|
123
|
+
totalTax: 0,
|
|
124
|
+
customerId: "244cac49-d014-11ef-8404-0242ac120003",
|
|
125
|
+
billingInformation: null,
|
|
126
|
+
shippingInformation: {
|
|
127
|
+
email: "john.doe@example.com",
|
|
128
|
+
phoneNumber: "+1-555-123-4567",
|
|
129
|
+
street: "123 Main Street",
|
|
130
|
+
city: "san_francisco",
|
|
131
|
+
postalCode: "94105",
|
|
132
|
+
state: "ca",
|
|
133
|
+
country: "us",
|
|
134
|
+
},
|
|
135
|
+
status: "confirmed",
|
|
136
|
+
paymentMethod: "bank_transfer",
|
|
137
|
+
deliveryType: "pickup",
|
|
138
|
+
transactionId: null,
|
|
139
|
+
customerIpAddress: "172.18.0.1",
|
|
140
|
+
customerUserAgent: "IntelliJ HTTP Client/PhpStorm 2024.3.6",
|
|
141
|
+
customerNote: null,
|
|
142
|
+
cartHash: "a121c980b381419d8341556b1f90445c05cbfa4605d6257330df605d20de2c87",
|
|
143
|
+
cartItems: [cartItem],
|
|
144
|
+
paymentUrl: null,
|
|
145
|
+
store: null,
|
|
146
|
+
};
|
|
147
|
+
const data = {
|
|
148
|
+
links: {
|
|
149
|
+
first: "/api/v1/store/cart/collection?per_page=24&page=1",
|
|
150
|
+
last: "/api/v1/store/cart/collection?per_page=24&page=1",
|
|
151
|
+
},
|
|
152
|
+
items: [cartSummary],
|
|
153
|
+
count: 1,
|
|
154
|
+
total: 1,
|
|
155
|
+
page: 1,
|
|
156
|
+
totalPage: 1,
|
|
157
|
+
perPage: 24,
|
|
158
|
+
metadata: [],
|
|
159
|
+
};
|
|
160
|
+
const response = {
|
|
161
|
+
data,
|
|
162
|
+
};
|
|
163
|
+
const requestMock = jest
|
|
164
|
+
.fn()
|
|
165
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
166
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
167
|
+
request: requestMock,
|
|
168
|
+
});
|
|
169
|
+
const query = {
|
|
170
|
+
page: 1,
|
|
171
|
+
per_page: 24,
|
|
172
|
+
status: "confirmed",
|
|
173
|
+
};
|
|
174
|
+
const result = await service.getCartCollection(query).toPromise();
|
|
175
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
176
|
+
expect(result?.hasSuccess).toBe(true);
|
|
177
|
+
expect(result?.response).toEqual(response);
|
|
178
|
+
});
|
|
179
|
+
it("getCartCollection error", async () => {
|
|
180
|
+
const requestMock = jest
|
|
181
|
+
.fn()
|
|
182
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
183
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
184
|
+
request: requestMock,
|
|
185
|
+
});
|
|
186
|
+
const query = {
|
|
187
|
+
page: 1,
|
|
188
|
+
per_page: 24,
|
|
189
|
+
};
|
|
190
|
+
const result = await service.getCartCollection(query).toPromise();
|
|
191
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
192
|
+
expect(result?.hasFailed).toBe(true);
|
|
193
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
194
|
+
});
|
|
195
|
+
it("getCustomerProductCollection success", async () => {
|
|
196
|
+
const product = {
|
|
197
|
+
id: "504e061d-a6bc-11f0-a3ef-0242ac120004",
|
|
198
|
+
barcode: "8935063610908",
|
|
199
|
+
expiryDate: null,
|
|
200
|
+
name: "AUBERGINE MARINE PIMENTEE NGOC LIEN 400G",
|
|
201
|
+
category: "CONSERVE",
|
|
202
|
+
subCategory: null,
|
|
203
|
+
vatInPercent: 5.5,
|
|
204
|
+
unit: "piece",
|
|
205
|
+
volume: null,
|
|
206
|
+
quantity: 1,
|
|
207
|
+
unitWeight: null,
|
|
208
|
+
articleWeight: null,
|
|
209
|
+
tareWeight: null,
|
|
210
|
+
supplier: "TCHEQUE",
|
|
211
|
+
supplierCode: null,
|
|
212
|
+
supplierItemName: null,
|
|
213
|
+
picture: "https://s3.smeservices.cloud/grandparismarche-fr/2025-04/8935063610908.png",
|
|
214
|
+
slug: "aubergine-marine-pimentee-ngoc-lien-400g-8935063610908",
|
|
215
|
+
internalCode: "5215",
|
|
216
|
+
htmlDescription: null,
|
|
217
|
+
inventory: true,
|
|
218
|
+
quantityInStock: 9,
|
|
219
|
+
minimumStockQuantity: 0,
|
|
220
|
+
pricePurchase: 3.25,
|
|
221
|
+
priceToSell: 3.25,
|
|
222
|
+
discountInPercent: 0,
|
|
223
|
+
priceAfterDiscount: 0,
|
|
224
|
+
priceByWeight: false,
|
|
225
|
+
};
|
|
226
|
+
const item = {
|
|
227
|
+
customerId: "c0e25a90-bc54-11f0-90ea-0242ac120004",
|
|
228
|
+
productId: "504e061d-a6bc-11f0-a3ef-0242ac120004",
|
|
229
|
+
category: "New Cate",
|
|
230
|
+
notes: "Customer note for this favorite product",
|
|
231
|
+
createdAt: "2025-11-08 03:45:51",
|
|
232
|
+
updatedAt: "2025-11-08 03:45:51",
|
|
233
|
+
product,
|
|
234
|
+
};
|
|
235
|
+
const productCollectionData = {
|
|
236
|
+
links: {
|
|
237
|
+
first: "/api/v1/store/customer-product/collection?per_page=24&page=1",
|
|
238
|
+
last: "/api/v1/store/customer-product/collection?per_page=24&page=1",
|
|
239
|
+
},
|
|
240
|
+
items: [item],
|
|
241
|
+
count: 1,
|
|
242
|
+
total: 1,
|
|
243
|
+
page: 1,
|
|
244
|
+
totalPage: 1,
|
|
245
|
+
perPage: 24,
|
|
246
|
+
metadata: [],
|
|
247
|
+
};
|
|
248
|
+
const response = {
|
|
249
|
+
data: productCollectionData,
|
|
250
|
+
};
|
|
251
|
+
const requestMock = jest
|
|
252
|
+
.fn()
|
|
253
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
254
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
255
|
+
request: requestMock,
|
|
256
|
+
});
|
|
257
|
+
const query = {
|
|
258
|
+
page: 1,
|
|
259
|
+
per_page: 24,
|
|
260
|
+
};
|
|
261
|
+
const result = await service.getCustomerProductCollection(query).toPromise();
|
|
262
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
263
|
+
expect(result?.hasSuccess).toBe(true);
|
|
264
|
+
expect(result?.response).toEqual(response);
|
|
265
|
+
});
|
|
266
|
+
it("getCustomerProductCollection error", async () => {
|
|
267
|
+
const requestMock = jest
|
|
268
|
+
.fn()
|
|
269
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
270
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
271
|
+
request: requestMock,
|
|
272
|
+
});
|
|
273
|
+
const query = {
|
|
274
|
+
page: 1,
|
|
275
|
+
per_page: 24,
|
|
276
|
+
};
|
|
277
|
+
const result = await service.getCustomerProductCollection(query).toPromise();
|
|
278
|
+
expect(requestMock).toHaveBeenCalledWith(query);
|
|
279
|
+
expect(result?.hasFailed).toBe(true);
|
|
280
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
281
|
+
});
|
|
282
|
+
it("createCustomerProduct success", async () => {
|
|
283
|
+
const product = {
|
|
284
|
+
id: "504e061d-a6bc-11f0-a3ef-0242ac120004",
|
|
285
|
+
barcode: "8935063610908",
|
|
286
|
+
expiryDate: null,
|
|
287
|
+
name: "AUBERGINE MARINE PIMENTEE NGOC LIEN 400G",
|
|
288
|
+
category: "CONSERVE",
|
|
289
|
+
subCategory: null,
|
|
290
|
+
vatInPercent: 5.5,
|
|
291
|
+
unit: "piece",
|
|
292
|
+
volume: null,
|
|
293
|
+
quantity: 1,
|
|
294
|
+
unitWeight: null,
|
|
295
|
+
articleWeight: null,
|
|
296
|
+
tareWeight: null,
|
|
297
|
+
supplier: "TCHEQUE",
|
|
298
|
+
supplierCode: null,
|
|
299
|
+
supplierItemName: null,
|
|
300
|
+
picture: "https://s3.smeservices.cloud/grandparismarche-fr/2025-04/8935063610908.png",
|
|
301
|
+
slug: "aubergine-marine-pimentee-ngoc-lien-400g-8935063610908",
|
|
302
|
+
internalCode: "5215",
|
|
303
|
+
htmlDescription: null,
|
|
304
|
+
inventory: true,
|
|
305
|
+
quantityInStock: 9,
|
|
306
|
+
minimumStockQuantity: 0,
|
|
307
|
+
pricePurchase: 3.25,
|
|
308
|
+
priceToSell: 3.25,
|
|
309
|
+
discountInPercent: 0,
|
|
310
|
+
priceAfterDiscount: 0,
|
|
311
|
+
priceByWeight: false,
|
|
312
|
+
};
|
|
313
|
+
const response = {
|
|
314
|
+
data: {
|
|
315
|
+
customerId: "c0e25a90-bc54-11f0-90ea-0242ac120004",
|
|
316
|
+
productId: "504e061d-a6bc-11f0-a3ef-0242ac120004",
|
|
317
|
+
category: "New Cate",
|
|
318
|
+
notes: "Customer note for this favorite product",
|
|
319
|
+
createdAt: "2025-11-08 03:45:51",
|
|
320
|
+
updatedAt: "2025-11-09 16:34:39",
|
|
321
|
+
product,
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
const requestMock = jest
|
|
325
|
+
.fn()
|
|
326
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
327
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
328
|
+
request: requestMock,
|
|
329
|
+
});
|
|
330
|
+
const payload = {
|
|
331
|
+
product_id: "product-123",
|
|
332
|
+
notes: "Customer note for this favorite product",
|
|
333
|
+
category: "New Cate",
|
|
334
|
+
};
|
|
335
|
+
const result = await service.createCustomerProduct(payload).toPromise();
|
|
336
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
337
|
+
expect(result?.hasSuccess).toBe(true);
|
|
338
|
+
expect(result?.response).toEqual(response);
|
|
339
|
+
});
|
|
340
|
+
it("createCustomerProduct error", async () => {
|
|
341
|
+
const requestMock = jest
|
|
342
|
+
.fn()
|
|
343
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
344
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
345
|
+
request: requestMock,
|
|
346
|
+
});
|
|
347
|
+
const payload = {
|
|
348
|
+
product_id: "product-123",
|
|
349
|
+
notes: "Customer note for this favorite product",
|
|
350
|
+
};
|
|
351
|
+
const result = await service.createCustomerProduct(payload).toPromise();
|
|
352
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
353
|
+
expect(result?.hasFailed).toBe(true);
|
|
354
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
355
|
+
});
|
|
356
|
+
it("removeCustomerProduct success", async () => {
|
|
357
|
+
const response = {
|
|
358
|
+
data: {
|
|
359
|
+
message: "Favorite removed successfully",
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
const requestMock = jest
|
|
363
|
+
.fn()
|
|
364
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
365
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
366
|
+
request: requestMock,
|
|
367
|
+
});
|
|
368
|
+
const payload = {
|
|
369
|
+
product_id: "product-123",
|
|
370
|
+
};
|
|
371
|
+
const result = await service.removeCustomerProduct(payload).toPromise();
|
|
372
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
373
|
+
expect(result?.hasSuccess).toBe(true);
|
|
374
|
+
expect(result?.response).toEqual(response);
|
|
375
|
+
});
|
|
376
|
+
it("removeCustomerProduct error", async () => {
|
|
377
|
+
const requestMock = jest
|
|
378
|
+
.fn()
|
|
379
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
380
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
381
|
+
request: requestMock,
|
|
382
|
+
});
|
|
383
|
+
const payload = {
|
|
384
|
+
product_id: "product-123",
|
|
385
|
+
};
|
|
386
|
+
const result = await service.removeCustomerProduct(payload).toPromise();
|
|
387
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
388
|
+
expect(result?.hasFailed).toBe(true);
|
|
389
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
390
|
+
});
|
|
391
|
+
it("updateCustomerProductCategory success", async () => {
|
|
392
|
+
const response = { data: true };
|
|
393
|
+
const requestMock = jest
|
|
394
|
+
.fn()
|
|
395
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.succeeded(response)));
|
|
396
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
397
|
+
request: requestMock,
|
|
398
|
+
});
|
|
399
|
+
const payload = {
|
|
400
|
+
product_id: "product-123",
|
|
401
|
+
old_category: "Standard",
|
|
402
|
+
category: "Preferred",
|
|
403
|
+
};
|
|
404
|
+
const result = await service
|
|
405
|
+
.updateCustomerProductCategory(payload)
|
|
406
|
+
.toPromise();
|
|
407
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
408
|
+
expect(result?.hasSuccess).toBe(true);
|
|
409
|
+
expect(result?.response).toEqual(response);
|
|
410
|
+
});
|
|
411
|
+
it("updateCustomerProductCategory error", async () => {
|
|
412
|
+
const requestMock = jest
|
|
413
|
+
.fn()
|
|
414
|
+
.mockReturnValue(of(NetworkingUIEventWrapped.failed(AlertModel.default())));
|
|
415
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
416
|
+
request: requestMock,
|
|
417
|
+
});
|
|
418
|
+
const payload = {
|
|
419
|
+
product_id: "product-123",
|
|
420
|
+
old_category: "Standard",
|
|
421
|
+
category: "Preferred",
|
|
422
|
+
};
|
|
423
|
+
const result = await service
|
|
424
|
+
.updateCustomerProductCategory(payload)
|
|
425
|
+
.toPromise();
|
|
426
|
+
expect(requestMock).toHaveBeenCalledWith(payload);
|
|
427
|
+
expect(result?.hasFailed).toBe(true);
|
|
428
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
429
|
+
});
|
|
430
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
|
|
2
|
+
import { SmessService } from "./smess.service";
|
|
3
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
4
|
+
export type EmployeeTarget = "get-profile" | "cart-client-collection" | "cart-bulk-action";
|
|
5
|
+
export interface EmployeeCartCollectionQuery {
|
|
6
|
+
page?: number;
|
|
7
|
+
per_page?: number;
|
|
8
|
+
status?: string;
|
|
9
|
+
search?: string;
|
|
10
|
+
sort_by?: string;
|
|
11
|
+
sort_order?: "asc" | "desc";
|
|
12
|
+
}
|
|
13
|
+
export interface EmployeeCartBulkActionRequest {
|
|
14
|
+
create?: Array<{
|
|
15
|
+
cart_id?: string;
|
|
16
|
+
status?: string;
|
|
17
|
+
customer_note?: string;
|
|
18
|
+
customer_id?: string;
|
|
19
|
+
payment_method?: string;
|
|
20
|
+
delivery_type?: string;
|
|
21
|
+
items?: Array<{
|
|
22
|
+
product_id: string;
|
|
23
|
+
quantity: number;
|
|
24
|
+
custom_price?: number;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}>;
|
|
27
|
+
billing_information?: Record<string, unknown>;
|
|
28
|
+
shipping_information?: Record<string, unknown>;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}>;
|
|
31
|
+
update?: Array<{
|
|
32
|
+
cart_id: string;
|
|
33
|
+
status?: string;
|
|
34
|
+
customer_note?: string;
|
|
35
|
+
customer_id?: string;
|
|
36
|
+
payment_method?: string;
|
|
37
|
+
delivery_type?: string;
|
|
38
|
+
items?: Array<{
|
|
39
|
+
product_id: string;
|
|
40
|
+
quantity: number;
|
|
41
|
+
custom_price?: number;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
}>;
|
|
44
|
+
billing_information?: Record<string, unknown>;
|
|
45
|
+
shipping_information?: Record<string, unknown>;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}>;
|
|
48
|
+
delete?: Array<{
|
|
49
|
+
cart_id: string;
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
}>;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
export declare class EmployeeProvider implements ProviderType {
|
|
55
|
+
private readonly config;
|
|
56
|
+
private readonly target;
|
|
57
|
+
private readonly $authToken;
|
|
58
|
+
constructor(config: NetworkingConfig, target: EmployeeTarget, $authToken: BehaviorSubject<string | null>);
|
|
59
|
+
get baseURL(): string;
|
|
60
|
+
get path(): string;
|
|
61
|
+
get method(): string;
|
|
62
|
+
get headers(): Record<string, string>;
|
|
63
|
+
getPath(...queryParams: unknown[]): string;
|
|
64
|
+
}
|
|
65
|
+
export declare class EmployeeService {
|
|
66
|
+
private readonly config;
|
|
67
|
+
private readonly $authToken;
|
|
68
|
+
constructor(config: NetworkingConfig, $authToken: BehaviorSubject<string | null>);
|
|
69
|
+
provider(target: EmployeeTarget): SmessService<EmployeeProvider>;
|
|
70
|
+
getProfile(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
71
|
+
getCartCollection(query?: EmployeeCartCollectionQuery): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
72
|
+
bulkCartAction(payload: EmployeeCartBulkActionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
73
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Accept, SMESSHeader, SmessService } from "./smess.service";
|
|
2
|
+
import { withAuthReset } from "./utils/withAuthReset";
|
|
3
|
+
export class EmployeeProvider {
|
|
4
|
+
constructor(config, target, $authToken) {
|
|
5
|
+
this.config = config;
|
|
6
|
+
this.target = target;
|
|
7
|
+
this.$authToken = $authToken;
|
|
8
|
+
}
|
|
9
|
+
get baseURL() {
|
|
10
|
+
return this.config.version
|
|
11
|
+
? `${this.config.baseUrl}/${this.config.version}`
|
|
12
|
+
: this.config.baseUrl;
|
|
13
|
+
}
|
|
14
|
+
get path() {
|
|
15
|
+
switch (this.target) {
|
|
16
|
+
case "get-profile":
|
|
17
|
+
return "/authentication/get-profile";
|
|
18
|
+
case "cart-client-collection":
|
|
19
|
+
return "/store/cart/client/collection";
|
|
20
|
+
case "cart-bulk-action":
|
|
21
|
+
return "/store/cart/bulk-action";
|
|
22
|
+
default:
|
|
23
|
+
return "/authentication/not-found";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
get method() {
|
|
27
|
+
switch (this.target) {
|
|
28
|
+
case "get-profile":
|
|
29
|
+
case "cart-client-collection":
|
|
30
|
+
return "GET";
|
|
31
|
+
case "cart-bulk-action":
|
|
32
|
+
return "POST";
|
|
33
|
+
default:
|
|
34
|
+
return "GET";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
get headers() {
|
|
38
|
+
const headers = SmessService.getHeaders(Accept.V1, this.$authToken.value);
|
|
39
|
+
if (this.config.clientId) {
|
|
40
|
+
headers[SMESSHeader.ClientId] = this.config.clientId;
|
|
41
|
+
}
|
|
42
|
+
if (this.config.apiKey) {
|
|
43
|
+
headers[SMESSHeader.ApiKey] = this.config.apiKey;
|
|
44
|
+
}
|
|
45
|
+
return SmessService.filterHeaders(headers);
|
|
46
|
+
}
|
|
47
|
+
getPath(...queryParams) {
|
|
48
|
+
let definedPath = this.path;
|
|
49
|
+
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
50
|
+
params?.forEach((value, index) => {
|
|
51
|
+
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
52
|
+
});
|
|
53
|
+
return definedPath;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class EmployeeService {
|
|
57
|
+
constructor(config, $authToken) {
|
|
58
|
+
this.config = config;
|
|
59
|
+
this.$authToken = $authToken;
|
|
60
|
+
}
|
|
61
|
+
provider(target) {
|
|
62
|
+
const targetWrapper = new EmployeeProvider(this.config, target, this.$authToken);
|
|
63
|
+
return new SmessService(targetWrapper);
|
|
64
|
+
}
|
|
65
|
+
getProfile() {
|
|
66
|
+
return withAuthReset(this.provider("get-profile").request(), this.$authToken);
|
|
67
|
+
}
|
|
68
|
+
getCartCollection(query) {
|
|
69
|
+
return withAuthReset(this.provider("cart-client-collection").request(query), this.$authToken);
|
|
70
|
+
}
|
|
71
|
+
bulkCartAction(payload) {
|
|
72
|
+
return withAuthReset(this.provider("cart-bulk-action").request(payload), this.$authToken);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|