@fiado/type-kit 3.477.0 → 3.478.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/_test_/unit/retailWizard/promotionM2mRequests.test.ts +37 -0
- package/bin/retailWizard/dtos/requests/SetAnchorGiftsRequest.d.ts +3 -0
- package/bin/retailWizard/dtos/requests/SetAnchorGiftsRequest.js +18 -0
- package/package.json +1 -1
- package/src/retailWizard/dtos/requests/SetAnchorGiftsRequest.ts +18 -0
|
@@ -83,6 +83,43 @@ describe('SetAnchorGiftsRequest', () => {
|
|
|
83
83
|
expect(errorsOf(SetAnchorGiftsRequest, { ...ok, items: [{ sku: '' }] })).toContain('items.0.sku'));
|
|
84
84
|
it('exige items como arreglo', () =>
|
|
85
85
|
expect(errorsOf(SetAnchorGiftsRequest, { promotionId: null, promotionVersion: null })).toContain('items'));
|
|
86
|
+
|
|
87
|
+
describe('promo por item', () => {
|
|
88
|
+
const own = { sku: 'CASE-1', promotionId: 'promo-2', promotionVersion: 3 };
|
|
89
|
+
|
|
90
|
+
it('acepta un item sin promo propia (usa la de la raíz)', () => {
|
|
91
|
+
const req = plainToInstance(SetAnchorGiftsRequest, ok);
|
|
92
|
+
expect(validateSync(req)).toEqual([]);
|
|
93
|
+
expect(req.items[0].promotionId).toBeUndefined();
|
|
94
|
+
expect(req.items[0].promotionVersion).toBeUndefined();
|
|
95
|
+
});
|
|
96
|
+
it('acepta un item con promotionId y promotionVersion', () =>
|
|
97
|
+
expect(errorsOf(SetAnchorGiftsRequest, { ...ok, items: [own] })).toEqual([]));
|
|
98
|
+
it('exige promotionVersion si el item trae solo promotionId', () =>
|
|
99
|
+
expect(errorsOf(SetAnchorGiftsRequest, { ...ok, items: [{ sku: 'CASE-1', promotionId: 'promo-2' }] })).toContain(
|
|
100
|
+
'items.0.promotionVersion',
|
|
101
|
+
));
|
|
102
|
+
it('exige promotionId si el item trae solo promotionVersion', () =>
|
|
103
|
+
expect(errorsOf(SetAnchorGiftsRequest, { ...ok, items: [{ sku: 'CASE-1', promotionVersion: 3 }] })).toContain(
|
|
104
|
+
'items.0.promotionId',
|
|
105
|
+
));
|
|
106
|
+
it('rechaza la versión 0 en el item', () =>
|
|
107
|
+
expect(errorsOf(SetAnchorGiftsRequest, { ...ok, items: [{ ...own, promotionVersion: 0 }] })).toContain(
|
|
108
|
+
'items.0.promotionVersion',
|
|
109
|
+
));
|
|
110
|
+
it('rechaza promotionId vacío en el item', () =>
|
|
111
|
+
expect(errorsOf(SetAnchorGiftsRequest, { ...ok, items: [{ ...own, promotionId: '' }] })).toContain(
|
|
112
|
+
'items.0.promotionId',
|
|
113
|
+
));
|
|
114
|
+
it('acepta dos items de la misma ancla con promos distintas', () => {
|
|
115
|
+
const req = plainToInstance(SetAnchorGiftsRequest, {
|
|
116
|
+
...ok,
|
|
117
|
+
items: [own, { sku: 'MICA-1', promotionId: 'promo-9', promotionVersion: 1 }],
|
|
118
|
+
});
|
|
119
|
+
expect(validateSync(req)).toEqual([]);
|
|
120
|
+
expect(req.items.map((i) => i.promotionId)).toEqual(['promo-2', 'promo-9']);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
86
123
|
});
|
|
87
124
|
|
|
88
125
|
describe('ApplySalePromotionRequest', () => {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** Un regalo del conjunto que queda ligado al ancla. */
|
|
2
2
|
export declare class AnchorGiftItem {
|
|
3
3
|
sku: string;
|
|
4
|
+
/** Promo propia de esta línea GIFT; va junto con `promotionVersion` y, si falta, se usa la de la raíz. */
|
|
5
|
+
promotionId?: string;
|
|
6
|
+
promotionVersion?: number;
|
|
4
7
|
}
|
|
5
8
|
/**
|
|
6
9
|
* PUT /private/wizard/sessions/{id}/lines/{anchorLineId}/gifts (M2M de Promociones).
|
|
@@ -12,6 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.SetAnchorGiftsRequest = exports.AnchorGiftItem = void 0;
|
|
13
13
|
const class_transformer_1 = require("class-transformer");
|
|
14
14
|
const class_validator_1 = require("class-validator");
|
|
15
|
+
/** Hay que validar la promo del item si vino cualquiera de sus dos campos. */
|
|
16
|
+
function hasOwnPromotion(o) {
|
|
17
|
+
return o.promotionId !== undefined || o.promotionVersion !== undefined;
|
|
18
|
+
}
|
|
15
19
|
/** Un regalo del conjunto que queda ligado al ancla. */
|
|
16
20
|
class AnchorGiftItem {
|
|
17
21
|
}
|
|
@@ -22,6 +26,20 @@ __decorate([
|
|
|
22
26
|
(0, class_validator_1.IsNotEmpty)(),
|
|
23
27
|
__metadata("design:type", String)
|
|
24
28
|
], AnchorGiftItem.prototype, "sku", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, class_transformer_1.Expose)(),
|
|
31
|
+
(0, class_validator_1.ValidateIf)(hasOwnPromotion),
|
|
32
|
+
(0, class_validator_1.IsString)(),
|
|
33
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
34
|
+
__metadata("design:type", String)
|
|
35
|
+
], AnchorGiftItem.prototype, "promotionId", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, class_transformer_1.Expose)(),
|
|
38
|
+
(0, class_validator_1.ValidateIf)(hasOwnPromotion),
|
|
39
|
+
(0, class_validator_1.IsInt)(),
|
|
40
|
+
(0, class_validator_1.Min)(1),
|
|
41
|
+
__metadata("design:type", Number)
|
|
42
|
+
], AnchorGiftItem.prototype, "promotionVersion", void 0);
|
|
25
43
|
/** Hay que validar el campo si hay regalos o si vino con valor. */
|
|
26
44
|
function mustValidate(o, value) {
|
|
27
45
|
return (Array.isArray(o.items) && o.items.length > 0) || (value !== null && value !== undefined);
|
package/package.json
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import { Expose, Type } from 'class-transformer';
|
|
2
2
|
import { IsArray, IsInt, IsNotEmpty, IsString, Min, ValidateIf, ValidateNested } from 'class-validator';
|
|
3
3
|
|
|
4
|
+
/** Hay que validar la promo del item si vino cualquiera de sus dos campos. */
|
|
5
|
+
function hasOwnPromotion(o: AnchorGiftItem): boolean {
|
|
6
|
+
return o.promotionId !== undefined || o.promotionVersion !== undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
/** Un regalo del conjunto que queda ligado al ancla. */
|
|
5
10
|
export class AnchorGiftItem {
|
|
6
11
|
@Expose()
|
|
7
12
|
@IsString()
|
|
8
13
|
@IsNotEmpty()
|
|
9
14
|
sku!: string;
|
|
15
|
+
|
|
16
|
+
/** Promo propia de esta línea GIFT; va junto con `promotionVersion` y, si falta, se usa la de la raíz. */
|
|
17
|
+
@Expose()
|
|
18
|
+
@ValidateIf(hasOwnPromotion)
|
|
19
|
+
@IsString()
|
|
20
|
+
@IsNotEmpty()
|
|
21
|
+
promotionId?: string;
|
|
22
|
+
|
|
23
|
+
@Expose()
|
|
24
|
+
@ValidateIf(hasOwnPromotion)
|
|
25
|
+
@IsInt()
|
|
26
|
+
@Min(1)
|
|
27
|
+
promotionVersion?: number;
|
|
10
28
|
}
|
|
11
29
|
|
|
12
30
|
/** Hay que validar el campo si hay regalos o si vino con valor. */
|