Skip to content

Commit

Permalink
fix(core): Fix occasional failing variantNameCollectionFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jul 1, 2021
1 parent d529db0 commit ac76e2c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 35 deletions.
31 changes: 14 additions & 17 deletions packages/core/e2e/collection.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import { ROOT_COLLECTION_NAME } from '@vendure/common/lib/shared-constants';
import {
DefaultJobQueuePlugin,
DefaultLogger,
facetValueCollectionFilter,
JobQueueService,
variantNameCollectionFilter,
} from '@vendure/core';
import { createTestEnvironment } from '@vendure/testing';
Expand Down Expand Up @@ -58,7 +56,6 @@ import { sortById } from './utils/test-order-utils';
describe('Collection resolver', () => {
const { server, adminClient, shopClient } = createTestEnvironment({
...testConfig,
logger: new DefaultLogger(),
plugins: [DefaultJobQueuePlugin],
});

Expand Down Expand Up @@ -408,7 +405,7 @@ describe('Collection resolver', () => {
},
});

await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);
expect(updateCollection).toMatchSnapshot();

pearCollection = updateCollection;
Expand All @@ -425,7 +422,7 @@ describe('Collection resolver', () => {
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]);
});

Expand All @@ -439,7 +436,7 @@ describe('Collection resolver', () => {
assetIds: [],
},
});
await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);
expect(updateCollection.assets).toEqual([]);
expect(updateCollection.featuredAsset).toBeNull();
});
Expand Down Expand Up @@ -712,7 +709,7 @@ describe('Collection resolver', () => {
});

it('re-evaluates Collection contents on move', async () => {
await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);

const result = await adminClient.query<
GetCollectionProducts.Query,
Expand Down Expand Up @@ -922,7 +919,7 @@ describe('Collection resolver', () => {
},
);
collectionToDeleteChild = result2.createCollection;
await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);
});

it(
Expand Down Expand Up @@ -1166,7 +1163,7 @@ describe('Collection resolver', () => {
} as CreateCollectionInput,
});

await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);
const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
GET_COLLECTION,
{
Expand Down Expand Up @@ -1211,7 +1208,7 @@ describe('Collection resolver', () => {
} as CreateCollectionInput,
});

await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);
const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
GET_COLLECTION,
{
Expand Down Expand Up @@ -1265,7 +1262,7 @@ describe('Collection resolver', () => {
} as CreateCollectionInput,
});

await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);
const { collection } = await adminClient.query<GetCollection.Query, GetCollection.Variables>(
GET_COLLECTION,
{
Expand Down Expand Up @@ -1321,7 +1318,7 @@ describe('Collection resolver', () => {
],
},
});
await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);
return createCollection;
}

Expand Down Expand Up @@ -1469,7 +1466,7 @@ describe('Collection resolver', () => {
},
});

await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);

const result = await adminClient.query<
GetCollectionProducts.Query,
Expand Down Expand Up @@ -1502,7 +1499,7 @@ describe('Collection resolver', () => {
},
);

await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);

const result = await adminClient.query<
GetCollectionProducts.Query,
Expand Down Expand Up @@ -1536,7 +1533,7 @@ describe('Collection resolver', () => {
},
);

await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);

const result = await adminClient.query<
GetCollectionProducts.Query,
Expand Down Expand Up @@ -1589,7 +1586,7 @@ describe('Collection resolver', () => {
} as CreateCollectionInput,
});

await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);

const result = await adminClient.query<
GetCollectionProducts.Query,
Expand Down Expand Up @@ -1680,7 +1677,7 @@ describe('Collection resolver', () => {
input: [{ id: 'T_1', enabled: false }],
},
);
await awaitRunningJobs(adminClient, 5000, 500);
await awaitRunningJobs(adminClient, 5000);

const { collection } = await shopClient.query<
GetCollectionProducts.Query,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"image-size": "^0.9.1",
"mime-types": "^2.1.27",
"ms": "^2.1.2",
"nanoid": "^2.1.11",
"nanoid": "^3.1.23",
"progress": "^2.0.3",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.6.3",
Expand All @@ -85,7 +85,6 @@
"@types/gulp": "^4.0.7",
"@types/mime-types": "^2.1.0",
"@types/ms": "^0.7.31",
"@types/nanoid": "^2.1.0",
"@types/node": "^14.14.31",
"@types/progress": "^2.0.3",
"@types/prompts": "^2.0.9",
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/common/generate-public-id.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,5 +18,5 @@ import generate = require('nanoid/generate');
* reach a probability of 1% that a collision would occur.
*/
export function generatePublicId(): string {
return generate('123456789ABCDEFGHJKLMNPQRSTUVWXYZ', 16);
return nanoid();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LanguageCode } from '@vendure/common/lib/generated-types';
import nanoid from 'nanoid';
import { customAlphabet } from 'nanoid';

import { UserInputError } from '../../common/error/errors';
import { ProductVariant } from '../../entity/product-variant/product-variant.entity';
Expand Down Expand Up @@ -90,7 +90,8 @@ export const variantNameCollectionFilter = new CollectionFilter({
description: [{ languageCode: LanguageCode.en, value: 'Filter by ProductVariant name' }],
apply: (qb, args) => {
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(
ja => ja.entityOrProperty === 'productVariant.translations',
);
Expand Down
17 changes: 5 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4005,13 +4005,6 @@
dependencies:
"@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/[email protected]", "@types/node-fetch@^2.5.10":
version "2.5.10"
resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.10.tgz#9b4d4a0425562f9fcea70b12cb3fcdd946ca8132"
Expand Down Expand Up @@ -13481,16 +13474,16 @@ nan@^2.12.1:
resolved "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
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:
version "3.1.20"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz#badc263c6b1dcf14b71efaa85f6ab4c1d6cfc788"
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:
version "1.2.13"
resolved "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
Expand Down

0 comments on commit ac76e2c

Please sign in to comment.