@Test public void channelsFilterDsl() { final StringHttpRequestBody body = (StringHttpRequestBody) ProductProjectionSearch.ofStaged().plusQueryFilters(m -> m.allVariants().availability().channels().channelId("channel-id-12") .availableQuantity().isGreaterThanOrEqualTo(new BigDecimal(3))).httpRequestIntent().getBody(); assertThat(body.getString()).contains("filter.query=variants.availability.channels.channel-id-12.availableQuantity%3Arange%283+to+*%29"); }
@Test public void searchForIsOnStock() { withProductOfStock(client(), 2, product -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability().isOnStock().is(true)); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); }); }); }
@Test public void searchForAvailableQuantityRanges() { withProductOfStock(client(), 10, productWith10Items -> { withProductOfStock(client(), 5, productWith5Items -> { final RangeFacetExpression<ProductProjection> productProjectionRangeFacetExpression = ProductProjectionSearchModel.of() .facet().allVariants().availability().availableQuantity().onlyGreaterThanOrEqualTo(new BigDecimal(1)); final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().isIn(asList(productWith10Items.getId(), productWith5Items.getId()))) .plusQueryFilters(m -> m.allVariants().availability().availableQuantity().isGreaterThanOrEqualTo(new BigDecimal(6))) .plusFacets(productProjectionRangeFacetExpression); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); assertThat(res.getResults().get(0).getId()) .as("finds only the product with the sufficient amount stocked") .isEqualTo(productWith10Items.getId()); final RangeFacetResult facetResult = res.getFacetResult(productProjectionRangeFacetExpression); assertThat(facetResult.getRanges().get(0).getMax()) .isEqualTo("10.0"); }); }); }); }
@Test public void searchForIsNotOnStock() { withProductOfStock(client(), 0, product -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability().isOnStock().is(false)); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(0); }); }); }
@Test public void searchForIsOnStockInChannels() { final String nonExistingChannel = "nonExistingChannelId"; withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withProductOfStockAndChannel(client(), 2, channel, product -> { final ProductProjectionSearch isOnStockInAnyChannelRequest = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability() .onStockInChannels().containsAny(Arrays.asList(nonExistingChannel, channel.getId()))); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(isOnStockInAnyChannelRequest); assertThat(res.getResults()).hasSize(1); }); final ProductProjectionSearch isOnStockInAllChannelsRequest = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability() .onStockInChannels().containsAll(Arrays.asList(nonExistingChannel, channel.getId()))); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(isOnStockInAllChannelsRequest); assertThat(res.getResults()).isEmpty(); }); }); }); }
@Test public void searchForAvailableQuantityRangesInChannels() { withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withProductOfStockAndChannel(client(), 10, channel, productWith10Items -> { withProductOfStockAndChannel(client(), 5, channel, productWith5Items -> { final RangeFacetExpression<ProductProjection> facet = ProductProjectionSearchModel.of() .facet().allVariants().availability().channels().channelId(channel.getId()) .availableQuantity().onlyGreaterThanOrEqualTo(new BigDecimal(1)); final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().isIn(asList(productWith10Items.getId(), productWith5Items.getId()))) .plusQueryFilters(m -> m.allVariants().availability().channels().channelId(channel.getId()) .availableQuantity().isGreaterThanOrEqualTo(new BigDecimal(6))) .plusFacets(facet); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); assertThat(res.getResults().get(0).getId()) .as("finds only the product with the sufficient amount stocked") .isEqualTo(productWith10Items.getId()); final RangeFacetResult facetResult = res.getFacetResult(facet); assertThat(facetResult.getRanges().get(0).getMax()) .isEqualTo("10.0"); }); }); }); }); }
@Test public void searchForIsOnStockWithChannel() { withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withProductOfStockAndChannel(client(), 2, channel, product -> { final ProductProjectionSearch request = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.id().is(product.getId())) .plusQueryFilters(m -> m.allVariants().availability() .channels().channelId(channel.getId()).isOnStock().is(true)); assertEventually(() -> { final PagedSearchResult<ProductProjection> res = client().executeBlocking(request); assertThat(res.getResults()).hasSize(1); }); }); }); }