Browse Source

test(core): Add test case to OrderCalculator

Michael Bromley 6 years ago
parent
commit
8c970bf214

+ 31 - 0
packages/core/src/service/helpers/order-calculator/order-calculator.spec.ts

@@ -541,6 +541,37 @@ describe('OrderCalculator', () => {
                 expect(order.total).toBe(126263);
                 expect(order.total).toBe(126263);
                 expect(order.adjustments.length).toBe(1);
                 expect(order.adjustments.length).toBe(1);
             });
             });
+
+            it('empty string couponCode does not prevent promotion being applied', async () => {
+                const hasEmptyStringCouponCode = new Promotion({
+                    id: 2,
+                    name: 'Has empty string couponCode',
+                    couponCode: '',
+                    conditions: [
+                        {
+                            code: orderTotalCondition.code,
+                            args: [{ name: 'minimum', type: 'int', value: '10' }],
+                        },
+                    ],
+                    promotionConditions: [orderTotalCondition],
+                    actions: [
+                        {
+                            code: percentageOrderAction.code,
+                            args: [{ name: 'discount', type: 'int', value: '10' }],
+                        },
+                    ],
+                    promotionActions: [percentageOrderAction],
+                });
+
+                const ctx = createRequestContext(false);
+                const order = createOrder({
+                    lines: [{ unitPrice: 100, taxCategory: taxCategoryStandard, quantity: 1 }],
+                });
+                await orderCalculator.applyPriceAdjustments(ctx, order, [hasEmptyStringCouponCode]);
+
+                expect(order.adjustments.length).toBe(1);
+                expect(order.adjustments[0].description).toBe(hasEmptyStringCouponCode.name);
+            });
         });
         });
     });
     });
 });
 });