Jelajahi Sumber

refactor: Clean up todos in search plugin e2e tests

Michael Bromley 4 tahun lalu
induk
melakukan
705bf085c2

+ 35 - 38
packages/core/e2e/default-search-plugin.e2e-spec.ts

@@ -71,6 +71,15 @@ import { awaitRunningJobs } from './utils/await-running-jobs';
 // on the default of 5s.
 jest.setTimeout(10000);
 
+interface SearchProductShopVariables extends SearchProductsShop.Variables {
+    input: SearchProductsShop.Variables['input'] & {
+        // This input field is dynamically added only when the `indexStockStatus` init option
+        // is set to `true`, and therefore not included in the generated type. Therefore
+        // we need to manually patch it here.
+        inStock?: boolean;
+    };
+}
+
 describe('Default search plugin', () => {
     const { server, adminClient, shopClient } = createTestEnvironment(
         mergeConfig(testConfig, {
@@ -99,13 +108,13 @@ describe('Default search plugin', () => {
     });
 
     function doAdminSearchQuery(input: SearchInput) {
-        return adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(SEARCH_PRODUCTS, {
+        return adminClient.query<SearchProductsShop.Query, SearchProductShopVariables>(SEARCH_PRODUCTS, {
             input,
         });
     }
 
     async function testGroupByProduct(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -117,7 +126,7 @@ describe('Default search plugin', () => {
     }
 
     async function testNoGrouping(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -132,7 +141,7 @@ describe('Default search plugin', () => {
         client: SimpleGraphQLClient,
         sortBy: keyof SearchResultSortParameter,
     ) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -155,7 +164,7 @@ describe('Default search plugin', () => {
         client: SimpleGraphQLClient,
         sortBy: keyof SearchResultSortParameter,
     ) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -175,7 +184,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchSearchTerm(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -195,7 +204,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchFacetIdsAnd(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -216,7 +225,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchFacetIdsOr(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -244,7 +253,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchFacetValueFiltersAnd(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -264,7 +273,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchFacetValueFiltersOr(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -291,7 +300,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchFacetValueFiltersOrWithAnd(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -315,7 +324,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchFacetValueFiltersWithFacetIdsOr(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -341,7 +350,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchFacetValueFiltersWithFacetIdsAnd(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -361,7 +370,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchCollectionId(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -378,7 +387,7 @@ describe('Default search plugin', () => {
     }
 
     async function testMatchCollectionSlug(client: SimpleGraphQLClient) {
-        const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+        const result = await client.query<SearchProductsShop.Query, SearchProductShopVariables>(
             SEARCH_PRODUCTS_SHOP,
             {
                 input: {
@@ -589,7 +598,7 @@ describe('Default search plugin', () => {
         });
 
         it('encodes the productId and productVariantId', async () => {
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
@@ -620,7 +629,7 @@ describe('Default search plugin', () => {
                 },
             );
             await awaitRunningJobs(adminClient);
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
@@ -633,7 +642,7 @@ describe('Default search plugin', () => {
         });
 
         it('encodes collectionIds', async () => {
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
@@ -648,13 +657,11 @@ describe('Default search plugin', () => {
         });
 
         it('inStock is false and not grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: false,
-                        // @ts-ignore
                         inStock: false,
                     },
                 },
@@ -663,13 +670,11 @@ describe('Default search plugin', () => {
         });
 
         it('inStock is false and grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: true,
-                        // @ts-ignore
                         inStock: false,
                     },
                 },
@@ -678,13 +683,11 @@ describe('Default search plugin', () => {
         });
 
         it('inStock is true and not grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: false,
-                        // @ts-ignore
                         inStock: true,
                     },
                 },
@@ -693,13 +696,11 @@ describe('Default search plugin', () => {
         });
 
         it('inStock is true and grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: true,
-                        // @ts-ignore
                         inStock: true,
                     },
                 },
@@ -708,13 +709,11 @@ describe('Default search plugin', () => {
         });
 
         it('inStock is undefined and not grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: false,
-                        // @ts-ignore
                         inStock: undefined,
                     },
                 },
@@ -723,13 +722,11 @@ describe('Default search plugin', () => {
         });
 
         it('inStock is undefined and grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: true,
-                        // @ts-ignore
                         inStock: undefined,
                     },
                 },
@@ -1445,7 +1442,7 @@ describe('Default search plugin', () => {
                     adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
                     const { search } = await adminClient.query<
                         SearchProductsShop.Query,
-                        SearchProductsShop.Variables
+                        SearchProductShopVariables
                     >(
                         SEARCH_PRODUCTS,
                         {
@@ -1478,7 +1475,7 @@ describe('Default search plugin', () => {
 
         describe('multiple language handling', () => {
             function searchInLanguage(languageCode: LanguageCode) {
-                return adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+                return adminClient.query<SearchProductsShop.Query, SearchProductShopVariables>(
                     SEARCH_PRODUCTS,
                     {
                         input: {

+ 8 - 7
packages/dev-server/dev-config.ts

@@ -3,6 +3,7 @@ import { AdminUiPlugin } from '@vendure/admin-ui-plugin';
 import { AssetServerPlugin } from '@vendure/asset-server-plugin';
 import { ADMIN_API_PATH, API_PORT, SHOP_API_PATH } from '@vendure/common/lib/shared-constants';
 import {
+    DefaultJobQueuePlugin,
     DefaultLogger,
     DefaultSearchPlugin,
     dummyPaymentHandler,
@@ -65,15 +66,15 @@ export const devConfig: VendureConfig = {
             route: 'assets',
             assetUploadDir: path.join(__dirname, 'assets'),
         }),
-        // DefaultSearchPlugin.init({ bufferUpdates: true }),
+        DefaultSearchPlugin.init({ bufferUpdates: true, indexStockStatus: false }),
         BullMQJobQueuePlugin.init({}),
-        // DefaultJobQueuePlugin,
+        // DefaultJobQueuePlugin.init(),
         // JobQueueTestPlugin.init({ queueCount: 10 }),
-        ElasticsearchPlugin.init({
-            host: 'http://localhost',
-            port: 9200,
-            bufferUpdates: true,
-        }),
+        // ElasticsearchPlugin.init({
+        //     host: 'http://localhost',
+        //     port: 9200,
+        //     bufferUpdates: true,
+        // }),
         EmailPlugin.init({
             devMode: true,
             route: 'mailbox',

+ 25 - 29
packages/elasticsearch-plugin/e2e/elasticsearch-plugin.e2e-spec.ts

@@ -100,6 +100,15 @@ if (process.env.CI) {
     jest.setTimeout(10 * 3000);
 }
 
+interface SearchProductShopVariables extends SearchProductsShop.Variables {
+    input: SearchProductsShop.Variables['input'] & {
+        // This input field is dynamically added only when the `indexStockStatus` init option
+        // of DefaultSearchPlugin is set to `true`, and therefore not included in the generated type. Therefore
+        // we need to manually patch it here.
+        inStock?: boolean;
+    };
+}
+
 const INDEX_PREFIX = 'e2e-tests';
 
 describe('Elasticsearch plugin', () => {
@@ -296,7 +305,7 @@ describe('Elasticsearch plugin', () => {
         });
 
         it('encodes the productId and productVariantId', async () => {
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
@@ -320,7 +329,7 @@ describe('Elasticsearch plugin', () => {
                 },
             );
             await awaitRunningJobs(adminClient);
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
@@ -333,7 +342,7 @@ describe('Elasticsearch plugin', () => {
         });
 
         it('encodes collectionIds', async () => {
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
@@ -348,14 +357,12 @@ describe('Elasticsearch plugin', () => {
         });
 
         it('inStock is false and not grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: false,
-                        // @ts-ignore
-                        inStock: false
+                        inStock: false,
                     },
                 },
             );
@@ -363,14 +370,12 @@ describe('Elasticsearch plugin', () => {
         });
 
         it('inStock is false and grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: true,
-                        // @ts-ignore
-                        inStock: false
+                        inStock: false,
                     },
                 },
             );
@@ -378,14 +383,12 @@ describe('Elasticsearch plugin', () => {
         });
 
         it('inStock is true and not grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: false,
-                        // @ts-ignore
-                        inStock: true
+                        inStock: true,
                     },
                 },
             );
@@ -393,14 +396,12 @@ describe('Elasticsearch plugin', () => {
         });
 
         it('inStock is true and grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: true,
-                        // @ts-ignore
-                        inStock: true
+                        inStock: true,
                     },
                 },
             );
@@ -408,14 +409,12 @@ describe('Elasticsearch plugin', () => {
         });
 
         it('inStock is undefined and not grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: false,
-                        // @ts-ignore
-                        inStock: undefined
+                        inStock: undefined,
                     },
                 },
             );
@@ -423,20 +422,17 @@ describe('Elasticsearch plugin', () => {
         });
 
         it('inStock is undefined and grouped by product', async () => {
-            // ToDo Remove @ts-ignore after implementing inStock in default-search-plugin
-            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
+            const result = await shopClient.query<SearchProductsShop.Query, SearchProductsShopVariables>(
                 SEARCH_PRODUCTS_SHOP,
                 {
                     input: {
                         groupByProduct: true,
-                        // @ts-ignore
-                        inStock: undefined
+                        inStock: undefined,
                     },
                 },
             );
             expect(result.search.totalItems).toBe(20);
         });
-
     });
 
     describe('admin api', () => {
@@ -1170,7 +1166,7 @@ describe('Elasticsearch plugin', () => {
                     adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
                     const { search } = await adminClient.query<
                         SearchProductsShop.Query,
-                        SearchProductsShop.Variables
+                        SearchProductsShopVariables
                     >(
                         SEARCH_PRODUCTS,
                         {