Parcourir la source

test(core): Add test case for importing custom fields data

Michael Bromley il y a 6 ans
Parent
commit
d07f977232

+ 42 - 0
packages/core/e2e/__snapshots__/import.e2e-spec.ts.snap

@@ -17,6 +17,9 @@ Array [
         "source": "test-url/test-assets/pps2.jpg",
       },
     ],
+    "customFields": Object {
+      "pageType": "default",
+    },
     "description": "A great device for stretching paper.",
     "facetValues": Array [],
     "featuredAsset": Object {
@@ -38,6 +41,9 @@ Array [
     "variants": Array [
       Object {
         "assets": Array [],
+        "customFields": Object {
+          "weight": 100,
+        },
         "facetValues": Array [
           Object {
             "code": "kb",
@@ -81,6 +87,9 @@ Array [
       },
       Object {
         "assets": Array [],
+        "customFields": Object {
+          "weight": 100,
+        },
         "facetValues": Array [
           Object {
             "code": "kb",
@@ -124,6 +133,9 @@ Array [
       },
       Object {
         "assets": Array [],
+        "customFields": Object {
+          "weight": 100,
+        },
         "facetValues": Array [
           Object {
             "code": "kb",
@@ -175,6 +187,9 @@ Array [
   },
   Object {
     "assets": Array [],
+    "customFields": Object {
+      "pageType": "expanded",
+    },
     "description": "Mabef description",
     "facetValues": Array [],
     "featuredAsset": null,
@@ -185,6 +200,9 @@ Array [
     "variants": Array [
       Object {
         "assets": Array [],
+        "customFields": Object {
+          "weight": 300,
+        },
         "facetValues": Array [
           Object {
             "code": "mabef",
@@ -231,6 +249,9 @@ Array [
   },
   Object {
     "assets": Array [],
+    "customFields": Object {
+      "pageType": "default",
+    },
     "description": "Really mega pencils",
     "facetValues": Array [],
     "featuredAsset": null,
@@ -254,6 +275,9 @@ Array [
             "source": "test-url/test-assets/box-of-8.jpg",
           },
         ],
+        "customFields": Object {
+          "weight": 200,
+        },
         "facetValues": Array [
           Object {
             "code": "xmas-sale",
@@ -300,6 +324,9 @@ Array [
             "source": "test-url/test-assets/box-of-12.jpg",
           },
         ],
+        "customFields": Object {
+          "weight": 200,
+        },
         "facetValues": Array [
           Object {
             "code": "xmas-sale",
@@ -341,6 +368,9 @@ Array [
   },
   Object {
     "assets": Array [],
+    "customFields": Object {
+      "pageType": "default",
+    },
     "description": "Keeps the paint off the clothes",
     "facetValues": Array [
       Object {
@@ -379,6 +409,9 @@ Array [
     "variants": Array [
       Object {
         "assets": Array [],
+        "customFields": Object {
+          "weight": 500,
+        },
         "facetValues": Array [],
         "featuredAsset": null,
         "id": "T_7",
@@ -407,6 +440,9 @@ Array [
       },
       Object {
         "assets": Array [],
+        "customFields": Object {
+          "weight": 500,
+        },
         "facetValues": Array [],
         "featuredAsset": null,
         "id": "T_8",
@@ -435,6 +471,9 @@ Array [
       },
       Object {
         "assets": Array [],
+        "customFields": Object {
+          "weight": 500,
+        },
         "facetValues": Array [],
         "featuredAsset": null,
         "id": "T_9",
@@ -463,6 +502,9 @@ Array [
       },
       Object {
         "assets": Array [],
+        "customFields": Object {
+          "weight": 500,
+        },
         "facetValues": Array [],
         "featuredAsset": null,
         "id": "T_10",

+ 11 - 11
packages/core/e2e/fixtures/product-import.csv

@@ -1,12 +1,12 @@
-name                    , slug                    , description                          , assets              , facets                            , optionGroups  , optionValues     , sku    , price , taxCategory , stockOnHand , trackInventory , variantAssets   , variantFacets
-Perfect Paper Stretcher , perfect-paper-stretcher , A great device for stretching paper. , "pps1.jpg|pps2.jpg" ,                                   , size          , Half Imperial    , PPS12  , 45.3  , standard    , 0           , false          ,                 , Brand:KB|Type:Accessory
-                        ,                         ,                                      ,                     ,                                   ,               , Quarter Imperial , PPS14  , 32.5  , standard    , 0           , false          ,                 , Brand:KB|Type:Accessory
-                        ,                         ,                                      ,                     ,                                   ,               , Full Imperial    , PPSF   , 59.5  , standard    , -10         , false          ,                 , Brand:KB|Type:Accessory
-Mabef M/02 Studio Easel ,                         , Mabef description                    ,                     ,                                   ,               ,                  , M02    , 910.7 , standard    , 100         , false          ,                 , Brand:Mabef|Type:Easel
-Giotto Mega Pencils     ,                         , Really mega pencils                  ,                     ,                                   , box size      , Box of 8         , 225400 , 4.16  , standard    ,             , false          , "box-of-8.jpg"  , Collection:Xmas Sale
-                        ,                         ,                                      ,                     ,                                   ,               , Box of 12        , 225600 , 6.24  , standard    ,             , false          , "box-of-12.jpg" , Collection:Xmas Sale
+name                    , slug                    , description                          , assets              , facets                            , optionGroups  , optionValues     , sku    , price , taxCategory , stockOnHand , trackInventory , variantAssets   , variantFacets           , product:pageType , variant:weight
+Perfect Paper Stretcher , perfect-paper-stretcher , A great device for stretching paper. , "pps1.jpg|pps2.jpg" ,                                   , size          , Half Imperial    , PPS12  , 45.3  , standard    , 0           , false          ,                 , Brand:KB|Type:Accessory , default          , 100
+                        ,                         ,                                      ,                     ,                                   ,               , Quarter Imperial , PPS14  , 32.5  , standard    , 0           , false          ,                 , Brand:KB|Type:Accessory ,                  , 100
+                        ,                         ,                                      ,                     ,                                   ,               , Full Imperial    , PPSF   , 59.5  , standard    , -10         , false          ,                 , Brand:KB|Type:Accessory ,                  , 100
+Mabef M/02 Studio Easel ,                         , Mabef description                    ,                     ,                                   ,               ,                  , M02    , 910.7 , standard    , 100         , false          ,                 , Brand:Mabef|Type:Easel  , expanded         , 300
+Giotto Mega Pencils     ,                         , Really mega pencils                  ,                     ,                                   , box size      , Box of 8         , 225400 , 4.16  , standard    ,             , false          , "box-of-8.jpg"  , Collection:Xmas Sale    , default          , 200
+                        ,                         ,                                      ,                     ,                                   ,               , Box of 12        , 225600 , 6.24  , standard    ,             , false          , "box-of-12.jpg" , Collection:Xmas Sale    ,                  , 200
 
-Artists Smock           ,                         , Keeps the paint off the clothes      ,                     , Material:Denim|Collection:clothes , "size|colour" , "small|beige"    , 10112  , 11.99 , reduced     ,             , false          ,                 ,
-                        ,                         ,                                      ,                     ,                                   ,               , "large|beige"    , 10113  , 11.99 , reduced     ,             , false          ,                 ,
-                        ,                         ,                                      ,                     ,                                   ,               , "small|navy"     , 10114  , 11.99 , reduced     ,             , false          ,                 ,
-                        ,                         ,                                      ,                     ,                                   ,               , "large|navy"     , 10115  , 11.99 , reduced     ,             , false          ,                 ,
+Artists Smock           ,                         , Keeps the paint off the clothes      ,                     , Material:Denim|Collection:clothes , "size|colour" , "small|beige"    , 10112  , 11.99 , reduced     ,             , false          ,                 ,                         , default          , 500
+                        ,                         ,                                      ,                     ,                                   ,               , "large|beige"    , 10113  , 11.99 , reduced     ,             , false          ,                 ,                         , default          , 500
+                        ,                         ,                                      ,                     ,                                   ,               , "small|navy"     , 10114  , 11.99 , reduced     ,             , false          ,                 ,                         , default          , 500
+                        ,                         ,                                      ,                     ,                                   ,               , "large|navy"     , 10115  , 11.99 , reduced     ,             , false          ,                 ,                         , default          , 500

+ 19 - 5
packages/core/e2e/import.e2e-spec.ts

@@ -10,10 +10,18 @@ describe('Import resolver', () => {
     const server = new TestServer();
 
     beforeAll(async () => {
-        const token = await server.init({
-            productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-empty.csv'),
-            customerCount: 0,
-        });
+        const token = await server.init(
+            {
+                productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-empty.csv'),
+                customerCount: 0,
+            },
+            {
+                customFields: {
+                    Product: [{ type: 'string', name: 'pageType' }],
+                    ProductVariant: [{ type: 'int', name: 'weight' }],
+                },
+            },
+        );
         await client.init();
     }, TEST_SETUP_TIMEOUT_MS);
 
@@ -39,7 +47,7 @@ describe('Import resolver', () => {
         const result = await client.importProducts(csvFile);
 
         expect(result.importProducts.errors).toEqual([
-            'Invalid Record Length: header length is 14, got 1 on line 8',
+            'Invalid Record Length: header length is 16, got 1 on line 8',
         ]);
         expect(result.importProducts.imported).toBe(4);
         expect(result.importProducts.processed).toBe(4);
@@ -79,6 +87,9 @@ describe('Import resolver', () => {
                                     name
                                 }
                             }
+                            customFields {
+                                pageType
+                            }
                             variants {
                                 id
                                 name
@@ -124,6 +135,9 @@ describe('Import resolver', () => {
                                         }
                                     }
                                 }
+                                customFields {
+                                    weight
+                                }
                             }
                         }
                     }

+ 1 - 1
scripts/codegen/generate-graphql-types.ts

@@ -9,7 +9,7 @@ import { ADMIN_API_PATH, API_PORT, SHOP_API_PATH } from '../../packages/common/s
 import { downloadIntrospectionSchema } from './download-introspection-schema';
 
 const CLIENT_QUERY_FILES = path.join(__dirname, '../../packages/admin-ui/src/app/data/definitions/**/*.ts');
-const E2E_ADMIN_QUERY_FILES = path.join(__dirname, '../../packages/core/e2e/**/!(plugin.e2e-spec|shop-definitions|custom-fields.e2e-spec).ts');
+const E2E_ADMIN_QUERY_FILES = path.join(__dirname, '../../packages/core/e2e/**/!(import.e2e-spec|plugin.e2e-spec|shop-definitions|custom-fields.e2e-spec).ts');
 const E2E_SHOP_QUERY_FILES = [
     path.join(__dirname, '../../packages/core/e2e/graphql/shop-definitions.ts'),
 ];