@smess/networking 1.0.18 → 1.0.20
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 +13 -13
- package/dist/services/store.product.service.d.ts +13 -52
- package/dist/services/store.product.service.js +1 -63
- package/dist/services/store.product.service.test.js +185 -254
- 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,4 +1,4 @@
|
|
|
1
|
-
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped } from "../types/types";
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
|
|
2
2
|
import { SmessService } from "./smess.service";
|
|
3
3
|
import { BehaviorSubject, Observable } from "rxjs";
|
|
4
4
|
export type StoreCartTarget = "cart-get" | "cart-update" | "cart-add-item" | "cart-update-item" | "cart-delete-item" | "cart-delete-all-items";
|
|
@@ -84,12 +84,12 @@ export declare class StoreCartProvider implements ProviderType {
|
|
|
84
84
|
getPath(...queryParams: unknown[]): string;
|
|
85
85
|
}
|
|
86
86
|
export interface StoreCartServiceType {
|
|
87
|
-
getCart(): Observable<NetworkingUIEventWrapped<
|
|
88
|
-
updateCart(payload: CartUpdateRequest): Observable<NetworkingUIEventWrapped<
|
|
89
|
-
addItem(payload: CartAddItemRequest): Observable<NetworkingUIEventWrapped<
|
|
90
|
-
updateItemQuantity(itemId: string, payload: CartUpdateItemQuantityRequest): Observable<NetworkingUIEventWrapped<
|
|
91
|
-
deleteItem(itemId: string): Observable<NetworkingUIEventWrapped<
|
|
92
|
-
deleteAllItems(): Observable<NetworkingUIEventWrapped<
|
|
87
|
+
getCart(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
88
|
+
updateCart(payload: CartUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
89
|
+
addItem(payload: CartAddItemRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
90
|
+
updateItemQuantity(itemId: string, payload: CartUpdateItemQuantityRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
91
|
+
deleteItem(itemId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
92
|
+
deleteAllItems(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
93
93
|
}
|
|
94
94
|
export declare class StoreCartService implements StoreCartServiceType {
|
|
95
95
|
private readonly config;
|
|
@@ -110,30 +110,30 @@ export declare class StoreCartService implements StoreCartServiceType {
|
|
|
110
110
|
* Get the current cart
|
|
111
111
|
* GET api/v1/store/cart
|
|
112
112
|
*/
|
|
113
|
-
getCart(): Observable<NetworkingUIEventWrapped<
|
|
113
|
+
getCart(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
114
114
|
/**
|
|
115
115
|
* Update cart (e.g., add notes, apply coupon)
|
|
116
116
|
* PUT api/v1/store/cart
|
|
117
117
|
*/
|
|
118
|
-
updateCart(payload: CartUpdateRequest): Observable<NetworkingUIEventWrapped<
|
|
118
|
+
updateCart(payload: CartUpdateRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
119
119
|
/**
|
|
120
120
|
* Add item to cart
|
|
121
121
|
* POST api/v1/store/cart/items
|
|
122
122
|
*/
|
|
123
|
-
addItem(payload: CartAddItemRequest): Observable<NetworkingUIEventWrapped<
|
|
123
|
+
addItem(payload: CartAddItemRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
124
124
|
/**
|
|
125
125
|
* Update item quantity in cart
|
|
126
126
|
* PUT api/v1/store/cart/items/{id}
|
|
127
127
|
*/
|
|
128
|
-
updateItemQuantity(itemId: string, payload: CartUpdateItemQuantityRequest): Observable<NetworkingUIEventWrapped<
|
|
128
|
+
updateItemQuantity(itemId: string, payload: CartUpdateItemQuantityRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
129
129
|
/**
|
|
130
130
|
* Delete item from cart
|
|
131
131
|
* DELETE api/v1/store/cart/items/{id}
|
|
132
132
|
*/
|
|
133
|
-
deleteItem(itemId: string): Observable<NetworkingUIEventWrapped<
|
|
133
|
+
deleteItem(itemId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
134
134
|
/**
|
|
135
135
|
* Delete all items from cart
|
|
136
136
|
* DELETE api/v1/store/cart/items
|
|
137
137
|
*/
|
|
138
|
-
deleteAllItems(): Observable<NetworkingUIEventWrapped<
|
|
138
|
+
deleteAllItems(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
139
139
|
}
|
|
@@ -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;
|
|
@@ -81,18 +78,12 @@ export declare class StoreProductProvider implements ProviderType {
|
|
|
81
78
|
getPath(...queryParams: unknown[]): string;
|
|
82
79
|
}
|
|
83
80
|
export interface StoreProductServiceType {
|
|
84
|
-
getFeaturedProductList(): Observable<NetworkingUIEventWrapped<
|
|
85
|
-
getFeaturedProductListByStore(storeId: string): Observable<NetworkingUIEventWrapped<
|
|
86
|
-
getProductCategoryList(): Observable<NetworkingUIEventWrapped<
|
|
87
|
-
getProductById(productId: string): Observable<NetworkingUIEventWrapped<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
getProductCollection(payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<StoreProductCollectionResponse>>;
|
|
91
|
-
getProductCollectionByStore(storeId: string, payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<StoreProductCollectionResponse>>;
|
|
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>>;
|
|
81
|
+
getFeaturedProductList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
82
|
+
getFeaturedProductListByStore(storeId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
83
|
+
getProductCategoryList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
84
|
+
getProductById(productId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
85
|
+
getProductCollection(payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
86
|
+
getProductCollectionByStore(storeId: string, payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
96
87
|
}
|
|
97
88
|
export declare class StoreProductService implements StoreProductServiceType {
|
|
98
89
|
private readonly config;
|
|
@@ -102,60 +93,30 @@ export declare class StoreProductService implements StoreProductServiceType {
|
|
|
102
93
|
* Get featured product list
|
|
103
94
|
* GET /api/v1/store/featured-product-list
|
|
104
95
|
*/
|
|
105
|
-
getFeaturedProductList(): Observable<NetworkingUIEventWrapped<
|
|
96
|
+
getFeaturedProductList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
106
97
|
/**
|
|
107
98
|
* Get featured product list by store
|
|
108
99
|
* GET /api/v1/store/{id}/featured-product-list
|
|
109
100
|
*/
|
|
110
|
-
getFeaturedProductListByStore(storeId: string): Observable<NetworkingUIEventWrapped<
|
|
101
|
+
getFeaturedProductListByStore(storeId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
111
102
|
/**
|
|
112
103
|
* Get product category list
|
|
113
104
|
* GET /api/v1/store/product-category/list
|
|
114
105
|
*/
|
|
115
|
-
getProductCategoryList(): Observable<NetworkingUIEventWrapped<
|
|
106
|
+
getProductCategoryList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
116
107
|
/**
|
|
117
108
|
* Get product by ID
|
|
118
109
|
* GET /api/v1/store/product/{id}
|
|
119
110
|
*/
|
|
120
|
-
getProductById(productId: string): Observable<NetworkingUIEventWrapped<
|
|
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>>;
|
|
111
|
+
getProductById(productId: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
131
112
|
/**
|
|
132
113
|
* Get product collection
|
|
133
114
|
* GET /api/v1/store/product-collection
|
|
134
115
|
*/
|
|
135
|
-
getProductCollection(payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<
|
|
116
|
+
getProductCollection(payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
136
117
|
/**
|
|
137
118
|
* Get product collection by store
|
|
138
119
|
* GET /api/v1/store/{id}/product-collection
|
|
139
120
|
*/
|
|
140
|
-
getProductCollectionByStore(storeId: string, payload?: StoreProductCollectionRequest): Observable<NetworkingUIEventWrapped<
|
|
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>>;
|
|
121
|
+
getProductCollectionByStore(storeId: string, payload?: StoreProductCollectionRequest): 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
|
}
|
|
@@ -14,193 +14,8 @@ describe("StoreProductService", () => {
|
|
|
14
14
|
});
|
|
15
15
|
describe("getFeaturedProductList", () => {
|
|
16
16
|
it("should get featured product list successfully", async () => {
|
|
17
|
-
const response = [
|
|
18
|
-
{
|
|
19
|
-
id: "1",
|
|
20
|
-
name: "Product 1",
|
|
21
|
-
barcode: "123",
|
|
22
|
-
category: "CONGELE",
|
|
23
|
-
vatInPercent: 5.5,
|
|
24
|
-
unit: "piece",
|
|
25
|
-
quantity: 1,
|
|
26
|
-
picture: "image.png",
|
|
27
|
-
slug: "product-1",
|
|
28
|
-
internalCode: "001",
|
|
29
|
-
inventory: true,
|
|
30
|
-
quantityInStock: 10,
|
|
31
|
-
minimumStockQuantity: 5,
|
|
32
|
-
pricePurchase: 10,
|
|
33
|
-
priceToSell: 15,
|
|
34
|
-
discountInPercent: 0,
|
|
35
|
-
priceAfterDiscount: 0,
|
|
36
|
-
expiryDate: null,
|
|
37
|
-
subCategory: null,
|
|
38
|
-
volume: null,
|
|
39
|
-
unitWeight: null,
|
|
40
|
-
articleWeight: null,
|
|
41
|
-
tareWeight: null,
|
|
42
|
-
supplier: null,
|
|
43
|
-
supplierCode: null,
|
|
44
|
-
supplierItemName: null,
|
|
45
|
-
htmlDescription: null,
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
49
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
50
|
-
});
|
|
51
|
-
const result = await service.getFeaturedProductList().toPromise();
|
|
52
|
-
expect(result?.hasSuccess).toBe(true);
|
|
53
|
-
expect(result?.response).toEqual(response);
|
|
54
|
-
});
|
|
55
|
-
it("should handle error", async () => {
|
|
56
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
57
|
-
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
58
|
-
});
|
|
59
|
-
const result = await service.getFeaturedProductList().toPromise();
|
|
60
|
-
expect(result?.hasFailed).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
describe("getFeaturedProductListByStore", () => {
|
|
64
|
-
it("should get featured product list by store successfully", async () => {
|
|
65
|
-
const storeId = "store-123";
|
|
66
|
-
const response = [
|
|
67
|
-
{
|
|
68
|
-
id: "1",
|
|
69
|
-
name: "Product 1",
|
|
70
|
-
barcode: "123",
|
|
71
|
-
category: "CONGELE",
|
|
72
|
-
vatInPercent: 5.5,
|
|
73
|
-
unit: "piece",
|
|
74
|
-
quantity: 1,
|
|
75
|
-
picture: "image.png",
|
|
76
|
-
slug: "product-1",
|
|
77
|
-
internalCode: "001",
|
|
78
|
-
inventory: true,
|
|
79
|
-
quantityInStock: 10,
|
|
80
|
-
minimumStockQuantity: 5,
|
|
81
|
-
pricePurchase: 10,
|
|
82
|
-
priceToSell: 15,
|
|
83
|
-
discountInPercent: 0,
|
|
84
|
-
priceAfterDiscount: 0,
|
|
85
|
-
expiryDate: null,
|
|
86
|
-
subCategory: null,
|
|
87
|
-
volume: null,
|
|
88
|
-
unitWeight: null,
|
|
89
|
-
articleWeight: null,
|
|
90
|
-
tareWeight: null,
|
|
91
|
-
supplier: null,
|
|
92
|
-
supplierCode: null,
|
|
93
|
-
supplierItemName: null,
|
|
94
|
-
htmlDescription: null,
|
|
95
|
-
},
|
|
96
|
-
];
|
|
97
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
98
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
99
|
-
});
|
|
100
|
-
const result = await service.getFeaturedProductListByStore(storeId).toPromise();
|
|
101
|
-
expect(result?.hasSuccess).toBe(true);
|
|
102
|
-
expect(result?.response).toEqual(response);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
describe("getProductCategoryList", () => {
|
|
106
|
-
it("should get product category list successfully", async () => {
|
|
107
|
-
const response = [
|
|
108
|
-
{
|
|
109
|
-
name: "BOISSON",
|
|
110
|
-
numberOfProducts: 443,
|
|
111
|
-
image: null,
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: "CONGELE",
|
|
115
|
-
numberOfProducts: 324,
|
|
116
|
-
image: null,
|
|
117
|
-
},
|
|
118
|
-
];
|
|
119
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
120
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
121
|
-
});
|
|
122
|
-
const result = await service.getProductCategoryList().toPromise();
|
|
123
|
-
expect(result?.hasSuccess).toBe(true);
|
|
124
|
-
expect(result?.response).toEqual(response);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
describe("getProductById", () => {
|
|
128
|
-
it("should get product by id successfully", async () => {
|
|
129
|
-
const productId = "product-123";
|
|
130
17
|
const response = {
|
|
131
|
-
|
|
132
|
-
name: "Product 1",
|
|
133
|
-
barcode: "123",
|
|
134
|
-
category: "CONGELE",
|
|
135
|
-
vatInPercent: 5.5,
|
|
136
|
-
unit: "piece",
|
|
137
|
-
quantity: 1,
|
|
138
|
-
picture: "image.png",
|
|
139
|
-
slug: "product-1",
|
|
140
|
-
internalCode: "001",
|
|
141
|
-
inventory: true,
|
|
142
|
-
quantityInStock: 10,
|
|
143
|
-
minimumStockQuantity: 5,
|
|
144
|
-
pricePurchase: 10,
|
|
145
|
-
priceToSell: 15,
|
|
146
|
-
discountInPercent: 0,
|
|
147
|
-
priceAfterDiscount: 0,
|
|
148
|
-
expiryDate: null,
|
|
149
|
-
subCategory: null,
|
|
150
|
-
volume: null,
|
|
151
|
-
unitWeight: null,
|
|
152
|
-
articleWeight: null,
|
|
153
|
-
tareWeight: null,
|
|
154
|
-
supplier: null,
|
|
155
|
-
supplierCode: null,
|
|
156
|
-
supplierItemName: null,
|
|
157
|
-
htmlDescription: null,
|
|
158
|
-
};
|
|
159
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
160
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
161
|
-
});
|
|
162
|
-
const result = await service.getProductById(productId).toPromise();
|
|
163
|
-
expect(result?.hasSuccess).toBe(true);
|
|
164
|
-
expect(result?.response).toEqual(response);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
describe("getStoreList", () => {
|
|
168
|
-
it("should get store list successfully", async () => {
|
|
169
|
-
const response = { data: [{ id: "1", name: "Store 1" }] };
|
|
170
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
171
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
172
|
-
});
|
|
173
|
-
const result = await service.getStoreList().toPromise();
|
|
174
|
-
expect(result?.hasSuccess).toBe(true);
|
|
175
|
-
expect(result?.response).toEqual(response);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
describe("getStoreInformation", () => {
|
|
179
|
-
it("should get store information successfully", async () => {
|
|
180
|
-
const storeId = "store-123";
|
|
181
|
-
const response = { data: { id: storeId, name: "Store 1" } };
|
|
182
|
-
jest.spyOn(service, "provider").mockReturnValue({
|
|
183
|
-
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
184
|
-
});
|
|
185
|
-
const result = await service.getStoreInformation(storeId).toPromise();
|
|
186
|
-
expect(result?.hasSuccess).toBe(true);
|
|
187
|
-
expect(result?.response).toEqual(response);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
describe("getProductCollection", () => {
|
|
191
|
-
it("should get product collection successfully", async () => {
|
|
192
|
-
const payload = {
|
|
193
|
-
page: 1,
|
|
194
|
-
per_page: 10,
|
|
195
|
-
search: "test",
|
|
196
|
-
};
|
|
197
|
-
const response = {
|
|
198
|
-
links: {
|
|
199
|
-
first: "/api/v1/store/product-collection?per_page=10&page=1",
|
|
200
|
-
last: "/api/v1/store/product-collection?per_page=10&page=5",
|
|
201
|
-
next: "/api/v1/store/product-collection?per_page=10&page=2",
|
|
202
|
-
},
|
|
203
|
-
items: [
|
|
18
|
+
data: [
|
|
204
19
|
{
|
|
205
20
|
id: "1",
|
|
206
21
|
name: "Product 1",
|
|
@@ -231,55 +46,27 @@ describe("StoreProductService", () => {
|
|
|
231
46
|
htmlDescription: null,
|
|
232
47
|
},
|
|
233
48
|
],
|
|
234
|
-
count: 10,
|
|
235
|
-
total: 50,
|
|
236
|
-
page: 1,
|
|
237
|
-
totalPage: 5,
|
|
238
|
-
perPage: 10,
|
|
239
|
-
metadata: [],
|
|
240
49
|
};
|
|
241
50
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
242
51
|
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
243
52
|
});
|
|
244
|
-
const result = await service.
|
|
53
|
+
const result = await service.getFeaturedProductList().toPromise();
|
|
245
54
|
expect(result?.hasSuccess).toBe(true);
|
|
246
55
|
expect(result?.response).toEqual(response);
|
|
247
56
|
});
|
|
248
|
-
it("should
|
|
249
|
-
const response = {
|
|
250
|
-
links: {
|
|
251
|
-
first: "/api/v1/store/product-collection?per_page=24&page=1",
|
|
252
|
-
last: "/api/v1/store/product-collection?per_page=24&page=1",
|
|
253
|
-
},
|
|
254
|
-
items: [],
|
|
255
|
-
count: 0,
|
|
256
|
-
total: 0,
|
|
257
|
-
page: 1,
|
|
258
|
-
totalPage: 1,
|
|
259
|
-
perPage: 24,
|
|
260
|
-
metadata: [],
|
|
261
|
-
};
|
|
57
|
+
it("should handle error", async () => {
|
|
262
58
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
263
|
-
request: () => of(NetworkingUIEventWrapped.
|
|
59
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
264
60
|
});
|
|
265
|
-
const result = await service.
|
|
266
|
-
expect(result?.
|
|
267
|
-
expect(result?.response).toEqual(response);
|
|
61
|
+
const result = await service.getFeaturedProductList().toPromise();
|
|
62
|
+
expect(result?.hasFailed).toBe(true);
|
|
268
63
|
});
|
|
269
64
|
});
|
|
270
|
-
describe("
|
|
271
|
-
it("should get product
|
|
65
|
+
describe("getFeaturedProductListByStore", () => {
|
|
66
|
+
it("should get featured product list by store successfully", async () => {
|
|
272
67
|
const storeId = "store-123";
|
|
273
|
-
const payload = {
|
|
274
|
-
page: 1,
|
|
275
|
-
per_page: 10,
|
|
276
|
-
};
|
|
277
68
|
const response = {
|
|
278
|
-
|
|
279
|
-
first: "/api/v1/store/product-collection?per_page=10&page=1",
|
|
280
|
-
last: "/api/v1/store/product-collection?per_page=10&page=1",
|
|
281
|
-
},
|
|
282
|
-
items: [
|
|
69
|
+
data: [
|
|
283
70
|
{
|
|
284
71
|
id: "1",
|
|
285
72
|
name: "Product 1",
|
|
@@ -310,77 +97,221 @@ describe("StoreProductService", () => {
|
|
|
310
97
|
htmlDescription: null,
|
|
311
98
|
},
|
|
312
99
|
],
|
|
313
|
-
count: 1,
|
|
314
|
-
total: 1,
|
|
315
|
-
page: 1,
|
|
316
|
-
totalPage: 1,
|
|
317
|
-
perPage: 10,
|
|
318
|
-
metadata: [],
|
|
319
100
|
};
|
|
320
101
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
321
102
|
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
322
103
|
});
|
|
323
|
-
const result = await service.
|
|
104
|
+
const result = await service.getFeaturedProductListByStore(storeId).toPromise();
|
|
324
105
|
expect(result?.hasSuccess).toBe(true);
|
|
325
106
|
expect(result?.response).toEqual(response);
|
|
326
107
|
});
|
|
327
108
|
});
|
|
328
|
-
describe("
|
|
329
|
-
it("should
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
109
|
+
describe("getProductCategoryList", () => {
|
|
110
|
+
it("should get product category list successfully", async () => {
|
|
111
|
+
const response = {
|
|
112
|
+
data: [
|
|
113
|
+
{
|
|
114
|
+
name: "BOISSON",
|
|
115
|
+
numberOfProducts: 443,
|
|
116
|
+
image: null,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "CONGELE",
|
|
120
|
+
numberOfProducts: 324,
|
|
121
|
+
image: null,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
333
124
|
};
|
|
334
|
-
const response = { data: { updated: 1 } };
|
|
335
125
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
336
126
|
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
337
127
|
});
|
|
338
|
-
const result = await service.
|
|
128
|
+
const result = await service.getProductCategoryList().toPromise();
|
|
339
129
|
expect(result?.hasSuccess).toBe(true);
|
|
340
130
|
expect(result?.response).toEqual(response);
|
|
341
131
|
});
|
|
342
132
|
});
|
|
343
|
-
describe("
|
|
344
|
-
it("should
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
|
|
133
|
+
describe("getProductById", () => {
|
|
134
|
+
it("should get product by id successfully", async () => {
|
|
135
|
+
const productId = "product-123";
|
|
136
|
+
const response = {
|
|
137
|
+
data: {
|
|
138
|
+
id: productId,
|
|
139
|
+
name: "Product 1",
|
|
140
|
+
barcode: "123",
|
|
141
|
+
category: "CONGELE",
|
|
142
|
+
vatInPercent: 5.5,
|
|
143
|
+
unit: "piece",
|
|
144
|
+
quantity: 1,
|
|
145
|
+
picture: "image.png",
|
|
146
|
+
slug: "product-1",
|
|
147
|
+
internalCode: "001",
|
|
148
|
+
inventory: true,
|
|
149
|
+
quantityInStock: 10,
|
|
150
|
+
minimumStockQuantity: 5,
|
|
151
|
+
pricePurchase: 10,
|
|
152
|
+
priceToSell: 15,
|
|
153
|
+
discountInPercent: 0,
|
|
154
|
+
priceAfterDiscount: 0,
|
|
155
|
+
expiryDate: null,
|
|
156
|
+
subCategory: null,
|
|
157
|
+
volume: null,
|
|
158
|
+
unitWeight: null,
|
|
159
|
+
articleWeight: null,
|
|
160
|
+
tareWeight: null,
|
|
161
|
+
supplier: null,
|
|
162
|
+
supplierCode: null,
|
|
163
|
+
supplierItemName: null,
|
|
164
|
+
htmlDescription: null,
|
|
165
|
+
},
|
|
348
166
|
};
|
|
349
|
-
const response = { data: { updated: 1 } };
|
|
350
167
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
351
168
|
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
352
169
|
});
|
|
353
|
-
const result = await service.
|
|
170
|
+
const result = await service.getProductById(productId).toPromise();
|
|
354
171
|
expect(result?.hasSuccess).toBe(true);
|
|
355
172
|
expect(result?.response).toEqual(response);
|
|
356
173
|
});
|
|
357
174
|
});
|
|
358
|
-
describe("
|
|
359
|
-
it("should
|
|
360
|
-
const storeId = "store-123";
|
|
175
|
+
describe("getProductCollection", () => {
|
|
176
|
+
it("should get product collection successfully", async () => {
|
|
361
177
|
const payload = {
|
|
362
|
-
|
|
178
|
+
page: 1,
|
|
179
|
+
per_page: 10,
|
|
180
|
+
search: "test",
|
|
181
|
+
};
|
|
182
|
+
const response = {
|
|
183
|
+
data: {
|
|
184
|
+
links: {
|
|
185
|
+
first: "/api/v1/store/product-collection?per_page=10&page=1",
|
|
186
|
+
last: "/api/v1/store/product-collection?per_page=10&page=5",
|
|
187
|
+
next: "/api/v1/store/product-collection?per_page=10&page=2",
|
|
188
|
+
},
|
|
189
|
+
items: [
|
|
190
|
+
{
|
|
191
|
+
id: "1",
|
|
192
|
+
name: "Product 1",
|
|
193
|
+
barcode: "123",
|
|
194
|
+
category: "CONGELE",
|
|
195
|
+
vatInPercent: 5.5,
|
|
196
|
+
unit: "piece",
|
|
197
|
+
quantity: 1,
|
|
198
|
+
picture: "image.png",
|
|
199
|
+
slug: "product-1",
|
|
200
|
+
internalCode: "001",
|
|
201
|
+
inventory: true,
|
|
202
|
+
quantityInStock: 10,
|
|
203
|
+
minimumStockQuantity: 5,
|
|
204
|
+
pricePurchase: 10,
|
|
205
|
+
priceToSell: 15,
|
|
206
|
+
discountInPercent: 0,
|
|
207
|
+
priceAfterDiscount: 0,
|
|
208
|
+
expiryDate: null,
|
|
209
|
+
subCategory: null,
|
|
210
|
+
volume: null,
|
|
211
|
+
unitWeight: null,
|
|
212
|
+
articleWeight: null,
|
|
213
|
+
tareWeight: null,
|
|
214
|
+
supplier: null,
|
|
215
|
+
supplierCode: null,
|
|
216
|
+
supplierItemName: null,
|
|
217
|
+
htmlDescription: null,
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
count: 10,
|
|
221
|
+
total: 50,
|
|
222
|
+
page: 1,
|
|
223
|
+
totalPage: 5,
|
|
224
|
+
perPage: 10,
|
|
225
|
+
metadata: [],
|
|
226
|
+
},
|
|
363
227
|
};
|
|
364
|
-
const response = { data: { updated: 1 } };
|
|
365
228
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
366
229
|
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
367
230
|
});
|
|
368
|
-
const result = await service.
|
|
231
|
+
const result = await service.getProductCollection(payload).toPromise();
|
|
232
|
+
expect(result?.hasSuccess).toBe(true);
|
|
233
|
+
expect(result?.response).toEqual(response);
|
|
234
|
+
});
|
|
235
|
+
it("should get product collection without payload", async () => {
|
|
236
|
+
const response = {
|
|
237
|
+
data: {
|
|
238
|
+
links: {
|
|
239
|
+
first: "/api/v1/store/product-collection?per_page=24&page=1",
|
|
240
|
+
last: "/api/v1/store/product-collection?per_page=24&page=1",
|
|
241
|
+
},
|
|
242
|
+
items: [],
|
|
243
|
+
count: 0,
|
|
244
|
+
total: 0,
|
|
245
|
+
page: 1,
|
|
246
|
+
totalPage: 1,
|
|
247
|
+
perPage: 24,
|
|
248
|
+
metadata: [],
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
252
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
253
|
+
});
|
|
254
|
+
const result = await service.getProductCollection().toPromise();
|
|
369
255
|
expect(result?.hasSuccess).toBe(true);
|
|
370
256
|
expect(result?.response).toEqual(response);
|
|
371
257
|
});
|
|
372
258
|
});
|
|
373
|
-
describe("
|
|
374
|
-
it("should
|
|
259
|
+
describe("getProductCollectionByStore", () => {
|
|
260
|
+
it("should get product collection by store successfully", async () => {
|
|
375
261
|
const storeId = "store-123";
|
|
376
262
|
const payload = {
|
|
377
|
-
|
|
263
|
+
page: 1,
|
|
264
|
+
per_page: 10,
|
|
265
|
+
};
|
|
266
|
+
const response = {
|
|
267
|
+
data: {
|
|
268
|
+
links: {
|
|
269
|
+
first: "/api/v1/store/product-collection?per_page=10&page=1",
|
|
270
|
+
last: "/api/v1/store/product-collection?per_page=10&page=1",
|
|
271
|
+
},
|
|
272
|
+
items: [
|
|
273
|
+
{
|
|
274
|
+
id: "1",
|
|
275
|
+
name: "Product 1",
|
|
276
|
+
barcode: "123",
|
|
277
|
+
category: "CONGELE",
|
|
278
|
+
vatInPercent: 5.5,
|
|
279
|
+
unit: "piece",
|
|
280
|
+
quantity: 1,
|
|
281
|
+
picture: "image.png",
|
|
282
|
+
slug: "product-1",
|
|
283
|
+
internalCode: "001",
|
|
284
|
+
inventory: true,
|
|
285
|
+
quantityInStock: 10,
|
|
286
|
+
minimumStockQuantity: 5,
|
|
287
|
+
pricePurchase: 10,
|
|
288
|
+
priceToSell: 15,
|
|
289
|
+
discountInPercent: 0,
|
|
290
|
+
priceAfterDiscount: 0,
|
|
291
|
+
expiryDate: null,
|
|
292
|
+
subCategory: null,
|
|
293
|
+
volume: null,
|
|
294
|
+
unitWeight: null,
|
|
295
|
+
articleWeight: null,
|
|
296
|
+
tareWeight: null,
|
|
297
|
+
supplier: null,
|
|
298
|
+
supplierCode: null,
|
|
299
|
+
supplierItemName: null,
|
|
300
|
+
htmlDescription: null,
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
count: 1,
|
|
304
|
+
total: 1,
|
|
305
|
+
page: 1,
|
|
306
|
+
totalPage: 1,
|
|
307
|
+
perPage: 10,
|
|
308
|
+
metadata: [],
|
|
309
|
+
},
|
|
378
310
|
};
|
|
379
|
-
const response = { data: { updated: 1 } };
|
|
380
311
|
jest.spyOn(service, "provider").mockReturnValue({
|
|
381
312
|
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
382
313
|
});
|
|
383
|
-
const result = await service.
|
|
314
|
+
const result = await service.getProductCollectionByStore(storeId, payload).toPromise();
|
|
384
315
|
expect(result?.hasSuccess).toBe(true);
|
|
385
316
|
expect(result?.response).toEqual(response);
|
|
386
317
|
});
|
|
@@ -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();
|