|
|
@@ -28,7 +28,9 @@ import { initialData } from '../../../e2e-common/e2e-initial-data';
|
|
|
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
|
|
|
import { freeShipping } from '../src/config/promotion/actions/free-shipping-action';
|
|
|
import { orderFixedDiscount } from '../src/config/promotion/actions/order-fixed-discount-action';
|
|
|
+import { orderLineFixedDiscount } from '../src/config/promotion/actions/order-line-fixed-discount-action';
|
|
|
|
|
|
+import { TestMoneyStrategy } from './fixtures/test-money-strategy';
|
|
|
import { testSuccessfulPaymentMethod } from './fixtures/test-payment-methods';
|
|
|
import { CurrencyCode, HistoryEntryType, LanguageCode } from './graphql/generated-e2e-admin-types';
|
|
|
import * as Codegen from './graphql/generated-e2e-admin-types';
|
|
|
@@ -66,6 +68,9 @@ describe('Promotions applied to Orders', () => {
|
|
|
paymentOptions: {
|
|
|
paymentMethodHandlers: [testSuccessfulPaymentMethod],
|
|
|
},
|
|
|
+ entityOptions: {
|
|
|
+ moneyStrategy: new TestMoneyStrategy(),
|
|
|
+ },
|
|
|
}),
|
|
|
);
|
|
|
|
|
|
@@ -834,6 +839,58 @@ describe('Promotions applied to Orders', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ describe('orderLineFixedDiscount', () => {
|
|
|
+ const couponCode = '1000_off_order_line';
|
|
|
+ let promotion: Codegen.PromotionFragment;
|
|
|
+
|
|
|
+ beforeAll(async () => {
|
|
|
+ promotion = await createPromotion({
|
|
|
+ enabled: true,
|
|
|
+ name: '$1000 discount on order line',
|
|
|
+ couponCode,
|
|
|
+ conditions: [],
|
|
|
+ actions: [
|
|
|
+ {
|
|
|
+ code: orderLineFixedDiscount.code,
|
|
|
+ arguments: [{ name: 'discount', value: '1000' }],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ afterAll(async () => {
|
|
|
+ await deletePromotion(promotion.id);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('prices exclude tax', async () => {
|
|
|
+ await shopClient.asAnonymousUser();
|
|
|
+ const { addItemToOrder } = await shopClient.query<
|
|
|
+ CodegenShop.AddItemToOrderMutation,
|
|
|
+ CodegenShop.AddItemToOrderMutationVariables
|
|
|
+ >(ADD_ITEM_TO_ORDER, {
|
|
|
+ productVariantId: getVariantBySlug('item-1000').id,
|
|
|
+ quantity: 3,
|
|
|
+ });
|
|
|
+ orderResultGuard.assertSuccess(addItemToOrder);
|
|
|
+ expect(addItemToOrder.discounts.length).toBe(0);
|
|
|
+ expect(addItemToOrder.lines[0].discounts.length).toBe(0);
|
|
|
+ expect(addItemToOrder.total).toBe(3000);
|
|
|
+ expect(addItemToOrder.totalWithTax).toBe(3600);
|
|
|
+
|
|
|
+ const { applyCouponCode } = await shopClient.query<
|
|
|
+ CodegenShop.ApplyCouponCodeMutation,
|
|
|
+ CodegenShop.ApplyCouponCodeMutationVariables
|
|
|
+ >(APPLY_COUPON_CODE, {
|
|
|
+ couponCode,
|
|
|
+ });
|
|
|
+ orderResultGuard.assertSuccess(applyCouponCode);
|
|
|
+
|
|
|
+ expect(applyCouponCode.total).toBe(2000);
|
|
|
+ expect(applyCouponCode.totalWithTax).toBe(2400);
|
|
|
+ expect(applyCouponCode.lines[0].discounts.length).toBe(1);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
describe('discountOnItemWithFacets', () => {
|
|
|
const couponCode = '50%_off_sale_items';
|
|
|
let promotion: Codegen.PromotionFragment;
|
|
|
@@ -925,9 +982,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
expect(removeCouponCode!.total).toBe(2200);
|
|
|
expect(removeCouponCode!.totalWithTax).toBe(2640);
|
|
|
|
|
|
- const { activeOrder } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(getItemSale1Line(activeOrder!.lines).discounts.length).toBe(0);
|
|
|
expect(activeOrder!.total).toBe(2200);
|
|
|
expect(activeOrder!.totalWithTax).toBe(2640);
|
|
|
@@ -986,9 +1042,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
expect(removeCouponCode!.total).toBe(2200);
|
|
|
expect(removeCouponCode!.totalWithTax).toBe(2640);
|
|
|
|
|
|
- const { activeOrder } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(getItemSale1Line(activeOrder!.lines).discounts.length).toBe(0);
|
|
|
expect(activeOrder!.total).toBe(2200);
|
|
|
expect(activeOrder!.totalWithTax).toBe(2640);
|
|
|
@@ -1534,9 +1589,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
|
|
|
await addGuestCustomerToOrder();
|
|
|
|
|
|
- const { activeOrder } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(activeOrder!.couponCodes).toEqual([]);
|
|
|
expect(activeOrder!.totalWithTax).toBe(6000);
|
|
|
});
|
|
|
@@ -1627,9 +1681,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
|
|
|
await logInAsRegisteredCustomer();
|
|
|
|
|
|
- const { activeOrder } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(activeOrder!.totalWithTax).toBe(6000);
|
|
|
expect(activeOrder!.couponCodes).toEqual([]);
|
|
|
});
|
|
|
@@ -1883,9 +1936,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
expect(addItemToOrder.discounts.length).toBe(1);
|
|
|
expect(addItemToOrder.discounts[0].description).toBe('Test Promo');
|
|
|
|
|
|
- const { activeOrder: check1 } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder: check1 } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(check1!.discounts.length).toBe(1);
|
|
|
expect(check1!.discounts[0].description).toBe('Test Promo');
|
|
|
|
|
|
@@ -1899,9 +1951,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
orderResultGuard.assertSuccess(removeOrderLine);
|
|
|
expect(removeOrderLine.discounts.length).toBe(0);
|
|
|
|
|
|
- const { activeOrder: check2 } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder: check2 } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(check2!.discounts.length).toBe(0);
|
|
|
});
|
|
|
|
|
|
@@ -2043,9 +2094,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
quantity: 1,
|
|
|
});
|
|
|
|
|
|
- const { activeOrder: check1 } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder: check1 } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
|
|
|
expect(check1!.lines[0].discountedUnitPriceWithTax).toBe(0);
|
|
|
expect(check1!.totalWithTax).toBe(0);
|
|
|
@@ -2055,9 +2105,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
CodegenShop.ApplyCouponCodeMutationVariables
|
|
|
>(APPLY_COUPON_CODE, { couponCode: couponCode2 });
|
|
|
|
|
|
- const { activeOrder: check2 } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder: check2 } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(check2!.lines[0].discountedUnitPriceWithTax).toBe(0);
|
|
|
expect(check2!.totalWithTax).toBe(0);
|
|
|
});
|
|
|
@@ -2080,9 +2129,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
quantity: 1,
|
|
|
});
|
|
|
|
|
|
- const { activeOrder: check1 } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder: check1 } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
|
|
|
expect(check1!.lines[0].discountedUnitPriceWithTax).toBe(0);
|
|
|
expect(check1!.totalWithTax).toBe(0);
|
|
|
@@ -2092,9 +2140,8 @@ describe('Promotions applied to Orders', () => {
|
|
|
CodegenShop.ApplyCouponCodeMutationVariables
|
|
|
>(APPLY_COUPON_CODE, { couponCode: couponCode2 });
|
|
|
|
|
|
- const { activeOrder: check2 } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
|
|
|
- GET_ACTIVE_ORDER,
|
|
|
- );
|
|
|
+ const { activeOrder: check2 } =
|
|
|
+ await shopClient.query<CodegenShop.GetActiveOrderQuery>(GET_ACTIVE_ORDER);
|
|
|
expect(check2!.lines[0].discountedUnitPriceWithTax).toBe(0);
|
|
|
expect(check2!.totalWithTax).toBe(0);
|
|
|
});
|