Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add RecentlyPurchasedFacet #80

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 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,29 @@ 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: {
byUser: purchaseQualifiers.byUser ?? false,
byUserCompany: purchaseQualifiers.byUserCompany ?? false,
byUserParentCompany: purchaseQualifiers.byUserParentCompany ?? false,
sinceMinutesAgo: purchaseQualifiers.sinceMinutesAgo ?? 1234,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for these fallbacks? Values are required right?
The 1234 seems like test code :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Det er helt klart noget jeg har glemt at fjerne ja! Det er nu rettet.

};

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
Loading