Просмотр исходного кода

Merge branch 'minor' into major

Michael Bromley 3 лет назад
Родитель
Сommit
23bcb27ef5

+ 1 - 1
packages/admin-ui/src/lib/core/src/common/utilities/configurable-operation-utils.ts

@@ -70,7 +70,7 @@ export function toConfigurableOperationInput(
         code: operation.code,
         code: operation.code,
         arguments: Object.values<any>(formValueOperations.args || {}).map((value, j) => ({
         arguments: Object.values<any>(formValueOperations.args || {}).map((value, j) => ({
             name: operation.args[j].name,
             name: operation.args[j].name,
-            value: value.hasOwnProperty('value')
+            value: value?.hasOwnProperty('value')
                 ? encodeConfigArgValue((value as any).value)
                 ? encodeConfigArgValue((value as any).value)
                 : encodeConfigArgValue(value),
                 : encodeConfigArgValue(value),
         })),
         })),

+ 57 - 0
packages/core/e2e/entity-prefix.e2e-spec.ts

@@ -0,0 +1,57 @@
+import { mergeConfig } from '@vendure/core';
+import { createTestEnvironment } from '@vendure/testing';
+import path from 'path';
+
+import { initialData } from '../../../e2e-common/e2e-initial-data';
+import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
+
+import { ListQueryPlugin } from './fixtures/test-plugins/list-query-plugin';
+import { GetCustomerListQuery, GetCustomerListQueryVariables } from './graphql/generated-e2e-admin-types';
+import { GET_CUSTOMER_LIST } from './graphql/shared-definitions';
+
+/**
+ * Tests edge-cases related to configurations with an `entityPrefix` defined in the
+ * dbConnectionOptions.
+ */
+describe('Entity prefix edge-cases', () => {
+    const { server, adminClient, shopClient } = createTestEnvironment(
+        mergeConfig(testConfig(), {
+            dbConnectionOptions: {
+                entityPrefix: 'prefix_',
+            },
+            plugins: [ListQueryPlugin],
+        }),
+    );
+
+    beforeAll(async () => {
+        await server.init({
+            initialData,
+            productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-minimal.csv'),
+            customerCount: 5,
+        });
+        await adminClient.asSuperAdmin();
+    }, TEST_SETUP_TIMEOUT_MS);
+
+    afterAll(async () => {
+        await server.destroy();
+    });
+
+    // https://github.com/vendure-ecommerce/vendure/issues/1569
+    it('customers list filter by postalCode', async () => {
+        const result = await adminClient.query<GetCustomerListQuery, GetCustomerListQueryVariables>(
+            GET_CUSTOMER_LIST,
+            {
+                options: {
+                    filter: {
+                        postalCode: {
+                            eq: 'NU9 0PW',
+                        },
+                    },
+                },
+            },
+        );
+
+        expect(result.customers.items.length).toBe(1);
+        expect(result.customers.items[0].emailAddress).toBe('eliezer56@yahoo.com');
+    });
+});

+ 20 - 0
packages/core/e2e/shop-order.e2e-spec.ts

@@ -30,6 +30,7 @@ import { ErrorCode } from './graphql/generated-e2e-shop-types';
 import * as CodegenShop from './graphql/generated-e2e-shop-types';
 import * as CodegenShop from './graphql/generated-e2e-shop-types';
 import {
 import {
     ATTEMPT_LOGIN,
     ATTEMPT_LOGIN,
+    CANCEL_ORDER,
     CREATE_SHIPPING_METHOD,
     CREATE_SHIPPING_METHOD,
     DELETE_PRODUCT,
     DELETE_PRODUCT,
     DELETE_PRODUCT_VARIANT,
     DELETE_PRODUCT_VARIANT,
@@ -103,6 +104,7 @@ describe('Shop orders', () => {
         | CodegenShop.UpdatedOrderFragment
         | CodegenShop.UpdatedOrderFragment
         | CodegenShop.TestOrderFragmentFragment
         | CodegenShop.TestOrderFragmentFragment
         | CodegenShop.TestOrderWithPaymentsFragment
         | CodegenShop.TestOrderWithPaymentsFragment
+        | CodegenShop.CanceledOrderFragment
         | CodegenShop.ActiveOrderCustomerFragment;
         | CodegenShop.ActiveOrderCustomerFragment;
     const orderResultGuard: ErrorResultGuard<OrderSuccessResult> = createErrorResultGuard(
     const orderResultGuard: ErrorResultGuard<OrderSuccessResult> = createErrorResultGuard(
         input => !!input.lines,
         input => !!input.lines,
@@ -1865,6 +1867,7 @@ describe('Shop orders', () => {
             }, `No ProductVariant with the id '34' could be found`),
             }, `No ProductVariant with the id '34' could be found`),
         );
         );
 
 
+        let orderWithDeletedProductVariantId: string;
         it('errors when transitioning to ArrangingPayment with deleted variant', async () => {
         it('errors when transitioning to ArrangingPayment with deleted variant', async () => {
             const orchidProductId = 'T_19';
             const orchidProductId = 'T_19';
             const orchidVariantId = 'T_33';
             const orchidVariantId = 'T_33';
@@ -1879,6 +1882,7 @@ describe('Shop orders', () => {
             });
             });
 
 
             orderResultGuard.assertSuccess(addItemToOrder);
             orderResultGuard.assertSuccess(addItemToOrder);
+            orderWithDeletedProductVariantId = addItemToOrder.id;
 
 
             await adminClient.query<Codegen.DeleteProductMutation, Codegen.DeleteProductMutationVariables>(
             await adminClient.query<Codegen.DeleteProductMutation, Codegen.DeleteProductMutationVariables>(
                 DELETE_PRODUCT,
                 DELETE_PRODUCT,
@@ -1900,6 +1904,22 @@ describe('Shop orders', () => {
             );
             );
             expect(transitionOrderToState!.errorCode).toBe(ErrorCode.ORDER_STATE_TRANSITION_ERROR);
             expect(transitionOrderToState!.errorCode).toBe(ErrorCode.ORDER_STATE_TRANSITION_ERROR);
         });
         });
+
+        // https://github.com/vendure-ecommerce/vendure/issues/1567
+        it('allows transitioning to Cancelled with deleted variant', async () => {
+            const { cancelOrder } = await adminClient.query<
+                CodegenShop.CancelOrderMutation,
+                CodegenShop.CancelOrderMutationVariables
+            >(CANCEL_ORDER, {
+                input: {
+                    orderId: orderWithDeletedProductVariantId,
+                },
+            });
+
+            orderResultGuard.assertSuccess(cancelOrder);
+
+            expect(cancelOrder.state).toBe('Cancelled');
+        });
     });
     });
 
 
     // https://github.com/vendure-ecommerce/vendure/issues/1195
     // https://github.com/vendure-ecommerce/vendure/issues/1195

+ 1 - 1
packages/core/src/service/helpers/list-query-builder/list-query-builder.ts

@@ -310,7 +310,7 @@ export class ListQueryBuilder implements OnApplicationBootstrap {
                 }
                 }
                 const tableNameLower = path.split('.')[0];
                 const tableNameLower = path.split('.')[0];
                 const entityMetadata = repository.manager.connection.entityMetadatas.find(
                 const entityMetadata = repository.manager.connection.entityMetadatas.find(
-                    em => em.tableName === tableNameLower,
+                    em => em.tableNameWithoutPrefix === tableNameLower,
                 );
                 );
                 if (entityMetadata) {
                 if (entityMetadata) {
                     const relationMetadata = metadata.relations.find(r => r.type === entityMetadata.target);
                     const relationMetadata = metadata.relations.find(r => r.type === entityMetadata.target);

+ 1 - 1
packages/core/src/service/helpers/order-state-machine/order-state-machine.ts

@@ -108,7 +108,7 @@ export class OrderStateMachine {
                 return `message.cannot-transition-from-arranging-additional-payment`;
                 return `message.cannot-transition-from-arranging-additional-payment`;
             }
             }
         }
         }
-        if (fromState === 'AddingItems') {
+        if (fromState === 'AddingItems' && toState !== 'Cancelled') {
             const variantIds = unique(data.order.lines.map(l => l.productVariant.id));
             const variantIds = unique(data.order.lines.map(l => l.productVariant.id));
             const qb = this.connection
             const qb = this.connection
                 .getRepository(data.ctx, ProductVariant)
                 .getRepository(data.ctx, ProductVariant)

+ 4 - 1
packages/core/src/service/services/product-variant.service.ts

@@ -107,7 +107,10 @@ export class ProductVariantService {
     ): Promise<Translated<ProductVariant> | undefined> {
     ): Promise<Translated<ProductVariant> | undefined> {
         return this.connection
         return this.connection
             .findOneInChannel(ctx, ProductVariant, productVariantId, ctx.channelId, {
             .findOneInChannel(ctx, ProductVariant, productVariantId, ctx.channelId, {
-                relations: [...(relations || ['product', 'product.featuredAsset']), 'taxCategory'],
+                relations: [
+                    ...(relations || ['product', 'featuredAsset', 'product.featuredAsset']),
+                    'taxCategory',
+                ],
                 where: { deletedAt: null },
                 where: { deletedAt: null },
             })
             })
             .then(async result => {
             .then(async result => {