Browse Source

fix(core): Fix occasional failing variantNameCollectionFilter

Michael Bromley 4 years ago
parent
commit
ac76e2cf4b

+ 14 - 17
packages/core/e2e/collection.e2e-spec.ts

@@ -2,9 +2,7 @@
 import { ROOT_COLLECTION_NAME } from '@vendure/common/lib/shared-constants';
 import { ROOT_COLLECTION_NAME } from '@vendure/common/lib/shared-constants';
 import {
 import {
     DefaultJobQueuePlugin,
     DefaultJobQueuePlugin,
-    DefaultLogger,
     facetValueCollectionFilter,
     facetValueCollectionFilter,
-    JobQueueService,
     variantNameCollectionFilter,
     variantNameCollectionFilter,
 } from '@vendure/core';
 } from '@vendure/core';
 import { createTestEnvironment } from '@vendure/testing';
 import { createTestEnvironment } from '@vendure/testing';
@@ -58,7 +56,6 @@ import { sortById } from './utils/test-order-utils';
 describe('Collection resolver', () => {
 describe('Collection resolver', () => {
     const { server, adminClient, shopClient } = createTestEnvironment({
     const { server, adminClient, shopClient } = createTestEnvironment({
         ...testConfig,
         ...testConfig,
-        logger: new DefaultLogger(),
         plugins: [DefaultJobQueuePlugin],
         plugins: [DefaultJobQueuePlugin],
     });
     });
 
 
@@ -408,7 +405,7 @@ describe('Collection resolver', () => {
                 },
                 },
             });
             });
 
 
-            await awaitRunningJobs(adminClient, 5000, 500);
+            await awaitRunningJobs(adminClient, 5000);
             expect(updateCollection).toMatchSnapshot();
             expect(updateCollection).toMatchSnapshot();
 
 
             pearCollection = updateCollection;
             pearCollection = updateCollection;
@@ -425,7 +422,7 @@ describe('Collection resolver', () => {
                     featuredAssetId: assets[3].id,
                     featuredAssetId: assets[3].id,
                 },
                 },
             });
             });
-            await awaitRunningJobs(adminClient, 5000, 500);
+            await awaitRunningJobs(adminClient, 5000);
             expect(updateCollection.assets.map(a => a.id)).toEqual([assets[3].id, assets[0].id]);
             expect(updateCollection.assets.map(a => a.id)).toEqual([assets[3].id, assets[0].id]);
         });
         });
 
 
@@ -439,7 +436,7 @@ describe('Collection resolver', () => {
                     assetIds: [],
                     assetIds: [],
                 },
                 },
             });
             });
-            await awaitRunningJobs(adminClient, 5000, 500);
+            await awaitRunningJobs(adminClient, 5000);
             expect(updateCollection.assets).toEqual([]);
             expect(updateCollection.assets).toEqual([]);
             expect(updateCollection.featuredAsset).toBeNull();
             expect(updateCollection.featuredAsset).toBeNull();
         });
         });
@@ -712,7 +709,7 @@ describe('Collection resolver', () => {
         });
         });
 
 
         it('re-evaluates Collection contents on move', async () => {
         it('re-evaluates Collection contents on move', async () => {
-            await awaitRunningJobs(adminClient, 5000, 500);
+            await awaitRunningJobs(adminClient, 5000);
 
 
             const result = await adminClient.query<
             const result = await adminClient.query<
                 GetCollectionProducts.Query,
                 GetCollectionProducts.Query,
@@ -922,7 +919,7 @@ describe('Collection resolver', () => {
                 },
                 },
             );
             );
             collectionToDeleteChild = result2.createCollection;
             collectionToDeleteChild = result2.createCollection;
-            await awaitRunningJobs(adminClient, 5000, 500);
+            await awaitRunningJobs(adminClient, 5000);
         });
         });
 
 
         it(
         it(
@@ -1166,7 +1163,7 @@ describe('Collection resolver', () => {
                     } as CreateCollectionInput,
                     } as CreateCollectionInput,
                 });
                 });
 
 
-                await awaitRunningJobs(adminClient, 5000, 500);
+                await awaitRunningJobs(adminClient, 5000);
                 const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
                 const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
                     GET_COLLECTION,
                     GET_COLLECTION,
                     {
                     {
@@ -1211,7 +1208,7 @@ describe('Collection resolver', () => {
                     } as CreateCollectionInput,
                     } as CreateCollectionInput,
                 });
                 });
 
 
-                await awaitRunningJobs(adminClient, 5000, 500);
+                await awaitRunningJobs(adminClient, 5000);
                 const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
                 const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
                     GET_COLLECTION,
                     GET_COLLECTION,
                     {
                     {
@@ -1265,7 +1262,7 @@ describe('Collection resolver', () => {
                     } as CreateCollectionInput,
                     } as CreateCollectionInput,
                 });
                 });
 
 
-                await awaitRunningJobs(adminClient, 5000, 500);
+                await awaitRunningJobs(adminClient, 5000);
                 const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
                 const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
                     GET_COLLECTION,
                     GET_COLLECTION,
                     {
                     {
@@ -1321,7 +1318,7 @@ describe('Collection resolver', () => {
                         ],
                         ],
                     },
                     },
                 });
                 });
-                await awaitRunningJobs(adminClient, 5000, 500);
+                await awaitRunningJobs(adminClient, 5000);
                 return createCollection;
                 return createCollection;
             }
             }
 
 
@@ -1469,7 +1466,7 @@ describe('Collection resolver', () => {
                     },
                     },
                 });
                 });
 
 
-                await awaitRunningJobs(adminClient, 5000, 500);
+                await awaitRunningJobs(adminClient, 5000);
 
 
                 const result = await adminClient.query<
                 const result = await adminClient.query<
                     GetCollectionProducts.Query,
                     GetCollectionProducts.Query,
@@ -1502,7 +1499,7 @@ describe('Collection resolver', () => {
                     },
                     },
                 );
                 );
 
 
-                await awaitRunningJobs(adminClient, 5000, 500);
+                await awaitRunningJobs(adminClient, 5000);
 
 
                 const result = await adminClient.query<
                 const result = await adminClient.query<
                     GetCollectionProducts.Query,
                     GetCollectionProducts.Query,
@@ -1536,7 +1533,7 @@ describe('Collection resolver', () => {
                     },
                     },
                 );
                 );
 
 
-                await awaitRunningJobs(adminClient, 5000, 500);
+                await awaitRunningJobs(adminClient, 5000);
 
 
                 const result = await adminClient.query<
                 const result = await adminClient.query<
                     GetCollectionProducts.Query,
                     GetCollectionProducts.Query,
@@ -1589,7 +1586,7 @@ describe('Collection resolver', () => {
                 } as CreateCollectionInput,
                 } as CreateCollectionInput,
             });
             });
 
 
-            await awaitRunningJobs(adminClient, 5000, 500);
+            await awaitRunningJobs(adminClient, 5000);
 
 
             const result = await adminClient.query<
             const result = await adminClient.query<
                 GetCollectionProducts.Query,
                 GetCollectionProducts.Query,
@@ -1680,7 +1677,7 @@ describe('Collection resolver', () => {
                     input: [{ id: 'T_1', enabled: false }],
                     input: [{ id: 'T_1', enabled: false }],
                 },
                 },
             );
             );
-            await awaitRunningJobs(adminClient, 5000, 500);
+            await awaitRunningJobs(adminClient, 5000);
 
 
             const { collection } = await shopClient.query<
             const { collection } = await shopClient.query<
                 GetCollectionProducts.Query,
                 GetCollectionProducts.Query,

+ 1 - 2
packages/core/package.json

@@ -69,7 +69,7 @@
     "image-size": "^0.9.1",
     "image-size": "^0.9.1",
     "mime-types": "^2.1.27",
     "mime-types": "^2.1.27",
     "ms": "^2.1.2",
     "ms": "^2.1.2",
-    "nanoid": "^2.1.11",
+    "nanoid": "^3.1.23",
     "progress": "^2.0.3",
     "progress": "^2.0.3",
     "reflect-metadata": "^0.1.13",
     "reflect-metadata": "^0.1.13",
     "rxjs": "^6.6.3",
     "rxjs": "^6.6.3",
@@ -85,7 +85,6 @@
     "@types/gulp": "^4.0.7",
     "@types/gulp": "^4.0.7",
     "@types/mime-types": "^2.1.0",
     "@types/mime-types": "^2.1.0",
     "@types/ms": "^0.7.31",
     "@types/ms": "^0.7.31",
-    "@types/nanoid": "^2.1.0",
     "@types/node": "^14.14.31",
     "@types/node": "^14.14.31",
     "@types/progress": "^2.0.3",
     "@types/progress": "^2.0.3",
     "@types/prompts": "^2.0.9",
     "@types/prompts": "^2.0.9",

+ 4 - 2
packages/core/src/common/generate-public-id.ts

@@ -1,4 +1,6 @@
-import generate = require('nanoid/generate');
+import { customAlphabet } from 'nanoid';
+
+const nanoid = customAlphabet('123456789ABCDEFGHJKLMNPQRSTUVWXYZ', 16);
 
 
 /**
 /**
  * Generates a random, human-readable string of numbers and upper-case letters
  * Generates a random, human-readable string of numbers and upper-case letters
@@ -16,5 +18,5 @@ import generate = require('nanoid/generate');
  * reach a probability of 1% that a collision would occur.
  * reach a probability of 1% that a collision would occur.
  */
  */
 export function generatePublicId(): string {
 export function generatePublicId(): string {
-    return generate('123456789ABCDEFGHJKLMNPQRSTUVWXYZ', 16);
+    return nanoid();
 }
 }

+ 3 - 2
packages/core/src/config/catalog/default-collection-filters.ts

@@ -1,5 +1,5 @@
 import { LanguageCode } from '@vendure/common/lib/generated-types';
 import { LanguageCode } from '@vendure/common/lib/generated-types';
-import nanoid from 'nanoid';
+import { customAlphabet } from 'nanoid';
 
 
 import { UserInputError } from '../../common/error/errors';
 import { UserInputError } from '../../common/error/errors';
 import { ProductVariant } from '../../entity/product-variant/product-variant.entity';
 import { ProductVariant } from '../../entity/product-variant/product-variant.entity';
@@ -90,7 +90,8 @@ export const variantNameCollectionFilter = new CollectionFilter({
     description: [{ languageCode: LanguageCode.en, value: 'Filter by ProductVariant name' }],
     description: [{ languageCode: LanguageCode.en, value: 'Filter by ProductVariant name' }],
     apply: (qb, args) => {
     apply: (qb, args) => {
         const translationAlias = `variant_name_filter_translation`;
         const translationAlias = `variant_name_filter_translation`;
-        const termName = `term_${nanoid(6)}`;
+        const nanoid = customAlphabet('123456789abcdefghijklmnopqrstuvwxyz', 6);
+        const termName = `term_${nanoid()}`;
         const hasJoinOnTranslations = !!qb.expressionMap.joinAttributes.find(
         const hasJoinOnTranslations = !!qb.expressionMap.joinAttributes.find(
             ja => ja.entityOrProperty === 'productVariant.translations',
             ja => ja.entityOrProperty === 'productVariant.translations',
         );
         );

+ 5 - 12
yarn.lock

@@ -4005,13 +4005,6 @@
   dependencies:
   dependencies:
     "@types/node" "*"
     "@types/node" "*"
 
 
-"@types/nanoid@^2.1.0":
-  version "2.1.0"
-  resolved "https://registry.npmjs.org/@types/nanoid/-/nanoid-2.1.0.tgz#41edfda78986e9127d0dc14de982de766f994020"
-  integrity sha512-xdkn/oRTA0GSNPLIKZgHWqDTWZsVrieKomxJBOQUK9YDD+zfSgmwD5t4WJYra5S7XyhTw7tfvwznW+pFexaepQ==
-  dependencies:
-    "@types/node" "*"
-
 "@types/node-fetch@2.5.10", "@types/node-fetch@^2.5.10":
 "@types/node-fetch@2.5.10", "@types/node-fetch@^2.5.10":
   version "2.5.10"
   version "2.5.10"
   resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.10.tgz#9b4d4a0425562f9fcea70b12cb3fcdd946ca8132"
   resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.10.tgz#9b4d4a0425562f9fcea70b12cb3fcdd946ca8132"
@@ -13481,16 +13474,16 @@ nan@^2.12.1:
   resolved "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
   resolved "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
   integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
   integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
 
 
-nanoid@^2.1.11:
-  version "2.1.11"
-  resolved "https://registry.npmjs.org/nanoid/-/nanoid-2.1.11.tgz#ec24b8a758d591561531b4176a01e3ab4f0f0280"
-  integrity sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==
-
 nanoid@^3.1.20:
 nanoid@^3.1.20:
   version "3.1.20"
   version "3.1.20"
   resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz#badc263c6b1dcf14b71efaa85f6ab4c1d6cfc788"
   resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz#badc263c6b1dcf14b71efaa85f6ab4c1d6cfc788"
   integrity sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==
   integrity sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==
 
 
+nanoid@^3.1.23:
+  version "3.1.23"
+  resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.1.23.tgz#f744086ce7c2bc47ee0a8472574d5c78e4183a81"
+  integrity sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw==
+
 nanomatch@^1.2.9:
 nanomatch@^1.2.9:
   version "1.2.13"
   version "1.2.13"
   resolved "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
   resolved "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"