@@ -49,6 +49,7 @@ describe(`ConstructorIO - Recommendations${bundledDescriptionSuffix}`, () => {
4949 const filteredItemsRecommendationsPodId = 'filtered_items' ;
5050 const itemId = 'power_drill' ;
5151 const itemIds = [ itemId , 'drill' ] ;
52+ const variationId = 'power_drill_variation' ;
5253
5354 it ( 'Should return a response with valid itemIds (singular)' , ( done ) => {
5455 const { recommendations } = new ConstructorIO ( {
@@ -99,6 +100,35 @@ describe(`ConstructorIO - Recommendations${bundledDescriptionSuffix}`, () => {
99100 } ) ;
100101 } ) ;
101102
103+ it ( 'Should return a response with valid variationId' , ( done ) => {
104+ const { recommendations } = new ConstructorIO ( {
105+ apiKey : testApiKey ,
106+ fetch : fetchSpy ,
107+ } ) ;
108+
109+ recommendations . getRecommendations ( podId , { itemIds : itemId , variationId } ) . then ( ( res ) => {
110+ const requestedUrlParams = helpers . extractUrlParamsFromFetch ( fetchSpy ) ;
111+
112+ expect ( res ) . to . have . property ( 'request' ) . to . be . an ( 'object' ) ;
113+ expect ( res ) . to . have . property ( 'response' ) . to . be . an ( 'object' ) ;
114+ expect ( res ) . to . have . property ( 'result_id' ) . to . be . an ( 'string' ) ;
115+ expect ( res . request . item_id ) . to . equal ( itemId ) ;
116+ expect ( res . response ) . to . have . property ( 'results' ) . to . be . an ( 'array' ) ;
117+ expect ( res . response ) . to . have . property ( 'pod' ) ;
118+ expect ( res . response . pod ) . to . have . property ( 'id' ) . to . equal ( podId ) ;
119+ expect ( res . response . pod ) . to . have . property ( 'display_name' ) ;
120+ expect ( fetchSpy ) . to . have . been . called ;
121+ expect ( requestedUrlParams ) . to . have . property ( 'key' ) ;
122+ expect ( requestedUrlParams ) . to . have . property ( 'i' ) ;
123+ expect ( requestedUrlParams ) . to . have . property ( 's' ) ;
124+ expect ( requestedUrlParams ) . to . have . property ( 'c' ) . to . equal ( clientVersion ) ;
125+ expect ( requestedUrlParams ) . to . have . property ( 'item_id' ) . to . equal ( itemId ) ;
126+ expect ( requestedUrlParams ) . to . have . property ( 'variation_id' ) . to . equal ( variationId ) ;
127+ expect ( res . request . variation_id ) . to . equal ( variationId ) ;
128+ done ( ) ;
129+ } ) ;
130+ } ) ;
131+
102132 it ( 'Should return a response with valid term for query recommendations strategy pod' , ( done ) => {
103133 const term = 'apple' ;
104134 const { recommendations } = new ConstructorIO ( {
@@ -462,6 +492,23 @@ describe(`ConstructorIO - Recommendations${bundledDescriptionSuffix}`, () => {
462492 recommendations . getRecommendations ( podId , { itemIds } ) ;
463493 } ) ;
464494
495+ it ( 'Should be rejected when variationId is provided without itemId' , ( ) => {
496+ const { recommendations } = new ConstructorIO ( { apiKey : testApiKey } ) ;
497+
498+ return expect ( recommendations . getRecommendations ( podId , {
499+ variationId,
500+ } ) ) . to . eventually . be . rejected ;
501+ } ) ;
502+
503+ it ( 'Should be rejected when variationId is provided with an empty itemIds array' , ( ) => {
504+ const { recommendations } = new ConstructorIO ( { apiKey : testApiKey } ) ;
505+
506+ return expect ( recommendations . getRecommendations ( podId , {
507+ variationId,
508+ itemIds : [ ] ,
509+ } ) ) . to . eventually . be . rejected ;
510+ } ) ;
511+
465512 it ( 'Should be rejected when invalid pod id parameter is provided' , ( ) => {
466513 const { recommendations } = new ConstructorIO ( { apiKey : testApiKey } ) ;
467514
0 commit comments