|
@@ -18,6 +18,7 @@ import { initialData } from '../../../e2e-common/e2e-initial-data';
|
|
|
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
|
|
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
|
|
|
import {
|
|
import {
|
|
|
AssignProductsToChannel,
|
|
AssignProductsToChannel,
|
|
|
|
|
+ AssignProductVariantsToChannel,
|
|
|
ChannelFragment,
|
|
ChannelFragment,
|
|
|
CreateChannel,
|
|
CreateChannel,
|
|
|
CreateCollection,
|
|
CreateCollection,
|
|
@@ -28,6 +29,7 @@ import {
|
|
|
DeleteProductVariant,
|
|
DeleteProductVariant,
|
|
|
LanguageCode,
|
|
LanguageCode,
|
|
|
RemoveProductsFromChannel,
|
|
RemoveProductsFromChannel,
|
|
|
|
|
+ RemoveProductVariantsFromChannel,
|
|
|
SearchFacetValues,
|
|
SearchFacetValues,
|
|
|
SearchGetPrices,
|
|
SearchGetPrices,
|
|
|
SearchInput,
|
|
SearchInput,
|
|
@@ -39,6 +41,7 @@ import {
|
|
|
} from '../../core/e2e/graphql/generated-e2e-admin-types';
|
|
} from '../../core/e2e/graphql/generated-e2e-admin-types';
|
|
|
import { LogicalOperator, SearchProductsShop } from '../../core/e2e/graphql/generated-e2e-shop-types';
|
|
import { LogicalOperator, SearchProductsShop } from '../../core/e2e/graphql/generated-e2e-shop-types';
|
|
|
import {
|
|
import {
|
|
|
|
|
+ ASSIGN_PRODUCTVARIANT_TO_CHANNEL,
|
|
|
ASSIGN_PRODUCT_TO_CHANNEL,
|
|
ASSIGN_PRODUCT_TO_CHANNEL,
|
|
|
CREATE_CHANNEL,
|
|
CREATE_CHANNEL,
|
|
|
CREATE_COLLECTION,
|
|
CREATE_COLLECTION,
|
|
@@ -46,6 +49,7 @@ import {
|
|
|
DELETE_ASSET,
|
|
DELETE_ASSET,
|
|
|
DELETE_PRODUCT,
|
|
DELETE_PRODUCT,
|
|
|
DELETE_PRODUCT_VARIANT,
|
|
DELETE_PRODUCT_VARIANT,
|
|
|
|
|
+ REMOVE_PRODUCTVARIANT_FROM_CHANNEL,
|
|
|
REMOVE_PRODUCT_FROM_CHANNEL,
|
|
REMOVE_PRODUCT_FROM_CHANNEL,
|
|
|
UPDATE_ASSET,
|
|
UPDATE_ASSET,
|
|
|
UPDATE_COLLECTION,
|
|
UPDATE_COLLECTION,
|
|
@@ -58,8 +62,19 @@ import { awaitRunningJobs } from '../../core/e2e/utils/await-running-jobs';
|
|
|
import { loggerCtx } from '../src/constants';
|
|
import { loggerCtx } from '../src/constants';
|
|
|
import { ElasticsearchPlugin } from '../src/plugin';
|
|
import { ElasticsearchPlugin } from '../src/plugin';
|
|
|
|
|
|
|
|
-// tslint:disable-next-line:no-var-requires
|
|
|
|
|
-const { elasticsearchHost, elasticsearchPort } = require('./constants');
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ doAdminSearchQuery,
|
|
|
|
|
+ dropElasticIndices,
|
|
|
|
|
+ testGroupByProduct,
|
|
|
|
|
+ testMatchCollectionId,
|
|
|
|
|
+ testMatchCollectionSlug,
|
|
|
|
|
+ testMatchFacetIdsAnd,
|
|
|
|
|
+ testMatchFacetIdsOr,
|
|
|
|
|
+ testMatchSearchTerm,
|
|
|
|
|
+ testNoGrouping,
|
|
|
|
|
+ testPriceRanges,
|
|
|
|
|
+ testSinglePrices,
|
|
|
|
|
+} from './e2e-helpers';
|
|
|
import {
|
|
import {
|
|
|
GetJobInfo,
|
|
GetJobInfo,
|
|
|
JobState,
|
|
JobState,
|
|
@@ -67,6 +82,9 @@ import {
|
|
|
SearchProductsAdmin,
|
|
SearchProductsAdmin,
|
|
|
} from './graphql/generated-e2e-elasticsearch-plugin-types';
|
|
} from './graphql/generated-e2e-elasticsearch-plugin-types';
|
|
|
|
|
|
|
|
|
|
+// tslint:disable-next-line:no-var-requires
|
|
|
|
|
+const { elasticsearchHost, elasticsearchPort } = require('./constants');
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* The Elasticsearch tests sometimes take a long time in CI due to limited resources.
|
|
* The Elasticsearch tests sometimes take a long time in CI due to limited resources.
|
|
|
* We increase the timeout to 30 seconds to prevent failure due to timeouts.
|
|
* We increase the timeout to 30 seconds to prevent failure due to timeouts.
|
|
@@ -75,6 +93,8 @@ if (process.env.CI) {
|
|
|
jest.setTimeout(10 * 3000);
|
|
jest.setTimeout(10 * 3000);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const INDEX_PREFIX = 'e2e-tests';
|
|
|
|
|
+
|
|
|
describe('Elasticsearch plugin', () => {
|
|
describe('Elasticsearch plugin', () => {
|
|
|
const { server, adminClient, shopClient } = createTestEnvironment(
|
|
const { server, adminClient, shopClient } = createTestEnvironment(
|
|
|
mergeConfig(testConfig, {
|
|
mergeConfig(testConfig, {
|
|
@@ -89,7 +109,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
logger: new DefaultLogger({ level: LogLevel.Info }),
|
|
logger: new DefaultLogger({ level: LogLevel.Info }),
|
|
|
plugins: [
|
|
plugins: [
|
|
|
ElasticsearchPlugin.init({
|
|
ElasticsearchPlugin.init({
|
|
|
- indexPrefix: 'e2e-tests',
|
|
|
|
|
|
|
+ indexPrefix: INDEX_PREFIX,
|
|
|
port: elasticsearchPort,
|
|
port: elasticsearchPort,
|
|
|
host: elasticsearchHost,
|
|
host: elasticsearchHost,
|
|
|
}),
|
|
}),
|
|
@@ -99,6 +119,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
beforeAll(async () => {
|
|
|
|
|
+ await dropElasticIndices(INDEX_PREFIX);
|
|
|
await server.init({
|
|
await server.init({
|
|
|
initialData,
|
|
initialData,
|
|
|
productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
|
|
productsCsvPath: path.join(__dirname, 'fixtures/e2e-products-full.csv'),
|
|
@@ -113,191 +134,6 @@ describe('Elasticsearch plugin', () => {
|
|
|
await server.destroy();
|
|
await server.destroy();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- function doAdminSearchQuery(input: SearchInput) {
|
|
|
|
|
- return adminClient.query<SearchProductsAdmin.Query, SearchProductsAdmin.Variables>(SEARCH_PRODUCTS, {
|
|
|
|
|
- input,
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testGroupByProduct(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
|
|
- SEARCH_PRODUCTS_SHOP,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- groupByProduct: true,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.totalItems).toBe(20);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testNoGrouping(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
|
|
- SEARCH_PRODUCTS_SHOP,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- groupByProduct: false,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.totalItems).toBe(34);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testMatchSearchTerm(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
|
|
- SEARCH_PRODUCTS_SHOP,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- term: 'camera',
|
|
|
|
|
- groupByProduct: true,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
|
|
- 'Instant Camera',
|
|
|
|
|
- 'Camera Lens',
|
|
|
|
|
- 'SLR Camera',
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testMatchFacetIdsAnd(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
|
|
- SEARCH_PRODUCTS_SHOP,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- facetValueIds: ['T_1', 'T_2'],
|
|
|
|
|
- facetValueOperator: LogicalOperator.AND,
|
|
|
|
|
- groupByProduct: true,
|
|
|
|
|
- sort: {
|
|
|
|
|
- name: SortOrder.ASC,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
|
|
- 'Clacky Keyboard',
|
|
|
|
|
- 'Curvy Monitor',
|
|
|
|
|
- 'Gaming PC',
|
|
|
|
|
- 'Hard Drive',
|
|
|
|
|
- 'Laptop',
|
|
|
|
|
- 'USB Cable',
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testMatchFacetIdsOr(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
|
|
- SEARCH_PRODUCTS_SHOP,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- facetValueIds: ['T_1', 'T_5'],
|
|
|
|
|
- facetValueOperator: LogicalOperator.OR,
|
|
|
|
|
- groupByProduct: true,
|
|
|
|
|
- sort: {
|
|
|
|
|
- name: SortOrder.ASC,
|
|
|
|
|
- },
|
|
|
|
|
- take: 20,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
|
|
- 'Bonsai Tree',
|
|
|
|
|
- 'Camera Lens',
|
|
|
|
|
- 'Clacky Keyboard',
|
|
|
|
|
- 'Curvy Monitor',
|
|
|
|
|
- 'Gaming PC',
|
|
|
|
|
- 'Hard Drive',
|
|
|
|
|
- 'Instant Camera',
|
|
|
|
|
- 'Laptop',
|
|
|
|
|
- 'Orchid',
|
|
|
|
|
- 'SLR Camera',
|
|
|
|
|
- 'Spiky Cactus',
|
|
|
|
|
- 'Tripod',
|
|
|
|
|
- 'USB Cable',
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testMatchCollectionId(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
|
|
- SEARCH_PRODUCTS_SHOP,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- collectionId: 'T_2',
|
|
|
|
|
- groupByProduct: true,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
|
|
- 'Spiky Cactus',
|
|
|
|
|
- 'Orchid',
|
|
|
|
|
- 'Bonsai Tree',
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testMatchCollectionSlug(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
|
|
- SEARCH_PRODUCTS_SHOP,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- collectionSlug: 'plants',
|
|
|
|
|
- groupByProduct: true,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
|
|
- 'Spiky Cactus',
|
|
|
|
|
- 'Orchid',
|
|
|
|
|
- 'Bonsai Tree',
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testSinglePrices(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchGetPrices.Query, SearchGetPrices.Variables>(
|
|
|
|
|
- SEARCH_GET_PRICES,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- groupByProduct: false,
|
|
|
|
|
- take: 3,
|
|
|
|
|
- sort: {
|
|
|
|
|
- price: SortOrder.ASC,
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.items).toEqual([
|
|
|
|
|
- {
|
|
|
|
|
- price: { value: 799 },
|
|
|
|
|
- priceWithTax: { value: 959 },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- price: { value: 1498 },
|
|
|
|
|
- priceWithTax: { value: 1798 },
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- price: { value: 1550 },
|
|
|
|
|
- priceWithTax: { value: 1860 },
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function testPriceRanges(client: SimpleGraphQLClient) {
|
|
|
|
|
- const result = await client.query<SearchGetPrices.Query, SearchGetPrices.Variables>(
|
|
|
|
|
- SEARCH_GET_PRICES,
|
|
|
|
|
- {
|
|
|
|
|
- input: {
|
|
|
|
|
- groupByProduct: true,
|
|
|
|
|
- take: 3,
|
|
|
|
|
- term: 'laptop',
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- );
|
|
|
|
|
- expect(result.search.items).toEqual([
|
|
|
|
|
- {
|
|
|
|
|
- price: { min: 129900, max: 229900 },
|
|
|
|
|
- priceWithTax: { min: 155880, max: 275880 },
|
|
|
|
|
- },
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
describe('shop api', () => {
|
|
describe('shop api', () => {
|
|
|
it('group by product', () => testGroupByProduct(shopClient));
|
|
it('group by product', () => testGroupByProduct(shopClient));
|
|
|
|
|
|
|
@@ -474,7 +310,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
describe('updating the index', () => {
|
|
describe('updating the index', () => {
|
|
|
it('updates index when ProductVariants are changed', async () => {
|
|
it('updates index when ProductVariants are changed', async () => {
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const { search } = await doAdminSearchQuery({ term: 'drive', groupByProduct: false });
|
|
|
|
|
|
|
+ const { search } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ term: 'drive',
|
|
|
|
|
+ groupByProduct: false,
|
|
|
|
|
+ });
|
|
|
expect(search.items.map(i => i.sku)).toEqual([
|
|
expect(search.items.map(i => i.sku)).toEqual([
|
|
|
'IHD455T1',
|
|
'IHD455T1',
|
|
|
'IHD455T2',
|
|
'IHD455T2',
|
|
@@ -494,7 +333,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const { search: search2 } = await doAdminSearchQuery({
|
|
|
|
|
|
|
+ const { search: search2 } = await doAdminSearchQuery(adminClient, {
|
|
|
term: 'drive',
|
|
term: 'drive',
|
|
|
groupByProduct: false,
|
|
groupByProduct: false,
|
|
|
});
|
|
});
|
|
@@ -510,7 +349,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
|
|
|
|
|
it('updates index when ProductVariants are deleted', async () => {
|
|
it('updates index when ProductVariants are deleted', async () => {
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const { search } = await doAdminSearchQuery({ term: 'drive', groupByProduct: false });
|
|
|
|
|
|
|
+ const { search } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ term: 'drive',
|
|
|
|
|
+ groupByProduct: false,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
await adminClient.query<DeleteProductVariant.Mutation, DeleteProductVariant.Variables>(
|
|
await adminClient.query<DeleteProductVariant.Mutation, DeleteProductVariant.Variables>(
|
|
|
DELETE_PRODUCT_VARIANT,
|
|
DELETE_PRODUCT_VARIANT,
|
|
@@ -520,7 +362,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const { search: search2 } = await doAdminSearchQuery({
|
|
|
|
|
|
|
+ const { search: search2 } = await doAdminSearchQuery(adminClient, {
|
|
|
term: 'drive',
|
|
term: 'drive',
|
|
|
groupByProduct: false,
|
|
groupByProduct: false,
|
|
|
});
|
|
});
|
|
@@ -541,7 +383,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const result = await doAdminSearchQuery({ facetValueIds: ['T_2'], groupByProduct: true });
|
|
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ facetValueIds: ['T_2'],
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ });
|
|
|
expect(result.search.items.map(i => i.productName).sort()).toEqual([
|
|
expect(result.search.items.map(i => i.productName).sort()).toEqual([
|
|
|
'Clacky Keyboard',
|
|
'Clacky Keyboard',
|
|
|
'Curvy Monitor',
|
|
'Curvy Monitor',
|
|
@@ -552,7 +397,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('updates index when a Product is deleted', async () => {
|
|
it('updates index when a Product is deleted', async () => {
|
|
|
- const { search } = await doAdminSearchQuery({ facetValueIds: ['T_2'], groupByProduct: true });
|
|
|
|
|
|
|
+ const { search } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ facetValueIds: ['T_2'],
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ });
|
|
|
expect(search.items.map(i => i.productId).sort()).toEqual([
|
|
expect(search.items.map(i => i.productId).sort()).toEqual([
|
|
|
'T_2',
|
|
'T_2',
|
|
|
'T_3',
|
|
'T_3',
|
|
@@ -564,7 +412,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
id: 'T_5',
|
|
id: 'T_5',
|
|
|
});
|
|
});
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const { search: search2 } = await doAdminSearchQuery({
|
|
|
|
|
|
|
+ const { search: search2 } = await doAdminSearchQuery(adminClient, {
|
|
|
facetValueIds: ['T_2'],
|
|
facetValueIds: ['T_2'],
|
|
|
groupByProduct: true,
|
|
groupByProduct: true,
|
|
|
});
|
|
});
|
|
@@ -598,7 +446,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
// add an additional check for the collection filters to update
|
|
// add an additional check for the collection filters to update
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const result1 = await doAdminSearchQuery({ collectionId: 'T_2', groupByProduct: true });
|
|
|
|
|
|
|
+ const result1 = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ collectionId: 'T_2',
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
expect(result1.search.items.map(i => i.productName)).toEqual([
|
|
expect(result1.search.items.map(i => i.productName)).toEqual([
|
|
|
'Road Bike',
|
|
'Road Bike',
|
|
@@ -610,7 +461,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
'Running Shoe',
|
|
'Running Shoe',
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
- const result2 = await doAdminSearchQuery({ collectionSlug: 'plants', groupByProduct: true });
|
|
|
|
|
|
|
+ const result2 = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ collectionSlug: 'plants',
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
expect(result2.search.items.map(i => i.productName)).toEqual([
|
|
expect(result2.search.items.map(i => i.productName)).toEqual([
|
|
|
'Road Bike',
|
|
'Road Bike',
|
|
@@ -657,7 +511,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
// add an additional check for the collection filters to update
|
|
// add an additional check for the collection filters to update
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const result = await doAdminSearchQuery({
|
|
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, {
|
|
|
collectionId: createCollection.id,
|
|
collectionId: createCollection.id,
|
|
|
groupByProduct: true,
|
|
groupByProduct: true,
|
|
|
});
|
|
});
|
|
@@ -698,7 +552,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
|
|
|
|
|
describe('asset changes', () => {
|
|
describe('asset changes', () => {
|
|
|
function searchForLaptop() {
|
|
function searchForLaptop() {
|
|
|
- return doAdminSearchQuery({
|
|
|
|
|
|
|
+ return doAdminSearchQuery(adminClient, {
|
|
|
term: 'laptop',
|
|
term: 'laptop',
|
|
|
groupByProduct: true,
|
|
groupByProduct: true,
|
|
|
take: 1,
|
|
take: 1,
|
|
@@ -752,7 +606,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('does not include deleted ProductVariants in index', async () => {
|
|
it('does not include deleted ProductVariants in index', async () => {
|
|
|
- const { search: s1 } = await doAdminSearchQuery({
|
|
|
|
|
|
|
+ const { search: s1 } = await doAdminSearchQuery(adminClient, {
|
|
|
term: 'hard drive',
|
|
term: 'hard drive',
|
|
|
groupByProduct: false,
|
|
groupByProduct: false,
|
|
|
});
|
|
});
|
|
@@ -777,7 +631,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('returns disabled field when not grouped', async () => {
|
|
it('returns disabled field when not grouped', async () => {
|
|
|
- const result = await doAdminSearchQuery({ groupByProduct: false, term: 'laptop' });
|
|
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: false,
|
|
|
|
|
+ term: 'laptop',
|
|
|
|
|
+ });
|
|
|
expect(result.search.items.map(pick(['productVariantId', 'enabled']))).toEqual([
|
|
expect(result.search.items.map(pick(['productVariantId', 'enabled']))).toEqual([
|
|
|
{ productVariantId: 'T_1', enabled: true },
|
|
{ productVariantId: 'T_1', enabled: true },
|
|
|
{ productVariantId: 'T_2', enabled: true },
|
|
{ productVariantId: 'T_2', enabled: true },
|
|
@@ -797,7 +654,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const result = await doAdminSearchQuery({ groupByProduct: true, term: 'laptop' });
|
|
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ term: 'laptop',
|
|
|
|
|
+ });
|
|
|
expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
{ productId: 'T_1', enabled: true },
|
|
{ productId: 'T_1', enabled: true },
|
|
|
]);
|
|
]);
|
|
@@ -811,7 +671,11 @@ describe('Elasticsearch plugin', () => {
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const result = await doAdminSearchQuery({ groupByProduct: true, take: 3, term: 'laptop' });
|
|
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ take: 3,
|
|
|
|
|
+ term: 'laptop',
|
|
|
|
|
+ });
|
|
|
expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
{ productId: 'T_1', enabled: false },
|
|
{ productId: 'T_1', enabled: false },
|
|
|
]);
|
|
]);
|
|
@@ -825,7 +689,10 @@ describe('Elasticsearch plugin', () => {
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const result = await doAdminSearchQuery({ groupByProduct: true, term: 'gaming' });
|
|
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ term: 'gaming',
|
|
|
|
|
+ });
|
|
|
expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
{ productId: 'T_3', enabled: false },
|
|
{ productId: 'T_3', enabled: false },
|
|
|
]);
|
|
]);
|
|
@@ -836,7 +703,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
await adminClient.query<Reindex.Mutation>(REINDEX);
|
|
await adminClient.query<Reindex.Mutation>(REINDEX);
|
|
|
|
|
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
- const result = await doAdminSearchQuery({ groupByProduct: true, take: 3 });
|
|
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, { groupByProduct: true, take: 3 });
|
|
|
expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
{ productId: 'T_1', enabled: false },
|
|
{ productId: 'T_1', enabled: false },
|
|
|
{ productId: 'T_2', enabled: true },
|
|
{ productId: 'T_2', enabled: true },
|
|
@@ -865,6 +732,21 @@ describe('Elasticsearch plugin', () => {
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
secondChannel = createChannel as ChannelFragment;
|
|
secondChannel = createChannel as ChannelFragment;
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+ await adminClient.query<Reindex.Mutation>(REINDEX);
|
|
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('new channel is initially empty', async () => {
|
|
|
|
|
+ const { search: searchGrouped } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ const { search: searchUngrouped } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ expect(searchGrouped.totalItems).toEqual(0);
|
|
|
|
|
+ expect(searchUngrouped.totalItems).toEqual(0);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('adding product to channel', async () => {
|
|
it('adding product to channel', async () => {
|
|
@@ -878,7 +760,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
|
|
|
|
|
adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
- const { search } = await doAdminSearchQuery({ groupByProduct: true });
|
|
|
|
|
|
|
+ const { search } = await doAdminSearchQuery(adminClient, { groupByProduct: true });
|
|
|
expect(search.items.map(i => i.productId).sort()).toEqual(['T_1', 'T_2']);
|
|
expect(search.items.map(i => i.productId).sort()).toEqual(['T_1', 'T_2']);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -896,7 +778,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
await awaitRunningJobs(adminClient);
|
|
await awaitRunningJobs(adminClient);
|
|
|
|
|
|
|
|
adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
- const { search } = await doAdminSearchQuery({ groupByProduct: true });
|
|
|
|
|
|
|
+ const { search } = await doAdminSearchQuery(adminClient, { groupByProduct: true });
|
|
|
expect(search.items.map(i => i.productId)).toEqual(['T_1']);
|
|
expect(search.items.map(i => i.productId)).toEqual(['T_1']);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -912,9 +794,67 @@ describe('Elasticsearch plugin', () => {
|
|
|
);
|
|
);
|
|
|
expect(job!.state).toBe(JobState.COMPLETED);
|
|
expect(job!.state).toBe(JobState.COMPLETED);
|
|
|
|
|
|
|
|
- const { search } = await doAdminSearchQuery({ groupByProduct: true });
|
|
|
|
|
|
|
+ const { search } = await doAdminSearchQuery(adminClient, { groupByProduct: true });
|
|
|
expect(search.items.map(i => i.productId).sort()).toEqual(['T_1']);
|
|
expect(search.items.map(i => i.productId).sort()).toEqual(['T_1']);
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ it('adding product variant to channel', async () => {
|
|
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
|
|
+ await adminClient.query<
|
|
|
|
|
+ AssignProductVariantsToChannel.Mutation,
|
|
|
|
|
+ AssignProductVariantsToChannel.Variables
|
|
|
|
|
+ >(ASSIGN_PRODUCTVARIANT_TO_CHANNEL, {
|
|
|
|
|
+ input: { channelId: secondChannel.id, productVariantIds: ['T_10', 'T_15'] },
|
|
|
|
|
+ });
|
|
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+
|
|
|
|
|
+ const { search: searchGrouped } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ expect(searchGrouped.items.map(i => i.productId).sort()).toEqual(['T_1', 'T_3', 'T_4']);
|
|
|
|
|
+
|
|
|
|
|
+ const { search: searchUngrouped } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ expect(searchUngrouped.items.map(i => i.productVariantId).sort()).toEqual([
|
|
|
|
|
+ 'T_1',
|
|
|
|
|
+ 'T_10',
|
|
|
|
|
+ 'T_15',
|
|
|
|
|
+ 'T_2',
|
|
|
|
|
+ 'T_3',
|
|
|
|
|
+ 'T_4',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('removing product variant from channel', async () => {
|
|
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
|
|
+ await adminClient.query<
|
|
|
|
|
+ RemoveProductVariantsFromChannel.Mutation,
|
|
|
|
|
+ RemoveProductVariantsFromChannel.Variables
|
|
|
|
|
+ >(REMOVE_PRODUCTVARIANT_FROM_CHANNEL, {
|
|
|
|
|
+ input: { channelId: secondChannel.id, productVariantIds: ['T_1', 'T_15'] },
|
|
|
|
|
+ });
|
|
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
|
|
+
|
|
|
|
|
+ adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
|
|
+
|
|
|
|
|
+ const { search: searchGrouped } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ });
|
|
|
|
|
+ expect(searchGrouped.items.map(i => i.productId).sort()).toEqual(['T_1', 'T_3']);
|
|
|
|
|
+
|
|
|
|
|
+ const { search: searchUngrouped } = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: false,
|
|
|
|
|
+ });
|
|
|
|
|
+ expect(searchUngrouped.items.map(i => i.productVariantId).sort()).toEqual([
|
|
|
|
|
+ 'T_10',
|
|
|
|
|
+ 'T_2',
|
|
|
|
|
+ 'T_3',
|
|
|
|
|
+ 'T_4',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('multiple language handling', () => {
|
|
describe('multiple language handling', () => {
|
|
@@ -935,6 +875,7 @@ describe('Elasticsearch plugin', () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
beforeAll(async () => {
|
|
|
|
|
+ adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
const { updateProduct } = await adminClient.query<
|
|
const { updateProduct } = await adminClient.query<
|
|
|
UpdateProduct.Mutation,
|
|
UpdateProduct.Mutation,
|
|
|
UpdateProduct.Variables
|
|
UpdateProduct.Variables
|