|
@@ -5,6 +5,7 @@ import {
|
|
|
defaultShippingCalculator,
|
|
defaultShippingCalculator,
|
|
|
defaultShippingEligibilityChecker,
|
|
defaultShippingEligibilityChecker,
|
|
|
mergeConfig,
|
|
mergeConfig,
|
|
|
|
|
+ productsPercentageDiscount,
|
|
|
ShippingCalculator,
|
|
ShippingCalculator,
|
|
|
} from '@vendure/core';
|
|
} from '@vendure/core';
|
|
|
import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
|
|
import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
|
|
@@ -37,7 +38,7 @@ import {
|
|
|
OrderFragment,
|
|
OrderFragment,
|
|
|
OrderWithLinesFragment,
|
|
OrderWithLinesFragment,
|
|
|
OrderWithModificationsFragment,
|
|
OrderWithModificationsFragment,
|
|
|
- SettlePayment,
|
|
|
|
|
|
|
+ UpdateChannel,
|
|
|
UpdateProductVariants,
|
|
UpdateProductVariants,
|
|
|
} from './graphql/generated-e2e-admin-types';
|
|
} from './graphql/generated-e2e-admin-types';
|
|
|
import {
|
|
import {
|
|
@@ -55,7 +56,7 @@ import {
|
|
|
CREATE_SHIPPING_METHOD,
|
|
CREATE_SHIPPING_METHOD,
|
|
|
GET_ORDER,
|
|
GET_ORDER,
|
|
|
GET_ORDER_HISTORY,
|
|
GET_ORDER_HISTORY,
|
|
|
- SETTLE_PAYMENT,
|
|
|
|
|
|
|
+ UPDATE_CHANNEL,
|
|
|
UPDATE_PRODUCT_VARIANTS,
|
|
UPDATE_PRODUCT_VARIANTS,
|
|
|
} from './graphql/shared-definitions';
|
|
} from './graphql/shared-definitions';
|
|
|
import {
|
|
import {
|
|
@@ -1352,6 +1353,96 @@ describe('Order modification', () => {
|
|
|
expect(modifyOrder.totalWithTax).toBe(originalTotalWithTax + surcharge);
|
|
expect(modifyOrder.totalWithTax).toBe(originalTotalWithTax + surcharge);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ // https://github.com/vendure-ecommerce/vendure/issues/872
|
|
|
|
|
+ describe('correct price calculations when prices include tax', () => {
|
|
|
|
|
+ async function modifyOrderLineQuantity(order: TestOrderWithPaymentsFragment) {
|
|
|
|
|
+ const { transitionOrderToState } = await adminClient.query<
|
|
|
|
|
+ AdminTransition.Mutation,
|
|
|
|
|
+ AdminTransition.Variables
|
|
|
|
|
+ >(ADMIN_TRANSITION_TO_STATE, {
|
|
|
|
|
+ id: order.id,
|
|
|
|
|
+ state: 'Modifying',
|
|
|
|
|
+ });
|
|
|
|
|
+ orderGuard.assertSuccess(transitionOrderToState);
|
|
|
|
|
+
|
|
|
|
|
+ expect(transitionOrderToState.state).toBe('Modifying');
|
|
|
|
|
+
|
|
|
|
|
+ const { modifyOrder } = await adminClient.query<ModifyOrder.Mutation, ModifyOrder.Variables>(
|
|
|
|
|
+ MODIFY_ORDER,
|
|
|
|
|
+ {
|
|
|
|
|
+ input: {
|
|
|
|
|
+ dryRun: true,
|
|
|
|
|
+ orderId: order.id,
|
|
|
|
|
+ adjustOrderLines: [{ orderLineId: order!.lines[0].id, quantity: 2 }],
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
+ orderGuard.assertSuccess(modifyOrder);
|
|
|
|
|
+ return modifyOrder;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ beforeAll(async () => {
|
|
|
|
|
+ await adminClient.query<UpdateChannel.Mutation, UpdateChannel.Variables>(UPDATE_CHANNEL, {
|
|
|
|
|
+ input: {
|
|
|
|
|
+ id: 'T_1',
|
|
|
|
|
+ pricesIncludeTax: true,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('without promotion', async () => {
|
|
|
|
|
+ await shopClient.asUserWithCredentials('hayden.zieme12@hotmail.com', 'test');
|
|
|
|
|
+ await shopClient.query(gql(ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS), {
|
|
|
|
|
+ productVariantId: 'T_1',
|
|
|
|
|
+ quantity: 1,
|
|
|
|
|
+ } as any);
|
|
|
|
|
+ await proceedToArrangingPayment(shopClient);
|
|
|
|
|
+ const order = await addPaymentToOrder(shopClient, testSuccessfulPaymentMethod);
|
|
|
|
|
+ orderGuard.assertSuccess(order);
|
|
|
|
|
+
|
|
|
|
|
+ const modifyOrder = await modifyOrderLineQuantity(order);
|
|
|
|
|
+ expect(modifyOrder.lines[0].linePriceWithTax).toBe(order.lines[0].linePriceWithTax * 2);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('with promotion', async () => {
|
|
|
|
|
+ await adminClient.query<CreatePromotion.Mutation, CreatePromotion.Variables>(CREATE_PROMOTION, {
|
|
|
|
|
+ input: {
|
|
|
|
|
+ name: 'half price',
|
|
|
|
|
+ couponCode: 'HALF',
|
|
|
|
|
+ enabled: true,
|
|
|
|
|
+ conditions: [],
|
|
|
|
|
+ actions: [
|
|
|
|
|
+ {
|
|
|
|
|
+ code: productsPercentageDiscount.code,
|
|
|
|
|
+ arguments: [
|
|
|
|
|
+ { name: 'discount', value: '50' },
|
|
|
|
|
+ { name: 'productVariantIds', value: JSON.stringify(['T_1']) },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ await shopClient.asUserWithCredentials('trevor_donnelly96@hotmail.com', 'test');
|
|
|
|
|
+ await shopClient.query(gql(ADD_ITEM_TO_ORDER_WITH_CUSTOM_FIELDS), {
|
|
|
|
|
+ productVariantId: 'T_1',
|
|
|
|
|
+ quantity: 1,
|
|
|
|
|
+ } as any);
|
|
|
|
|
+ await shopClient.query<ApplyCouponCode.Mutation, ApplyCouponCode.Variables>(APPLY_COUPON_CODE, {
|
|
|
|
|
+ couponCode: 'HALF',
|
|
|
|
|
+ });
|
|
|
|
|
+ await proceedToArrangingPayment(shopClient);
|
|
|
|
|
+ const order = await addPaymentToOrder(shopClient, testSuccessfulPaymentMethod);
|
|
|
|
|
+ orderGuard.assertSuccess(order);
|
|
|
|
|
+
|
|
|
|
|
+ const modifyOrder = await modifyOrderLineQuantity(order);
|
|
|
|
|
+
|
|
|
|
|
+ expect(modifyOrder.lines[0].discountedLinePriceWithTax).toBe(
|
|
|
|
|
+ modifyOrder.lines[0].linePriceWithTax / 2,
|
|
|
|
|
+ );
|
|
|
|
|
+ expect(modifyOrder.lines[0].linePriceWithTax).toBe(order.lines[0].linePriceWithTax * 2);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
async function assertOrderIsUnchanged(order: OrderWithLinesFragment) {
|
|
async function assertOrderIsUnchanged(order: OrderWithLinesFragment) {
|
|
|
const { order: order2 } = await adminClient.query<GetOrder.Query, GetOrder.Variables>(GET_ORDER, {
|
|
const { order: order2 } = await adminClient.query<GetOrder.Query, GetOrder.Variables>(GET_ORDER, {
|
|
|
id: order.id,
|
|
id: order.id,
|
|
@@ -1416,6 +1507,7 @@ export const ORDER_WITH_MODIFICATION_FRAGMENT = gql`
|
|
|
quantity
|
|
quantity
|
|
|
linePrice
|
|
linePrice
|
|
|
linePriceWithTax
|
|
linePriceWithTax
|
|
|
|
|
+ discountedLinePriceWithTax
|
|
|
productVariant {
|
|
productVariant {
|
|
|
id
|
|
id
|
|
|
name
|
|
name
|