@smess/networking 1.0.29 → 1.1.0
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/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 +54 -0
- package/dist/services/storefront.store.service.js +142 -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/dist/types/types.d.ts +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Accept, SMESSHeader, SmessService } from "./smess.service";
|
|
2
|
+
export class StoreProductProvider {
|
|
3
|
+
constructor(config, target) {
|
|
4
|
+
this.config = config;
|
|
5
|
+
this.target = target;
|
|
6
|
+
}
|
|
7
|
+
get baseURL() {
|
|
8
|
+
return this.config.version
|
|
9
|
+
? `${this.config.baseUrl}/${this.config.version}`
|
|
10
|
+
: this.config.baseUrl;
|
|
11
|
+
}
|
|
12
|
+
get path() {
|
|
13
|
+
switch (this.target) {
|
|
14
|
+
case "featured-product-list":
|
|
15
|
+
return "/store/featured-product-list";
|
|
16
|
+
case "featured-product-list-by-store":
|
|
17
|
+
return "/store/${id}/featured-product-list";
|
|
18
|
+
case "product-category-list":
|
|
19
|
+
return "/store/product-category/list";
|
|
20
|
+
case "product-get-by-id":
|
|
21
|
+
return "/store/product/${id}";
|
|
22
|
+
case "product-collection":
|
|
23
|
+
return "/store/product-collection";
|
|
24
|
+
case "product-collection-by-store":
|
|
25
|
+
return "/store/${id}/product-collection";
|
|
26
|
+
default:
|
|
27
|
+
return "/store";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
get method() {
|
|
31
|
+
return "GET";
|
|
32
|
+
}
|
|
33
|
+
get headers() {
|
|
34
|
+
let headers = SmessService.getHeaders(Accept.V1, null);
|
|
35
|
+
if (this.config.clientId) {
|
|
36
|
+
headers[SMESSHeader.ClientId] = this.config.clientId;
|
|
37
|
+
}
|
|
38
|
+
if (this.config.apiKey) {
|
|
39
|
+
headers[SMESSHeader.ApiKey] = this.config.apiKey;
|
|
40
|
+
}
|
|
41
|
+
return SmessService.filterHeaders(headers);
|
|
42
|
+
}
|
|
43
|
+
getPath(...queryParams) {
|
|
44
|
+
let definedPath = this.path;
|
|
45
|
+
const params = definedPath.match(/\$\{(.+?)\}/g);
|
|
46
|
+
params?.forEach((value, index) => {
|
|
47
|
+
definedPath = definedPath.replace(value, String(queryParams[index]));
|
|
48
|
+
});
|
|
49
|
+
return definedPath;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class StoreProductService {
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.config = config;
|
|
55
|
+
}
|
|
56
|
+
provider(target) {
|
|
57
|
+
const targetWrapper = new StoreProductProvider(this.config, target);
|
|
58
|
+
return new SmessService(targetWrapper);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get featured product list
|
|
62
|
+
* GET /api/v1/store/featured-product-list
|
|
63
|
+
*/
|
|
64
|
+
getFeaturedProductList() {
|
|
65
|
+
return this.provider("featured-product-list").request();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get featured product list by store
|
|
69
|
+
* GET /api/v1/store/{id}/featured-product-list
|
|
70
|
+
*/
|
|
71
|
+
getFeaturedProductListByStore(storeId) {
|
|
72
|
+
return this.provider("featured-product-list-by-store").request(undefined, undefined, storeId);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get product category list
|
|
76
|
+
* GET /api/v1/store/product-category/list
|
|
77
|
+
*/
|
|
78
|
+
getProductCategoryList() {
|
|
79
|
+
return this.provider("product-category-list").request();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get product by ID
|
|
83
|
+
* GET /api/v1/store/product/{id}
|
|
84
|
+
*/
|
|
85
|
+
getProductById(productId) {
|
|
86
|
+
return this.provider("product-get-by-id").request(undefined, undefined, productId);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get product collection
|
|
90
|
+
* GET /api/v1/store/product-collection
|
|
91
|
+
*/
|
|
92
|
+
getProductCollection(payload) {
|
|
93
|
+
return this.provider("product-collection").request(payload, undefined, undefined);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get product collection by store
|
|
97
|
+
* GET /api/v1/store/{id}/product-collection
|
|
98
|
+
*/
|
|
99
|
+
getProductCollectionByStore(storeId, payload) {
|
|
100
|
+
return this.provider("product-collection-by-store").request(payload, undefined, storeId);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { StoreProductService, } from "./store.product.service";
|
|
2
|
+
import { NetworkingUIEventWrapped, AlertModel, } from "../types/types";
|
|
3
|
+
import { of } from "rxjs";
|
|
4
|
+
describe("StoreProductService", () => {
|
|
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
|
+
beforeEach(() => {
|
|
13
|
+
service = new StoreProductService(config);
|
|
14
|
+
});
|
|
15
|
+
describe("getFeaturedProductList", () => {
|
|
16
|
+
it("should get featured product list successfully", async () => {
|
|
17
|
+
const response = {
|
|
18
|
+
data: [
|
|
19
|
+
{
|
|
20
|
+
id: "1",
|
|
21
|
+
name: "Product 1",
|
|
22
|
+
barcode: "123",
|
|
23
|
+
category: "CONGELE",
|
|
24
|
+
vatInPercent: 5.5,
|
|
25
|
+
unit: "piece",
|
|
26
|
+
quantity: 1,
|
|
27
|
+
picture: "image.png",
|
|
28
|
+
slug: "product-1",
|
|
29
|
+
internalCode: "001",
|
|
30
|
+
inventory: true,
|
|
31
|
+
quantityInStock: 10,
|
|
32
|
+
minimumStockQuantity: 5,
|
|
33
|
+
pricePurchase: 10,
|
|
34
|
+
priceToSell: 15,
|
|
35
|
+
discountInPercent: 0,
|
|
36
|
+
priceAfterDiscount: 0,
|
|
37
|
+
expiryDate: null,
|
|
38
|
+
subCategory: null,
|
|
39
|
+
volume: null,
|
|
40
|
+
unitWeight: null,
|
|
41
|
+
articleWeight: null,
|
|
42
|
+
tareWeight: null,
|
|
43
|
+
supplier: null,
|
|
44
|
+
supplierCode: null,
|
|
45
|
+
supplierItemName: null,
|
|
46
|
+
htmlDescription: null,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
51
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
52
|
+
});
|
|
53
|
+
const result = await service.getFeaturedProductList().toPromise();
|
|
54
|
+
expect(result?.hasSuccess).toBe(true);
|
|
55
|
+
expect(result?.response).toEqual(response);
|
|
56
|
+
});
|
|
57
|
+
it("should handle error", async () => {
|
|
58
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
59
|
+
request: () => of(NetworkingUIEventWrapped.failed(AlertModel.default())),
|
|
60
|
+
});
|
|
61
|
+
const result = await service.getFeaturedProductList().toPromise();
|
|
62
|
+
expect(result?.hasFailed).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe("getFeaturedProductListByStore", () => {
|
|
66
|
+
it("should get featured product list by store successfully", async () => {
|
|
67
|
+
const storeId = "store-123";
|
|
68
|
+
const response = {
|
|
69
|
+
data: [
|
|
70
|
+
{
|
|
71
|
+
id: "1",
|
|
72
|
+
name: "Product 1",
|
|
73
|
+
barcode: "123",
|
|
74
|
+
category: "CONGELE",
|
|
75
|
+
vatInPercent: 5.5,
|
|
76
|
+
unit: "piece",
|
|
77
|
+
quantity: 1,
|
|
78
|
+
picture: "image.png",
|
|
79
|
+
slug: "product-1",
|
|
80
|
+
internalCode: "001",
|
|
81
|
+
inventory: true,
|
|
82
|
+
quantityInStock: 10,
|
|
83
|
+
minimumStockQuantity: 5,
|
|
84
|
+
pricePurchase: 10,
|
|
85
|
+
priceToSell: 15,
|
|
86
|
+
discountInPercent: 0,
|
|
87
|
+
priceAfterDiscount: 0,
|
|
88
|
+
expiryDate: null,
|
|
89
|
+
subCategory: null,
|
|
90
|
+
volume: null,
|
|
91
|
+
unitWeight: null,
|
|
92
|
+
articleWeight: null,
|
|
93
|
+
tareWeight: null,
|
|
94
|
+
supplier: null,
|
|
95
|
+
supplierCode: null,
|
|
96
|
+
supplierItemName: null,
|
|
97
|
+
htmlDescription: null,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
102
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
103
|
+
});
|
|
104
|
+
const result = await service.getFeaturedProductListByStore(storeId).toPromise();
|
|
105
|
+
expect(result?.hasSuccess).toBe(true);
|
|
106
|
+
expect(result?.response).toEqual(response);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
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
|
+
],
|
|
124
|
+
};
|
|
125
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
126
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
127
|
+
});
|
|
128
|
+
const result = await service.getProductCategoryList().toPromise();
|
|
129
|
+
expect(result?.hasSuccess).toBe(true);
|
|
130
|
+
expect(result?.response).toEqual(response);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
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
|
+
},
|
|
166
|
+
};
|
|
167
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
168
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
169
|
+
});
|
|
170
|
+
const result = await service.getProductById(productId).toPromise();
|
|
171
|
+
expect(result?.hasSuccess).toBe(true);
|
|
172
|
+
expect(result?.response).toEqual(response);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe("getProductCollection", () => {
|
|
176
|
+
it("should get product collection successfully", async () => {
|
|
177
|
+
const payload = {
|
|
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
|
+
},
|
|
227
|
+
};
|
|
228
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
229
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
230
|
+
});
|
|
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();
|
|
255
|
+
expect(result?.hasSuccess).toBe(true);
|
|
256
|
+
expect(result?.response).toEqual(response);
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
describe("getProductCollectionByStore", () => {
|
|
260
|
+
it("should get product collection by store successfully", async () => {
|
|
261
|
+
const storeId = "store-123";
|
|
262
|
+
const payload = {
|
|
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
|
+
},
|
|
310
|
+
};
|
|
311
|
+
jest.spyOn(service, "provider").mockReturnValue({
|
|
312
|
+
request: () => of(NetworkingUIEventWrapped.succeeded(response)),
|
|
313
|
+
});
|
|
314
|
+
const result = await service.getProductCollectionByStore(storeId, payload).toPromise();
|
|
315
|
+
expect(result?.hasSuccess).toBe(true);
|
|
316
|
+
expect(result?.response).toEqual(response);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ProviderType, NetworkingConfig, NetworkingUIEventWrapped, HttpResponse } from "../types/types";
|
|
2
|
+
import { SmessService } from "./smess.service";
|
|
3
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
4
|
+
export type StoreTarget = "store-get" | "store-list" | "store-product-category-list" | "store-product-collection" | "store-featured-product-list";
|
|
5
|
+
export interface ProductCollectionRequest {
|
|
6
|
+
page?: number;
|
|
7
|
+
per_page?: number;
|
|
8
|
+
search?: string;
|
|
9
|
+
sort_by?: string;
|
|
10
|
+
category?: string;
|
|
11
|
+
min_price?: number;
|
|
12
|
+
max_price?: number;
|
|
13
|
+
only_discounted?: boolean;
|
|
14
|
+
unit?: string;
|
|
15
|
+
supplier?: string;
|
|
16
|
+
has_offer?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class StoreProvider implements ProviderType {
|
|
19
|
+
private readonly config;
|
|
20
|
+
private readonly target;
|
|
21
|
+
constructor(config: NetworkingConfig, target: StoreTarget);
|
|
22
|
+
get baseURL(): string;
|
|
23
|
+
get path(): string;
|
|
24
|
+
get method(): string;
|
|
25
|
+
get headers(): Record<string, string>;
|
|
26
|
+
getPath(...queryParams: unknown[]): string;
|
|
27
|
+
}
|
|
28
|
+
export interface StoreData {
|
|
29
|
+
id: string;
|
|
30
|
+
data: HttpResponse;
|
|
31
|
+
timestamp: number;
|
|
32
|
+
}
|
|
33
|
+
export interface StoreListData {
|
|
34
|
+
data: HttpResponse;
|
|
35
|
+
timestamp: number;
|
|
36
|
+
}
|
|
37
|
+
export interface ProductCollectionData {
|
|
38
|
+
storeId: string;
|
|
39
|
+
request: ProductCollectionRequest;
|
|
40
|
+
data: HttpResponse;
|
|
41
|
+
timestamp: number;
|
|
42
|
+
}
|
|
43
|
+
export interface ProductCategoryData {
|
|
44
|
+
data: HttpResponse;
|
|
45
|
+
timestamp: number;
|
|
46
|
+
}
|
|
47
|
+
export interface FeaturedProductData {
|
|
48
|
+
storeId: string;
|
|
49
|
+
data: HttpResponse;
|
|
50
|
+
timestamp: number;
|
|
51
|
+
}
|
|
52
|
+
export declare class StoreService {
|
|
53
|
+
private readonly config;
|
|
54
|
+
readonly $selectedStoreId: BehaviorSubject<string | null>;
|
|
55
|
+
private readonly cacheService;
|
|
56
|
+
private readonly storeListCache;
|
|
57
|
+
private readonly productCollectionCache;
|
|
58
|
+
private readonly productCategoryCache;
|
|
59
|
+
private readonly featuredProductCache;
|
|
60
|
+
constructor(config: NetworkingConfig);
|
|
61
|
+
provider(target: StoreTarget): SmessService<StoreProvider>;
|
|
62
|
+
/**
|
|
63
|
+
* Set the selected store ID
|
|
64
|
+
*/
|
|
65
|
+
setSelectedStoreId(storeId: string | null): void;
|
|
66
|
+
/**
|
|
67
|
+
* Get the current selected store ID
|
|
68
|
+
*/
|
|
69
|
+
get currentSelectedStoreId(): string | null;
|
|
70
|
+
get(id: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
71
|
+
list(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
72
|
+
productCategoryList(): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
73
|
+
productCollection(id: string, payload: ProductCollectionRequest): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
74
|
+
featuredProductList(id: string): Observable<NetworkingUIEventWrapped<HttpResponse>>;
|
|
75
|
+
clearCache(): Promise<void>;
|
|
76
|
+
clearStoreCache(id: string): Promise<void>;
|
|
77
|
+
clearProductCollectionCache(id: string): Promise<void>;
|
|
78
|
+
private isCacheValid;
|
|
79
|
+
}
|