Skip to content

Commit

Permalink
test(core): Add e2e test for #1150
Browse files Browse the repository at this point in the history
Relates to #1150
  • Loading branch information
michaelbromley committed Oct 19, 2021
1 parent eb1dcc4 commit 715a2e0
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion packages/core/e2e/order-promotion.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)!;
}
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 715a2e0

Please sign in to comment.