idosell 0.4.18 → 0.4.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/changelog.md +6 -1
- package/dist/enums.d.ts +3 -2
- package/dist/enums.js +2 -1
- package/dist/gateways.d.ts +2 -2
- package/dist/utils.d.ts +16 -5
- package/dist/utils.js +76 -15
- package/package.json +1 -1
- package/tests/getMenu.test.js +1 -1
- package/tests/getOrdersAuctionDetails.test.js +1 -1
- package/tests/getOrdersExportdocumentsEPP.test.js +1 -1
- package/tests/getPayments.test.js +1 -1
- package/tests/putRefundsConfirmRefund.test.js +1 -1
- package/tests/utilMapAllProductCodes.test.js +24 -0
- package/tests/utilMapProductCodes.test.js +18 -6
- package/tests/utilMapProductLocations.test.js +25 -7
- package/tests/utilMapSizeQuantites.test.js +23 -11
- package/tests/utilSumProductQuantities.test.js +10 -11
- package/tests/{util.data.ts → utilTestData.ts} +3 -2
package/changelog.md
CHANGED
|
@@ -5,12 +5,17 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.4.20] - 2025-12-18
|
|
9
|
+
- Added indexing option for utils functions
|
|
10
|
+
- Fixed typings and tests
|
|
11
|
+
- Added descriptions
|
|
12
|
+
|
|
8
13
|
## [0.4.18] - 2025-12-18
|
|
9
14
|
- Updated to v7.10
|
|
10
15
|
- Updated utils
|
|
11
16
|
- Fixed dates helper default value
|
|
12
17
|
- Improved typing on empty PHP objects conversion
|
|
13
|
-
- Updated axios
|
|
18
|
+
- Updated axios version
|
|
14
19
|
|
|
15
20
|
## [0.4.13] - 2025-10-15
|
|
16
21
|
### Changed
|
package/dist/enums.d.ts
CHANGED
|
@@ -379,15 +379,16 @@ export enum PRODUCT_SIZE_COUNTABLE {
|
|
|
379
379
|
QUANTITY_OWN = 'productSizeQuantityOwnStock',
|
|
380
380
|
QUANTITY_OUTSIDE = 'productSizeQuantityOutsideStock',
|
|
381
381
|
QUANTITY_ALL = 'productSizeQuantityAllStocks',
|
|
382
|
-
|
|
382
|
+
QUANTITY_UNFINISHED = 'productOrdersUnfinishedQuantities',
|
|
383
383
|
DELIVERIES = 'productSizesDeliveries',
|
|
384
384
|
AUCTIONS = 'productSizesDispositionsInAuctions',
|
|
385
|
+
RESERVATIONS = 'productSizeReservationOrder'
|
|
385
386
|
}
|
|
386
387
|
|
|
387
388
|
export enum PRODUCT_SIZE_CODES {
|
|
388
389
|
NAME = 'sizePanelName',
|
|
389
390
|
CODE_PRODUCER = 'productSizeCodeProducer',
|
|
390
|
-
CODE_EXTERNAL = 'productSizeCodeExternal'
|
|
391
|
+
CODE_EXTERNAL = 'productSizeCodeExternal'
|
|
391
392
|
}
|
|
392
393
|
|
|
393
394
|
export enum PRODUCT_SIZE_LOCATIONS {
|
package/dist/enums.js
CHANGED
|
@@ -380,9 +380,10 @@ var PRODUCT_SIZE_COUNTABLE;
|
|
|
380
380
|
PRODUCT_SIZE_COUNTABLE["QUANTITY_OWN"] = "productSizeQuantityOwnStock";
|
|
381
381
|
PRODUCT_SIZE_COUNTABLE["QUANTITY_OUTSIDE"] = "productSizeQuantityOutsideStock";
|
|
382
382
|
PRODUCT_SIZE_COUNTABLE["QUANTITY_ALL"] = "productSizeQuantityAllStocks";
|
|
383
|
-
PRODUCT_SIZE_COUNTABLE["
|
|
383
|
+
PRODUCT_SIZE_COUNTABLE["QUANTITY_UNFINISHED"] = "productOrdersUnfinishedQuantities";
|
|
384
384
|
PRODUCT_SIZE_COUNTABLE["DELIVERIES"] = "productSizesDeliveries";
|
|
385
385
|
PRODUCT_SIZE_COUNTABLE["AUCTIONS"] = "productSizesDispositionsInAuctions";
|
|
386
|
+
PRODUCT_SIZE_COUNTABLE["RESERVATIONS"] = "productSizeReservationOrder";
|
|
386
387
|
})(PRODUCT_SIZE_COUNTABLE || (PRODUCT_SIZE_COUNTABLE = {}));
|
|
387
388
|
var PRODUCT_SIZE_CODES;
|
|
388
389
|
(function (PRODUCT_SIZE_CODES) {
|
package/dist/gateways.d.ts
CHANGED
|
@@ -3343,7 +3343,7 @@ export interface SearchProductsRequest extends PagableGateway<SearchProductsRequ
|
|
|
3343
3343
|
/** Price range for sought products. */
|
|
3344
3344
|
productSearchPriceRange: (value: RequestParams.SearchProductsParams["productSearchPriceRange"]) => this;
|
|
3345
3345
|
/** VAT value for sought products */
|
|
3346
|
-
productVatRates: (value:
|
|
3346
|
+
productVatRates: (value: number|number[]) => this;
|
|
3347
3347
|
/** Is product VAT-free Allowed values "y" - yes, "n" - no. */
|
|
3348
3348
|
productIsVatFree: (value: string) => this;
|
|
3349
3349
|
/** Product has defined wholesale price. Available values: "y" - has wholesale price, "n" - does not have wholesale price. */
|
|
@@ -5206,4 +5206,4 @@ export interface Gateways {
|
|
|
5206
5206
|
|
|
5207
5207
|
declare const defaultExport: (url: string, apiKey: string, version?: number | string) => Gateways;
|
|
5208
5208
|
export default defaultExport;
|
|
5209
|
-
export { ENUMS, RequestParams }
|
|
5209
|
+
export { ENUMS, RequestParams, utils }
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PRODUCT_SIZE_COUNTABLE, PRODUCT_SIZE_LOCATIONS, PRODUCT_SIZE_CODES } from "./enums.d";
|
|
1
|
+
import type { PRODUCT_SIZE_COUNTABLE, PRODUCT_SIZE_LOCATIONS, PRODUCT_SIZE_CODES, PRODUCE_SIZE_INDEX } from "./enums.d";
|
|
2
2
|
import type { SearchProductsResponse } from "./responses.d.ts"
|
|
3
3
|
|
|
4
4
|
export type IdosellProduct = SearchProductsResponse['results'][0];
|
|
@@ -7,24 +7,35 @@ export type GetIaICodeFunction = (productId: number|string, sizeId: string) => s
|
|
|
7
7
|
|
|
8
8
|
export type SumProductQuantitiesFunction = (productStocksData: IdosellProduct['productStocksData'], stockType?: PRODUCT_SIZE_COUNTABLE | `${PRODUCT_SIZE_COUNTABLE}`) => number;
|
|
9
9
|
|
|
10
|
-
export type MapSizeQuantitesFunction = (product: IdosellProduct, stockType?: `${PRODUCT_SIZE_COUNTABLE}`) => Record<string,number>;
|
|
10
|
+
export type MapSizeQuantitesFunction = (product: IdosellProduct, stockType?: `${PRODUCT_SIZE_COUNTABLE}`, indexBy?: `${PRODUCE_SIZE_INDEX}`) => Record<string,number>;
|
|
11
11
|
|
|
12
|
-
export type MapProductCodesFunction = (product: IdosellProduct, codeType?: `${PRODUCT_SIZE_CODES}`) => Record<string,string>;
|
|
12
|
+
export type MapProductCodesFunction = (product: IdosellProduct, codeType?: `${PRODUCT_SIZE_CODES}`, indexBy?: `${PRODUCE_SIZE_INDEX}`) => Record<string,string>;
|
|
13
13
|
|
|
14
|
-
export type
|
|
14
|
+
export type MapProductAllCodesFunction = (product: IdosellProduct, indexBy?: `${PRODUCE_SIZE_INDEX}`) => Record<string,string[]>;
|
|
15
|
+
|
|
16
|
+
export type MapProductLocationsFunction = (product: IdosellProduct, stockId?: number, codeType?: `${PRODUCT_SIZE_LOCATIONS}`, indexBy?: `${PRODUCE_SIZE_INDEX}`) => Record<string,string[]>;
|
|
15
17
|
|
|
16
18
|
export type GetLangDataFunction = <T extends { langId: string}>(array: T[], langId?: string) => T|undefined;
|
|
17
19
|
|
|
18
20
|
export type ClearParametersLangDataFunction = (products: SearchProductsResponse['results'], langId: string = 'pol') => SearchProductsResponse['results'];
|
|
19
21
|
|
|
20
22
|
declare namespace utils {
|
|
23
|
+
/** @description The method allows you to build an IAI code from the product ID and size ID. */
|
|
21
24
|
const getIaiCode: GetIaICodeFunction;
|
|
25
|
+
/** @description The method allows you to sum up the current stock levels: warehouses, available stocks, etc. */
|
|
22
26
|
const sumProductQuantities: SumProductQuantitiesFunction;
|
|
27
|
+
/** @description The method allows mapping the sum of the current stock levels (in warehouses, at disposal, etc.) divided into sizes */
|
|
23
28
|
const mapSizeQuantites: MapSizeQuantitesFunction;
|
|
29
|
+
/** @description The method allows mapping the producers's or external system's codes stored in the system to SKUs */
|
|
24
30
|
const mapProductCodes: MapProductCodesFunction;
|
|
31
|
+
/** @description The method allows mapping all known codes: IAI code, manufacturer code or external code as an array */
|
|
32
|
+
const mapAllProductCodes: MapProductAllCodesFunction;
|
|
33
|
+
/** @description This method allows you to map product locations stored in the system, broken down by size. You can select a specific warehouse or list all of them, both primary and secondary. */
|
|
34
|
+
const mapProductLocations: MapProductLocationsFunction;
|
|
35
|
+
/** @description Get first item (description, series, parameter name or value) with the selected langId */
|
|
25
36
|
const getLangData: GetLangDataFunction;
|
|
37
|
+
/** @description Modifies product response by removing all parameter names nad values that are not in selected langId */
|
|
26
38
|
const clearParametersLangData: ClearParametersLangDataFunction;
|
|
27
|
-
const mapProductLocations: MapProductLocationsFunction;
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
export default utils;
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PRODUCE_SIZE_INDEX } from "./enums.d.js";
|
|
1
2
|
import ENUMS from "./enums.js";
|
|
2
3
|
const getIaiCode = (productId, sizeId) => {
|
|
3
4
|
if (sizeId === 'uniw')
|
|
@@ -50,7 +51,7 @@ const productSizesPathMap = {
|
|
|
50
51
|
'productSizesDispositionsInSales',
|
|
51
52
|
'array'
|
|
52
53
|
],
|
|
53
|
-
[ENUMS.PRODUCT_SIZE_COUNTABLE.
|
|
54
|
+
[ENUMS.PRODUCT_SIZE_COUNTABLE.QUANTITY_UNFINISHED]: [
|
|
54
55
|
'productStocksData',
|
|
55
56
|
'productOrdersUnfinishedQuantities',
|
|
56
57
|
'array',
|
|
@@ -68,6 +69,13 @@ const productSizesPathMap = {
|
|
|
68
69
|
'productSizesDispositionsInAuctions',
|
|
69
70
|
'array'
|
|
70
71
|
],
|
|
72
|
+
[ENUMS.PRODUCT_SIZE_COUNTABLE.RESERVATIONS]: [
|
|
73
|
+
'productStocksData',
|
|
74
|
+
'productStocksQuantities',
|
|
75
|
+
'array',
|
|
76
|
+
'productSizesData',
|
|
77
|
+
'array'
|
|
78
|
+
],
|
|
71
79
|
[ENUMS.PRODUCT_SIZE_CODES.NAME]: [
|
|
72
80
|
'productSizes',
|
|
73
81
|
'array'
|
|
@@ -126,29 +134,55 @@ const sumProductQuantities = (productStocksData, nodeName = ENUMS.PRODUCT_SIZE_C
|
|
|
126
134
|
});
|
|
127
135
|
return sum;
|
|
128
136
|
};
|
|
129
|
-
const
|
|
137
|
+
const getProductIndexFunction = (type, product) => {
|
|
138
|
+
switch (type) {
|
|
139
|
+
case PRODUCE_SIZE_INDEX.ID: return (obj) => obj.sizeId;
|
|
140
|
+
case PRODUCE_SIZE_INDEX.IAI_CODE: return (obj) => getIaiCode(product.productId, obj.sizeId);
|
|
141
|
+
case PRODUCE_SIZE_INDEX.NAME: {
|
|
142
|
+
return (obj) => {
|
|
143
|
+
if (obj.sizePanelName)
|
|
144
|
+
return obj.sizePanelName;
|
|
145
|
+
if (product.productSizes) {
|
|
146
|
+
const nameItem = product.productSizes.find(size => size.sizeId === obj.sizeId);
|
|
147
|
+
if (nameItem)
|
|
148
|
+
return nameItem.sizePanelName;
|
|
149
|
+
}
|
|
150
|
+
throw new Error("Could not index by name - sizePanelName and productSizes missing");
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
default: throw new Error('Invalid indexBy');
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const mapSizeQuantites = (product, nodeName = ENUMS.PRODUCT_SIZE_COUNTABLE.QUANTITY_OWN, indexBy = ENUMS.PRODUCE_SIZE_INDEX.ID) => {
|
|
130
157
|
const results = getTraversedPathElements(product, nodeName);
|
|
158
|
+
if (nodeName === 'productSizeReservationOrder') {
|
|
159
|
+
results.forEach(node => {
|
|
160
|
+
node.productSizeReservationOrder = node.productSizeReservations.productSizeReservationOrder;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
131
163
|
const aggregated = {};
|
|
132
164
|
if (['productOrdersUnfinishedQuantities', 'productSizesDeliveries', 'productSizesDispositionsInAuctions'].includes(nodeName))
|
|
133
165
|
nodeName = 'productSizeQuantity';
|
|
166
|
+
const getIndex = getProductIndexFunction(indexBy, product);
|
|
134
167
|
results.forEach(item => {
|
|
135
168
|
if (item?.sizeId && item[nodeName] !== undefined) {
|
|
136
|
-
const
|
|
169
|
+
const index = getIndex(item) ?? item.sizeId;
|
|
137
170
|
const value = Number(item[nodeName]) || 0;
|
|
138
|
-
aggregated[
|
|
171
|
+
aggregated[index] = (aggregated[index] || 0) + value;
|
|
139
172
|
}
|
|
140
173
|
});
|
|
141
174
|
return aggregated;
|
|
142
175
|
};
|
|
143
|
-
const mapProductCodes = (product, codeType = ENUMS.PRODUCT_SIZE_CODES.NAME) => {
|
|
176
|
+
const mapProductCodes = (product, codeType = ENUMS.PRODUCT_SIZE_CODES.NAME, indexBy = ENUMS.PRODUCE_SIZE_INDEX.ID) => {
|
|
144
177
|
const results = getTraversedPathElements(product, codeType);
|
|
145
178
|
const mapped = {};
|
|
179
|
+
const getIndex = getProductIndexFunction(indexBy, product);
|
|
146
180
|
results.forEach(item => {
|
|
147
181
|
if (item?.sizeId && item[codeType] !== undefined) {
|
|
148
|
-
const
|
|
182
|
+
const index = getIndex(item) ?? item.sizeId;
|
|
149
183
|
const value = String(item[codeType] || '');
|
|
150
|
-
if (!mapped[
|
|
151
|
-
mapped[
|
|
184
|
+
if (!mapped[index] || value) {
|
|
185
|
+
mapped[index] = value;
|
|
152
186
|
}
|
|
153
187
|
}
|
|
154
188
|
});
|
|
@@ -159,7 +193,24 @@ const SUB_TYPE_NODES = {
|
|
|
159
193
|
stockLocationId: 'stockAdditionalLocationId',
|
|
160
194
|
stockLocationCode: 'stockAdditionalLocationCode'
|
|
161
195
|
};
|
|
162
|
-
const
|
|
196
|
+
const mapAllProductCodes = (product, indexBy) => {
|
|
197
|
+
const results = getTraversedPathElements(product, ENUMS.PRODUCT_SIZE_CODES.CODE_PRODUCER);
|
|
198
|
+
const mapped = {};
|
|
199
|
+
const getIndex = getProductIndexFunction(indexBy, product);
|
|
200
|
+
for (const item of results) {
|
|
201
|
+
const index = getIndex(item);
|
|
202
|
+
if (!mapped[index]) {
|
|
203
|
+
mapped[index] = [];
|
|
204
|
+
}
|
|
205
|
+
mapped[index].push(getIaiCode(product.productId, item.sizeId));
|
|
206
|
+
if (item.productSizeCodeProducer?.length)
|
|
207
|
+
mapped[index].push(item.productSizeCodeProducer);
|
|
208
|
+
if (item.productSizeCodeExternal?.length)
|
|
209
|
+
mapped[index].push(item.productSizeCodeExternal);
|
|
210
|
+
}
|
|
211
|
+
return mapped;
|
|
212
|
+
};
|
|
213
|
+
const mapProductLocations = (product, stockId, locationType = ENUMS.PRODUCT_SIZE_LOCATIONS.NAME, indexBy = ENUMS.PRODUCE_SIZE_INDEX.ID) => {
|
|
163
214
|
let results = getTraversedPathElements(product, locationType);
|
|
164
215
|
if (stockId) {
|
|
165
216
|
const prefix = 'M' + stockId;
|
|
@@ -167,22 +218,23 @@ const mapProductLocations = (product, stockId, locationType = ENUMS.PRODUCT_SIZE
|
|
|
167
218
|
}
|
|
168
219
|
const mapped = {};
|
|
169
220
|
const subNode = SUB_TYPE_NODES[locationType];
|
|
221
|
+
const getIndex = getProductIndexFunction(indexBy, product);
|
|
170
222
|
for (const item of results) {
|
|
171
|
-
const
|
|
172
|
-
if (!mapped[
|
|
173
|
-
mapped[
|
|
223
|
+
const index = getIndex(item);
|
|
224
|
+
if (!mapped[index]) {
|
|
225
|
+
mapped[index] = [];
|
|
174
226
|
}
|
|
175
227
|
// main location
|
|
176
228
|
const mainLocation = item[locationType];
|
|
177
229
|
if (mainLocation) {
|
|
178
|
-
mapped[
|
|
230
|
+
mapped[index].push(mainLocation.toString());
|
|
179
231
|
}
|
|
180
232
|
// additional locations
|
|
181
233
|
if (item.stockAdditionalLocations?.length) {
|
|
182
234
|
for (const additional of item.stockAdditionalLocations) {
|
|
183
235
|
const value = additional[subNode];
|
|
184
236
|
if (value) {
|
|
185
|
-
mapped[
|
|
237
|
+
mapped[index].push(value.toString());
|
|
186
238
|
}
|
|
187
239
|
}
|
|
188
240
|
}
|
|
@@ -212,11 +264,20 @@ const clearParametersLangData = (products, langId = 'pol') => {
|
|
|
212
264
|
return products;
|
|
213
265
|
};
|
|
214
266
|
export default {
|
|
215
|
-
|
|
267
|
+
/** @description The method allows you to build an IAI code from the product ID and size ID. */
|
|
216
268
|
getIaiCode,
|
|
269
|
+
/** @description The method allows you to sum up the current stock levels: warehouses, available stocks, etc. */
|
|
270
|
+
sumProductQuantities,
|
|
271
|
+
/** @description The method allows mapping the sum of the current stock levels (in warehouses, at disposal, etc.) divided into sizes */
|
|
217
272
|
mapSizeQuantites,
|
|
273
|
+
/** @description The method allows mapping the producers's or external system's codes stored in the system to SKUs */
|
|
218
274
|
mapProductCodes,
|
|
275
|
+
/** @description The method allows mapping all known codes: IAI code, manufacturer code or external code as an array */
|
|
276
|
+
mapAllProductCodes,
|
|
277
|
+
/** @description This method allows you to map product locations stored in the system, broken down by size. You can select a specific warehouse or list all of them, both primary and secondary. */
|
|
219
278
|
mapProductLocations,
|
|
279
|
+
/** @description Get first item (description, series, parameter name or value) with the selected langId */
|
|
220
280
|
getLangData,
|
|
281
|
+
/** @description Modifies product response by removing all parameter names nad values that are not in selected langId */
|
|
221
282
|
clearParametersLangData
|
|
222
283
|
};
|
package/package.json
CHANGED
package/tests/getMenu.test.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ENUMS, utils } from '../dist/index';
|
|
2
|
+
import { expect, test } from "vitest"
|
|
3
|
+
import { STOCK_PRODUCT } from './utilTestData';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const INDEX = ENUMS.PRODUCE_SIZE_INDEX;
|
|
7
|
+
|
|
8
|
+
test('Utils mapAllProductCodes by ID', () => {
|
|
9
|
+
const codes = utils.mapAllProductCodes(STOCK_PRODUCT, INDEX.ID)
|
|
10
|
+
console.log(JSON.stringify(codes));
|
|
11
|
+
expect(codes).toEqual({"3":["1234-3","1234567890128","PX-ZERO-S"],"4":["1234-4","1234567890135","PX-ZERO-M"],"5":["1234-5","1234567890142","PX-ZERO-L"],"6":["1234-6","1234567890159","PX-ZERO-X"]});
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('Utils mapAllProductCodes by IAI code', () => {
|
|
15
|
+
const codes = utils.mapAllProductCodes(STOCK_PRODUCT, INDEX.IAI_CODE)
|
|
16
|
+
console.log(JSON.stringify(codes));
|
|
17
|
+
expect(codes).toEqual({"1234-3":["1234-3","1234567890128","PX-ZERO-S"],"1234-4":["1234-4","1234567890135","PX-ZERO-M"],"1234-5":["1234-5","1234567890142","PX-ZERO-L"],"1234-6":["1234-6","1234567890159","PX-ZERO-X"]});
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('Utils mapAllProductCodes by name', () => {
|
|
21
|
+
const codes = utils.mapAllProductCodes(STOCK_PRODUCT, INDEX.NAME)
|
|
22
|
+
console.log(JSON.stringify(codes));
|
|
23
|
+
expect(codes).toEqual({"S":["1234-3","1234567890128","PX-ZERO-S"],"M":["1234-4","1234567890135","PX-ZERO-M"],"L":["1234-5","1234567890142","PX-ZERO-L"],"XL":["1234-6","1234567890159","PX-ZERO-X"]});
|
|
24
|
+
})
|
|
@@ -1,24 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ENUMS, utils } from '../dist/index';
|
|
2
2
|
import { expect, test } from "vitest"
|
|
3
|
-
import { STOCK_PRODUCT } from
|
|
4
|
-
import ENUMS from '$dist/enums';
|
|
3
|
+
import { STOCK_PRODUCT } from './utilTestData';
|
|
5
4
|
|
|
6
5
|
const CODES = ENUMS.PRODUCT_SIZE_CODES;
|
|
6
|
+
const INDEX = ENUMS.PRODUCE_SIZE_INDEX;
|
|
7
7
|
|
|
8
8
|
test('Utils mapProductCodes on sizePanelName', () => {
|
|
9
9
|
expect(CODES.NAME).toEqual('sizePanelName');
|
|
10
|
-
const codes =
|
|
10
|
+
const codes = utils.mapProductCodes(STOCK_PRODUCT, CODES.NAME)
|
|
11
11
|
expect(codes).toEqual({"3": "S","4": "M","5": "L","6": "XL"});
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
test('Utils mapProductCodes on productSizeCodeProducer', () => {
|
|
15
15
|
expect(CODES.CODE_PRODUCER).toEqual('productSizeCodeProducer');
|
|
16
|
-
const codes =
|
|
16
|
+
const codes = utils.mapProductCodes(STOCK_PRODUCT, CODES.CODE_PRODUCER)
|
|
17
17
|
expect(codes).toEqual({"3": "1234567890128","4": "1234567890135","5": "1234567890142","6": "1234567890159"});
|
|
18
18
|
})
|
|
19
19
|
|
|
20
20
|
test('Utils mapProductCodes on productSizeCodeExternal', () => {
|
|
21
21
|
expect(CODES.CODE_EXTERNAL).toEqual('productSizeCodeExternal');
|
|
22
|
-
const codes =
|
|
22
|
+
const codes = utils.mapProductCodes(STOCK_PRODUCT, CODES.CODE_EXTERNAL)
|
|
23
23
|
expect(codes).toEqual({"3": "PX-ZERO-S","4": "PX-ZERO-M","5": "PX-ZERO-L","6": "PX-ZERO-X"});
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('Utils mapProductCodes on sizePanelName by IAI code', () => {
|
|
27
|
+
expect(CODES.NAME).toEqual('sizePanelName');
|
|
28
|
+
const codes = utils.mapProductCodes(STOCK_PRODUCT, CODES.NAME, INDEX.IAI_CODE)
|
|
29
|
+
expect(codes).toEqual({"1234-3":"S","1234-4":"M","1234-5":"L","1234-6":"XL"});
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('Utils mapProductCodes on productSizeCodeProducer by size name', () => {
|
|
33
|
+
expect(CODES.NAME).toEqual('sizePanelName');
|
|
34
|
+
const codes = utils.mapProductCodes(STOCK_PRODUCT, CODES.CODE_PRODUCER, INDEX.NAME)
|
|
35
|
+
expect(codes).toEqual({"S":"1234567890128","M":"1234567890135","L":"1234567890142","XL":"1234567890159"});
|
|
24
36
|
})
|
|
@@ -1,29 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ENUMS, utils } from '../dist/index';
|
|
2
2
|
import { expect, test } from "vitest"
|
|
3
|
-
import { STOCK_PRODUCT } from
|
|
4
|
-
import { ENUMS } from '$dist';
|
|
3
|
+
import { STOCK_PRODUCT } from './utilTestData';
|
|
5
4
|
|
|
6
5
|
const LOCATION = ENUMS.PRODUCT_SIZE_LOCATIONS;
|
|
6
|
+
const INDEX = ENUMS.PRODUCE_SIZE_INDEX;
|
|
7
7
|
|
|
8
8
|
test('Utils mapProductLocations on stockLocationCode', () => {
|
|
9
9
|
expect(LOCATION.CODE).toEqual('stockLocationCode');
|
|
10
|
-
const locations =
|
|
10
|
+
const locations = utils.mapProductLocations(STOCK_PRODUCT, 1, LOCATION.CODE)
|
|
11
11
|
expect(locations).toEqual({"3":["F","P","A"],"4":["F"],"5":["B"],"6":["B"]});
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
+
test('Utils mapProductLocations on stockLocationId', () => {
|
|
15
|
+
expect(LOCATION.ID).toEqual('stockLocationId');
|
|
16
|
+
const locations = utils.mapProductLocations(STOCK_PRODUCT, 1, LOCATION.ID)
|
|
17
|
+
expect(locations).toEqual({"3":["16","46","1"],"4":["16"],"5":["4"],"6":["4"]});
|
|
18
|
+
})
|
|
19
|
+
|
|
14
20
|
test('Utils mapProductLocations on stockLocationTextId', () => {
|
|
15
21
|
expect(LOCATION.NAME).toEqual('stockLocationTextId');
|
|
16
|
-
const locations =
|
|
22
|
+
const locations = utils.mapProductLocations(STOCK_PRODUCT, 1, LOCATION.NAME)
|
|
17
23
|
expect(locations).toEqual({"3":["M1\\A014","M1\\A015","M1\\A113"],"4":["M1\\A014"],"5":["M1\\B013"],"6":["M1\\B013"]});
|
|
18
24
|
})
|
|
19
25
|
|
|
26
|
+
test('Utils mapProductLocations on stockLocationTextId by IAI code', () => {
|
|
27
|
+
expect(LOCATION.NAME).toEqual('stockLocationTextId');
|
|
28
|
+
const locations = utils.mapProductLocations(STOCK_PRODUCT, 1, LOCATION.NAME, INDEX.IAI_CODE)
|
|
29
|
+
expect(locations).toEqual({"1234-3":["M1\\A014","M1\\A015","M1\\A113"],"1234-4":["M1\\A014"],"1234-5":["M1\\B013"],"1234-6":["M1\\B013"]});
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('Utils mapProductLocations on stockLocationTextId by size name', () => {
|
|
33
|
+
expect(LOCATION.NAME).toEqual('stockLocationTextId');
|
|
34
|
+
const locations = utils.mapProductLocations(STOCK_PRODUCT, 1, LOCATION.NAME, INDEX.NAME)
|
|
35
|
+
expect(locations).toEqual({"S":["M1\\A014","M1\\A015","M1\\A113"],"M":["M1\\A014"],"L":["M1\\B013"],"XL":["M1\\B013"]});
|
|
36
|
+
})
|
|
37
|
+
|
|
20
38
|
test('Utils mapProductLocations on stockLocationId', () => {
|
|
21
39
|
expect(LOCATION.ID).toEqual('stockLocationId');
|
|
22
|
-
const locations =
|
|
40
|
+
const locations = utils.mapProductLocations(STOCK_PRODUCT, 1, LOCATION.ID)
|
|
23
41
|
expect(locations).toEqual({"3":["16","46","1"],"4":["16"],"5":["4"],"6":["4"]});
|
|
24
42
|
})
|
|
25
43
|
|
|
26
44
|
test('Utils mapProductLocations full', () => {
|
|
27
|
-
const locations =
|
|
45
|
+
const locations = utils.mapProductLocations(STOCK_PRODUCT)
|
|
28
46
|
expect(locations).toEqual({"3":["M1\\A014","M1\\A015","M1\\A113","M2\\G013","M3\\K014"],"4":["M1\\A014","M2\\G015","M3\\L013"],"5":["M1\\B013","M2\\G114","M3\\L013"],"6":["M1\\B013","M2\\G214","M3\\K014"]});
|
|
29
47
|
})
|
|
@@ -1,48 +1,60 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ENUMS, utils } from '../dist/index';
|
|
2
2
|
import { expect, test } from "vitest"
|
|
3
|
-
import { STOCK_PRODUCT } from
|
|
4
|
-
import ENUMS from '$dist/enums';
|
|
3
|
+
import { STOCK_PRODUCT } from './utilTestData';
|
|
5
4
|
|
|
6
5
|
const COUNTABLE = ENUMS.PRODUCT_SIZE_COUNTABLE;
|
|
6
|
+
const INDEX = ENUMS.PRODUCE_SIZE_INDEX;
|
|
7
7
|
|
|
8
8
|
test('Utils mapSizeQuantites on productSizeQuantity', () => {
|
|
9
9
|
expect(COUNTABLE.QUANTITY).toEqual('productSizeQuantity');
|
|
10
|
-
const quantities =
|
|
10
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.QUANTITY)
|
|
11
11
|
expect(quantities).toEqual({"3":10,"4":10,"5":0,"6":0});
|
|
12
12
|
})
|
|
13
13
|
|
|
14
|
+
test('Utils mapSizeQuantites on productSizeQuantity by IAI code', () => {
|
|
15
|
+
expect(COUNTABLE.QUANTITY).toEqual('productSizeQuantity');
|
|
16
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.QUANTITY, INDEX.IAI_CODE)
|
|
17
|
+
expect(quantities).toEqual({"1234-3":10,"1234-4":10,"1234-5":0,"1234-6":0});
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('Utils mapSizeQuantites on productSizeQuantity by size name', () => {
|
|
21
|
+
expect(COUNTABLE.QUANTITY).toEqual('productSizeQuantity');
|
|
22
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.QUANTITY, INDEX.NAME)
|
|
23
|
+
expect(quantities).toEqual({"S":10,"M":10,"L":0,"XL":0});
|
|
24
|
+
})
|
|
25
|
+
|
|
14
26
|
test('Utils mapSizeQuantites on productSizeQuantityOwnStock', () => {
|
|
15
27
|
expect(COUNTABLE.QUANTITY_OWN).toEqual('productSizeQuantityOwnStock');
|
|
16
|
-
const quantities =
|
|
28
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.QUANTITY_OWN)
|
|
17
29
|
expect(quantities).toEqual({"3":8,"4":10,"5":0,"6":0});
|
|
18
30
|
})
|
|
19
31
|
|
|
20
32
|
test('Utils mapSizeQuantites on productSizeQuantityOutsideStock', () => {
|
|
21
33
|
expect(COUNTABLE.QUANTITY_OUTSIDE).toEqual('productSizeQuantityOutsideStock');
|
|
22
|
-
const quantities =
|
|
34
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.QUANTITY_OUTSIDE)
|
|
23
35
|
expect(quantities).toEqual({"3":0,"4":0,"5":5,"6":0});
|
|
24
36
|
})
|
|
25
37
|
|
|
26
38
|
test('Utils mapSizeQuantites on productSizeQuantityAllStocks', () => {
|
|
27
39
|
expect(COUNTABLE.QUANTITY_ALL).toEqual('productSizeQuantityAllStocks');
|
|
28
|
-
const quantities =
|
|
40
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.QUANTITY_ALL)
|
|
29
41
|
expect(quantities).toEqual({"3":8,"4":10,"5":5,"6":0});
|
|
30
42
|
})
|
|
31
43
|
|
|
32
44
|
test('Utils mapSizeQuantites on productOrdersUnfinishedQuantities', () => {
|
|
33
|
-
expect(COUNTABLE.
|
|
34
|
-
const quantities =
|
|
45
|
+
expect(COUNTABLE.QUANTITY_UNFINISHED).toEqual('productOrdersUnfinishedQuantities');
|
|
46
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.QUANTITY_UNFINISHED)
|
|
35
47
|
expect(quantities).toEqual({"3":2});
|
|
36
48
|
})
|
|
37
49
|
|
|
38
50
|
test('Utils mapSizeQuantites on productSizesDeliveries', () => {
|
|
39
51
|
expect(COUNTABLE.DELIVERIES).toEqual('productSizesDeliveries');
|
|
40
|
-
const quantities =
|
|
52
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.DELIVERIES)
|
|
41
53
|
expect(quantities).toEqual({"5":3,"6":3});
|
|
42
54
|
})
|
|
43
55
|
|
|
44
56
|
test('Utils mapSizeQuantites on productSizesDispositionsInAuctions', () => {
|
|
45
57
|
expect(COUNTABLE.AUCTIONS).toEqual('productSizesDispositionsInAuctions');
|
|
46
|
-
const quantities =
|
|
58
|
+
const quantities = utils.mapSizeQuantites(STOCK_PRODUCT, COUNTABLE.AUCTIONS)
|
|
47
59
|
expect(quantities).toEqual({"3":1,"4":0,"5":0,"6":0});
|
|
48
60
|
})
|
|
@@ -1,48 +1,47 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ENUMS, utils } from '../dist/index';
|
|
2
2
|
import { expect, test } from "vitest"
|
|
3
|
-
import { STOCK_PRODUCT } from
|
|
4
|
-
import ENUMS from '$dist/enums';
|
|
3
|
+
import { STOCK_PRODUCT } from './utilTestData';
|
|
5
4
|
|
|
6
5
|
const COUNTABLE = ENUMS.PRODUCT_SIZE_COUNTABLE;
|
|
7
6
|
|
|
8
7
|
test('Utils sumProductQuantities on productSizeQuantity', () => {
|
|
9
8
|
expect(ENUMS.PRODUCT_SIZE_COUNTABLE.QUANTITY).toEqual('productSizeQuantity');
|
|
10
|
-
const sum =
|
|
9
|
+
const sum = utils.sumProductQuantities(STOCK_PRODUCT.productStocksData, COUNTABLE.QUANTITY)
|
|
11
10
|
expect(sum).toEqual(20);
|
|
12
11
|
})
|
|
13
12
|
|
|
14
13
|
test('Utils sumProductQuantities on productSizeQuantityOwnStock', () => {
|
|
15
14
|
expect(ENUMS.PRODUCT_SIZE_COUNTABLE.QUANTITY_OWN).toEqual('productSizeQuantityOwnStock');
|
|
16
|
-
const sum =
|
|
15
|
+
const sum = utils.sumProductQuantities(STOCK_PRODUCT.productStocksData, COUNTABLE.QUANTITY_OWN)
|
|
17
16
|
expect(sum).toEqual(18);
|
|
18
17
|
})
|
|
19
18
|
|
|
20
19
|
test('Utils sumProductQuantities on productSizeQuantityOutsideStock', () => {
|
|
21
20
|
expect(ENUMS.PRODUCT_SIZE_COUNTABLE.QUANTITY_OUTSIDE).toEqual('productSizeQuantityOutsideStock');
|
|
22
|
-
const sum =
|
|
21
|
+
const sum = utils.sumProductQuantities(STOCK_PRODUCT.productStocksData, COUNTABLE.QUANTITY_OUTSIDE)
|
|
23
22
|
expect(sum).toEqual(5);
|
|
24
23
|
})
|
|
25
24
|
|
|
26
25
|
test('Utils sumProductQuantities on productSizeQuantityAllStocks', () => {
|
|
27
26
|
expect(ENUMS.PRODUCT_SIZE_COUNTABLE.QUANTITY_ALL).toEqual('productSizeQuantityAllStocks');
|
|
28
|
-
const sum =
|
|
27
|
+
const sum = utils.sumProductQuantities(STOCK_PRODUCT.productStocksData, COUNTABLE.QUANTITY_ALL)
|
|
29
28
|
expect(sum).toEqual(23);
|
|
30
29
|
})
|
|
31
30
|
|
|
32
31
|
test('Utils sumProductQuantities on productOrdersUnfinishedQuantities', () => {
|
|
33
|
-
expect(ENUMS.PRODUCT_SIZE_COUNTABLE.
|
|
34
|
-
const sum =
|
|
32
|
+
expect(ENUMS.PRODUCT_SIZE_COUNTABLE.QUANTITY_UNFINISHED).toEqual('productOrdersUnfinishedQuantities');
|
|
33
|
+
const sum = utils.sumProductQuantities(STOCK_PRODUCT.productStocksData, COUNTABLE.QUANTITY_UNFINISHED)
|
|
35
34
|
expect(sum).toEqual(2);
|
|
36
35
|
})
|
|
37
36
|
|
|
38
37
|
test('Utils sumProductQuantities on productSizesDeliveries', () => {
|
|
39
38
|
expect(ENUMS.PRODUCT_SIZE_COUNTABLE.DELIVERIES).toEqual('productSizesDeliveries');
|
|
40
|
-
const sum =
|
|
39
|
+
const sum = utils.sumProductQuantities(STOCK_PRODUCT.productStocksData, COUNTABLE.DELIVERIES)
|
|
41
40
|
expect(sum).toEqual(6);
|
|
42
41
|
})
|
|
43
42
|
|
|
44
43
|
test('Utils sumProductQuantities on productSizesDispositionsInAuctions', () => {
|
|
45
44
|
expect(ENUMS.PRODUCT_SIZE_COUNTABLE.AUCTIONS).toEqual('productSizesDispositionsInAuctions');
|
|
46
|
-
const sum =
|
|
45
|
+
const sum = utils.sumProductQuantities(STOCK_PRODUCT.productStocksData, COUNTABLE.AUCTIONS)
|
|
47
46
|
expect(sum).toEqual(1);
|
|
48
47
|
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { SearchProductsResponse } from "
|
|
1
|
+
import type { SearchProductsResponse } from "../dist/responses";
|
|
2
2
|
|
|
3
3
|
export const STOCK_PRODUCT: SearchProductsResponse['results'][number] = {
|
|
4
|
-
"productId":
|
|
4
|
+
"productId": 1234,
|
|
5
|
+
"productDisplayedCode": 'ZERO',
|
|
5
6
|
"productStocksData": {
|
|
6
7
|
"productSizesDeliveries": [
|
|
7
8
|
{
|