Browse Source

test(admin-ui): Fix failing test

Michael Bromley 2 years ago
parent
commit
2879baccf8

+ 40 - 7
packages/admin-ui/src/lib/core/src/common/utilities/create-updated-translatable.spec.ts

@@ -5,7 +5,7 @@ import { CustomFieldConfig, LanguageCode, ProductDetailFragment } from '../gener
 import { createUpdatedTranslatable } from './create-updated-translatable';
 
 /* eslint-disable @typescript-eslint/no-non-null-assertion */
-describe('createUpdatedTranslatable()', () => {
+fdescribe('createUpdatedTranslatable()', () => {
     let product: any;
 
     beforeEach(() => {
@@ -182,13 +182,13 @@ describe('createUpdatedTranslatable()', () => {
         });
     });
 
-    it('coerces empty customFields to correct type', () => {
+    it('coerces empty customFields to correct type (non-nullable)', () => {
         const customFieldConfig: CustomFieldConfig[] = [
-            { name: 'a', type: 'boolean', list: false },
-            { name: 'b', type: 'int', list: false },
-            { name: 'c', type: 'float', list: false },
-            { name: 'd', type: 'datetime', list: false },
-            { name: 'e', type: 'string', list: false },
+            { name: 'a', type: 'boolean', list: false, nullable: false },
+            { name: 'b', type: 'int', list: false, nullable: false },
+            { name: 'c', type: 'float', list: false, nullable: false },
+            { name: 'd', type: 'datetime', list: false, nullable: false },
+            { name: 'e', type: 'string', list: false, nullable: false },
         ];
 
         const formValue = {
@@ -214,4 +214,37 @@ describe('createUpdatedTranslatable()', () => {
         expect(result.customFields.d instanceof Date).toBe(true);
         expect(result.customFields.e).toBe('');
     });
+
+    it('coerces empty customFields to correct type (nullable)', () => {
+        const customFieldConfig: CustomFieldConfig[] = [
+            { name: 'a', type: 'boolean', list: false, nullable: true },
+            { name: 'b', type: 'int', list: false, nullable: true },
+            { name: 'c', type: 'float', list: false, nullable: true },
+            { name: 'd', type: 'datetime', list: false, nullable: true },
+            { name: 'e', type: 'string', list: false, nullable: true },
+        ];
+
+        const formValue = {
+            customFields: {
+                a: '',
+                b: '',
+                c: '',
+                d: '',
+                e: '',
+            },
+        };
+
+        const result = createUpdatedTranslatable({
+            translatable: product,
+            updatedFields: formValue,
+            customFieldConfig,
+            languageCode: LanguageCode.en,
+        });
+
+        expect(result.customFields.a).toBe(false);
+        expect(result.customFields.b).toBe(null);
+        expect(result.customFields.c).toBe(null);
+        expect(result.customFields.d).toBe(null);
+        expect(result.customFields.e).toBe('');
+    });
 });