Ver Fonte

test(core): Add e2e test for #1150

Relates to #1150
Michael Bromley há 4 anos atrás
pai
commit
715a2e0463
1 ficheiros alterados com 46 adições e 1 exclusões
  1. 46 1
      packages/core/e2e/order-promotion.e2e-spec.ts

+ 46 - 1
packages/core/e2e/order-promotion.e2e-spec.ts

@@ -724,7 +724,7 @@ describe('Promotions applied to Orders', () => {
             function getItemSale1Line<
                 T extends Array<
                     UpdatedOrderFragment['lines'][number] | TestOrderFragmentFragment['lines'][number]
-                >
+                >,
             >(lines: T): T[number] {
                 return lines.find(l => l.productVariant.id === getVariantBySlug('item-sale-100').id)!;
             }
@@ -1086,6 +1086,51 @@ describe('Promotions applied to Orders', () => {
                 expect(applyCouponCode.total).toBe(4167);
                 expect(applyCouponCode.totalWithTax).toBe(5000);
             });
+
+            // https://github.com/vendure-ecommerce/vendure/pull/1150
+            it('shipping discounts get correctly removed', async () => {
+                shopClient.setChannelToken(TAX_INCLUDED_CHANNEL_TOKEN);
+                const { addItemToOrder } = await shopClient.query<
+                    AddItemToOrder.Mutation,
+                    AddItemToOrder.Variables
+                >(ADD_ITEM_TO_ORDER, {
+                    productVariantId: getVariantBySlug('item-5000').id,
+                    quantity: 1,
+                });
+                const method = await createTestShippingMethod(TAX_INCLUDED_CHANNEL_TOKEN);
+                const { setOrderShippingMethod } = await shopClient.query<
+                    SetShippingMethod.Mutation,
+                    SetShippingMethod.Variables
+                >(SET_SHIPPING_METHOD, {
+                    id: method.id,
+                });
+                orderResultGuard.assertSuccess(setOrderShippingMethod);
+                expect(setOrderShippingMethod.discounts).toEqual([]);
+                expect(setOrderShippingMethod.shippingWithTax).toBe(345);
+
+                const { applyCouponCode } = await shopClient.query<
+                    ApplyCouponCode.Mutation,
+                    ApplyCouponCode.Variables
+                >(APPLY_COUPON_CODE, {
+                    couponCode,
+                });
+                orderResultGuard.assertSuccess(applyCouponCode);
+
+                expect(applyCouponCode.discounts.length).toBe(1);
+                expect(applyCouponCode.discounts[0].description).toBe('Free shipping');
+                expect(applyCouponCode.shippingWithTax).toBe(0);
+
+                const { removeCouponCode } = await shopClient.query<
+                    RemoveCouponCode.Mutation,
+                    RemoveCouponCode.Variables
+                >(REMOVE_COUPON_CODE, {
+                    couponCode,
+                });
+
+                orderResultGuard.assertSuccess(removeCouponCode);
+                expect(removeCouponCode.discounts).toEqual([]);
+                expect(removeCouponCode.shippingWithTax).toBe(345);
+            });
         });
 
         describe('multiple promotions simultaneously', () => {