@@ -35,6 +35,78 @@ afterAll(() => {
3535} )
3636
3737describe ( 'EinsteinAPI' , ( ) => {
38+ test ( '_constructEinsteinProduct handles variationGroup product type' , ( ) => {
39+ const variationGroupProduct = {
40+ id : 'test-variation-group-id' ,
41+ price : 99.99 ,
42+ type : {
43+ variationGroup : true
44+ } ,
45+ master : {
46+ masterId : 'master-product-id'
47+ }
48+ }
49+
50+ const result = einsteinApi . _constructEinsteinProduct ( variationGroupProduct )
51+
52+ expect ( result ) . toEqual ( {
53+ altId : 'test-variation-group-id' ,
54+ id : 'master-product-id' ,
55+ price : 99.99 ,
56+ sku : 'test-variation-group-id' ,
57+ type : 'vgroup'
58+ } )
59+ } )
60+
61+ test ( '_constructEinsteinProduct handles variant product type' , ( ) => {
62+ const variantProduct = {
63+ id : 'test-variant-id' ,
64+ price : 99.99 ,
65+ type : {
66+ variant : true
67+ } ,
68+ master : {
69+ masterId : 'master-product-id'
70+ }
71+ }
72+
73+ const result = einsteinApi . _constructEinsteinProduct ( variantProduct )
74+
75+ expect ( result ) . toEqual ( {
76+ id : 'master-product-id' ,
77+ price : 99.99 ,
78+ sku : 'test-variant-id'
79+ } )
80+ } )
81+
82+ test ( '_constructEinsteinItem handles variationGroup product type' , ( ) => {
83+ const variationGroupItem = {
84+ product : {
85+ id : 'test-variation-group-id' ,
86+ type : {
87+ variationGroup : true
88+ } ,
89+ master : {
90+ masterId : 'master-product-id'
91+ }
92+ } ,
93+ productId : 'test-variation-group-id' ,
94+ price : 99.99 ,
95+ quantity : 2
96+ }
97+
98+ const result = einsteinApi . _constructEinsteinItem ( variationGroupItem )
99+
100+ expect ( result ) . toEqual ( {
101+ id : 'master-product-id' ,
102+ quantity : 2 ,
103+ price : 99.99 ,
104+ sku : 'test-variation-group-id' ,
105+ type : 'vgroup' ,
106+ altId : 'test-variation-group-id'
107+ } )
108+ } )
109+
38110 test ( 'viewProduct sends expected api request' , async ( ) => {
39111 await einsteinApi . sendViewProduct ( mockProduct , { cookieId : 'test-usid' } )
40112
@@ -46,7 +118,7 @@ describe('EinsteinAPI', () => {
46118 'Content-Type' : 'application/json' ,
47119 'x-cq-client-id' : 'test-id'
48120 } ,
49- body : '{"product":{"id":"56736828M","sku":"56736828M","altId":"","altIdType":"" },"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
121+ body : '{"product":{"id":"56736828M","price":155 },"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
50122 }
51123 )
52124 } )
@@ -158,12 +230,12 @@ describe('EinsteinAPI', () => {
158230 'Content-Type' : 'application/json' ,
159231 'x-cq-client-id' : 'test-id'
160232 } ,
161- body : '{"products":[{"id":"682875719029M","sku":""," price":29.99,"quantity":1}],"amount":29.99,"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
233+ body : '{"products":[{"id":"682875719029M","price":29.99,"quantity":1}],"amount":29.99,"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
162234 }
163235 )
164236 } )
165237
166- test ( 'checkouStep sends expected api request' , async ( ) => {
238+ test ( 'checkoutStep sends expected api request' , async ( ) => {
167239 const checkoutStepName = 'CheckoutStep'
168240 const checkoutStep = 0
169241 await einsteinApi . sendCheckoutStep ( checkoutStepName , checkoutStep , mockBasket , {
@@ -192,7 +264,7 @@ describe('EinsteinAPI', () => {
192264 'Content-Type' : 'application/json' ,
193265 'x-cq-client-id' : 'test-id'
194266 } ,
195- body : '{"products":[{"id":"883360544021M","sku":""," price":155,"quantity":1}],"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
267+ body : '{"products":[{"id":"883360544021M","price":155,"quantity":1}],"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
196268 }
197269 )
198270 } )
@@ -209,7 +281,7 @@ describe('EinsteinAPI', () => {
209281 'Content-Type' : 'application/json' ,
210282 'x-cq-client-id' : 'test-id'
211283 } ,
212- body : '{"recommenderName":"testRecommender","__recoUUID":"883360544021M","product":{"id":"56736828M","sku":"56736828M","altId":"","altIdType":"" },"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
284+ body : '{"recommenderName":"testRecommender","__recoUUID":"883360544021M","product":{"id":"56736828M","price":155 },"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
213285 }
214286 )
215287 } )
@@ -249,4 +321,31 @@ describe('EinsteinAPI', () => {
249321 }
250322 )
251323 } )
324+
325+ test ( 'sendViewProduct handles variationGroup product type' , async ( ) => {
326+ const variationGroupProduct = {
327+ id : 'test-variation-group-id' ,
328+ price : 99.99 ,
329+ type : {
330+ variationGroup : true
331+ } ,
332+ master : {
333+ masterId : 'master-product-id'
334+ }
335+ }
336+
337+ await einsteinApi . sendViewProduct ( variationGroupProduct , { cookieId : 'test-usid' } )
338+
339+ expect ( fetch ) . toHaveBeenCalledWith (
340+ 'http://localhost/test-path/v3/activities/test-site-id/viewProduct' ,
341+ {
342+ method : 'POST' ,
343+ headers : {
344+ 'Content-Type' : 'application/json' ,
345+ 'x-cq-client-id' : 'test-id'
346+ } ,
347+ body : '{"product":{"altId":"test-variation-group-id","id":"master-product-id","price":99.99,"sku":"test-variation-group-id","type":"vgroup"},"cookieId":"test-usid","realm":"test","instanceType":"sbx"}'
348+ }
349+ )
350+ } )
252351} )
0 commit comments