Browse Source

test(core): Add e2e test for localeString length

Relates to #434
Michael Bromley 5 years ago
parent
commit
42b39fb812

+ 32 - 0
packages/core/e2e/custom-fields.e2e-spec.ts

@@ -87,6 +87,11 @@ const customConfig = mergeConfig(testConfig, {
                 type: 'string',
                 length: 10000,
             },
+            {
+                name: 'longLocaleString',
+                type: 'localeString',
+                length: 10000,
+            },
             {
                 name: 'readonlyString',
                 type: 'string',
@@ -196,6 +201,7 @@ describe('Custom fields', () => {
                 { name: 'nonPublic', type: 'string', list: false },
                 { name: 'public', type: 'string', list: false },
                 { name: 'longString', type: 'string', list: false },
+                { name: 'longLocaleString', type: 'localeString', list: false },
                 { name: 'readonlyString', type: 'string', list: false },
                 { name: 'stringList', type: 'string', list: true },
                 { name: 'localeStringList', type: 'localeString', list: true },
@@ -361,6 +367,32 @@ describe('Custom fields', () => {
         expect(result.updateProduct.customFields.longString).toBe(longString);
     });
 
+    it('string length allows long localeStrings', async () => {
+        const longString = Array.from({ length: 500 }, v => 'hello there!').join(' ');
+        const result = await adminClient.query(
+            gql`
+                mutation($stringValue: String!) {
+                    updateProduct(
+                        input: {
+                            id: "T_1"
+                            translations: [
+                                { languageCode: en, customFields: { longLocaleString: $stringValue } }
+                            ]
+                        }
+                    ) {
+                        id
+                        customFields {
+                            longLocaleString
+                        }
+                    }
+                }
+            `,
+            { stringValue: longString },
+        );
+
+        expect(result.updateProduct.customFields.longLocaleString).toBe(longString);
+    });
+
     describe('validation', () => {
         it(
             'invalid string',

+ 1 - 0
packages/core/src/config/custom-field/custom-field-types.ts

@@ -127,6 +127,7 @@ export type CustomFieldConfig =
  * #### `localeString` type
  *
  * * `pattern?: string`: A regex pattern which the field value must match
+ * * `length?: number`: The max length of the varchar created in the database. Defaults to 255. Maximum is 65,535.
  *
  * #### `int` & `float` type
  *