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

fix(core): Fix issues with Promotion & PaymentMethod null descriptions

BREAKING CHANGE: `Promotion` & `PaymentMethod` `description` is once again non-nullable. This will
require a simple non-destructive DB migration.
Michael Bromley 2 лет назад
Родитель
Сommit
7b407de250

+ 7 - 0
packages/core/e2e/graphql/fragments.ts

@@ -441,6 +441,7 @@ export const PROMOTION_FRAGMENT = gql`
         startsAt
         endsAt
         name
+        description
         enabled
         conditions {
             ...ConfigurableOperation
@@ -448,6 +449,12 @@ export const PROMOTION_FRAGMENT = gql`
         actions {
             ...ConfigurableOperation
         }
+        translations {
+            id
+            languageCode
+            name
+            description
+        }
     }
     ${CONFIGURABLE_FRAGMENT}
 `;

Разница между файлами не показана из-за своего большого размера
+ 520 - 539
packages/core/e2e/graphql/generated-e2e-admin-types.ts


Разница между файлами не показана из-за своего большого размера
+ 603 - 621
packages/core/e2e/graphql/generated-e2e-shop-types.ts


+ 70 - 0
packages/core/e2e/payment-method.e2e-spec.ts

@@ -112,6 +112,14 @@ describe('PaymentMethod resolver', () => {
                 ],
                 code: 'dummy-payment-handler',
             },
+            translations: [
+                {
+                    description: 'This is a test payment method',
+                    id: 'T_1',
+                    languageCode: 'en',
+                    name: 'No Checker',
+                },
+            ],
         });
     });
 
@@ -158,6 +166,14 @@ describe('PaymentMethod resolver', () => {
                 ],
                 code: dummyPaymentHandler.code,
             },
+            translations: [
+                {
+                    description: 'modified',
+                    id: 'T_1',
+                    languageCode: 'en',
+                    name: 'No Checker',
+                },
+            ],
         });
     });
 
@@ -483,6 +499,54 @@ describe('PaymentMethod resolver', () => {
             expect(check2.totalItems).toBe(4);
         });
     });
+
+    it('create without description', async () => {
+        const { createPaymentMethod } = await adminClient.query<
+            Codegen.CreatePaymentMethodMutation,
+            Codegen.CreatePaymentMethodMutationVariables
+        >(CREATE_PAYMENT_METHOD, {
+            input: {
+                code: 'no-description',
+                enabled: true,
+                handler: {
+                    code: dummyPaymentHandler.code,
+                    arguments: [{ name: 'automaticSettle', value: 'true' }],
+                },
+                translations: [
+                    {
+                        languageCode: LanguageCode.en,
+                        name: 'No Description',
+                    },
+                ],
+            },
+        });
+
+        expect(createPaymentMethod).toEqual({
+            id: 'T_6',
+            name: 'No Description',
+            code: 'no-description',
+            description: '',
+            enabled: true,
+            checker: null,
+            handler: {
+                args: [
+                    {
+                        name: 'automaticSettle',
+                        value: 'true',
+                    },
+                ],
+                code: 'dummy-payment-handler',
+            },
+            translations: [
+                {
+                    description: '',
+                    id: 'T_6',
+                    languageCode: 'en',
+                    name: 'No Description',
+                },
+            ],
+        });
+    });
 });
 
 export const PAYMENT_METHOD_FRAGMENT = gql`
@@ -506,6 +570,12 @@ export const PAYMENT_METHOD_FRAGMENT = gql`
                 value
             }
         }
+        translations {
+            id
+            languageCode
+            name
+            description
+        }
     }
 `;
 

+ 36 - 1
packages/core/e2e/promotion.e2e-spec.ts

@@ -110,6 +110,41 @@ describe('Promotion resolver', () => {
         expect(pick(promotion, snapshotProps)).toMatchSnapshot();
     });
 
+    it('createPromotion with no description', async () => {
+        const { createPromotion } = await adminClient.query<
+            Codegen.CreatePromotionMutation,
+            Codegen.CreatePromotionMutationVariables
+        >(CREATE_PROMOTION, {
+            input: {
+                enabled: true,
+                couponCode: 'TEST567',
+                translations: [
+                    {
+                        languageCode: LanguageCode.en,
+                        name: 'test promotion no description',
+                        customFields: {},
+                    },
+                ],
+                conditions: [],
+                actions: [
+                    {
+                        code: promoAction.code,
+                        arguments: [
+                            {
+                                name: 'facetValueIds',
+                                value: '["T_1"]',
+                            },
+                        ],
+                    },
+                ],
+            },
+        });
+        promotionGuard.assertSuccess(createPromotion);
+        expect(createPromotion.name).toBe('test promotion no description');
+        expect(createPromotion.description).toBe('');
+        expect(createPromotion.translations[0].description).toBe('');
+    });
+
     it('createPromotion return error result with empty conditions and no couponCode', async () => {
         const { createPromotion } = await adminClient.query<
             Codegen.CreatePromotionMutation,
@@ -208,7 +243,7 @@ describe('Promotion resolver', () => {
             Codegen.GetPromotionListQueryVariables
         >(GET_PROMOTION_LIST, {});
 
-        expect(result.promotions.totalItems).toBe(1);
+        expect(result.promotions.totalItems).toBe(2);
         expect(result.promotions.items[0].name).toBe('test promotion');
     });
 

+ 6 - 1
packages/core/src/entity/payment-method/payment-method-translation.entity.ts

@@ -16,13 +16,18 @@ export class PaymentMethodTranslation
 {
     constructor(input?: DeepPartial<Translation<PaymentMethod>>) {
         super(input);
+        // This is a workaround for the fact that
+        // MySQL does not support default values on TEXT columns
+        if (this.description === undefined) {
+            this.description = '';
+        }
     }
 
     @Column('varchar') languageCode: LanguageCode;
 
     @Column() name: string;
 
-    @Column('text', { nullable: true }) description: string;
+    @Column('text') description: string;
 
     @Index()
     @ManyToOne(type => PaymentMethod, base => base.translations, { onDelete: 'CASCADE' })

+ 6 - 1
packages/core/src/entity/promotion/promotion-translation.entity.ts

@@ -13,13 +13,18 @@ import { Promotion } from './promotion.entity';
 export class PromotionTranslation extends VendureEntity implements Translation<Promotion>, HasCustomFields {
     constructor(input?: DeepPartial<Translation<Promotion>>) {
         super(input);
+        // This is a workaround for the fact that
+        // MySQL does not support default values on TEXT columns
+        if (this.description === undefined) {
+            this.description = '';
+        }
     }
 
     @Column('varchar') languageCode: LanguageCode;
 
     @Column() name: string;
 
-    @Column('text', { nullable: true }) description: string;
+    @Column('text') description: string;
 
     @Index()
     @ManyToOne(type => Promotion, base => base.translations, { onDelete: 'CASCADE' })

Некоторые файлы не были показаны из-за большого количества измененных файлов