Skip to content

Commit

Permalink
Merge pull request #80 from Relewise/feat/recently-purchased-facet
Browse files Browse the repository at this point in the history
Feat: add RecentlyPurchasedFacet
  • Loading branch information
mzanoni authored Aug 22, 2024
2 parents ee2cef4 + 5a80e8f commit ff09caa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/client/src/builders/search/facetBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProductCategoryAssortmentFacet, BrandFacet, CategoryFacet, CategoryPath, CategoryHierarchyFacet, SelectedProductCategoryPropertiesSettings, SelectedContentCategoryPropertiesSettings, ContentAssortmentFacet, ContentDataBooleanValueFacet, ContentDataDoubleRangeFacet, ContentDataDoubleRangesFacet, ContentDataDoubleValueFacet, ContentDataStringValueFacet, FacetSettings, PriceRangeFacet, PriceRangesFacet, ProductAssortmentFacet, ProductCategoryDataBooleanValueFacet, ProductCategoryDataDoubleRangeFacet, ProductCategoryDataDoubleRangesFacet, ProductCategoryDataDoubleValueFacet, ProductCategoryDataStringValueFacet, ProductDataBooleanValueFacet, ProductDataDoubleRangeFacet, ProductDataDoubleRangesFacet, ProductDataDoubleValueFacet, ProductDataStringValueFacet, ProductFacetQuery, VariantSpecificationFacet, ProductDataObjectFacet, DoubleNullableRange, ContentDataObjectFacet, ProductCategoryDataObjectFacet } from '../../models/data-contracts';
import { ProductCategoryAssortmentFacet, BrandFacet, CategoryFacet, CategoryPath, CategoryHierarchyFacet, SelectedProductCategoryPropertiesSettings, SelectedContentCategoryPropertiesSettings, ContentAssortmentFacet, ContentDataBooleanValueFacet, ContentDataDoubleRangeFacet, ContentDataDoubleRangesFacet, ContentDataDoubleValueFacet, ContentDataStringValueFacet, FacetSettings, PriceRangeFacet, PriceRangesFacet, ProductAssortmentFacet, ProductCategoryDataBooleanValueFacet, ProductCategoryDataDoubleRangeFacet, ProductCategoryDataDoubleRangesFacet, ProductCategoryDataDoubleValueFacet, ProductCategoryDataStringValueFacet, ProductDataBooleanValueFacet, ProductDataDoubleRangeFacet, ProductDataDoubleRangesFacet, ProductDataDoubleValueFacet, ProductDataStringValueFacet, ProductFacetQuery, VariantSpecificationFacet, ProductDataObjectFacet, DoubleNullableRange, ContentDataObjectFacet, ProductCategoryDataObjectFacet, RecentlyPurchasedFacet, PurchaseQualifiers } from '../../models/data-contracts';
import { DataObjectFilterConditionBuilder } from '../dataObjectFilterConditionBuilder';
import { DataObjectFacetBuilder } from './dataObjectFacetBuilder';

Expand Down Expand Up @@ -30,7 +30,8 @@ export class FacetBuilder {
| ProductDataStringValueFacet
| ProductDataBooleanValueFacet
| ProductDataDoubleValueFacet
| VariantSpecificationFacet)[] = [];
| VariantSpecificationFacet
| RecentlyPurchasedFacet)[] = [];

//#region Product
public addCategoryFacet(categorySelectionStrategy: 'ImmediateParent' | 'Ancestors', selectedValues: string[] | null = null, facetSettings?: FacetSettings): this {
Expand Down Expand Up @@ -357,6 +358,24 @@ export class FacetBuilder {

return this;
}

public addRecentlyPurchasedFacet(
purchaseQualifiers: PurchaseQualifiers,
selectedValues: boolean[] | null = null,
facetSettings?: FacetSettings): this {

const facet: RecentlyPurchasedFacet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.RecentlyPurchasedFacet, Relewise.Client',
field: 'Data',
settings: facetSettings,
selected: selectedValues,
purchaseQualifiers: purchaseQualifiers,
};

this.facets.push(facet);

return this;
}
//#endregion

//#region Content
Expand Down
16 changes: 16 additions & 0 deletions packages/client/tests/integration-tests/facets.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ function baseBuilder() {
});
};

test('RecentlyPurchased facet', async() => {

const request: ProductSearchRequest = baseBuilder()
.facets(f => f.addRecentlyPurchasedFacet({
byUser: true,
byUserCompany: false,
byUserParentCompany: false,
sinceMinutesAgo: 1140,
}, [true]))
.build();

const result = await searcher.searchProducts(request);

expect(result?.facets?.items![0].field).toBe('User');
});

test('SalesPrice facet', async() => {

const request: ProductSearchRequest = baseBuilder()
Expand Down

0 comments on commit ff09caa

Please sign in to comment.