Browse Source

test(elasticsearch-plugin): Add e2e tests for customMappings

Michael Bromley 4 years ago
parent
commit
ad296b0b5b
1 changed files with 64 additions and 0 deletions
  1. 64 0
      packages/elasticsearch-plugin/e2e/elasticsearch-plugin.e2e-spec.ts

+ 64 - 0
packages/elasticsearch-plugin/e2e/elasticsearch-plugin.e2e-spec.ts

@@ -108,6 +108,22 @@ describe('Elasticsearch plugin', () => {
                     indexPrefix: INDEX_PREFIX,
                     port: elasticsearchPort,
                     host: elasticsearchHost,
+                    customProductVariantMappings: {
+                        inStock: {
+                            graphQlType: 'Boolean!',
+                            valueFn: variant => {
+                                return variant.stockOnHand > 0;
+                            },
+                        },
+                    },
+                    customProductMappings: {
+                        answer: {
+                            graphQlType: 'Int!',
+                            valueFn: args => {
+                                return 42;
+                            },
+                        },
+                    },
                 }),
                 DefaultJobQueuePlugin,
             ],
@@ -1051,6 +1067,54 @@ describe('Elasticsearch plugin', () => {
             });
         });
     });
+
+    describe('customMappings', () => {
+        it('variant mappings', async () => {
+            const query = `{
+            search(input: { take: 1, groupByProduct: false, sort: { name: ASC } }) {
+                items {
+                  productVariantName
+                  customMappings {
+                    ...on CustomProductVariantMappings {
+                      inStock
+                    }
+                  }
+                }
+              }
+            }`;
+            const { search } = await shopClient.query(gql(query));
+
+            expect(search.items[0]).toEqual({
+                productVariantName: 'Bonsai Tree',
+                customMappings: {
+                    inStock: true,
+                },
+            });
+        });
+
+        it('product mappings', async () => {
+            const query = `{
+            search(input: { take: 1, groupByProduct: true, sort: { name: ASC } }) {
+                items {
+                  productName
+                  customMappings {
+                    ...on CustomProductMappings {
+                      answer
+                    }
+                  }
+                }
+              }
+            }`;
+            const { search } = await shopClient.query(gql(query));
+
+            expect(search.items[0]).toEqual({
+                productName: 'Bonsai Tree',
+                customMappings: {
+                    answer: 42,
+                },
+            });
+        });
+    });
 });
 
 export const SEARCH_PRODUCTS = gql`