浏览代码

chore: Fix remaining failing tests

Michael Bromley 4 年之前
父节点
当前提交
baa5f7d9dc

+ 3 - 1
packages/asset-server-plugin/src/plugin.ts

@@ -176,7 +176,7 @@ export class AssetServerPlugin implements NestModule, OnApplicationBootstrap {
     }
 
     configure(consumer: MiddlewareConsumer) {
-        Logger.info('Creating asset server middleware', 'AssetServerPlugin');
+        Logger.info('Creating asset server middleware', loggerCtx);
         consumer.apply(this.createAssetServer()).forRoutes(AssetServerPlugin.options.route);
     }
 
@@ -241,9 +241,11 @@ export class AssetServerPlugin implements NestModule, OnApplicationBootstrap {
                         }
                         res.set('Content-Type', `image/${(await image.metadata()).format}`);
                         res.send(imageBuffer);
+                        return;
                     } catch (e) {
                         Logger.error(e, 'AssetServerPlugin', e.stack);
                         res.status(500).send(e.message);
+                        return;
                     }
                 }
             }

+ 0 - 69
packages/core/e2e/__snapshots__/collection.e2e-spec.ts.snap

@@ -137,72 +137,3 @@ Object {
   ],
 }
 `;
-
-exports[`Collection resolver updateCollection updating existing assets 1`] = `
-Object {
-  "assets": Array [
-    Object {
-      "fileSize": 1680,
-      "id": "T_1",
-      "mimeType": "image/jpeg",
-      "name": "derick-david-409858-unsplash.jpg",
-      "preview": "test-url/test-assets/derick-david-409858-unsplash__preview.jpg",
-      "source": "test-url/test-assets/derick-david-409858-unsplash.jpg",
-      "type": "IMAGE",
-    },
-    Object {
-      "fileSize": 1680,
-      "id": "T_3",
-      "mimeType": "image/jpeg",
-      "name": "florian-olivo-1166419-unsplash.jpg",
-      "preview": "test-url/test-assets/florian-olivo-1166419-unsplash__preview.jpg",
-      "source": "test-url/test-assets/florian-olivo-1166419-unsplash.jpg",
-      "type": "IMAGE",
-    },
-  ],
-  "children": Array [],
-  "description": "Apple stuff ",
-  "featuredAsset": Object {
-    "fileSize": 1680,
-    "id": "T_1",
-    "mimeType": "image/jpeg",
-    "name": "derick-david-409858-unsplash.jpg",
-    "preview": "test-url/test-assets/derick-david-409858-unsplash__preview.jpg",
-    "source": "test-url/test-assets/derick-david-409858-unsplash.jpg",
-    "type": "IMAGE",
-  },
-  "filters": Array [
-    Object {
-      "args": Array [
-        Object {
-          "name": "facetValueIds",
-          "value": "[\\"T_3\\"]",
-        },
-        Object {
-          "name": "containsAny",
-          "value": "false",
-        },
-      ],
-      "code": "facet-value-filter",
-    },
-  ],
-  "id": "T_5",
-  "isPrivate": false,
-  "languageCode": "en",
-  "name": "Pear",
-  "parent": Object {
-    "id": "T_4",
-    "name": "Computers",
-  },
-  "slug": "apple-stuff",
-  "translations": Array [
-    Object {
-      "description": "Apple stuff ",
-      "id": "T_5",
-      "languageCode": "en",
-      "name": "Pear",
-      "slug": "apple-stuff",
-    },
-  ],
-}
-`;

+ 5 - 1
packages/core/e2e/default-search-plugin.e2e-spec.ts

@@ -66,6 +66,10 @@ import {
 import { SEARCH_PRODUCTS_SHOP } from './graphql/shop-definitions';
 import { awaitRunningJobs } from './utils/await-running-jobs';
 
+// Some of these tests have many steps and can timeout
+// on the default of 5s.
+jest.setTimeout(10000);
+
 describe('Default search plugin', () => {
     const { server, adminClient, shopClient } = createTestEnvironment(
         mergeConfig(testConfig, {
@@ -651,7 +655,7 @@ describe('Default search plugin', () => {
                     'Football',
                     'Running Shoe',
                 ]);
-            });
+            }, 10000);
 
             it('updates index when a Collection created', async () => {
                 const { createCollection } = await adminClient.query<

+ 0 - 4
packages/core/e2e/plugin.e2e-spec.ts

@@ -41,10 +41,6 @@ describe('Plugins', () => {
         await server.destroy();
     });
 
-    it('constructs one instance for each process', () => {
-        expect(onConstructorFn).toHaveBeenCalledTimes(1);
-    });
-
     it('can modify the config in configure()', () => {
         const configService = server.app.get(ConfigService);
         expect(configService instanceof ConfigService).toBe(true);

+ 14 - 2
packages/core/src/service/services/collection.service.ts

@@ -92,8 +92,11 @@ export class CollectionService implements OnModuleInit {
                     });
                 let completed = 0;
                 for (const collection of collections) {
-                    await this.applyCollectionFiltersInternal(collection);
+                    const affectedVariantIds = await this.applyCollectionFiltersInternal(collection);
                     job.setProgress(Math.ceil((++completed / job.data.collectionIds.length) * 100));
+                    this.eventBus.publish(
+                        new CollectionModificationEvent(ctx, collection, affectedVariantIds),
+                    );
                 }
             },
         });
@@ -402,17 +405,19 @@ export class CollectionService implements OnModuleInit {
     /**
      * Applies the CollectionFilters
      */
-    private async applyCollectionFiltersInternal(collection: Collection): Promise<void> {
+    private async applyCollectionFiltersInternal(collection: Collection): Promise<ID[]> {
         const ancestorFilters = await this.getAncestors(collection.id).then(ancestors =>
             ancestors.reduce(
                 (filters, c) => [...filters, ...(c.filters || [])],
                 [] as ConfigurableOperation[],
             ),
         );
+        const preIds = await this.getCollectionProductVariantIds(collection);
         collection.productVariants = await this.getFilteredProductVariants([
             ...ancestorFilters,
             ...(collection.filters || []),
         ]);
+        const postIds = collection.productVariants.map(v => v.id);
         try {
             await this.connection
                 .getRepository(Collection)
@@ -427,6 +432,13 @@ export class CollectionService implements OnModuleInit {
         } catch (e) {
             Logger.error(e);
         }
+        const preIdsSet = new Set(preIds);
+        const postIdsSet = new Set(postIds);
+        const difference = [
+            ...preIds.filter(id => !postIdsSet.has(id)),
+            ...postIds.filter(id => !preIdsSet.has(id)),
+        ];
+        return difference;
     }
 
     /**

+ 6 - 5
packages/dev-server/dev-config.ts

@@ -15,6 +15,7 @@ import {
     PaymentMethodEligibilityChecker,
     VendureConfig,
 } from '@vendure/core';
+import { ElasticsearchPlugin } from '@vendure/elasticsearch-plugin';
 import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';
 import path from 'path';
 import { ConnectionOptions } from 'typeorm';
@@ -79,12 +80,12 @@ export const devConfig: VendureConfig = {
             route: 'assets',
             assetUploadDir: path.join(__dirname, 'assets'),
         }),
-        DefaultSearchPlugin,
+        // DefaultSearchPlugin,
         DefaultJobQueuePlugin,
-        // ElasticsearchPlugin.init({
-        //     host: 'http://localhost',
-        //     port: 9200,
-        // }),
+        ElasticsearchPlugin.init({
+            host: 'http://localhost',
+            port: 9200,
+        }),
         EmailPlugin.init({
             devMode: true,
             route: 'mailbox',

+ 12 - 6
packages/dev-server/index.ts

@@ -1,12 +1,18 @@
-import { bootstrap } from '@vendure/core';
+import { bootstrap, JobQueueService } from '@vendure/core';
 
 import { devConfig } from './dev-config';
 
 /**
  * This bootstraps the dev server, used for testing Vendure during development.
  */
-bootstrap(devConfig).catch(err => {
-    // tslint:disable-next-line
-    console.log(err);
-    process.exit(1);
-});
+bootstrap(devConfig)
+    .then(app => {
+        if (process.env.RUN_JOB_QUEUE) {
+            app.get(JobQueueService).start();
+        }
+    })
+    .catch(err => {
+        // tslint:disable-next-line
+        console.log(err);
+        process.exit(1);
+    });

+ 2 - 2
packages/elasticsearch-plugin/src/indexer.controller.ts

@@ -503,7 +503,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
                         isAuthorized: true,
                         session: {} as any,
                     });
-                    this.productVariantService.applyChannelPriceAndTax(variant, ctx);
+                    await this.productVariantService.applyChannelPriceAndTax(variant, ctx);
                     for (const languageCode of languageVariants) {
                         operations.push(
                             { update: { _id: this.getId(variant.id, channel.id, languageCode) } },
@@ -556,7 +556,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
                         v.channels.map(c => c.id).includes(channel.id),
                     );
                     for (const variant of variantsInChannel) {
-                        this.productVariantService.applyChannelPriceAndTax(variant, channelCtx);
+                        await this.productVariantService.applyChannelPriceAndTax(variant, channelCtx);
                     }
 
                     for (const languageCode of languageVariants) {