diff --git a/packages/core/e2e/order-promotion.e2e-spec.ts b/packages/core/e2e/order-promotion.e2e-spec.ts index a8a0cd9336..5c8dcf3281 100644 --- a/packages/core/e2e/order-promotion.e2e-spec.ts +++ b/packages/core/e2e/order-promotion.e2e-spec.ts @@ -36,6 +36,7 @@ import { GetOrderPromotionsByCode, RemoveCouponCode, SetCustomerForOrder, + TestOrderFragment, } from './graphql/generated-e2e-shop-types'; import { CREATE_CUSTOMER_GROUP, @@ -519,8 +520,12 @@ describe('Promotions applied to Orders', () => { productVariantId: getVariantBySlug('item-sale-1').id, quantity: 2, }); + + function getItemSale1Line(lines: TestOrderFragment.Lines[]): TestOrderFragment.Lines { + return lines.find(l => l.productVariant.id === getVariantBySlug('item-sale-1').id)!; + } expect(addItemToOrder!.adjustments.length).toBe(0); - expect(addItemToOrder!.lines[2].adjustments.length).toBe(2); // 2x tax + expect(getItemSale1Line(addItemToOrder!.lines).adjustments.length).toBe(2); // 2x tax expect(addItemToOrder!.total).toBe(2640); const { applyCouponCode } = await shopClient.query< @@ -531,7 +536,7 @@ describe('Promotions applied to Orders', () => { }); expect(applyCouponCode!.total).toBe(1920); - expect(applyCouponCode!.lines[2].adjustments.length).toBe(4); // 2x tax, 2x promotion + expect(getItemSale1Line(applyCouponCode!.lines).adjustments.length).toBe(4); // 2x tax, 2x promotion const { removeCouponCode } = await shopClient.query< RemoveCouponCode.Mutation, @@ -540,11 +545,11 @@ describe('Promotions applied to Orders', () => { couponCode, }); - expect(removeCouponCode!.lines[2].adjustments.length).toBe(2); // 2x tax + expect(getItemSale1Line(removeCouponCode!.lines).adjustments.length).toBe(2); // 2x tax expect(removeCouponCode!.total).toBe(2640); const { activeOrder } = await shopClient.query(GET_ACTIVE_ORDER); - expect(activeOrder!.lines[2].adjustments.length).toBe(2); // 2x tax + expect(getItemSale1Line(activeOrder!.lines).adjustments.length).toBe(2); // 2x tax expect(activeOrder!.total).toBe(2640); await deletePromotion(promotion.id);