@smess/networking 1.0.20 → 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.
|
@@ -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";
|