|
@@ -1,16 +1,14 @@
|
|
|
/* tslint:disable:no-non-null-assertion no-console */
|
|
/* tslint:disable:no-non-null-assertion no-console */
|
|
|
-import { Client } from '@elastic/elasticsearch';
|
|
|
|
|
import { SortOrder } from '@vendure/common/lib/generated-types';
|
|
import { SortOrder } from '@vendure/common/lib/generated-types';
|
|
|
import { pick } from '@vendure/common/lib/pick';
|
|
import { pick } from '@vendure/common/lib/pick';
|
|
|
import {
|
|
import {
|
|
|
DefaultJobQueuePlugin,
|
|
DefaultJobQueuePlugin,
|
|
|
DefaultLogger,
|
|
DefaultLogger,
|
|
|
facetValueCollectionFilter,
|
|
facetValueCollectionFilter,
|
|
|
- Logger,
|
|
|
|
|
LogLevel,
|
|
LogLevel,
|
|
|
mergeConfig,
|
|
mergeConfig,
|
|
|
} from '@vendure/core';
|
|
} from '@vendure/core';
|
|
|
-import { createTestEnvironment, E2E_DEFAULT_CHANNEL_TOKEN, SimpleGraphQLClient } from '@vendure/testing';
|
|
|
|
|
|
|
+import { createTestEnvironment, E2E_DEFAULT_CHANNEL_TOKEN } from '@vendure/testing';
|
|
|
import gql from 'graphql-tag';
|
|
import gql from 'graphql-tag';
|
|
|
import path from 'path';
|
|
import path from 'path';
|
|
|
|
|
|
|
@@ -23,6 +21,8 @@ import {
|
|
|
CreateChannel,
|
|
CreateChannel,
|
|
|
CreateCollection,
|
|
CreateCollection,
|
|
|
CreateFacet,
|
|
CreateFacet,
|
|
|
|
|
+ CreateProduct,
|
|
|
|
|
+ CreateProductVariants,
|
|
|
CurrencyCode,
|
|
CurrencyCode,
|
|
|
DeleteAsset,
|
|
DeleteAsset,
|
|
|
DeleteProduct,
|
|
DeleteProduct,
|
|
@@ -39,13 +39,15 @@ import {
|
|
|
UpdateProductVariants,
|
|
UpdateProductVariants,
|
|
|
UpdateTaxRate,
|
|
UpdateTaxRate,
|
|
|
} 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 { SearchProductsShop } from '../../core/e2e/graphql/generated-e2e-shop-types';
|
|
|
import {
|
|
import {
|
|
|
ASSIGN_PRODUCTVARIANT_TO_CHANNEL,
|
|
ASSIGN_PRODUCTVARIANT_TO_CHANNEL,
|
|
|
ASSIGN_PRODUCT_TO_CHANNEL,
|
|
ASSIGN_PRODUCT_TO_CHANNEL,
|
|
|
CREATE_CHANNEL,
|
|
CREATE_CHANNEL,
|
|
|
CREATE_COLLECTION,
|
|
CREATE_COLLECTION,
|
|
|
CREATE_FACET,
|
|
CREATE_FACET,
|
|
|
|
|
+ CREATE_PRODUCT,
|
|
|
|
|
+ CREATE_PRODUCT_VARIANTS,
|
|
|
DELETE_ASSET,
|
|
DELETE_ASSET,
|
|
|
DELETE_PRODUCT,
|
|
DELETE_PRODUCT,
|
|
|
DELETE_PRODUCT_VARIANT,
|
|
DELETE_PRODUCT_VARIANT,
|
|
@@ -59,7 +61,6 @@ import {
|
|
|
} from '../../core/e2e/graphql/shared-definitions';
|
|
} from '../../core/e2e/graphql/shared-definitions';
|
|
|
import { SEARCH_PRODUCTS_SHOP } from '../../core/e2e/graphql/shop-definitions';
|
|
import { SEARCH_PRODUCTS_SHOP } from '../../core/e2e/graphql/shop-definitions';
|
|
|
import { awaitRunningJobs } from '../../core/e2e/utils/await-running-jobs';
|
|
import { awaitRunningJobs } from '../../core/e2e/utils/await-running-jobs';
|
|
|
-import { loggerCtx } from '../src/constants';
|
|
|
|
|
import { ElasticsearchPlugin } from '../src/plugin';
|
|
import { ElasticsearchPlugin } from '../src/plugin';
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
@@ -713,6 +714,86 @@ describe('Elasticsearch plugin', () => {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ // https://github.com/vendure-ecommerce/vendure/issues/609
|
|
|
|
|
+ describe('Synthetic index items', () => {
|
|
|
|
|
+ let createdProductId: string;
|
|
|
|
|
+
|
|
|
|
|
+ it('creates synthetic index item for Product with no variants', async () => {
|
|
|
|
|
+ const { createProduct } = await adminClient.query<
|
|
|
|
|
+ CreateProduct.Mutation,
|
|
|
|
|
+ CreateProduct.Variables
|
|
|
|
|
+ >(CREATE_PRODUCT, {
|
|
|
|
|
+ input: {
|
|
|
|
|
+ facetValueIds: ['T_1'],
|
|
|
|
|
+ translations: [
|
|
|
|
|
+ {
|
|
|
|
|
+ languageCode: LanguageCode.en,
|
|
|
|
|
+ name: 'Strawberry cheesecake',
|
|
|
|
|
+ slug: 'strawberry-cheesecake',
|
|
|
|
|
+ description: 'A yummy dessert',
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ term: 'strawberry',
|
|
|
|
|
+ });
|
|
|
|
|
+ expect(
|
|
|
|
|
+ result.search.items.map(
|
|
|
|
|
+ pick([
|
|
|
|
|
+ 'productId',
|
|
|
|
|
+ 'enabled',
|
|
|
|
|
+ 'productName',
|
|
|
|
|
+ 'productVariantName',
|
|
|
|
|
+ 'slug',
|
|
|
|
|
+ 'description',
|
|
|
|
|
+ ]),
|
|
|
|
|
+ ),
|
|
|
|
|
+ ).toEqual([
|
|
|
|
|
+ {
|
|
|
|
|
+ productId: createProduct.id,
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ productName: 'Strawberry cheesecake',
|
|
|
|
|
+ productVariantName: 'Strawberry cheesecake',
|
|
|
|
|
+ slug: 'strawberry-cheesecake',
|
|
|
|
|
+ description: 'A yummy dessert',
|
|
|
|
|
+ },
|
|
|
|
|
+ ]);
|
|
|
|
|
+ createdProductId = createProduct.id;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('removes synthetic index item once a variant is created', async () => {
|
|
|
|
|
+ const { createProductVariants } = await adminClient.query<
|
|
|
|
|
+ CreateProductVariants.Mutation,
|
|
|
|
|
+ CreateProductVariants.Variables
|
|
|
|
|
+ >(CREATE_PRODUCT_VARIANTS, {
|
|
|
|
|
+ input: [
|
|
|
|
|
+ {
|
|
|
|
|
+ productId: createdProductId,
|
|
|
|
|
+ sku: 'SC01',
|
|
|
|
|
+ price: 1399,
|
|
|
|
|
+ translations: [
|
|
|
|
|
+ { languageCode: LanguageCode.en, name: 'Strawberry Cheesecake Pie' },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
|
|
+
|
|
|
|
|
+ const result = await doAdminSearchQuery(adminClient, {
|
|
|
|
|
+ groupByProduct: true,
|
|
|
|
|
+ term: 'strawberry',
|
|
|
|
|
+ });
|
|
|
|
|
+ expect(result.search.items.map(pick(['productVariantName']))).toEqual([
|
|
|
|
|
+ { productVariantName: 'Strawberry Cheesecake Pie' },
|
|
|
|
|
+ ]);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
describe('channel handling', () => {
|
|
describe('channel handling', () => {
|
|
|
const SECOND_CHANNEL_TOKEN = 'second-channel-token';
|
|
const SECOND_CHANNEL_TOKEN = 'second-channel-token';
|
|
|
let secondChannel: ChannelFragment;
|
|
let secondChannel: ChannelFragment;
|