فهرست منبع

chore: Tidy up

Michael Bromley 3 سال پیش
والد
کامیت
f19965dfb9

+ 56 - 56
packages/core/e2e/order-modification.e2e-spec.ts

@@ -17,7 +17,7 @@ import gql from 'graphql-tag';
 import path from 'path';
 
 import { initialData } from '../../../e2e-common/e2e-initial-data';
-import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
+import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
 import { manualFulfillmentHandler } from '../src/config/fulfillment/manual-fulfillment-handler';
 import { orderFixedDiscount } from '../src/config/promotion/actions/order-fixed-discount-action';
 
@@ -2095,35 +2095,35 @@ describe('Order modification', () => {
         const CODE_FREE_SHIPPING = 'FREESHIP';
         let order: TestOrderWithPaymentsFragment;
         beforeAll(async () => {
-            await adminClient.query<CreatePromotionMutation, CreatePromotionMutationVariables>(
-                CREATE_PROMOTION,
-                {
-                    input: {
-                        name: '50% off',
-                        couponCode: CODE_50PC_OFF,
-                        enabled: true,
-                        conditions: [],
-                        actions: [
-                            {
-                                code: orderPercentageDiscount.code,
-                                arguments: [{ name: 'discount', value: '50' }],
-                            },
-                        ],
-                    },
+            await adminClient.query<
+                Codegen.CreatePromotionMutation,
+                Codegen.CreatePromotionMutationVariables
+            >(CREATE_PROMOTION, {
+                input: {
+                    name: '50% off',
+                    couponCode: CODE_50PC_OFF,
+                    enabled: true,
+                    conditions: [],
+                    actions: [
+                        {
+                            code: orderPercentageDiscount.code,
+                            arguments: [{ name: 'discount', value: '50' }],
+                        },
+                    ],
                 },
-            );
-            await adminClient.query<CreatePromotionMutation, CreatePromotionMutationVariables>(
-                CREATE_PROMOTION,
-                {
-                    input: {
-                        name: 'Free shipping',
-                        couponCode: CODE_FREE_SHIPPING,
-                        enabled: true,
-                        conditions: [],
-                        actions: [{ code: freeShipping.code, arguments: [] }],
-                    },
+            });
+            await adminClient.query<
+                Codegen.CreatePromotionMutation,
+                Codegen.CreatePromotionMutationVariables
+            >(CREATE_PROMOTION, {
+                input: {
+                    name: 'Free shipping',
+                    couponCode: CODE_FREE_SHIPPING,
+                    enabled: true,
+                    conditions: [],
+                    actions: [{ code: freeShipping.code, arguments: [] }],
                 },
-            );
+            });
 
             // create an order and check out
             await shopClient.asUserWithCredentials('trevor_donnelly96@hotmail.com', 'test');
@@ -2149,8 +2149,8 @@ describe('Order modification', () => {
 
         it('invalid coupon code returns ErrorResult', async () => {
             const { modifyOrder } = await adminClient.query<
-                ModifyOrderMutation,
-                ModifyOrderMutationVariables
+                Codegen.ModifyOrderMutation,
+                Codegen.ModifyOrderMutationVariables
             >(MODIFY_ORDER, {
                 input: {
                     dryRun: false,
@@ -2164,8 +2164,8 @@ describe('Order modification', () => {
 
         it('valid coupon code applies Promotion', async () => {
             const { modifyOrder } = await adminClient.query<
-                ModifyOrderMutation,
-                ModifyOrderMutationVariables
+                Codegen.ModifyOrderMutation,
+                Codegen.ModifyOrderMutationVariables
             >(MODIFY_ORDER, {
                 input: {
                     dryRun: false,
@@ -2182,8 +2182,8 @@ describe('Order modification', () => {
 
         it('adds order.discounts', async () => {
             const { order: orderWithModifications } = await adminClient.query<
-                GetOrderWithModificationsQuery,
-                GetOrderWithModificationsQueryVariables
+                Codegen.GetOrderWithModificationsQuery,
+                Codegen.GetOrderWithModificationsQueryVariables
             >(GET_ORDER_WITH_MODIFICATIONS, { id: order.id });
             expect(orderWithModifications?.discounts.length).toBe(1);
             expect(orderWithModifications?.discounts[0].description).toBe('50% off');
@@ -2191,8 +2191,8 @@ describe('Order modification', () => {
 
         it('adds order.promotions', async () => {
             const { order: orderWithModifications } = await adminClient.query<
-                GetOrderWithModificationsQuery,
-                GetOrderWithModificationsQueryVariables
+                Codegen.GetOrderWithModificationsQuery,
+                Codegen.GetOrderWithModificationsQueryVariables
             >(GET_ORDER_WITH_MODIFICATIONS, { id: order.id });
             expect(orderWithModifications?.promotions.length).toBe(1);
             expect(orderWithModifications?.promotions[0].name).toBe('50% off');
@@ -2200,8 +2200,8 @@ describe('Order modification', () => {
 
         it('creates correct refund amount', async () => {
             const { order: orderWithModifications } = await adminClient.query<
-                GetOrderWithModificationsQuery,
-                GetOrderWithModificationsQueryVariables
+                Codegen.GetOrderWithModificationsQuery,
+                Codegen.GetOrderWithModificationsQueryVariables
             >(GET_ORDER_WITH_MODIFICATIONS, { id: order.id });
             expect(orderWithModifications?.payments![0].refunds.length).toBe(1);
             expect(orderWithModifications!.totalWithTax).toBe(
@@ -2214,8 +2214,8 @@ describe('Order modification', () => {
 
         it('creates history entry for applying couponCode', async () => {
             const { order: history } = await adminClient.query<
-                GetOrderHistory.Query,
-                GetOrderHistory.Variables
+                Codegen.GetOrderHistoryQuery,
+                Codegen.GetOrderHistoryQueryVariables
             >(GET_ORDER_HISTORY, {
                 id: order.id,
                 options: { filter: { type: { eq: HistoryEntryType.ORDER_COUPON_APPLIED } } },
@@ -2231,8 +2231,8 @@ describe('Order modification', () => {
 
         it('removes coupon code', async () => {
             const { modifyOrder } = await adminClient.query<
-                ModifyOrderMutation,
-                ModifyOrderMutationVariables
+                Codegen.ModifyOrderMutation,
+                Codegen.ModifyOrderMutationVariables
             >(MODIFY_ORDER, {
                 input: {
                     dryRun: false,
@@ -2246,24 +2246,24 @@ describe('Order modification', () => {
 
         it('removes order.discounts', async () => {
             const { order: orderWithModifications } = await adminClient.query<
-                GetOrderWithModificationsQuery,
-                GetOrderWithModificationsQueryVariables
+                Codegen.GetOrderWithModificationsQuery,
+                Codegen.GetOrderWithModificationsQueryVariables
             >(GET_ORDER_WITH_MODIFICATIONS, { id: order.id });
             expect(orderWithModifications?.discounts.length).toBe(0);
         });
 
         it('removes order.promotions', async () => {
             const { order: orderWithModifications } = await adminClient.query<
-                GetOrderWithModificationsQuery,
-                GetOrderWithModificationsQueryVariables
+                Codegen.GetOrderWithModificationsQuery,
+                Codegen.GetOrderWithModificationsQueryVariables
             >(GET_ORDER_WITH_MODIFICATIONS, { id: order.id });
             expect(orderWithModifications?.promotions.length).toBe(0);
         });
 
         it('creates history entry for removing couponCode', async () => {
             const { order: history } = await adminClient.query<
-                GetOrderHistory.Query,
-                GetOrderHistory.Variables
+                Codegen.GetOrderHistoryQuery,
+                Codegen.GetOrderHistoryQueryVariables
             >(GET_ORDER_HISTORY, {
                 id: order.id,
                 options: { filter: { type: { eq: HistoryEntryType.ORDER_COUPON_REMOVED } } },
@@ -2292,8 +2292,8 @@ describe('Order modification', () => {
             expect(result2.state).toBe('Modifying');
 
             const { modifyOrder } = await adminClient.query<
-                ModifyOrderMutation,
-                ModifyOrderMutationVariables
+                Codegen.ModifyOrderMutation,
+                Codegen.ModifyOrderMutationVariables
             >(MODIFY_ORDER, {
                 input: {
                     dryRun: false,
@@ -2363,12 +2363,12 @@ describe('Order modification', () => {
             id: testShippingMethodId,
         });
 
-        await shopClient.query<Codegen.TransitionToStateMutation, Codegen.TransitionToStateMutationVariables>(
-            TRANSITION_TO_STATE,
-            {
-                state: 'ArrangingPayment',
-            },
-        );
+        await shopClient.query<
+            CodegenShop.TransitionToStateMutation,
+            CodegenShop.TransitionToStateMutationVariables
+        >(TRANSITION_TO_STATE, {
+            state: 'ArrangingPayment',
+        });
 
         const order = await addPaymentToOrder(shopClient, testSuccessfulPaymentMethod);
         orderGuard.assertSuccess(order);

+ 13 - 2
packages/dev-server/test-plugins/multivendor-plugin/config/mv-fulfillment-process.ts

@@ -43,7 +43,10 @@ async function checkAggregateOrderFulfillments(input: {
     orders: Order[];
     fulfillment: Fulfillment;
     toState: FulfillmentState;
-    aggregateOrderHandler: (aggregateOrder: Order, allFulfillmentStates: FulfillmentState[]) => Promise<void>;
+    aggregateOrderHandler: (
+        aggregateOrder: Order,
+        allFulfillmentStates: Array<FulfillmentState | 'none'>,
+    ) => Promise<void>;
 }) {
     const { ctx, orders, fulfillment, toState, aggregateOrderHandler } = input;
     for (const order of orders) {
@@ -57,8 +60,16 @@ async function checkAggregateOrderFulfillments(input: {
                     ),
                 )
             )
+                .map(fulfillments => {
+                    if (fulfillments.length === 0) {
+                        // This order has no fulfillments yet, so we need to add a placeholder to indicate this
+                        return 'none';
+                    } else {
+                        return fulfillments;
+                    }
+                })
                 .flat()
-                .map(f => (f.id === fulfillment.id ? toState : f.state));
+                .map(f => (f === 'none' ? f : f.id === fulfillment.id ? toState : f.state));
             await aggregateOrderHandler(aggregateOrder, allFulfillmentStates);
         }
     }

+ 78 - 2
packages/dev-server/test-plugins/multivendor-plugin/config/mv-order-process.ts

@@ -1,7 +1,29 @@
-import { CustomOrderProcess } from '@vendure/core';
+import { OrderType } from '@vendure/common/lib/generated-types';
+import { ID } from '@vendure/common/lib/shared-types';
+import {
+    CustomOrderProcess,
+    idsAreEqual,
+    Order,
+    orderItemsAreDelivered,
+    orderItemsArePartiallyDelivered,
+    orderItemsArePartiallyShipped,
+    orderItemsAreShipped,
+    OrderService,
+    RequestContext,
+    TransactionalConnection,
+} from '@vendure/core';
+
+let connection: TransactionalConnection;
+let orderService: OrderService;
 
 export const multivendorOrderProcess: CustomOrderProcess<any> = {
-    onTransitionStart(fromState, toState, data) {
+    init(injector) {
+        connection = injector.get(TransactionalConnection);
+        orderService = injector.get(OrderService);
+    },
+
+    async onTransitionStart(fromState, toState, data) {
+        const { ctx, order } = data;
         if (fromState === 'AddingItems' && toState === 'ArrangingPayment') {
             for (const line of data.order.lines) {
                 if (!line.shippingLineId) {
@@ -9,5 +31,59 @@ export const multivendorOrderProcess: CustomOrderProcess<any> = {
                 }
             }
         }
+
+        if (order.type !== OrderType.Aggregate) {
+            if (toState === 'PartiallyShipped') {
+                const orderWithFulfillments = await findOrderWithFulfillments(ctx, order.id);
+                if (!orderItemsArePartiallyShipped(orderWithFulfillments)) {
+                    return `message.cannot-transition-unless-some-order-items-shipped`;
+                }
+            }
+            if (toState === 'Shipped') {
+                const orderWithFulfillments = await findOrderWithFulfillments(ctx, order.id);
+                if (!orderItemsAreShipped(orderWithFulfillments)) {
+                    return `message.cannot-transition-unless-all-order-items-shipped`;
+                }
+            }
+            if (toState === 'PartiallyDelivered') {
+                const orderWithFulfillments = await findOrderWithFulfillments(ctx, order.id);
+                if (!orderItemsArePartiallyDelivered(orderWithFulfillments)) {
+                    return `message.cannot-transition-unless-some-order-items-delivered`;
+                }
+            }
+            if (toState === 'Delivered') {
+                const orderWithFulfillments = await findOrderWithFulfillments(ctx, order.id);
+                if (!orderItemsAreDelivered(orderWithFulfillments)) {
+                    return `message.cannot-transition-unless-all-order-items-delivered`;
+                }
+            }
+        }
+    },
+    async onTransitionEnd(fromState, toState, data) {
+        const { ctx, order } = data;
+        if (order.type === OrderType.Seller) {
+            const aggregateOrder = await orderService.getAggregateOrder(ctx, order);
+            if (aggregateOrder) {
+                const otherSellerOrders = (await orderService.getSellerOrders(ctx, aggregateOrder)).filter(
+                    so => !idsAreEqual(so.id, order.id),
+                );
+                const sellerOrderStates = [...otherSellerOrders.map(so => so.state), toState];
+                if (sellerOrderStates.every(state => state === 'Shipped')) {
+                    await orderService.transitionToState(data.ctx, aggregateOrder.id, 'Shipped');
+                } else if (sellerOrderStates.every(state => state === 'Delivered')) {
+                    await orderService.transitionToState(data.ctx, aggregateOrder.id, 'Delivered');
+                } else if (sellerOrderStates.some(state => state === 'Delivered')) {
+                    await orderService.transitionToState(data.ctx, aggregateOrder.id, 'PartiallyDelivered');
+                } else if (sellerOrderStates.some(state => state === 'Shipped')) {
+                    await orderService.transitionToState(data.ctx, aggregateOrder.id, 'PartiallyShipped');
+                }
+            }
+        }
     },
 };
+
+async function findOrderWithFulfillments(ctx: RequestContext, id: ID): Promise<Order> {
+    return await connection.getEntityOrThrow(ctx, Order, id, {
+        relations: ['lines', 'lines.items', 'lines.items.fulfillments'],
+    });
+}

+ 0 - 1
packages/dev-server/test-plugins/multivendor-plugin/config/mv-order-seller-strategy.ts

@@ -6,7 +6,6 @@ import {
     Injector,
     InternalServerError,
     isGraphQlErrorResult,
-    Logger,
     Order,
     OrderLine,
     OrderSellerStrategy,

+ 6 - 3
packages/dev-server/test-plugins/multivendor-plugin/multivendor.plugin.ts

@@ -2,6 +2,7 @@ import { OnApplicationBootstrap } from '@nestjs/common';
 import {
     Channel,
     ChannelService,
+    configureDefaultOrderProcess,
     LanguageCode,
     PaymentMethod,
     PaymentMethodService,
@@ -11,7 +12,6 @@ import {
     VendurePlugin,
 } from '@vendure/core';
 
-import { multivendorFulfillmentProcess } from './config/mv-fulfillment-process';
 import { multivendorOrderProcess } from './config/mv-order-process';
 import { MultivendorSellerStrategy } from './config/mv-order-seller-strategy';
 import { multivendorPaymentMethodHandler } from './config/mv-payment-handler';
@@ -31,8 +31,11 @@ import { CONNECTED_PAYMENT_METHOD_CODE } from './constants';
             public: false,
         });
         config.paymentOptions.paymentMethodHandlers.push(multivendorPaymentMethodHandler);
-        config.shippingOptions.customFulfillmentProcess.push(multivendorFulfillmentProcess);
-        config.orderOptions.process.push(multivendorOrderProcess);
+
+        const customDefaultOrderProcess = configureDefaultOrderProcess({
+            checkFulfillmentStates: false,
+        });
+        config.orderOptions.process = [customDefaultOrderProcess, multivendorOrderProcess];
         config.orderOptions.orderSellerStrategy = new MultivendorSellerStrategy();
         config.shippingOptions.shippingLineAssignmentStrategy =
             new MultivendorShippingLineAssignmentStrategy();

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 528 - 510
packages/elasticsearch-plugin/e2e/graphql/generated-e2e-elasticsearch-plugin-types.ts


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 528 - 510
packages/payments-plugin/e2e/graphql/generated-admin-types.ts


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 616 - 600
packages/payments-plugin/e2e/graphql/generated-shop-types.ts


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 645 - 629
packages/payments-plugin/src/mollie/graphql/generated-shop-types.ts


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است