1- import { DataValueFactory , ProductRecommendationResponse , ProductsViewedAfterViewingProductBuilder , PurchasedWithProductBuilder , Recommender , UserFactory } from '../../src' ;
1+ import { DataValueFactory , PopularProductsBuilder , ProductRecommendationResponse , ProductsViewedAfterViewingProductBuilder , PurchasedWithProductBuilder , Recommender , UserFactory } from '../../src' ;
22import { test , expect } from '@jest/globals'
33
44const { npm_config_API_KEY : API_KEY , npm_config_DATASET_ID : DATASET_ID , npm_config_SERVER_URL : SERVER_URL } = process . env ;
@@ -14,15 +14,15 @@ const settings = {
1414
1515test ( 'PurchasedWithProduct' , async ( ) => {
1616
17- const result : ProductRecommendationResponse | undefined = await recommender . recommendPurchasedWithProduct ( new PurchasedWithProductBuilder ( settings ) . product ( { productId : '1' } ) . build ( ) ) ;
17+ const result : ProductRecommendationResponse | undefined = await recommender . recommendPurchasedWithProduct ( new PurchasedWithProductBuilder ( settings ) . product ( { productId : '1' } ) . build ( ) ) ;
1818
1919 expect ( result ) . not . toBe ( undefined ) ;
2020 expect ( result ! . recommendations ?. length ) . toBeGreaterThan ( 0 ) ;
2121} ) ;
2222
2323test ( 'ProductsViewedAfterViewingProduct' , async ( ) => {
2424
25- const result : ProductRecommendationResponse | undefined = await recommender . recommendProductsViewedAfterViewingProduct ( new ProductsViewedAfterViewingProductBuilder ( settings ) . product ( { productId : '1' } ) . build ( ) ) ;
25+ const result : ProductRecommendationResponse | undefined = await recommender . recommendProductsViewedAfterViewingProduct ( new ProductsViewedAfterViewingProductBuilder ( settings ) . product ( { productId : '1' } ) . build ( ) ) ;
2626
2727 expect ( result ) . not . toBe ( undefined ) ;
2828 expect ( result ! . recommendations ?. length ) . toBeGreaterThan ( 0 ) ;
@@ -36,18 +36,29 @@ test('ProductsViewedAfterViewingProduct with all conditions', async() => {
3636 displayedAtLocation : 'integration test Conditions' ,
3737 user : UserFactory . anonymous ( ) ,
3838 } )
39- . product ( { productId : '1' } )
39+ . product ( { productId : '1' } )
4040 . filters ( f => f
4141 . addProductDataFilter ( 'ShortDescription' , b => b
4242 . addContainsCondition ( DataValueFactory . stringCollection ( [ 'd' ] ) , 'Any' )
4343 . addContainsCondition ( DataValueFactory . booleanCollection ( [ true ] ) , 'Any' )
4444 . addContainsCondition ( DataValueFactory . doubleCollection ( [ 1 ] ) , 'Any' )
45- . addContainsCondition ( DataValueFactory . multilingual ( [ { language : 'en-us' , value : 'd' } ] ) , 'Any' )
46- . addContainsCondition ( DataValueFactory . multiCurrency ( [ { currency : 'USD' , amount : 1 } ] ) , 'Any' ) ,
45+ . addContainsCondition ( DataValueFactory . multilingual ( [ { language : 'en-us' , value : 'd' } ] ) , 'Any' )
46+ . addContainsCondition ( DataValueFactory . multiCurrency ( [ { currency : 'USD' , amount : 1 } ] ) , 'Any' ) ,
4747 ) ) ;
4848
4949 const result : ProductRecommendationResponse | undefined = await recommender . recommendProductsViewedAfterViewingProduct ( recommendationBuilder . build ( ) ) ;
5050
5151 expect ( result ) . not . toBe ( undefined ) ;
5252 expect ( result ! . recommendations ?. length ) . toEqual ( 0 ) ;
53+ } ) ;
54+
55+ test ( 'ProductsViewedAfterViewingProduct with all conditions' , async ( ) => {
56+
57+ const recommendationBuilder = new PopularProductsBuilder ( settings )
58+ . setPopularityMultiplier ( pm => pm . setDataKeyPopularityMultiplierSelector ( { key : 'some-data-key' } ) ) ;
59+
60+ const result : ProductRecommendationResponse | undefined = await recommender . recommendPopularProducts ( recommendationBuilder . build ( ) ) ;
61+
62+ expect ( result ) . not . toBe ( undefined ) ;
63+ expect ( result ! . recommendations ?. length ) . toBeGreaterThan ( 0 ) ;
5364} ) ;
0 commit comments