@@ -17,123 +17,69 @@ describe('useBonusProductSearch', () => {
1717 let mockUseProductSearch
1818
1919 beforeEach ( ( ) => {
20- mockUseProductSearch = {
21- data : null ,
22- isLoading : false ,
23- error : null
24- }
25- useProductSearch . mockReturnValue ( mockUseProductSearch )
20+ mockUseProductSearch = jest . fn ( )
21+ useProductSearch . mockImplementation ( mockUseProductSearch )
2622 } )
2723
2824 afterEach ( ( ) => {
2925 jest . clearAllMocks ( )
3026 } )
3127
32- test ( 'should call useProductSearch with correct parameters when promotionId is provided' , ( ) => {
28+ it ( 'should call useProductSearch with correct parameters when promotionId is provided' , ( ) => {
3329 const promotionId = 'test-promotion-id'
30+ const mockData = { hits : [ ] }
31+ mockUseProductSearch . mockReturnValue ( { data : mockData } )
3432
3533 renderHook ( ( ) => useBonusProductSearch ( promotionId ) )
3634
37- expect ( useProductSearch ) . toHaveBeenCalledWith ( {
38- parameters : {
39- allImages : true ,
40- allVariationProperties : true ,
41- expand : [ 'promotions' , 'variations' , 'prices' , 'images' , 'custom_properties' ] ,
42- limit : HOME_SHOP_PRODUCTS_LIMIT ,
43- perPricebook : true ,
44- refine : [ `pmid=${ promotionId } ` , 'htype=master' ]
45- }
46- } )
47- } )
48-
49- test ( 'should call useProductSearch with null promotionId' , ( ) => {
50- renderHook ( ( ) => useBonusProductSearch ( null ) )
51-
52- expect ( useProductSearch ) . toHaveBeenCalledWith ( {
53- parameters : {
54- allImages : true ,
55- allVariationProperties : true ,
56- expand : [ 'promotions' , 'variations' , 'prices' , 'images' , 'custom_properties' ] ,
57- limit : HOME_SHOP_PRODUCTS_LIMIT ,
58- perPricebook : true ,
59- refine : [ 'pmid=null' , 'htype=master' ]
60- }
61- } )
62- } )
63-
64- test ( 'should call useProductSearch with undefined promotionId' , ( ) => {
65- renderHook ( ( ) => useBonusProductSearch ( undefined ) )
66-
67- expect ( useProductSearch ) . toHaveBeenCalledWith ( {
68- parameters : {
69- allImages : true ,
70- allVariationProperties : true ,
71- expand : [ 'promotions' , 'variations' , 'prices' , 'images' , 'custom_properties' ] ,
72- limit : HOME_SHOP_PRODUCTS_LIMIT ,
73- perPricebook : true ,
74- refine : [ 'pmid=undefined' , 'htype=master' ]
35+ expect ( useProductSearch ) . toHaveBeenCalledWith (
36+ {
37+ parameters : {
38+ allImages : true ,
39+ allVariationProperties : true ,
40+ expand : [ 'promotions' , 'variations' , 'prices' , 'images' , 'custom_properties' ] ,
41+ limit : HOME_SHOP_PRODUCTS_LIMIT ,
42+ perPricebook : true ,
43+ refine : [ `pmid=${ promotionId } ` , 'htype=master' ]
44+ }
45+ } ,
46+ {
47+ enabled : true
7548 }
76- } )
49+ )
7750 } )
7851
79- test ( 'should return data from useProductSearch' , ( ) => {
80- const mockData = {
81- hits : [
82- {
83- productId : 'test-product-1' ,
84- productName : 'Test Product 1'
85- } ,
86- {
87- productId : 'test-product-2' ,
88- productName : 'Test Product 2'
89- }
90- ]
91- }
92-
93- mockUseProductSearch . data = mockData
52+ it ( 'should return data from useProductSearch when promotionId is provided' , ( ) => {
53+ const promotionId = 'test-promotion-id'
54+ const mockData = { hits : [ { productId : '123' , productName : 'Test Product' } ] }
55+ mockUseProductSearch . mockReturnValue ( { data : mockData } )
9456
95- const { result} = renderHook ( ( ) => useBonusProductSearch ( 'test-promotion' ) )
57+ const { result} = renderHook ( ( ) => useBonusProductSearch ( promotionId ) )
9658
9759 expect ( result . current . data ) . toBe ( mockData )
9860 } )
9961
100- test ( 'should return null data when useProductSearch returns null' , ( ) => {
101- mockUseProductSearch . data = null
102-
103- const { result} = renderHook ( ( ) => useBonusProductSearch ( 'test-promotion' ) )
104-
105- expect ( result . current . data ) . toBeNull ( )
106- } )
107-
108- test ( 'should handle empty string promotionId' , ( ) => {
109- renderHook ( ( ) => useBonusProductSearch ( '' ) )
110-
111- expect ( useProductSearch ) . toHaveBeenCalledWith ( {
112- parameters : {
113- allImages : true ,
114- allVariationProperties : true ,
115- expand : [ 'promotions' , 'variations' , 'prices' , 'images' , 'custom_properties' ] ,
116- limit : HOME_SHOP_PRODUCTS_LIMIT ,
117- perPricebook : true ,
118- refine : [ 'pmid=' , 'htype=master' ]
119- }
120- } )
121- } )
122-
123- test ( 'should use correct refine parameters for promotion search' , ( ) => {
62+ it ( 'should use correct refine parameters for promotion search' , ( ) => {
12463 const promotionId = 'ChoiceOfBonusProdect-ProductLevel-ruleBased'
64+ const mockData = { hits : [ ] }
65+ mockUseProductSearch . mockReturnValue ( { data : mockData } )
12566
12667 renderHook ( ( ) => useBonusProductSearch ( promotionId ) )
12768
128- expect ( useProductSearch ) . toHaveBeenCalledWith ( {
129- parameters : {
130- allImages : true ,
131- allVariationProperties : true ,
132- expand : [ 'promotions' , 'variations' , 'prices' , 'images' , 'custom_properties' ] ,
133- limit : HOME_SHOP_PRODUCTS_LIMIT ,
134- perPricebook : true ,
135- refine : [ `pmid=${ promotionId } ` , 'htype=master' ]
69+ expect ( useProductSearch ) . toHaveBeenCalledWith (
70+ {
71+ parameters : {
72+ allImages : true ,
73+ allVariationProperties : true ,
74+ expand : [ 'promotions' , 'variations' , 'prices' , 'images' , 'custom_properties' ] ,
75+ limit : HOME_SHOP_PRODUCTS_LIMIT ,
76+ perPricebook : true ,
77+ refine : [ `pmid=${ promotionId } ` , 'htype=master' ]
78+ }
79+ } ,
80+ {
81+ enabled : true
13682 }
137- } )
83+ )
13884 } )
13985} )
0 commit comments