Browse Source

test(elasticsearch-plugin): Add unit tests for #870

Artem Danilov 4 years ago
parent
commit
511c0b6342
1 changed files with 106 additions and 0 deletions
  1. 106 0
      packages/elasticsearch-plugin/src/build-elastic-body.spec.ts

+ 106 - 0
packages/elasticsearch-plugin/src/build-elastic-body.spec.ts

@@ -234,6 +234,112 @@ describe('buildElasticBody()', () => {
         });
     });
 
+    it('inStock is True and groupByProduct', () => {
+        const result = buildElasticBody(
+            { inStock: true, groupByProduct: true },
+            searchConfig,
+            CHANNEL_ID,
+            LanguageCode.en,
+        );
+        expect(result.query).toEqual({
+            bool: {
+                filter: [
+                    CHANNEL_ID_TERM,
+                    LANGUAGE_CODE_TERM,
+                    { term: { productInStock: true }},
+                ],
+            },
+        });
+    });
+
+    it('inStock is False and groupByProduct', () => {
+        const result = buildElasticBody(
+            { inStock: false, groupByProduct: true },
+            searchConfig,
+            CHANNEL_ID,
+            LanguageCode.en,
+        );
+        expect(result.query).toEqual({
+            bool: {
+                filter: [
+                    CHANNEL_ID_TERM,
+                    LANGUAGE_CODE_TERM,
+                    { term: { productInStock: false }},
+                ],
+            },
+        });
+    });
+
+    it('inStock is undefined and groupByProduct', () => {
+        const result = buildElasticBody(
+            { groupByProduct: true },
+            searchConfig,
+            CHANNEL_ID,
+            LanguageCode.en,
+        );
+        expect(result.query).toEqual({
+            bool: {
+                filter: [
+                    CHANNEL_ID_TERM,
+                    LANGUAGE_CODE_TERM,
+                ],
+            },
+        });
+    });
+
+    it('inStock is True and not groupByProduct', () => {
+        const result = buildElasticBody(
+            { inStock: true, groupByProduct: false },
+            searchConfig,
+            CHANNEL_ID,
+            LanguageCode.en,
+        );
+        expect(result.query).toEqual({
+            bool: {
+                filter: [
+                    CHANNEL_ID_TERM,
+                    LANGUAGE_CODE_TERM,
+                    { term: { inStock: true }},
+                ],
+            },
+        });
+    });
+
+    it('inStock is False and not groupByProduct', () => {
+        const result = buildElasticBody(
+            { inStock: false, groupByProduct: false },
+            searchConfig,
+            CHANNEL_ID,
+            LanguageCode.en,
+        );
+        expect(result.query).toEqual({
+            bool: {
+                filter: [
+                    CHANNEL_ID_TERM,
+                    LANGUAGE_CODE_TERM,
+                    { term: { inStock: false }},
+                ],
+            },
+        });
+    });
+
+    it('inStock is undefined and not groupByProduct', () => {
+        const result = buildElasticBody(
+            { groupByProduct: false },
+            searchConfig,
+            CHANNEL_ID,
+            LanguageCode.en,
+        );
+        expect(result.query).toEqual({
+            bool: {
+                filter: [
+                    CHANNEL_ID_TERM,
+                    LANGUAGE_CODE_TERM,
+                ],
+            },
+        });
+    });
+
     describe('sorting', () => {
         it('name', () => {
             const result = buildElasticBody(