|
|
@@ -235,6 +235,123 @@ describe('Default search plugin', () => {
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ async function testMatchFacetValueFiltersAnd(client: SimpleGraphQLClient) {
|
|
|
+ const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
+ SEARCH_PRODUCTS_SHOP,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ groupByProduct: true,
|
|
|
+ facetValueFilters: [{ and: 'T_1' }, { and: 'T_2' }],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
+ 'Laptop',
|
|
|
+ 'Curvy Monitor',
|
|
|
+ 'Gaming PC',
|
|
|
+ 'Hard Drive',
|
|
|
+ 'Clacky Keyboard',
|
|
|
+ 'USB Cable',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ async function testMatchFacetValueFiltersOr(client: SimpleGraphQLClient) {
|
|
|
+ const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
+ SEARCH_PRODUCTS_SHOP,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ groupByProduct: true,
|
|
|
+ facetValueFilters: [ { or: ['T_1', 'T_5'] }],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
+ 'Laptop',
|
|
|
+ 'Curvy Monitor',
|
|
|
+ 'Gaming PC',
|
|
|
+ 'Hard Drive',
|
|
|
+ 'Clacky Keyboard',
|
|
|
+ 'USB Cable',
|
|
|
+ 'Instant Camera',
|
|
|
+ 'Camera Lens',
|
|
|
+ 'Tripod',
|
|
|
+ 'Slr Camera',
|
|
|
+ 'Spiky Cactus',
|
|
|
+ 'Orchid',
|
|
|
+ 'Bonsai Tree',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ async function testMatchFacetValueFiltersOrWithAnd(client: SimpleGraphQLClient) {
|
|
|
+ const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
+ SEARCH_PRODUCTS_SHOP,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ groupByProduct: true,
|
|
|
+ facetValueFilters: [{and: 'T_1'}, { or: ['T_2', 'T_3'] }],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
+ 'Laptop',
|
|
|
+ 'Curvy Monitor',
|
|
|
+ 'Gaming PC',
|
|
|
+ 'Hard Drive',
|
|
|
+ 'Clacky Keyboard',
|
|
|
+ 'USB Cable',
|
|
|
+ 'Instant Camera',
|
|
|
+ 'Camera Lens',
|
|
|
+ 'Tripod',
|
|
|
+ 'Slr Camera'
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ async function testMatchFacetValueFiltersWithFacetIdsOr(client: SimpleGraphQLClient) {
|
|
|
+ const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
+ SEARCH_PRODUCTS_SHOP,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ facetValueIds: ['T_2', 'T_3'],
|
|
|
+ facetValueOperator: LogicalOperator.OR,
|
|
|
+ facetValueFilters: [{and:'T_1'}],
|
|
|
+ groupByProduct: true,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
+ 'Laptop',
|
|
|
+ 'Curvy Monitor',
|
|
|
+ 'Gaming PC',
|
|
|
+ 'Hard Drive',
|
|
|
+ 'Clacky Keyboard',
|
|
|
+ 'USB Cable',
|
|
|
+ 'Instant Camera',
|
|
|
+ 'Camera Lens',
|
|
|
+ 'Tripod',
|
|
|
+ 'Slr Camera'
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ async function testMatchFacetValueFiltersWithFacetIdsAnd(client: SimpleGraphQLClient) {
|
|
|
+ const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
+ SEARCH_PRODUCTS_SHOP,
|
|
|
+ {
|
|
|
+ input: {
|
|
|
+ facetValueIds: ['T_1'],
|
|
|
+ facetValueFilters: [{and:'T_3'}],
|
|
|
+ facetValueOperator: LogicalOperator.AND,
|
|
|
+ groupByProduct: true,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ );
|
|
|
+ expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
+ 'Instant Camera',
|
|
|
+ 'Camera Lens',
|
|
|
+ 'Tripod',
|
|
|
+ 'Slr Camera'
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
async function testMatchCollectionId(client: SimpleGraphQLClient) {
|
|
|
const result = await client.query<SearchProductsShop.Query, SearchProductsShop.Variables>(
|
|
|
SEARCH_PRODUCTS_SHOP,
|
|
|
@@ -332,6 +449,16 @@ describe('Default search plugin', () => {
|
|
|
|
|
|
it('matches by facetId with OR operator', () => testMatchFacetIdsOr(shopClient));
|
|
|
|
|
|
+ it('matches by FacetValueFilters AND', () => testMatchFacetValueFiltersAnd(shopClient));
|
|
|
+
|
|
|
+ it('matches by FacetValueFilters OR', () => testMatchFacetValueFiltersOr(shopClient));
|
|
|
+
|
|
|
+ it('matches by FacetValueFilters OR and AND', () => testMatchFacetValueFiltersOrWithAnd(shopClient));
|
|
|
+
|
|
|
+ it('matches by FacetValueFilters with facetId OR operator', () => testMatchFacetValueFiltersWithFacetIdsOr(shopClient));
|
|
|
+
|
|
|
+ it('matches by FacetValueFilters with facetId AND operator', () => testMatchFacetValueFiltersWithFacetIdsAnd(shopClient));
|
|
|
+
|
|
|
it('matches by collectionId', () => testMatchCollectionId(shopClient));
|
|
|
|
|
|
it('matches by collectionSlug', () => testMatchCollectionSlug(shopClient));
|
|
|
@@ -494,6 +621,16 @@ describe('Default search plugin', () => {
|
|
|
|
|
|
it('matches by facetId with OR operator', () => testMatchFacetIdsOr(adminClient));
|
|
|
|
|
|
+ it('matches by FacetValueFilters AND', () => testMatchFacetValueFiltersAnd(shopClient));
|
|
|
+
|
|
|
+ it('matches by FacetValueFilters OR', () => testMatchFacetValueFiltersOr(shopClient));
|
|
|
+
|
|
|
+ it('matches by FacetValueFilters OR and AND', () => testMatchFacetValueFiltersOrWithAnd(shopClient));
|
|
|
+
|
|
|
+ it('matches by FacetValueFilters with facetId OR operator', () => testMatchFacetValueFiltersWithFacetIdsOr(shopClient));
|
|
|
+
|
|
|
+ it('matches by FacetValueFilters with facetId AND operator', () => testMatchFacetValueFiltersWithFacetIdsAnd(shopClient));
|
|
|
+
|
|
|
it('matches by collectionId', () => testMatchCollectionId(adminClient));
|
|
|
|
|
|
it('matches by collectionSlug', () => testMatchCollectionSlug(adminClient));
|
|
|
@@ -657,10 +794,8 @@ describe('Default search plugin', () => {
|
|
|
}, 10000);
|
|
|
|
|
|
it('updates index when a Collection created', async () => {
|
|
|
- const { createCollection } = await adminClient.query<
|
|
|
- CreateCollection.Mutation,
|
|
|
- CreateCollection.Variables
|
|
|
- >(CREATE_COLLECTION, {
|
|
|
+ const { createCollection } = await adminClient.query<CreateCollection.Mutation,
|
|
|
+ CreateCollection.Variables>(CREATE_COLLECTION, {
|
|
|
input: {
|
|
|
translations: [
|
|
|
{
|
|
|
@@ -793,10 +928,8 @@ describe('Default search plugin', () => {
|
|
|
groupByProduct: false,
|
|
|
});
|
|
|
|
|
|
- const { deleteProductVariant } = await adminClient.query<
|
|
|
- DeleteProductVariant.Mutation,
|
|
|
- DeleteProductVariant.Variables
|
|
|
- >(DELETE_PRODUCT_VARIANT, { id: s1.items[0].productVariantId });
|
|
|
+ const { deleteProductVariant } = await adminClient.query<DeleteProductVariant.Mutation,
|
|
|
+ DeleteProductVariant.Variables>(DELETE_PRODUCT_VARIANT, { id: s1.items[0].productVariantId });
|
|
|
|
|
|
await awaitRunningJobs(adminClient);
|
|
|
|
|
|
@@ -892,10 +1025,8 @@ describe('Default search plugin', () => {
|
|
|
.map(() => Math.random().toString(36))
|
|
|
.join(' ');
|
|
|
|
|
|
- const { createProduct } = await adminClient.query<
|
|
|
- CreateProduct.Mutation,
|
|
|
- CreateProduct.Variables
|
|
|
- >(CREATE_PRODUCT, {
|
|
|
+ const { createProduct } = await adminClient.query<CreateProduct.Mutation,
|
|
|
+ CreateProduct.Variables>(CREATE_PRODUCT, {
|
|
|
input: {
|
|
|
translations: [
|
|
|
{
|
|
|
@@ -927,6 +1058,9 @@ describe('Default search plugin', () => {
|
|
|
expect(result.search.items.map(i => i.productName)).toEqual([
|
|
|
'Very long description aabbccdd',
|
|
|
]);
|
|
|
+ await adminClient.query<DeleteProduct.Mutation, DeleteProduct.Variables>(DELETE_PRODUCT, {
|
|
|
+ id: createProduct.id,
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -935,10 +1069,8 @@ describe('Default search plugin', () => {
|
|
|
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, {
|
|
|
+ const { createProduct } = await adminClient.query<CreateProduct.Mutation,
|
|
|
+ CreateProduct.Variables>(CREATE_PRODUCT, {
|
|
|
input: {
|
|
|
facetValueIds: ['T_1'],
|
|
|
translations: [
|
|
|
@@ -979,10 +1111,8 @@ describe('Default search plugin', () => {
|
|
|
});
|
|
|
|
|
|
it('removes synthetic index item once a variant is created', async () => {
|
|
|
- const { createProductVariants } = await adminClient.query<
|
|
|
- CreateProductVariants.Mutation,
|
|
|
- CreateProductVariants.Variables
|
|
|
- >(CREATE_PRODUCT_VARIANTS, {
|
|
|
+ const { createProductVariants } = await adminClient.query<CreateProductVariants.Mutation,
|
|
|
+ CreateProductVariants.Variables>(CREATE_PRODUCT_VARIANTS, {
|
|
|
input: [
|
|
|
{
|
|
|
productId: createdProductId,
|
|
|
@@ -1008,10 +1138,8 @@ describe('Default search plugin', () => {
|
|
|
let secondChannel: ChannelFragment;
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
- const { createChannel } = await adminClient.query<
|
|
|
- CreateChannel.Mutation,
|
|
|
- CreateChannel.Variables
|
|
|
- >(CREATE_CHANNEL, {
|
|
|
+ const { createChannel } = await adminClient.query<CreateChannel.Mutation,
|
|
|
+ CreateChannel.Variables>(CREATE_CHANNEL, {
|
|
|
input: {
|
|
|
code: 'second-channel',
|
|
|
token: SECOND_CHANNEL_TOKEN,
|
|
|
@@ -1042,10 +1170,8 @@ describe('Default search plugin', () => {
|
|
|
|
|
|
it('removing product from channel', async () => {
|
|
|
adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
- const { removeProductsFromChannel } = await adminClient.query<
|
|
|
- RemoveProductsFromChannel.Mutation,
|
|
|
- RemoveProductsFromChannel.Variables
|
|
|
- >(REMOVE_PRODUCT_FROM_CHANNEL, {
|
|
|
+ const { removeProductsFromChannel } = await adminClient.query<RemoveProductsFromChannel.Mutation,
|
|
|
+ RemoveProductsFromChannel.Variables>(REMOVE_PRODUCT_FROM_CHANNEL, {
|
|
|
input: {
|
|
|
productIds: ['T_2'],
|
|
|
channelId: secondChannel.id,
|
|
|
@@ -1060,10 +1186,8 @@ describe('Default search plugin', () => {
|
|
|
|
|
|
it('adding product variant to channel', async () => {
|
|
|
adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
- await adminClient.query<
|
|
|
- AssignProductVariantsToChannel.Mutation,
|
|
|
- AssignProductVariantsToChannel.Variables
|
|
|
- >(ASSIGN_PRODUCTVARIANT_TO_CHANNEL, {
|
|
|
+ await adminClient.query<AssignProductVariantsToChannel.Mutation,
|
|
|
+ AssignProductVariantsToChannel.Variables>(ASSIGN_PRODUCTVARIANT_TO_CHANNEL, {
|
|
|
input: { channelId: secondChannel.id, productVariantIds: ['T_10', 'T_15'] },
|
|
|
});
|
|
|
await awaitRunningJobs(adminClient);
|
|
|
@@ -1086,10 +1210,8 @@ describe('Default search plugin', () => {
|
|
|
|
|
|
it('removing product variant from channel', async () => {
|
|
|
adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
|
|
|
- await adminClient.query<
|
|
|
- RemoveProductVariantsFromChannel.Mutation,
|
|
|
- RemoveProductVariantsFromChannel.Variables
|
|
|
- >(REMOVE_PRODUCTVARIANT_FROM_CHANNEL, {
|
|
|
+ await adminClient.query<RemoveProductVariantsFromChannel.Mutation,
|
|
|
+ RemoveProductVariantsFromChannel.Variables>(REMOVE_PRODUCTVARIANT_FROM_CHANNEL, {
|
|
|
input: { channelId: secondChannel.id, productVariantIds: ['T_1', 'T_15'] },
|
|
|
});
|
|
|
await awaitRunningJobs(adminClient);
|
|
|
@@ -1110,10 +1232,8 @@ describe('Default search plugin', () => {
|
|
|
|
|
|
it('updating product affects current channel', async () => {
|
|
|
adminClient.setChannelToken(SECOND_CHANNEL_TOKEN);
|
|
|
- const { updateProduct } = await adminClient.query<
|
|
|
- UpdateProduct.Mutation,
|
|
|
- UpdateProduct.Variables
|
|
|
- >(UPDATE_PRODUCT, {
|
|
|
+ const { updateProduct } = await adminClient.query<UpdateProduct.Mutation,
|
|
|
+ UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
input: {
|
|
|
id: 'T_3',
|
|
|
enabled: true,
|
|
|
@@ -1156,10 +1276,8 @@ describe('Default search plugin', () => {
|
|
|
}
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
- const { updateProduct } = await adminClient.query<
|
|
|
- UpdateProduct.Mutation,
|
|
|
- UpdateProduct.Variables
|
|
|
- >(UPDATE_PRODUCT, {
|
|
|
+ const { updateProduct } = await adminClient.query<UpdateProduct.Mutation,
|
|
|
+ UpdateProduct.Variables>(UPDATE_PRODUCT, {
|
|
|
input: {
|
|
|
id: 'T_1',
|
|
|
translations: [
|