@managesome/eposmatic-toolkit 0.2.707 → 0.2.709
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/lib/helpers/utils/platform-num.d.ts +18 -0
- package/lib/helpers/utils/platform-num.js +55 -0
- package/lib/helpers/utils/simplified-halfhalf.d.ts +16 -3
- package/lib/helpers/utils/simplified-halfhalf.js +33 -6
- package/lib/helpers/utils/simplified-specials.d.ts +18 -4
- package/lib/helpers/utils/simplified-specials.js +38 -9
- package/lib/tests/simplified-halfhalf.test.js +34 -4
- package/lib/tests/simplified-specials.test.js +38 -6
- package/package.json +1 -1
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import { IItemSpecialHour, IModifier } from '../../schemas';
|
|
2
2
|
import { IPrice } from '../../schemas/types/common';
|
|
3
|
+
import { IMinifiedItemSpecialHour, IMinifiedPrice } from '../types';
|
|
3
4
|
export declare function convertPriceObjToCents(price: IPrice | null | undefined): IPrice | null;
|
|
4
5
|
export declare function convertPriceObjFromCents(priceObj: IPrice | null | undefined): IPrice | null;
|
|
6
|
+
/**
|
|
7
|
+
* Scales a minified price (IMinifiedPrice: number when all platforms share
|
|
8
|
+
* one value, otherwise an IPrice object) between the cents domain and the
|
|
9
|
+
* dollar/UI domain while preserving the minified shape — a scalar stays a
|
|
10
|
+
* scalar, an object stays an object. The counterpart of
|
|
11
|
+
* `convertPriceObjToCents` / `convertPriceObjFromCents` for minified values.
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertMinifiedPriceToCents(price: IMinifiedPrice | undefined): IMinifiedPrice | undefined;
|
|
14
|
+
export declare function convertMinifiedPriceFromCents(price: IMinifiedPrice | undefined): IMinifiedPrice | undefined;
|
|
5
15
|
export declare function mergePriceObjs(priceObj1: IPrice | null, priceObj2: IPrice | null): IPrice | null;
|
|
6
16
|
export declare function convertPriceObjToSegmentPrice(priceObj: IPrice | null, segments: number): IPrice | null;
|
|
7
17
|
export declare function convertModifiersPriceToCents(modifiers: IModifier[] | null | undefined): IModifier[] | null;
|
|
8
18
|
export declare function convertSpecialHoursToCents(specialHours: IItemSpecialHour[] | null | undefined): IItemSpecialHour[] | null;
|
|
9
19
|
export declare function convertSpecialHoursFromCents(specialHours: IItemSpecialHour[] | null | undefined): IItemSpecialHour[] | null;
|
|
20
|
+
/**
|
|
21
|
+
* Same as `convertSpecialHoursToCents` / `convertSpecialHoursFromCents` but for
|
|
22
|
+
* the minified special-hours form (each schedule's `price`/`discount_amount`
|
|
23
|
+
* are IMinifiedPrice values). An empty/missing list stays `undefined` — the
|
|
24
|
+
* simplified payloads do not carry a null special-hours list.
|
|
25
|
+
*/
|
|
26
|
+
export declare function convertMinifiedSpecialHoursToCents(specialHours: IMinifiedItemSpecialHour[] | null | undefined): IMinifiedItemSpecialHour[] | undefined;
|
|
27
|
+
export declare function convertMinifiedSpecialHoursFromCents(specialHours: IMinifiedItemSpecialHour[] | null | undefined): IMinifiedItemSpecialHour[] | undefined;
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertPriceObjToCents = convertPriceObjToCents;
|
|
4
4
|
exports.convertPriceObjFromCents = convertPriceObjFromCents;
|
|
5
|
+
exports.convertMinifiedPriceToCents = convertMinifiedPriceToCents;
|
|
6
|
+
exports.convertMinifiedPriceFromCents = convertMinifiedPriceFromCents;
|
|
5
7
|
exports.mergePriceObjs = mergePriceObjs;
|
|
6
8
|
exports.convertPriceObjToSegmentPrice = convertPriceObjToSegmentPrice;
|
|
7
9
|
exports.convertModifiersPriceToCents = convertModifiersPriceToCents;
|
|
8
10
|
exports.convertSpecialHoursToCents = convertSpecialHoursToCents;
|
|
9
11
|
exports.convertSpecialHoursFromCents = convertSpecialHoursFromCents;
|
|
12
|
+
exports.convertMinifiedSpecialHoursToCents = convertMinifiedSpecialHoursToCents;
|
|
13
|
+
exports.convertMinifiedSpecialHoursFromCents = convertMinifiedSpecialHoursFromCents;
|
|
10
14
|
const catalog_conversion_1 = require("./catalog-conversion");
|
|
11
15
|
const common_1 = require("./common");
|
|
12
16
|
const ingredients_1 = require("./ingredients");
|
|
@@ -41,6 +45,28 @@ function convertPriceObjFromCents(priceObj) {
|
|
|
41
45
|
return keys.reduce((obj, key) => ({ ...obj, [key]: (0, price_conversion_1.convertPriceFromCents)(priceObj[key]) }), {});
|
|
42
46
|
}
|
|
43
47
|
// ====================================================================================================
|
|
48
|
+
/**
|
|
49
|
+
* Scales a minified price (IMinifiedPrice: number when all platforms share
|
|
50
|
+
* one value, otherwise an IPrice object) between the cents domain and the
|
|
51
|
+
* dollar/UI domain while preserving the minified shape — a scalar stays a
|
|
52
|
+
* scalar, an object stays an object. The counterpart of
|
|
53
|
+
* `convertPriceObjToCents` / `convertPriceObjFromCents` for minified values.
|
|
54
|
+
*/
|
|
55
|
+
function convertMinifiedPriceToCents(price) {
|
|
56
|
+
if (price == null)
|
|
57
|
+
return price;
|
|
58
|
+
if (typeof price === 'number')
|
|
59
|
+
return (0, price_conversion_1.convertPriceToCents)(price);
|
|
60
|
+
return convertPriceObjToCents(price) ?? undefined;
|
|
61
|
+
}
|
|
62
|
+
function convertMinifiedPriceFromCents(price) {
|
|
63
|
+
if (price == null)
|
|
64
|
+
return price;
|
|
65
|
+
if (typeof price === 'number')
|
|
66
|
+
return (0, price_conversion_1.convertPriceFromCents)(price);
|
|
67
|
+
return convertPriceObjFromCents(price) ?? undefined;
|
|
68
|
+
}
|
|
69
|
+
// ====================================================================================================
|
|
44
70
|
function mergePriceObjs(priceObj1, priceObj2) {
|
|
45
71
|
if (!priceObj1 && !priceObj2)
|
|
46
72
|
return null;
|
|
@@ -126,3 +152,32 @@ function convertSpecialHoursFromCents(specialHours) {
|
|
|
126
152
|
discount_amount: convertPriceObjFromCents(specialHour.discount_amount),
|
|
127
153
|
}));
|
|
128
154
|
}
|
|
155
|
+
// ====================================================================================================
|
|
156
|
+
/**
|
|
157
|
+
* Same as `convertSpecialHoursToCents` / `convertSpecialHoursFromCents` but for
|
|
158
|
+
* the minified special-hours form (each schedule's `price`/`discount_amount`
|
|
159
|
+
* are IMinifiedPrice values). An empty/missing list stays `undefined` — the
|
|
160
|
+
* simplified payloads do not carry a null special-hours list.
|
|
161
|
+
*/
|
|
162
|
+
function convertMinifiedSpecialHoursToCents(specialHours) {
|
|
163
|
+
if (!specialHours || specialHours.length === 0)
|
|
164
|
+
return undefined;
|
|
165
|
+
return specialHours.map((specialHour) => ({
|
|
166
|
+
...specialHour,
|
|
167
|
+
...(specialHour.price != null ? { price: convertMinifiedPriceToCents(specialHour.price) } : {}),
|
|
168
|
+
...(specialHour.discount_amount != null
|
|
169
|
+
? { discount_amount: convertMinifiedPriceToCents(specialHour.discount_amount) }
|
|
170
|
+
: {}),
|
|
171
|
+
}));
|
|
172
|
+
}
|
|
173
|
+
function convertMinifiedSpecialHoursFromCents(specialHours) {
|
|
174
|
+
if (!specialHours || specialHours.length === 0)
|
|
175
|
+
return undefined;
|
|
176
|
+
return specialHours.map((specialHour) => ({
|
|
177
|
+
...specialHour,
|
|
178
|
+
...(specialHour.price != null ? { price: convertMinifiedPriceFromCents(specialHour.price) } : {}),
|
|
179
|
+
...(specialHour.discount_amount != null
|
|
180
|
+
? { discount_amount: convertMinifiedPriceFromCents(specialHour.discount_amount) }
|
|
181
|
+
: {}),
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
@@ -13,12 +13,25 @@ export declare function convertHalfHalfSetupsToSimplifiedHalfHalfSetups(halfhalf
|
|
|
13
13
|
* mapping of what ISimplifiedCatalogItem can represent:
|
|
14
14
|
* - item `price`/`tax_rate` are null (there is no base price on the payload;
|
|
15
15
|
* the per-segment prices come from the constituent items at selection time),
|
|
16
|
-
* - `discount_amount` and `item_special_hours` are
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* - `discount_amount` and `item_special_hours` are already in the dollar/UI
|
|
17
|
+
* domain (converted at slice ingest via `getSimplifiedHalfHalfSetupWithPrice`),
|
|
18
|
+
* so only the minified shape is normalized — NO currency re-scaling,
|
|
19
|
+
* mirroring `convertHalfHalfToItem` after `getHalfhalfSetupWithPrice`,
|
|
19
20
|
* - no `modifiers` are produced (selection structure isn't part of the
|
|
20
21
|
* simplified setup),
|
|
21
22
|
* - `sort_id` is not part of the payload, so it defaults to 0 (same as
|
|
22
23
|
* `convertHalfHalfToItem`).
|
|
23
24
|
*/
|
|
24
25
|
export declare function convertSimplifiedHalfHalfToSimplifiedItem(halfhalfSetup: ISimplifiedHalfHalfSetup): ISimplifiedCatalogItem;
|
|
26
|
+
/**
|
|
27
|
+
* Converts an ISimplifiedHalfHalfSetup's minified money fields (and those
|
|
28
|
+
* nested in `item_special_hours`) between the cents (server) domain and the
|
|
29
|
+
* dollar/UI domain while preserving the simplified payload shape. Mirrors
|
|
30
|
+
* `getHalfhalfSetupWithPrice` for the full IHalfHalfSetup:
|
|
31
|
+
* - `discount_amount` (IMinifiedPrice) is scaled (a scalar stays a scalar),
|
|
32
|
+
* - `item_special_hours` prices are scaled in place.
|
|
33
|
+
*
|
|
34
|
+
* Only present fields are rewritten; absent fields stay absent (the payload
|
|
35
|
+
* carries no upsell/items to convert).
|
|
36
|
+
*/
|
|
37
|
+
export declare function getSimplifiedHalfHalfSetupWithPrice<T extends Partial<ISimplifiedHalfHalfSetup> | ISimplifiedHalfHalfSetup>(halfhalfSetup: T, writeable?: boolean): T;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.convertHalfHalfSetupToSimplifiedHalfHalfSetup = convertHalfHalfSetupToSimplifiedHalfHalfSetup;
|
|
4
4
|
exports.convertHalfHalfSetupsToSimplifiedHalfHalfSetups = convertHalfHalfSetupsToSimplifiedHalfHalfSetups;
|
|
5
5
|
exports.convertSimplifiedHalfHalfToSimplifiedItem = convertSimplifiedHalfHalfToSimplifiedItem;
|
|
6
|
+
exports.getSimplifiedHalfHalfSetupWithPrice = getSimplifiedHalfHalfSetupWithPrice;
|
|
6
7
|
const minified_catalog_1 = require("./minified-catalog");
|
|
7
8
|
const platform_num_1 = require("./platform-num");
|
|
8
9
|
function convertHalfHalfSetupToSimplifiedHalfHalfSetup(halfhalfSetup, tenantId) {
|
|
@@ -41,18 +42,20 @@ function convertHalfHalfSetupsToSimplifiedHalfHalfSetups(halfhalfSetups, tenantI
|
|
|
41
42
|
* mapping of what ISimplifiedCatalogItem can represent:
|
|
42
43
|
* - item `price`/`tax_rate` are null (there is no base price on the payload;
|
|
43
44
|
* the per-segment prices come from the constituent items at selection time),
|
|
44
|
-
* - `discount_amount` and `item_special_hours` are
|
|
45
|
-
*
|
|
46
|
-
*
|
|
45
|
+
* - `discount_amount` and `item_special_hours` are already in the dollar/UI
|
|
46
|
+
* domain (converted at slice ingest via `getSimplifiedHalfHalfSetupWithPrice`),
|
|
47
|
+
* so only the minified shape is normalized — NO currency re-scaling,
|
|
48
|
+
* mirroring `convertHalfHalfToItem` after `getHalfhalfSetupWithPrice`,
|
|
47
49
|
* - no `modifiers` are produced (selection structure isn't part of the
|
|
48
50
|
* simplified setup),
|
|
49
51
|
* - `sort_id` is not part of the payload, so it defaults to 0 (same as
|
|
50
52
|
* `convertHalfHalfToItem`).
|
|
51
53
|
*/
|
|
52
54
|
function convertSimplifiedHalfHalfToSimplifiedItem(halfhalfSetup) {
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
const
|
|
55
|
+
// Dollar/UI domain input (set at slice ingest) — normalize the minified
|
|
56
|
+
// shape only, no currency re-scaling (mirrors convertHalfHalfToItem).
|
|
57
|
+
const discount_amount = (0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(halfhalfSetup.discount_amount);
|
|
58
|
+
const item_special_hours = (0, minified_catalog_1.convertMinifiedSpecialHoursToOriginalSpecialHours)(halfhalfSetup.item_special_hours);
|
|
56
59
|
return {
|
|
57
60
|
sold_out: halfhalfSetup.sold_out,
|
|
58
61
|
is_discount_percentage: halfhalfSetup.is_discount_percentage,
|
|
@@ -78,3 +81,27 @@ function convertSimplifiedHalfHalfToSimplifiedItem(halfhalfSetup) {
|
|
|
78
81
|
image_url: halfhalfSetup.image_url,
|
|
79
82
|
};
|
|
80
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Converts an ISimplifiedHalfHalfSetup's minified money fields (and those
|
|
86
|
+
* nested in `item_special_hours`) between the cents (server) domain and the
|
|
87
|
+
* dollar/UI domain while preserving the simplified payload shape. Mirrors
|
|
88
|
+
* `getHalfhalfSetupWithPrice` for the full IHalfHalfSetup:
|
|
89
|
+
* - `discount_amount` (IMinifiedPrice) is scaled (a scalar stays a scalar),
|
|
90
|
+
* - `item_special_hours` prices are scaled in place.
|
|
91
|
+
*
|
|
92
|
+
* Only present fields are rewritten; absent fields stay absent (the payload
|
|
93
|
+
* carries no upsell/items to convert).
|
|
94
|
+
*/
|
|
95
|
+
function getSimplifiedHalfHalfSetupWithPrice(halfhalfSetup, writeable) {
|
|
96
|
+
const convertToPrice = writeable ? platform_num_1.convertMinifiedPriceToCents : platform_num_1.convertMinifiedPriceFromCents;
|
|
97
|
+
const convertItemSpecialHours = writeable ? platform_num_1.convertMinifiedSpecialHoursToCents : platform_num_1.convertMinifiedSpecialHoursFromCents;
|
|
98
|
+
return {
|
|
99
|
+
...halfhalfSetup,
|
|
100
|
+
...(halfhalfSetup.discount_amount != null
|
|
101
|
+
? { discount_amount: convertToPrice(halfhalfSetup.discount_amount) }
|
|
102
|
+
: {}),
|
|
103
|
+
...(halfhalfSetup.item_special_hours != null
|
|
104
|
+
? { item_special_hours: convertItemSpecialHours(halfhalfSetup.item_special_hours) }
|
|
105
|
+
: {}),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -11,13 +11,27 @@ export declare function convertSpecialsToSimplifiedSpecials(specials: ISpecial[]
|
|
|
11
11
|
* The simplified special payload carries only menu-list data — the
|
|
12
12
|
* modifier_specials selection structure is dropped — so this is a pure field
|
|
13
13
|
* mapping of what ISimplifiedCatalogItem can represent:
|
|
14
|
-
* -
|
|
15
|
-
*
|
|
16
|
-
* (
|
|
17
|
-
*
|
|
14
|
+
* - the simplified setup is already in the dollar/UI domain (converted at
|
|
15
|
+
* slice ingest via `getSimplifiedSpecialWithPrice`), so only the minified
|
|
16
|
+
* shape is normalized (scalar → `{ BASE_PRICE }`) — NO currency re-scaling,
|
|
17
|
+
* mirroring `convertSpecialToItem` after `getSpecialWithPrice`,
|
|
18
18
|
* - `tax_rate` is null (not part of the special payload, mirrors
|
|
19
19
|
* `convertSpecialToItem`),
|
|
20
20
|
* - no `modifiers` are produced (selection structure isn't part of the
|
|
21
21
|
* simplified setup).
|
|
22
22
|
*/
|
|
23
23
|
export declare function convertSimplifiedSpecialToSimplifiedItem(special: ISimplifiedSpecial): ISimplifiedCatalogItem;
|
|
24
|
+
/**
|
|
25
|
+
* Converts an ISimplifiedSpecial's minified money fields (and those nested in
|
|
26
|
+
* `item_special_hours`) between the cents (server) domain and the dollar/UI
|
|
27
|
+
* domain while preserving the simplified payload shape. Mirrors
|
|
28
|
+
* `getSpecialWithPrice` for the full ISpecial:
|
|
29
|
+
* - `price` / `discount_amount` (IMinifiedPrice) are scaled (a scalar stays a
|
|
30
|
+
* scalar),
|
|
31
|
+
* - `display_price` (scalar) is scaled,
|
|
32
|
+
* - `item_special_hours` prices are scaled in place.
|
|
33
|
+
*
|
|
34
|
+
* Only present fields are rewritten; absent fields stay absent (the payload
|
|
35
|
+
* carries no modifier_specials to convert).
|
|
36
|
+
*/
|
|
37
|
+
export declare function getSimplifiedSpecialWithPrice<T extends Partial<ISimplifiedSpecial> | ISimplifiedSpecial>(special: T, writeable?: boolean): T;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.convertSpecialToSimplifiedSpecial = convertSpecialToSimplifiedSpecial;
|
|
4
4
|
exports.convertSpecialsToSimplifiedSpecials = convertSpecialsToSimplifiedSpecials;
|
|
5
5
|
exports.convertSimplifiedSpecialToSimplifiedItem = convertSimplifiedSpecialToSimplifiedItem;
|
|
6
|
+
exports.getSimplifiedSpecialWithPrice = getSimplifiedSpecialWithPrice;
|
|
6
7
|
const minified_catalog_1 = require("./minified-catalog");
|
|
7
8
|
const platform_num_1 = require("./platform-num");
|
|
8
9
|
const price_conversion_1 = require("./price-conversion");
|
|
@@ -42,21 +43,22 @@ function convertSpecialsToSimplifiedSpecials(specials, tenantId) {
|
|
|
42
43
|
* The simplified special payload carries only menu-list data — the
|
|
43
44
|
* modifier_specials selection structure is dropped — so this is a pure field
|
|
44
45
|
* mapping of what ISimplifiedCatalogItem can represent:
|
|
45
|
-
* -
|
|
46
|
-
*
|
|
47
|
-
* (
|
|
48
|
-
*
|
|
46
|
+
* - the simplified setup is already in the dollar/UI domain (converted at
|
|
47
|
+
* slice ingest via `getSimplifiedSpecialWithPrice`), so only the minified
|
|
48
|
+
* shape is normalized (scalar → `{ BASE_PRICE }`) — NO currency re-scaling,
|
|
49
|
+
* mirroring `convertSpecialToItem` after `getSpecialWithPrice`,
|
|
49
50
|
* - `tax_rate` is null (not part of the special payload, mirrors
|
|
50
51
|
* `convertSpecialToItem`),
|
|
51
52
|
* - no `modifiers` are produced (selection structure isn't part of the
|
|
52
53
|
* simplified setup).
|
|
53
54
|
*/
|
|
54
55
|
function convertSimplifiedSpecialToSimplifiedItem(special) {
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
56
|
+
// Dollar/UI domain input (set at slice ingest) — normalize the minified
|
|
57
|
+
// shape only, no currency re-scaling (mirrors convertSpecialToItem).
|
|
58
|
+
const price = (0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(special.price);
|
|
59
|
+
const discount_amount = (0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(special.discount_amount);
|
|
60
|
+
const item_special_hours = (0, minified_catalog_1.convertMinifiedSpecialHoursToOriginalSpecialHours)(special.item_special_hours);
|
|
61
|
+
const display_price = special.display_price ?? undefined;
|
|
60
62
|
return {
|
|
61
63
|
sold_out: special.sold_out,
|
|
62
64
|
is_discount_percentage: special.is_discount_percentage,
|
|
@@ -82,3 +84,30 @@ function convertSimplifiedSpecialToSimplifiedItem(special) {
|
|
|
82
84
|
image_url: special.image_url,
|
|
83
85
|
};
|
|
84
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Converts an ISimplifiedSpecial's minified money fields (and those nested in
|
|
89
|
+
* `item_special_hours`) between the cents (server) domain and the dollar/UI
|
|
90
|
+
* domain while preserving the simplified payload shape. Mirrors
|
|
91
|
+
* `getSpecialWithPrice` for the full ISpecial:
|
|
92
|
+
* - `price` / `discount_amount` (IMinifiedPrice) are scaled (a scalar stays a
|
|
93
|
+
* scalar),
|
|
94
|
+
* - `display_price` (scalar) is scaled,
|
|
95
|
+
* - `item_special_hours` prices are scaled in place.
|
|
96
|
+
*
|
|
97
|
+
* Only present fields are rewritten; absent fields stay absent (the payload
|
|
98
|
+
* carries no modifier_specials to convert).
|
|
99
|
+
*/
|
|
100
|
+
function getSimplifiedSpecialWithPrice(special, writeable) {
|
|
101
|
+
const convertToPrice = writeable ? platform_num_1.convertMinifiedPriceToCents : platform_num_1.convertMinifiedPriceFromCents;
|
|
102
|
+
const convertItemSpecialHours = writeable ? platform_num_1.convertMinifiedSpecialHoursToCents : platform_num_1.convertMinifiedSpecialHoursFromCents;
|
|
103
|
+
const convertNumPrice = writeable ? price_conversion_1.convertPriceToCents : price_conversion_1.convertPriceFromCents;
|
|
104
|
+
return {
|
|
105
|
+
...special,
|
|
106
|
+
...(special.price != null ? { price: convertToPrice(special.price) } : {}),
|
|
107
|
+
...(special.discount_amount != null ? { discount_amount: convertToPrice(special.discount_amount) } : {}),
|
|
108
|
+
...(special.display_price != null ? { display_price: convertNumPrice(special.display_price) } : {}),
|
|
109
|
+
...(special.item_special_hours != null
|
|
110
|
+
? { item_special_hours: convertItemSpecialHours(special.item_special_hours) }
|
|
111
|
+
: {}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -116,19 +116,19 @@ describe('convertSimplifiedHalfHalfToSimplifiedItem', () => {
|
|
|
116
116
|
const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({ sold_out: true }));
|
|
117
117
|
expect(item.sold_out).toBe(true);
|
|
118
118
|
});
|
|
119
|
-
it('
|
|
120
|
-
const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({ discount_amount:
|
|
119
|
+
it('maps dollar discount_amount to IPrice (no re-scaling)', () => {
|
|
120
|
+
const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({ discount_amount: 3, is_discount_percentage: true }));
|
|
121
121
|
expect(item.discount_amount).toEqual({ BASE_PRICE: 3 });
|
|
122
122
|
expect(item.is_discount_percentage).toBe(true);
|
|
123
123
|
});
|
|
124
|
-
it('
|
|
124
|
+
it('maps item_special_hours (shape only)', () => {
|
|
125
125
|
const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({
|
|
126
126
|
item_special_hours: [
|
|
127
127
|
{
|
|
128
128
|
days_index: [constants_1.DAY_INDEX_ENUM.MON],
|
|
129
129
|
start_time: 60,
|
|
130
130
|
end_time: 120,
|
|
131
|
-
price:
|
|
131
|
+
price: 5,
|
|
132
132
|
},
|
|
133
133
|
],
|
|
134
134
|
}));
|
|
@@ -143,3 +143,33 @@ describe('convertSimplifiedHalfHalfToSimplifiedItem', () => {
|
|
|
143
143
|
]);
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
|
+
describe('getSimplifiedHalfHalfSetupWithPrice', () => {
|
|
147
|
+
it('converts minified discount and special hours from cents to dollars by default', () => {
|
|
148
|
+
const result = (0, simplified_halfhalf_1.getSimplifiedHalfHalfSetupWithPrice)(makeSimplifiedHalfHalfSetup({
|
|
149
|
+
discount_amount: 300,
|
|
150
|
+
item_special_hours: [
|
|
151
|
+
{ days_index: [constants_1.DAY_INDEX_ENUM.MON], start_time: 60, end_time: 120, price: 500, discount_amount: 200 },
|
|
152
|
+
],
|
|
153
|
+
}));
|
|
154
|
+
expect(result.discount_amount).toBe(3);
|
|
155
|
+
expect(result.item_special_hours).toEqual([expect.objectContaining({ price: 5, discount_amount: 2 })]);
|
|
156
|
+
});
|
|
157
|
+
it('writeable converts dollar values back to cents', () => {
|
|
158
|
+
const result = (0, simplified_halfhalf_1.getSimplifiedHalfHalfSetupWithPrice)(makeSimplifiedHalfHalfSetup({
|
|
159
|
+
discount_amount: 3,
|
|
160
|
+
item_special_hours: [
|
|
161
|
+
{ days_index: [constants_1.DAY_INDEX_ENUM.MON], start_time: 60, end_time: 120, price: 5, discount_amount: 2 },
|
|
162
|
+
],
|
|
163
|
+
}), true);
|
|
164
|
+
expect(result.discount_amount).toBe(300);
|
|
165
|
+
expect(result.item_special_hours).toEqual([expect.objectContaining({ price: 500, discount_amount: 200 })]);
|
|
166
|
+
});
|
|
167
|
+
it('handles IPrice-object discounts and leaves absent fields untouched', () => {
|
|
168
|
+
const result = (0, simplified_halfhalf_1.getSimplifiedHalfHalfSetupWithPrice)(makeSimplifiedHalfHalfSetup({
|
|
169
|
+
discount_amount: { BASE_PRICE: 1200, [constants_1.PLATFORMS_ENUM.WEB_DELIVERY]: 1500 },
|
|
170
|
+
}));
|
|
171
|
+
expect(result.discount_amount).toEqual({ BASE_PRICE: 12, [constants_1.PLATFORMS_ENUM.WEB_DELIVERY]: 15 });
|
|
172
|
+
expect(result.item_special_hours).toBeUndefined();
|
|
173
|
+
expect(result._id).toBe('halfhalf-1');
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -87,24 +87,24 @@ describe('convertSimplifiedSpecialToSimplifiedItem', () => {
|
|
|
87
87
|
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ sold_out: true }));
|
|
88
88
|
expect(item.sold_out).toBe(true);
|
|
89
89
|
});
|
|
90
|
-
it('
|
|
91
|
-
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ price:
|
|
90
|
+
it('maps dollar price/discount_amount to IPrice (no re-scaling)', () => {
|
|
91
|
+
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ price: 12, discount_amount: 3, is_discount_percentage: true }));
|
|
92
92
|
expect(item.price).toEqual({ BASE_PRICE: 12 });
|
|
93
93
|
expect(item.discount_amount).toEqual({ BASE_PRICE: 3 });
|
|
94
94
|
expect(item.is_discount_percentage).toBe(true);
|
|
95
95
|
});
|
|
96
|
-
it('
|
|
97
|
-
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ display_price:
|
|
96
|
+
it('carries display_price through unscaled', () => {
|
|
97
|
+
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ display_price: 12.5 }));
|
|
98
98
|
expect(item.display_price).toBe(12.5);
|
|
99
99
|
});
|
|
100
|
-
it('
|
|
100
|
+
it('maps item_special_hours (shape only)', () => {
|
|
101
101
|
const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({
|
|
102
102
|
item_special_hours: [
|
|
103
103
|
{
|
|
104
104
|
days_index: [constants_1.DAY_INDEX_ENUM.MON],
|
|
105
105
|
start_time: 60,
|
|
106
106
|
end_time: 120,
|
|
107
|
-
price:
|
|
107
|
+
price: 5,
|
|
108
108
|
},
|
|
109
109
|
],
|
|
110
110
|
}));
|
|
@@ -119,3 +119,35 @@ describe('convertSimplifiedSpecialToSimplifiedItem', () => {
|
|
|
119
119
|
]);
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
|
+
describe('getSimplifiedSpecialWithPrice', () => {
|
|
123
|
+
it('converts minified price/discount/display and special hours from cents to dollars by default', () => {
|
|
124
|
+
const result = (0, simplified_specials_1.getSimplifiedSpecialWithPrice)(makeSimplifiedSpecial({
|
|
125
|
+
price: 1200,
|
|
126
|
+
discount_amount: 300,
|
|
127
|
+
display_price: 1250,
|
|
128
|
+
item_special_hours: [
|
|
129
|
+
{ days_index: [constants_1.DAY_INDEX_ENUM.MON], start_time: 60, end_time: 120, price: 500, discount_amount: 200 },
|
|
130
|
+
],
|
|
131
|
+
}));
|
|
132
|
+
expect(result.price).toBe(12);
|
|
133
|
+
expect(result.discount_amount).toBe(3);
|
|
134
|
+
expect(result.display_price).toBe(12.5);
|
|
135
|
+
expect(result.item_special_hours).toEqual([expect.objectContaining({ price: 5, discount_amount: 2 })]);
|
|
136
|
+
});
|
|
137
|
+
it('writeable converts dollar values back to cents', () => {
|
|
138
|
+
const result = (0, simplified_specials_1.getSimplifiedSpecialWithPrice)(makeSimplifiedSpecial({ price: 12, discount_amount: 3, display_price: 12.5 }), true);
|
|
139
|
+
expect(result.price).toBe(1200);
|
|
140
|
+
expect(result.discount_amount).toBe(300);
|
|
141
|
+
expect(result.display_price).toBe(1250);
|
|
142
|
+
});
|
|
143
|
+
it('handles IPrice-object prices and leaves absent fields untouched', () => {
|
|
144
|
+
const result = (0, simplified_specials_1.getSimplifiedSpecialWithPrice)(makeSimplifiedSpecial({
|
|
145
|
+
price: { BASE_PRICE: 1200, [constants_1.PLATFORMS_ENUM.POS_WALK_IN]: 1500 },
|
|
146
|
+
}));
|
|
147
|
+
expect(result.price).toEqual({ BASE_PRICE: 12, [constants_1.PLATFORMS_ENUM.POS_WALK_IN]: 15 });
|
|
148
|
+
expect(result.discount_amount).toBeUndefined();
|
|
149
|
+
expect(result.display_price).toBeUndefined();
|
|
150
|
+
expect(result._id).toBe('special-1');
|
|
151
|
+
expect(result.sort_id).toBe(3);
|
|
152
|
+
});
|
|
153
|
+
});
|