@@ -67,25 +67,21 @@ describe('fetchSoon', () => {
6767 } ) ;
6868
6969 test ( 'should execute asap if config is set to not batch searches' , ( ) => {
70- const config = {
71- get : getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : false } ) ,
72- } ;
70+ const getConfig = getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : false } ) ;
7371 const request = { } ;
7472 const options = { } ;
7573
76- fetchSoon ( request , options , { config } as FetchHandlers ) ;
74+ fetchSoon ( request , options , { getConfig } as FetchHandlers ) ;
7775
7876 expect ( callClient ) . toBeCalled ( ) ;
7977 } ) ;
8078
8179 test ( 'should delay by 50ms if config is set to batch searches' , ( ) => {
82- const config = {
83- get : getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : true } ) ,
84- } ;
80+ const getConfig = getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : true } ) ;
8581 const request = { } ;
8682 const options = { } ;
8783
88- fetchSoon ( request , options , { config } as FetchHandlers ) ;
84+ fetchSoon ( request , options , { getConfig } as FetchHandlers ) ;
8985
9086 expect ( callClient ) . not . toBeCalled ( ) ;
9187 jest . advanceTimersByTime ( 0 ) ;
@@ -95,14 +91,12 @@ describe('fetchSoon', () => {
9591 } ) ;
9692
9793 test ( 'should send a batch of requests to callClient' , ( ) => {
98- const config = {
99- get : getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : true } ) ,
100- } ;
94+ const getConfig = getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : true } ) ;
10195 const requests = [ { foo : 1 } , { foo : 2 } ] ;
10296 const options = [ { bar : 1 } , { bar : 2 } ] ;
10397
10498 requests . forEach ( ( request , i ) => {
105- fetchSoon ( request , options [ i ] as ISearchOptions , { config } as FetchHandlers ) ;
99+ fetchSoon ( request , options [ i ] as ISearchOptions , { getConfig } as FetchHandlers ) ;
106100 } ) ;
107101
108102 jest . advanceTimersByTime ( 50 ) ;
@@ -112,13 +106,11 @@ describe('fetchSoon', () => {
112106 } ) ;
113107
114108 test ( 'should return the response to the corresponding call for multiple batched requests' , async ( ) => {
115- const config = {
116- get : getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : true } ) ,
117- } ;
109+ const getConfig = getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : true } ) ;
118110 const requests = [ { _mockResponseId : 'foo' } , { _mockResponseId : 'bar' } ] ;
119111
120112 const promises = requests . map ( ( request ) => {
121- return fetchSoon ( request , { } , { config } as FetchHandlers ) ;
113+ return fetchSoon ( request , { } , { getConfig } as FetchHandlers ) ;
122114 } ) ;
123115 jest . advanceTimersByTime ( 50 ) ;
124116 const results = await Promise . all ( promises ) ;
@@ -127,18 +119,16 @@ describe('fetchSoon', () => {
127119 } ) ;
128120
129121 test ( 'should wait for the previous batch to start before starting a new batch' , ( ) => {
130- const config = {
131- get : getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : true } ) ,
132- } ;
122+ const getConfig = getConfigStub ( { [ UI_SETTINGS . COURIER_BATCH_SEARCHES ] : true } ) ;
133123 const firstBatch = [ { foo : 1 } , { foo : 2 } ] ;
134124 const secondBatch = [ { bar : 1 } , { bar : 2 } ] ;
135125
136126 firstBatch . forEach ( ( request ) => {
137- fetchSoon ( request , { } , { config } as FetchHandlers ) ;
127+ fetchSoon ( request , { } , { getConfig } as FetchHandlers ) ;
138128 } ) ;
139129 jest . advanceTimersByTime ( 50 ) ;
140130 secondBatch . forEach ( ( request ) => {
141- fetchSoon ( request , { } , { config } as FetchHandlers ) ;
131+ fetchSoon ( request , { } , { getConfig } as FetchHandlers ) ;
142132 } ) ;
143133
144134 expect ( callClient ) . toBeCalledTimes ( 1 ) ;
0 commit comments