@@ -111,6 +111,14 @@ describe('abstract endpoint', () => {
111
111
describe ( 'auto batching' , ( ) => {
112
112
const batchDelay = 10
113
113
114
+ beforeEach ( ( ) => {
115
+ mockClient . autoBatching = true
116
+ } )
117
+
118
+ afterEach ( ( ) => {
119
+ mockClient . autoBatching = false
120
+ } )
121
+
114
122
it ( 'sets up _autoBatch variable' , ( ) => {
115
123
let x = endpoint . autoBatch ( batchDelay )
116
124
expect ( x ) . toBeInstanceOf ( Module )
@@ -137,10 +145,11 @@ describe('abstract endpoint', () => {
137
145
endpoint . autoBatch ( batchDelay )
138
146
fetchMock . addResponse ( content )
139
147
140
- let [ entry1 , entry2 ] = await Promise . all ( [ endpoint . get ( 1 ) , endpoint . get ( 2 ) ] )
148
+ let [ entry1 , entry2 , entry3 ] = await Promise . all ( [ endpoint . get ( 1 ) , endpoint . get ( 2 ) , endpoint . get ( 1 ) ] )
141
149
expect ( fetchMock . lastUrl ( ) ) . toEqual ( 'https://api.guildwars2.com/v2/test?v=schema&ids=1,2' )
142
150
expect ( entry1 ) . toEqual ( content [ 0 ] )
143
151
expect ( entry2 ) . toEqual ( content [ 1 ] )
152
+ expect ( entry3 ) . toEqual ( content [ 0 ] )
144
153
} )
145
154
146
155
it ( 'returns null from get with no response' , async ( ) => {
@@ -190,6 +199,45 @@ describe('abstract endpoint', () => {
190
199
expect ( entry2 ) . toEqual ( content2 [ 0 ] )
191
200
192
201
} )
202
+
203
+ it ( 'can batch requests from different endpoints in parallel' , async ( ) => {
204
+ console . log ( '@@@@@@@@@@@@@@@@@@@@@@@' )
205
+ let content1 = [ { id : 1 , name : 'foo' } , { id : 2 , name : 'bar' } ]
206
+ let content2 = [ { id : 1 , name : 'bar' } ]
207
+
208
+ endpoint = new Module ( mockClient )
209
+ endpoint . caches . map ( cache => cache . flush ( ) )
210
+ endpoint . isBulk = true
211
+ endpoint . url = '/v2/test'
212
+ endpoint . schemaVersion = 'schema'
213
+ // endpoint.autoBatch(batchDelay*100)
214
+
215
+ differentEndpoint = new Module ( mockClient )
216
+ differentEndpoint . caches . map ( cache => cache . flush ( ) )
217
+ differentEndpoint . isBulk = true
218
+ differentEndpoint . url = '/v2/differentTest'
219
+ differentEndpoint . schemaVersion = 'schema'
220
+ // differentEndpoint.autoBatch(batchDelay*100)
221
+
222
+ fetchMock . addResponse ( content1 )
223
+ fetchMock . addResponse ( content2 )
224
+
225
+ let [ entry1 , entry2 , entry3 ] = await Promise . all ( [
226
+ endpoint . get ( 1 ) ,
227
+ differentEndpoint . get ( 1 ) ,
228
+ endpoint . get ( 2 ) ,
229
+ ] )
230
+ console . log ( '@@@@@@@@@@@@@@@@@@@@@@@' )
231
+ expect ( fetchMock . urls ( ) ) . toEqual ( [
232
+ 'https://api.guildwars2.com/v2/test?v=schema&ids=1,2' ,
233
+ 'https://api.guildwars2.com/v2/differentTest?v=schema&ids=1'
234
+ ] )
235
+ expect ( entry1 ) . toEqual ( content1 [ 0 ] )
236
+ expect ( entry2 ) . toEqual ( content2 [ 0 ] )
237
+ expect ( entry3 ) . toEqual ( content1 [ 1 ] )
238
+
239
+ console . log ( '@@@@@@@@@@@@@@@@@@@@@@@' )
240
+ } )
193
241
} )
194
242
195
243
describe ( 'get' , ( ) => {
0 commit comments