Skip to content

Commit

Permalink
test(core): Fix failing e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Aug 25, 2020
1 parent 9bb5750 commit e4fda09
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/core/e2e/order-promotion.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
GetOrderPromotionsByCode,
RemoveCouponCode,
SetCustomerForOrder,
TestOrderFragment,
} from './graphql/generated-e2e-shop-types';
import {
CREATE_CUSTOMER_GROUP,
Expand Down Expand Up @@ -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<
Expand All @@ -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,
Expand All @@ -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<GetActiveOrder.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);
Expand Down

0 comments on commit e4fda09

Please sign in to comment.