@smess/networking 1.0.19 → 1.0.21
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/services/store.cart.service.d.ts +20 -1
- package/dist/services/store.cart.service.js +11 -0
- package/dist/services/store.cart.service.test.js +59 -0
- package/dist/services/store.product.service.d.ts +1 -40
- package/dist/services/store.product.service.js +1 -63
- package/dist/services/store.product.service.test.js +0 -83
- package/dist/services/store.service.d.ts +2 -4
- package/dist/services/store.service.js +4 -6
- package/dist/services/store.service.test.js +2 -4
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
|
|
2
2
|
import { SmessService } from "./smess.service";
|
|
3
3
|
import { BehaviorSubject, Observable } from "rxjs";
|
|
4
|
-
export type StoreCartTarget = "cart-get" | "cart-update" | "cart-add-item" | "cart-update-item" | "cart-delete-item" | "cart-delete-all-items";
|
|
4
|
+
export type StoreCartTarget = "cart-get" | "cart-update" | "cart-add-item" | "cart-update-item" | "cart-delete-item" | "cart-delete-all-items" | "cart-batch-items";
|
|
5
5
|
export interface BillingInformation {
|
|
6
6
|
email?: string;
|
|
7
7
|
phone_number?: string;
|
|
@@ -71,6 +71,19 @@ export interface CartAddItemRequest {
|
|
|
71
71
|
export interface CartUpdateItemQuantityRequest {
|
|
72
72
|
quantity: number;
|
|
73
73
|
}
|
|
74
|
+
export interface CartBatchItemsRequest {
|
|
75
|
+
create?: Array<{
|
|
76
|
+
product_id: string;
|
|
77
|
+
quantity: number;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}>;
|
|
80
|
+
update?: Array<{
|
|
81
|
+
product_id: string;
|
|
82
|
+
quantity: number;
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
}>;
|
|
85
|
+
[key: string]: unknown;
|
|
86
|
+
}
|
|
74
87
|
export declare class StoreCartProvider implements ProviderType {
|
|
75
88
|
private readonly config;
|
|
76
89
|
private readonly target;
|
|
@@ -87,6 +100,7 @@ export interface StoreCartServiceType {
|
|
|
87
100
|
getCart(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
88
101
|
updateCart(payload: CartUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
89
102
|
addItem(payload: CartAddItemRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
103
|
+
batchItems(payload: CartBatchItemsRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
90
104
|
updateItemQuantity(itemId: string, payload: CartUpdateItemQuantityRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
91
105
|
deleteItem(itemId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
92
106
|
deleteAllItems(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
@@ -121,6 +135,11 @@ export declare class StoreCartService implements StoreCartServiceType {
|
|
|
121
135
|
* POST api/v1/store/cart/items
|
|
122
136
|
*/
|
|
123
137
|
addItem(payload: CartAddItemRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
138
|
+
/**
|
|
139
|
+
* Batch create/update items in cart
|
|
140
|
+
* POST api/v1/store/cart/items/batch
|
|
141
|
+
*/
|
|
142
|
+
batchItems(payload: CartBatchItemsRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
124
143
|
/**
|
|
125
144
|
* Update item quantity in cart
|
|
126
145
|
* PUT api/v1/store/cart/items/{id}
|
|
@@ -27,6 +27,8 @@ export class StoreCartProvider {
|
|
|
27
27
|
return "/store/cart/items/\${id}";
|
|
28
28
|
case "cart-delete-all-items":
|
|
29
29
|
return "/store/cart/items";
|
|
30
|
+
case "cart-batch-items":
|
|
31
|
+
return "/store/cart/items/batch";
|
|
30
32
|
default:
|
|
31
33
|
return "/store/cart";
|
|
32
34
|
}
|
|
@@ -45,6 +47,8 @@ export class StoreCartProvider {
|
|
|
45
47
|
return "DELETE";
|
|
46
48
|
case "cart-delete-all-items":
|
|
47
49
|
return "DELETE";
|
|
50
|
+
case "cart-batch-items":
|
|
51
|
+
return "POST";
|
|
48
52
|
default:
|
|
49
53
|
return "GET";
|
|
50
54
|
}
|
|
@@ -142,6 +146,13 @@ export class StoreCartService {
|
|
|
142
146
|
addItem(payload) {
|
|
143
147
|
return this.provider("cart-add-item").request(payload).pipe(tap((result) => this.updateCartHash(result)));
|
|
144
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Batch create/update items in cart
|
|
151
|
+
* POST api/v1/store/cart/items/batch
|
|
152
|
+
*/
|
|
153
|
+
batchItems(payload) {
|
|
154
|
+
return this.provider("cart-batch-items").request(payload).pipe(tap((result) => this.updateCartHash(result)));
|
|
155
|
+
}
|
|
145
156
|
/**
|
|
146
157
|
* Update item quantity in cart
|
|
147
158
|
* PUT api/v1/store/cart/items/{id}
|
|
@@ -211,6 +211,65 @@ describe("StoreCartService", () => {
|
|
|
211
211
|
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
212
212
|
});
|
|
213
213
|
});
|
|
214
|
+
describe("batchItems", () => {
|
|
215
|
+
it("should batch create/update items successfully and update cartHash", async () => {
|
|
216
|
+
const payload = {
|
|
217
|
+
create: [
|
|
218
|
+
{ product_id: "prod-111", quantity: 2 },
|
|
219
|
+
{ product_id: "prod-222", quantity: 1 },
|
|
220
|
+
],
|
|
221
|
+
update: [
|
|
222
|
+
{ product_id: "prod-333", quantity: 5 },
|
|
223
|
+
],
|
|
224
|
+
};
|
|
225
|
+
const cart = {
|
|
226
|
+
dateCreated: "2025-10-14 12:56:31",
|
|
227
|
+
dateModified: "2025-10-14 12:56:31",
|
|
228
|
+
discountTotal: 0,
|
|
229
|
+
discountTax: 0,
|
|
230
|
+
shippingTotal: 0,
|
|
231
|
+
shippingTax: 0,
|
|
232
|
+
cartTax: 0,
|
|
233
|
+
total: 100.0,
|
|
234
|
+
totalTax: 0,
|
|
235
|
+
customerId: null,
|
|
236
|
+
billingInformation: null,
|
|
237
|
+
shippingInformation: null,
|
|
238
|
+
paymentMethod: "cash",
|
|
239
|
+
deliveryType: "pickup",
|
|
240
|
+
transactionId: null,
|
|
241
|
+
customerIpAddress: "172.18.0.1",
|
|
242
|
+
customerUserAgent: "Test Agent",
|
|
243
|
+
customerNote: null,
|
|
244
|
+
cartHash: "hash-batch-123",
|
|
245
|
+
cartItems: [
|
|
246
|
+
{ id: "item-1", productId: "prod-111", quantity: 2, price: 10, total: 20 },
|
|
247
|
+
{ id: "item-2", productId: "prod-222", quantity: 1, price: 30, total: 30 },
|
|
248
|
+
{ id: "item-3", productId: "prod-333", quantity: 5, price: 10, total: 50 },
|
|
249
|
+
],
|
|
250
|
+
paymentUrl: null,
|
|
251
|
+
store: null,
|
|
252
|
+
};
|
|
253
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
254
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(cart)),
|
|
255
|
+
});
|
|
256
|
+
const result = await service.batchItems(payload).toPromise();
|
|
257
|
+
expect(result?.hasSuccess).toBe(true);
|
|
258
|
+
expect(result?.response).toEqual(cart);
|
|
259
|
+
expect(service.currentCartHash).toBe("hash-batch-123");
|
|
260
|
+
});
|
|
261
|
+
it("should handle batchItems error", async () => {
|
|
262
|
+
const payload = {
|
|
263
|
+
create: [{ product_id: "invalid", quantity: 0 }],
|
|
264
|
+
};
|
|
265
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
266
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
267
|
+
});
|
|
268
|
+
const result = await service.batchItems(payload).toPromise();
|
|
269
|
+
expect(result?.hasFailed).toBe(true);
|
|
270
|
+
expect(result?.alertModel).toBeInstanceOf(AlertModel);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
214
273
|
describe("updateItemQuantity", () => {
|
|
215
274
|
it("should update item quantity successfully", async () => {
|
|
216
275
|
const itemId = "item-123";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
|
|
2
2
|
import { SmessService } from "./smess.service";
|
|
3
3
|
import { Observable } from "rxjs";
|
|
4
|
-
export type StoreProductTarget = "featured-product-list" | "featured-product-list-by-store" | "product-category-list" | "product-get-by-id" | "
|
|
4
|
+
export type StoreProductTarget = "featured-product-list" | "featured-product-list-by-store" | "product-category-list" | "product-get-by-id" | "product-collection" | "product-collection-by-store";
|
|
5
5
|
export interface StoreProductCollectionRequest {
|
|
6
6
|
page?: number;
|
|
7
7
|
per_page?: number;
|
|
@@ -16,9 +16,6 @@ export interface StoreProductCollectionRequest {
|
|
|
16
16
|
has_offer?: boolean;
|
|
17
17
|
[key: string]: unknown;
|
|
18
18
|
}
|
|
19
|
-
export interface BatchUpdateRequest {
|
|
20
|
-
[key: string]: unknown;
|
|
21
|
-
}
|
|
22
19
|
export interface PaginationLinks {
|
|
23
20
|
first: string;
|
|
24
21
|
last: string;
|
|
@@ -85,14 +82,8 @@ export interface StoreProductServiceType {
|
|
|
85
82
|
getFeaturedProductListByStore(storeId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
86
83
|
getProductCategoryList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
87
84
|
getProductById(productId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
88
|
-
getStoreList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
89
|
-
getStoreInformation(storeId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
90
85
|
getProductCollection(payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
91
86
|
getProductCollectionByStore(storeId: string, payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
92
|
-
updateProductBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
93
|
-
updateCustomerBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
94
|
-
updateCartBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
95
|
-
updateOrderItemBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
96
87
|
}
|
|
97
88
|
export declare class StoreProductService implements StoreProductServiceType {
|
|
98
89
|
private readonly config;
|
|
@@ -118,16 +109,6 @@ export declare class StoreProductService implements StoreProductServiceType {
|
|
|
118
109
|
* GET /api/v1/store/product/{id}
|
|
119
110
|
*/
|
|
120
111
|
getProductById(productId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
121
|
-
/**
|
|
122
|
-
* Get store list
|
|
123
|
-
* GET /api/v1/store/list
|
|
124
|
-
*/
|
|
125
|
-
getStoreList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
126
|
-
/**
|
|
127
|
-
* Get store information
|
|
128
|
-
* GET /api/v1/store/{id}/information
|
|
129
|
-
*/
|
|
130
|
-
getStoreInformation(storeId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
131
112
|
/**
|
|
132
113
|
* Get product collection
|
|
133
114
|
* GET /api/v1/store/product-collection
|
|
@@ -138,24 +119,4 @@ export declare class StoreProductService implements StoreProductServiceType {
|
|
|
138
119
|
* GET /api/v1/store/{id}/product-collection
|
|
139
120
|
*/
|
|
140
121
|
getProductCollectionByStore(storeId: string, payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
141
|
-
/**
|
|
142
|
-
* Update product batch
|
|
143
|
-
* POST /api/v1/store/{id}/product
|
|
144
|
-
*/
|
|
145
|
-
updateProductBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
146
|
-
/**
|
|
147
|
-
* Update customer batch
|
|
148
|
-
* POST /api/v1/store/{id}/customer/batch
|
|
149
|
-
*/
|
|
150
|
-
updateCustomerBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
151
|
-
/**
|
|
152
|
-
* Update cart batch
|
|
153
|
-
* POST /api/v1/store/{id}/order/batch
|
|
154
|
-
*/
|
|
155
|
-
updateCartBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
156
|
-
/**
|
|
157
|
-
* Update order item batch
|
|
158
|
-
* POST /api/v1/store/{id}/order-item
|
|
159
|
-
*/
|
|
160
|
-
updateOrderItemBatch(storeId: string, payload: BatchUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
161
122
|
}
|
|
@@ -19,36 +19,16 @@ export class StoreProductProvider {
|
|
|
19
19
|
return "/store/product-category/list";
|
|
20
20
|
case "product-get-by-id":
|
|
21
21
|
return "/store/product/${id}";
|
|
22
|
-
case "store-list":
|
|
23
|
-
return "/store/list";
|
|
24
|
-
case "store-information":
|
|
25
|
-
return "/store/${id}/information";
|
|
26
22
|
case "product-collection":
|
|
27
23
|
return "/store/product-collection";
|
|
28
24
|
case "product-collection-by-store":
|
|
29
25
|
return "/store/${id}/product-collection";
|
|
30
|
-
case "product-update-batch":
|
|
31
|
-
return "/store/${id}/product";
|
|
32
|
-
case "customer-update-batch":
|
|
33
|
-
return "/store/${id}/customer/batch";
|
|
34
|
-
case "cart-update-batch":
|
|
35
|
-
return "/store/${id}/order/batch";
|
|
36
|
-
case "order-item-update-batch":
|
|
37
|
-
return "/store/${id}/order-item";
|
|
38
26
|
default:
|
|
39
27
|
return "/store";
|
|
40
28
|
}
|
|
41
29
|
}
|
|
42
30
|
get method() {
|
|
43
|
-
|
|
44
|
-
case "product-update-batch":
|
|
45
|
-
case "customer-update-batch":
|
|
46
|
-
case "cart-update-batch":
|
|
47
|
-
case "order-item-update-batch":
|
|
48
|
-
return "POST";
|
|
49
|
-
default:
|
|
50
|
-
return "GET";
|
|
51
|
-
}
|
|
31
|
+
return "GET";
|
|
52
32
|
}
|
|
53
33
|
get headers() {
|
|
54
34
|
let headers = SmessService.getHeaders(Accept.V1, null);
|
|
@@ -105,20 +85,6 @@ export class StoreProductService {
|
|
|
105
85
|
getProductById(productId) {
|
|
106
86
|
return this.provider("product-get-by-id").request(undefined, undefined, productId);
|
|
107
87
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Get store list
|
|
110
|
-
* GET /api/v1/store/list
|
|
111
|
-
*/
|
|
112
|
-
getStoreList() {
|
|
113
|
-
return this.provider("store-list").request();
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Get store information
|
|
117
|
-
* GET /api/v1/store/{id}/information
|
|
118
|
-
*/
|
|
119
|
-
getStoreInformation(storeId) {
|
|
120
|
-
return this.provider("store-information").request(undefined, undefined, storeId);
|
|
121
|
-
}
|
|
122
88
|
/**
|
|
123
89
|
* Get product collection
|
|
124
90
|
* GET /api/v1/store/product-collection
|
|
@@ -133,32 +99,4 @@ export class StoreProductService {
|
|
|
133
99
|
getProductCollectionByStore(storeId, payload) {
|
|
134
100
|
return this.provider("product-collection-by-store").request(null, undefined, storeId, payload);
|
|
135
101
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Update product batch
|
|
138
|
-
* POST /api/v1/store/{id}/product
|
|
139
|
-
*/
|
|
140
|
-
updateProductBatch(storeId, payload) {
|
|
141
|
-
return this.provider("product-update-batch").request(payload, undefined, storeId);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Update customer batch
|
|
145
|
-
* POST /api/v1/store/{id}/customer/batch
|
|
146
|
-
*/
|
|
147
|
-
updateCustomerBatch(storeId, payload) {
|
|
148
|
-
return this.provider("customer-update-batch").request(payload, undefined, storeId);
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Update cart batch
|
|
152
|
-
* POST /api/v1/store/{id}/order/batch
|
|
153
|
-
*/
|
|
154
|
-
updateCartBatch(storeId, payload) {
|
|
155
|
-
return this.provider("cart-update-batch").request(payload, undefined, storeId);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Update order item batch
|
|
159
|
-
* POST /api/v1/store/{id}/order-item
|
|
160
|
-
*/
|
|
161
|
-
updateOrderItemBatch(storeId, payload) {
|
|
162
|
-
return this.provider("order-item-update-batch").request(payload, undefined, storeId);
|
|
163
|
-
}
|
|
164
102
|
}
|
|
@@ -172,29 +172,6 @@ describe("StoreProductService", () => {
|
|
|
172
172
|
expect(result?.response).toEqual(response);
|
|
173
173
|
});
|
|
174
174
|
});
|
|
175
|
-
describe("getStoreList", () => {
|
|
176
|
-
it("should get store list successfully", async () => {
|
|
177
|
-
const response = { data: [{ id: "1", name: "Store 1" }] };
|
|
178
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
179
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
180
|
-
});
|
|
181
|
-
const result = await service.getStoreList().toPromise();
|
|
182
|
-
expect(result?.hasSuccess).toBe(true);
|
|
183
|
-
expect(result?.response).toEqual(response);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
describe("getStoreInformation", () => {
|
|
187
|
-
it("should get store information successfully", async () => {
|
|
188
|
-
const storeId = "store-123";
|
|
189
|
-
const response = { data: { id: storeId, name: "Store 1" } };
|
|
190
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
191
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
192
|
-
});
|
|
193
|
-
const result = await service.getStoreInformation(storeId).toPromise();
|
|
194
|
-
expect(result?.hasSuccess).toBe(true);
|
|
195
|
-
expect(result?.response).toEqual(response);
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
175
|
describe("getProductCollection", () => {
|
|
199
176
|
it("should get product collection successfully", async () => {
|
|
200
177
|
const payload = {
|
|
@@ -339,64 +316,4 @@ describe("StoreProductService", () => {
|
|
|
339
316
|
expect(result?.response).toEqual(response);
|
|
340
317
|
});
|
|
341
318
|
});
|
|
342
|
-
describe("updateProductBatch", () => {
|
|
343
|
-
it("should update product batch successfully", async () => {
|
|
344
|
-
const storeId = "store-123";
|
|
345
|
-
const payload = {
|
|
346
|
-
products: [{ id: "1", price: 100 }],
|
|
347
|
-
};
|
|
348
|
-
const response = { data: { updated: 1 } };
|
|
349
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
350
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
351
|
-
});
|
|
352
|
-
const result = await service.updateProductBatch(storeId, payload).toPromise();
|
|
353
|
-
expect(result?.hasSuccess).toBe(true);
|
|
354
|
-
expect(result?.response).toEqual(response);
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
describe("updateCustomerBatch", () => {
|
|
358
|
-
it("should update customer batch successfully", async () => {
|
|
359
|
-
const storeId = "store-123";
|
|
360
|
-
const payload = {
|
|
361
|
-
customers: [{ id: "1", status: "active" }],
|
|
362
|
-
};
|
|
363
|
-
const response = { data: { updated: 1 } };
|
|
364
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
365
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
366
|
-
});
|
|
367
|
-
const result = await service.updateCustomerBatch(storeId, payload).toPromise();
|
|
368
|
-
expect(result?.hasSuccess).toBe(true);
|
|
369
|
-
expect(result?.response).toEqual(response);
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
describe("updateCartBatch", () => {
|
|
373
|
-
it("should update cart batch successfully", async () => {
|
|
374
|
-
const storeId = "store-123";
|
|
375
|
-
const payload = {
|
|
376
|
-
orders: [{ id: "1", status: "completed" }],
|
|
377
|
-
};
|
|
378
|
-
const response = { data: { updated: 1 } };
|
|
379
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
380
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
381
|
-
});
|
|
382
|
-
const result = await service.updateCartBatch(storeId, payload).toPromise();
|
|
383
|
-
expect(result?.hasSuccess).toBe(true);
|
|
384
|
-
expect(result?.response).toEqual(response);
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
describe("updateOrderItemBatch", () => {
|
|
388
|
-
it("should update order item batch successfully", async () => {
|
|
389
|
-
const storeId = "store-123";
|
|
390
|
-
const payload = {
|
|
391
|
-
items: [{ id: "1", quantity: 5 }],
|
|
392
|
-
};
|
|
393
|
-
const response = { data: { updated: 1 } };
|
|
394
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
395
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
396
|
-
});
|
|
397
|
-
const result = await service.updateOrderItemBatch(storeId, payload).toPromise();
|
|
398
|
-
expect(result?.hasSuccess).toBe(true);
|
|
399
|
-
expect(result?.response).toEqual(response);
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
319
|
});
|
|
@@ -18,8 +18,7 @@ export interface ProductCollectionRequest {
|
|
|
18
18
|
export declare class StoreProvider implements ProviderType {
|
|
19
19
|
private readonly config;
|
|
20
20
|
private readonly target;
|
|
21
|
-
|
|
22
|
-
constructor(config: NetworkingConfig, target: StoreTarget, $authToken: BehaviorSubject<string | null>);
|
|
21
|
+
constructor(config: NetworkingConfig, target: StoreTarget);
|
|
23
22
|
get baseURL(): string;
|
|
24
23
|
get path(): string;
|
|
25
24
|
get method(): string;
|
|
@@ -52,14 +51,13 @@ export interface FeaturedProductData {
|
|
|
52
51
|
}
|
|
53
52
|
export declare class StoreService {
|
|
54
53
|
private readonly config;
|
|
55
|
-
private readonly $authToken;
|
|
56
54
|
readonly $selectedStoreId: BehaviorSubject<string | null>;
|
|
57
55
|
private readonly cacheService;
|
|
58
56
|
private readonly storeListCache;
|
|
59
57
|
private readonly productCollectionCache;
|
|
60
58
|
private readonly productCategoryCache;
|
|
61
59
|
private readonly featuredProductCache;
|
|
62
|
-
constructor(config: NetworkingConfig
|
|
60
|
+
constructor(config: NetworkingConfig);
|
|
63
61
|
provider(target: StoreTarget): SmessService<StoreProvider>;
|
|
64
62
|
/**
|
|
65
63
|
* Set the selected store ID
|
|
@@ -4,10 +4,9 @@ import { BehaviorSubject, from, of } from "rxjs";
|
|
|
4
4
|
import { map, switchMap, catchError } from "rxjs/operators";
|
|
5
5
|
import { GenericIndexedDBService } from "./cache.service";
|
|
6
6
|
export class StoreProvider {
|
|
7
|
-
constructor(config, target
|
|
7
|
+
constructor(config, target) {
|
|
8
8
|
this.config = config;
|
|
9
9
|
this.target = target;
|
|
10
|
-
this.$authToken = $authToken;
|
|
11
10
|
}
|
|
12
11
|
get baseURL() {
|
|
13
12
|
return this.config.version
|
|
@@ -34,7 +33,7 @@ export class StoreProvider {
|
|
|
34
33
|
return "GET";
|
|
35
34
|
}
|
|
36
35
|
get headers() {
|
|
37
|
-
let headers = SmessService.getHeaders(Accept.V1,
|
|
36
|
+
let headers = SmessService.getHeaders(Accept.V1, null);
|
|
38
37
|
if (this.config.clientId) {
|
|
39
38
|
headers[SMESSHeader.ClientId] = this.config.clientId;
|
|
40
39
|
}
|
|
@@ -53,9 +52,8 @@ export class StoreProvider {
|
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
export class StoreService {
|
|
56
|
-
constructor(config
|
|
55
|
+
constructor(config) {
|
|
57
56
|
this.config = config;
|
|
58
|
-
this.$authToken = $authToken;
|
|
59
57
|
this.$selectedStoreId = new BehaviorSubject(null);
|
|
60
58
|
// Initialize cache services for different data types
|
|
61
59
|
this.cacheService = new GenericIndexedDBService("StoreCache", "id, timestamp", (data) => data, (data) => data);
|
|
@@ -65,7 +63,7 @@ export class StoreService {
|
|
|
65
63
|
this.featuredProductCache = new GenericIndexedDBService("FeaturedProductCache", "storeId, timestamp", (data) => data, (data) => data);
|
|
66
64
|
}
|
|
67
65
|
provider(target) {
|
|
68
|
-
const targetWrapper = new StoreProvider(this.config, target
|
|
66
|
+
const targetWrapper = new StoreProvider(this.config, target);
|
|
69
67
|
return new SmessService(targetWrapper);
|
|
70
68
|
}
|
|
71
69
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "fake-indexeddb/auto";
|
|
2
2
|
import { StoreService, } from "./store.service";
|
|
3
3
|
import { NetworkingUIEventWrapped, AlertModel, } from "../types/types";
|
|
4
|
-
import { of
|
|
4
|
+
import { of } from "rxjs";
|
|
5
5
|
describe("StoreService", () => {
|
|
6
6
|
const config = {
|
|
7
7
|
baseUrl: "https://api.example.com",
|
|
@@ -10,10 +10,8 @@ describe("StoreService", () => {
|
|
|
10
10
|
apiKey: "test-api-key",
|
|
11
11
|
};
|
|
12
12
|
let service;
|
|
13
|
-
let $authToken;
|
|
14
13
|
beforeEach(() => {
|
|
15
|
-
|
|
16
|
-
service = new StoreService(config, $authToken);
|
|
14
|
+
service = new StoreService(config);
|
|
17
15
|
});
|
|
18
16
|
afterEach(async () => {
|
|
19
17
|
await service.clearCache();
|