|
|
@@ -1,6 +1,5 @@
|
|
|
import { pick } from '@vendure/common/lib/pick';
|
|
|
-import { mergeConfig } from '@vendure/core';
|
|
|
-import { DefaultSearchPlugin } from '@vendure/core';
|
|
|
+import { DefaultSearchPlugin, mergeConfig } from '@vendure/core';
|
|
|
import { facetValueCollectionFilter } from '@vendure/core/dist/config/collection/default-collection-filters';
|
|
|
import { createTestEnvironment, SimpleGraphQLClient } from '@vendure/testing';
|
|
|
import gql from 'graphql-tag';
|
|
|
@@ -11,6 +10,8 @@ import { initialData } from './fixtures/e2e-initial-data';
|
|
|
import {
|
|
|
CreateCollection,
|
|
|
CreateFacet,
|
|
|
+ DeleteProduct,
|
|
|
+ DeleteProductVariant,
|
|
|
LanguageCode,
|
|
|
SearchFacetValues,
|
|
|
SearchGetPrices,
|
|
|
@@ -24,6 +25,8 @@ import { SearchProductsShop } from './graphql/generated-e2e-shop-types';
|
|
|
import {
|
|
|
CREATE_COLLECTION,
|
|
|
CREATE_FACET,
|
|
|
+ DELETE_PRODUCT,
|
|
|
+ DELETE_PRODUCT_VARIANT,
|
|
|
UPDATE_COLLECTION,
|
|
|
UPDATE_PRODUCT,
|
|
|
UPDATE_PRODUCT_VARIANTS,
|
|
|
@@ -51,6 +54,12 @@ describe('Default search plugin', () => {
|
|
|
await server.destroy();
|
|
|
});
|
|
|
|
|
|
+ function doAdminSearchQuery(input: SearchInput) {
|
|
|
+ return adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(SEARCH_PRODUCTS, {
|
|
|
+ input,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
async function testGroupByProduct(client: SimpleGraphQLClient) {
|
|
|
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
SEARCH_PRODUCTS_SHOP,
|
|
|
@@ -344,45 +353,160 @@ describe('Default search plugin', () => {
|
|
|
|
|
|
it('price ranges', () => testPriceRanges(adminClient));
|
|
|
|
|
|
- it('updates index when a Product is changed', async () => {
|
|
|
- await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
- input: {
|
|
|
- id: 'T_1',
|
|
|
- facetValueIds: [],
|
|
|
- },
|
|
|
+ describe('updating the index', () => {
|
|
|
+ it('updates index when ProductVariants are changed', async () => {
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const { search } = await doAdminSearchQuery({ term: 'drive', groupByProduct: false });
|
|
|
+ expect(search.items.map(i => i.sku)).toEqual([
|
|
|
+ 'IHD455T1',
|
|
|
+ 'IHD455T2',
|
|
|
+ 'IHD455T3',
|
|
|
+ 'IHD455T4',
|
|
|
+ 'IHD455T6',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
|
|
|
+ UPDATE_PRODUCT_VARIANTS,
|
|
|
+ {
|
|
|
+ input: search.items.map(i => ({
|
|
|
+ id: i.productVariantId,
|
|
|
+ sku: i.sku + '_updated',
|
|
|
+ })),
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const { search: search2 } = await doAdminSearchQuery({
|
|
|
+ term: 'drive',
|
|
|
+ groupByProduct: false,
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(search2.items.map(i => i.sku)).toEqual([
|
|
|
+ 'IHD455T1_updated',
|
|
|
+ 'IHD455T2_updated',
|
|
|
+ 'IHD455T3_updated',
|
|
|
+ 'IHD455T4_updated',
|
|
|
+ 'IHD455T6_updated',
|
|
|
+ ]);
|
|
|
});
|
|
|
- await awaitRunningJobs(adminClient);
|
|
|
- const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
- SEARCH_PRODUCTS,
|
|
|
- {
|
|
|
+
|
|
|
+ it('updates index when ProductVariants are deleted', async () => {
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const { search } = await doAdminSearchQuery({ term: 'drive', groupByProduct: false });
|
|
|
+
|
|
|
+ await adminClient.query<DeleteProductVariant.Mutation, DeleteProductVariant.Variables>(
|
|
|
+ DELETE_PRODUCT_VARIANT,
|
|
|
+ {
|
|
|
+ id: search.items[0].productVariantId,
|
|
|
+ },
|
|
|
+ );
|
|
|
+
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const { search: search2 } = await doAdminSearchQuery({
|
|
|
+ term: 'drive',
|
|
|
+ groupByProduct: false,
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(search2.items.map(i => i.sku)).toEqual([
|
|
|
+ 'IHD455T2_updated',
|
|
|
+ 'IHD455T3_updated',
|
|
|
+ 'IHD455T4_updated',
|
|
|
+ 'IHD455T6_updated',
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('updates index when a Product is changed', async () => {
|
|
|
+ await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
input: {
|
|
|
- facetValueIds: ['T_2'],
|
|
|
- groupByProduct: true,
|
|
|
+ id: 'T_1',
|
|
|
+ facetValueIds: [],
|
|
|
},
|
|
|
- },
|
|
|
- );
|
|
|
- expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
- 'Curvy Monitor',
|
|
|
- 'Gaming PC',
|
|
|
- 'Hard Drive',
|
|
|
- 'Clacky Keyboard',
|
|
|
- 'USB Cable',
|
|
|
- ]);
|
|
|
- });
|
|
|
+ });
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const result = await doAdminSearchQuery({ facetValueIds: ['T_2'], groupByProduct: true });
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
+ 'Curvy Monitor',
|
|
|
+ 'Gaming PC',
|
|
|
+ 'Hard Drive',
|
|
|
+ 'Clacky Keyboard',
|
|
|
+ 'USB Cable',
|
|
|
+ ]);
|
|
|
+ });
|
|
|
|
|
|
- it('updates index when a Collection is changed', async () => {
|
|
|
- await adminClient.query<UpdateCollection.Mutation, UpdateCollection.Variables>(
|
|
|
- UPDATE_COLLECTION,
|
|
|
- {
|
|
|
+ it('updates index when a Product is deleted', async () => {
|
|
|
+ const { search } = await doAdminSearchQuery({ facetValueIds: ['T_2'], groupByProduct: true });
|
|
|
+ expect(search.items.map(i => i.productId)).toEqual(['T_2', 'T_3', 'T_4', 'T_5', 'T_6']);
|
|
|
+ await adminClient.query<DeleteProduct.Mutation, DeleteProduct.Variables>(DELETE_PRODUCT, {
|
|
|
+ id: 'T_5',
|
|
|
+ });
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const { search: search2 } = await doAdminSearchQuery({
|
|
|
+ facetValueIds: ['T_2'],
|
|
|
+ groupByProduct: true,
|
|
|
+ });
|
|
|
+ expect(search2.items.map(i => i.productId)).toEqual(['T_2', 'T_3', 'T_4', 'T_6']);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('updates index when a Collection is changed', async () => {
|
|
|
+ await adminClient.query<UpdateCollection.Mutation, UpdateCollection.Variables>(
|
|
|
+ UPDATE_COLLECTION,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ id: 'T_2',
|
|
|
+ filters: [
|
|
|
+ {
|
|
|
+ code: facetValueCollectionFilter.code,
|
|
|
+ arguments: [
|
|
|
+ {
|
|
|
+ name: 'facetValueIds',
|
|
|
+ value: `["T_4"]`,
|
|
|
+ type: 'facetValueIds',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'containsAny',
|
|
|
+ value: `false`,
|
|
|
+ type: 'boolean',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const result = await doAdminSearchQuery({ collectionId: 'T_2', groupByProduct: true });
|
|
|
+
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
+ 'Road Bike',
|
|
|
+ 'Skipping Rope',
|
|
|
+ 'Boxing Gloves',
|
|
|
+ 'Tent',
|
|
|
+ 'Cruiser Skateboard',
|
|
|
+ 'Football',
|
|
|
+ 'Running Shoe',
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('updates index when a Collection created', async () => {
|
|
|
+ const { createCollection } = await adminClient.query<
|
|
|
+ CreateCollection.Mutation,
|
|
|
+ CreateCollection.Variables
|
|
|
+ >(CREATE_COLLECTION, {
|
|
|
input: {
|
|
|
- id: 'T_2',
|
|
|
+ translations: [
|
|
|
+ {
|
|
|
+ languageCode: LanguageCode.en,
|
|
|
+ name: 'Photo',
|
|
|
+ description: '',
|
|
|
+ },
|
|
|
+ ],
|
|
|
filters: [
|
|
|
{
|
|
|
code: facetValueCollectionFilter.code,
|
|
|
arguments: [
|
|
|
{
|
|
|
name: 'facetValueIds',
|
|
|
- value: `["T_4"]`,
|
|
|
+ value: `["T_3"]`,
|
|
|
type: 'facetValueIds',
|
|
|
},
|
|
|
{
|
|
|
@@ -394,193 +518,103 @@ describe('Default search plugin', () => {
|
|
|
},
|
|
|
],
|
|
|
},
|
|
|
- },
|
|
|
- );
|
|
|
- await awaitRunningJobs(adminClient);
|
|
|
- const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
- SEARCH_PRODUCTS,
|
|
|
- {
|
|
|
- input: {
|
|
|
- collectionId: 'T_2',
|
|
|
- groupByProduct: true,
|
|
|
- },
|
|
|
- },
|
|
|
- );
|
|
|
- expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
- 'Road Bike',
|
|
|
- 'Skipping Rope',
|
|
|
- 'Boxing Gloves',
|
|
|
- 'Tent',
|
|
|
- 'Cruiser Skateboard',
|
|
|
- 'Football',
|
|
|
- 'Running Shoe',
|
|
|
- ]);
|
|
|
- });
|
|
|
-
|
|
|
- it('updates index when a Collection created', async () => {
|
|
|
- const { createCollection } = await adminClient.query<
|
|
|
- CreateCollection.Mutation,
|
|
|
- CreateCollection.Variables
|
|
|
- >(CREATE_COLLECTION, {
|
|
|
- input: {
|
|
|
- translations: [
|
|
|
- {
|
|
|
- languageCode: LanguageCode.en,
|
|
|
- name: 'Photo',
|
|
|
- description: '',
|
|
|
- },
|
|
|
- ],
|
|
|
- filters: [
|
|
|
- {
|
|
|
- code: facetValueCollectionFilter.code,
|
|
|
- arguments: [
|
|
|
- {
|
|
|
- name: 'facetValueIds',
|
|
|
- value: `["T_3"]`,
|
|
|
- type: 'facetValueIds',
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'containsAny',
|
|
|
- value: `false`,
|
|
|
- type: 'boolean',
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
+ });
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const result = await doAdminSearchQuery({
|
|
|
+ collectionId: createCollection.id,
|
|
|
+ groupByProduct: true,
|
|
|
+ });
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
+ 'Instant Camera',
|
|
|
+ 'Camera Lens',
|
|
|
+ 'Tripod',
|
|
|
+ 'SLR Camera',
|
|
|
+ ]);
|
|
|
});
|
|
|
- await awaitRunningJobs(adminClient);
|
|
|
- const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
- SEARCH_PRODUCTS,
|
|
|
- {
|
|
|
+
|
|
|
+ it('updates index when a taxRate is changed', async () => {
|
|
|
+ await adminClient.query<UpdateTaxRate.Mutation, UpdateTaxRate.Variables>(UPDATE_TAX_RATE, {
|
|
|
input: {
|
|
|
- collectionId: createCollection.id,
|
|
|
- groupByProduct: true,
|
|
|
+ // Default Channel's defaultTaxZone is Europe (id 2) and the id of the standard TaxRate
|
|
|
+ // to Europe is 2.
|
|
|
+ id: 'T_2',
|
|
|
+ value: 50,
|
|
|
},
|
|
|
- },
|
|
|
- );
|
|
|
- expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
- 'Instant Camera',
|
|
|
- 'Camera Lens',
|
|
|
- 'Tripod',
|
|
|
- 'SLR Camera',
|
|
|
- ]);
|
|
|
- });
|
|
|
+ });
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const result = await adminClient.query<SearchGetPrices.Query, SearchGetPrices.Variables>(
|
|
|
+ SEARCH_GET_PRICES,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ groupByProduct: true,
|
|
|
+ term: 'laptop',
|
|
|
+ } as SearchInput,
|
|
|
+ },
|
|
|
+ );
|
|
|
+ expect(result.search.items).toEqual([
|
|
|
+ {
|
|
|
+ price: { min: 129900, max: 229900 },
|
|
|
+ priceWithTax: { min: 194850, max: 344850 },
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+ });
|
|
|
|
|
|
- it('updates index when a taxRate is changed', async () => {
|
|
|
- await adminClient.query<UpdateTaxRate.Mutation, UpdateTaxRate.Variables>(UPDATE_TAX_RATE, {
|
|
|
- input: {
|
|
|
- // Default Channel's defaultTaxZone is Europe (id 2) and the id of the standard TaxRate
|
|
|
- // to Europe is 2.
|
|
|
- id: 'T_2',
|
|
|
- value: 50,
|
|
|
- },
|
|
|
+ it('returns disabled field when not grouped', async () => {
|
|
|
+ const result = await doAdminSearchQuery({ groupByProduct: false, take: 3 });
|
|
|
+ expect(result.search.items.map(pick(['productVariantId', 'enabled']))).toEqual([
|
|
|
+ { productVariantId: 'T_1', enabled: true },
|
|
|
+ { productVariantId: 'T_2', enabled: true },
|
|
|
+ { productVariantId: 'T_3', enabled: false },
|
|
|
+ ]);
|
|
|
});
|
|
|
- await awaitRunningJobs(adminClient);
|
|
|
- const result = await adminClient.query<SearchGetPrices.Query, SearchGetPrices.Variables>(
|
|
|
- SEARCH_GET_PRICES,
|
|
|
- {
|
|
|
- input: {
|
|
|
- groupByProduct: true,
|
|
|
- term: 'laptop',
|
|
|
- } as SearchInput,
|
|
|
- },
|
|
|
- );
|
|
|
- expect(result.search.items).toEqual([
|
|
|
- {
|
|
|
- price: { min: 129900, max: 229900 },
|
|
|
- priceWithTax: { min: 194850, max: 344850 },
|
|
|
- },
|
|
|
- ]);
|
|
|
- });
|
|
|
|
|
|
- it('returns disabled field when not grouped', async () => {
|
|
|
- const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
- SEARCH_PRODUCTS,
|
|
|
- {
|
|
|
- input: {
|
|
|
- groupByProduct: false,
|
|
|
- take: 3,
|
|
|
+ it('when grouped, disabled is false if at least one variant is enabled', async () => {
|
|
|
+ await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
|
|
|
+ UPDATE_PRODUCT_VARIANTS,
|
|
|
+ {
|
|
|
+ input: [{ id: 'T_1', enabled: false }, { id: 'T_2', enabled: false }],
|
|
|
},
|
|
|
- },
|
|
|
- );
|
|
|
- expect(result.search.items.map(pick(['productVariantId', 'enabled']))).toEqual([
|
|
|
- { productVariantId: 'T_1', enabled: true },
|
|
|
- { productVariantId: 'T_2', enabled: true },
|
|
|
- { productVariantId: 'T_3', enabled: false },
|
|
|
- ]);
|
|
|
- });
|
|
|
+ );
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const result = await doAdminSearchQuery({ groupByProduct: true, take: 3 });
|
|
|
+ expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
+ { productId: 'T_1', enabled: true },
|
|
|
+ { productId: 'T_2', enabled: true },
|
|
|
+ { productId: 'T_3', enabled: true },
|
|
|
+ ]);
|
|
|
+ });
|
|
|
|
|
|
- it('when grouped, disabled is false if at least one variant is enabled', async () => {
|
|
|
- await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
|
|
|
- UPDATE_PRODUCT_VARIANTS,
|
|
|
- {
|
|
|
- input: [{ id: 'T_1', enabled: false }, { id: 'T_2', enabled: false }],
|
|
|
- },
|
|
|
- );
|
|
|
- await awaitRunningJobs(adminClient);
|
|
|
- const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
- SEARCH_PRODUCTS,
|
|
|
- {
|
|
|
- input: {
|
|
|
- groupByProduct: true,
|
|
|
- take: 3,
|
|
|
+ it('when grouped, disabled is true if all variants are disabled', async () => {
|
|
|
+ await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
|
|
|
+ UPDATE_PRODUCT_VARIANTS,
|
|
|
+ {
|
|
|
+ input: [{ id: 'T_4', enabled: false }],
|
|
|
},
|
|
|
- },
|
|
|
- );
|
|
|
- expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
- { productId: 'T_1', enabled: true },
|
|
|
- { productId: 'T_2', enabled: true },
|
|
|
- { productId: 'T_3', enabled: true },
|
|
|
- ]);
|
|
|
- });
|
|
|
+ );
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const result = await doAdminSearchQuery({ groupByProduct: true, take: 3 });
|
|
|
+ expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
+ { productId: 'T_1', enabled: false },
|
|
|
+ { productId: 'T_2', enabled: true },
|
|
|
+ { productId: 'T_3', enabled: true },
|
|
|
+ ]);
|
|
|
+ });
|
|
|
|
|
|
- it('when grouped, disabled is true if all variants are disabled', async () => {
|
|
|
- await adminClient.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
|
|
|
- UPDATE_PRODUCT_VARIANTS,
|
|
|
- {
|
|
|
- input: [{ id: 'T_4', enabled: false }],
|
|
|
- },
|
|
|
- );
|
|
|
- await awaitRunningJobs(adminClient);
|
|
|
- const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
- SEARCH_PRODUCTS,
|
|
|
- {
|
|
|
+ it('when grouped, disabled is true product is disabled', async () => {
|
|
|
+ await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
input: {
|
|
|
- groupByProduct: true,
|
|
|
- take: 3,
|
|
|
+ id: 'T_3',
|
|
|
+ enabled: false,
|
|
|
},
|
|
|
- },
|
|
|
- );
|
|
|
- expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
- { productId: 'T_1', enabled: false },
|
|
|
- { productId: 'T_2', enabled: true },
|
|
|
- { productId: 'T_3', enabled: true },
|
|
|
- ]);
|
|
|
- });
|
|
|
-
|
|
|
- it('when grouped, disabled is true product is disabled', async () => {
|
|
|
- await adminClient.query<UpdateProduct.Mutation, UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
- input: {
|
|
|
- id: 'T_3',
|
|
|
- enabled: false,
|
|
|
- },
|
|
|
+ });
|
|
|
+ await awaitRunningJobs(adminClient);
|
|
|
+ const result = await doAdminSearchQuery({ groupByProduct: true, take: 3 });
|
|
|
+ expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
+ { productId: 'T_1', enabled: false },
|
|
|
+ { productId: 'T_2', enabled: true },
|
|
|
+ { productId: 'T_3', enabled: false },
|
|
|
+ ]);
|
|
|
});
|
|
|
- await awaitRunningJobs(adminClient);
|
|
|
- const result = await adminClient.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
- SEARCH_PRODUCTS,
|
|
|
- {
|
|
|
- input: {
|
|
|
- groupByProduct: true,
|
|
|
- take: 3,
|
|
|
- },
|
|
|
- },
|
|
|
- );
|
|
|
- expect(result.search.items.map(pick(['productId', 'enabled']))).toEqual([
|
|
|
- { productId: 'T_1', enabled: false },
|
|
|
- { productId: 'T_2', enabled: true },
|
|
|
- { productId: 'T_3', enabled: false },
|
|
|
- ]);
|
|
|
});
|
|
|
});
|
|
|
});
|