@@ -143,131 +143,121 @@ describe('api', () => {
143
143
} ) ;
144
144
} ) ;
145
145
146
- describe ( 'init clients' , ( ) => {
147
- test ( 'provides an init method for the analytics client' , ( ) => {
148
- expect ( client . initAnalytics ) . not . toBeUndefined ( ) ;
146
+ describe ( 'bridge methods' , ( ) => {
147
+ test ( 'throws when missing transformation.region' , ( ) => {
148
+ //@ts -expect-error
149
+ expect ( ( ) => algoliasearch ( 'APP_ID' , 'API_KEY' , { transformation : { taskID : 'foo' } } ) ) . toThrow (
150
+ '`region` must be provided when leveraging the transformation pipeline' ,
151
+ ) ;
149
152
} ) ;
150
153
151
- test ( 'provides an init method for the abtesting client' , ( ) => {
152
- expect ( client . initAbtesting ) . not . toBeUndefined ( ) ;
154
+ test ( 'throws when missing transformation.taskID' , ( ) => {
155
+ //@ts -expect-error
156
+ expect ( ( ) => algoliasearch ( 'APP_ID' , 'API_KEY' , { transformation : { region : 'us' } } ) ) . toThrow (
157
+ '`taskID` must be provided when leveraging the transformation pipeline' ,
158
+ ) ;
153
159
} ) ;
154
160
155
- test ( 'provides an init method for the personalization client' , ( ) => {
156
- expect ( client . initPersonalization ) . not . toBeUndefined ( ) ;
157
- } ) ;
161
+ test ( 'throws when calling the transformation methods without init parameters' , async ( ) => {
162
+ await expect (
163
+ client . saveObjectsWithTransformation ( {
164
+ indexName : 'foo' ,
165
+ objects : [ { objectID : 'bar' , baz : 42 } ] ,
166
+ waitForTasks : true ,
167
+ } ) ,
168
+ ) . rejects . toThrow (
169
+ '`transformation.taskID` and `transformation.region` must be provided at client instantiation before calling this method.' ,
170
+ ) ;
158
171
159
- test ( 'provides an init method for the recommend client' , ( ) => {
160
- expect ( client . initRecommend ) . not . toBeUndefined ( ) ;
172
+ await expect (
173
+ client . partialUpdateObjectsWithTransformation ( {
174
+ indexName : 'foo' ,
175
+ objects : [ { objectID : 'bar' , baz : 42 } ] ,
176
+ waitForTasks : true ,
177
+ } ) ,
178
+ ) . rejects . toThrow (
179
+ '`transformation.taskID` and `transformation.region` must be provided at client instantiation before calling this method.' ,
180
+ ) ;
161
181
} ) ;
162
182
163
- test ( 'default `init` clients to the root `algoliasearch` credentials' , async ( ) => {
164
- const abtestingClient = client . initAbtesting ( { options : { requester : browserEchoRequester ( ) } } ) ;
165
- const analyticsClient = client . initAnalytics ( { options : { requester : browserEchoRequester ( ) } } ) ;
166
- const recommendClient = client . initRecommend ( { options : { requester : browserEchoRequester ( ) } } ) ;
167
- const personalizationClient = client . initPersonalization ( {
168
- region : 'eu' ,
169
- options : { requester : browserEchoRequester ( ) } ,
183
+ test ( 'exposes the transformation methods at the root of the client' , async ( ) => {
184
+ const ingestionClient = algoliasearch ( 'APP_ID' , 'API_KEY' , {
185
+ requester : browserEchoRequester ( ) ,
186
+ transformation : { taskID : 'foo' , region : 'us' } ,
170
187
} ) ;
171
188
172
- const res1 = ( await abtestingClient . customGet ( {
173
- path : 'abtestingClient' ,
174
- } ) ) as unknown as EchoResponse ;
175
- const res2 = ( await analyticsClient . customGet ( {
176
- path : 'analyticsClient' ,
177
- } ) ) as unknown as EchoResponse ;
178
- const res3 = ( await personalizationClient . customGet ( {
179
- path : 'personalizationClient' ,
180
- } ) ) as unknown as EchoResponse ;
181
- const res4 = ( await recommendClient . customGet ( {
182
- path : 'recommendClient' ,
189
+ expect ( ingestionClient . saveObjectsWithTransformation ) . not . toBeUndefined ( ) ;
190
+
191
+ let res = ( await ingestionClient . saveObjectsWithTransformation ( {
192
+ indexName : 'foo' ,
193
+ objects : [ { objectID : 'bar' , baz : 42 } ] ,
194
+ waitForTasks : true ,
183
195
} ) ) as unknown as EchoResponse ;
184
196
185
- expect ( res1 . headers ) . toEqual (
197
+ expect ( res . headers ) . toEqual (
186
198
expect . objectContaining ( {
187
199
'x-algolia-application-id' : 'APP_ID' ,
188
200
'x-algolia-api-key' : 'API_KEY' ,
189
201
} ) ,
190
202
) ;
191
- expect ( res2 . headers ) . toEqual (
192
- expect . objectContaining ( {
193
- 'x-algolia-application-id' : 'APP_ID' ,
194
- 'x-algolia-api-key' : 'API_KEY' ,
195
- } ) ,
196
- ) ;
197
- expect ( res3 . headers ) . toEqual (
198
- expect . objectContaining ( {
199
- 'x-algolia-application-id' : 'APP_ID' ,
200
- 'x-algolia-api-key' : 'API_KEY' ,
201
- } ) ,
202
- ) ;
203
- expect ( res4 . headers ) . toEqual (
203
+ expect ( res . url . startsWith ( 'https://data.us.algolia.com/2/tasks/foo/push?watch=true' ) ) . toBeTruthy ( ) ;
204
+ expect ( res . data ) . toEqual ( {
205
+ action : 'addObject' ,
206
+ records : [
207
+ {
208
+ baz : 42 ,
209
+ objectID : 'bar' ,
210
+ } ,
211
+ ] ,
212
+ } ) ;
213
+ expect ( ingestionClient . partialUpdateObjectsWithTransformation ) . not . toBeUndefined ( ) ;
214
+
215
+ res = ( await ingestionClient . partialUpdateObjectsWithTransformation ( {
216
+ indexName : 'foo' ,
217
+ objects : [ { objectID : 'bar' , baz : 42 } ] ,
218
+ waitForTasks : true ,
219
+ createIfNotExists : true ,
220
+ } ) ) as unknown as EchoResponse ;
221
+
222
+ expect ( res . headers ) . toEqual (
204
223
expect . objectContaining ( {
205
224
'x-algolia-application-id' : 'APP_ID' ,
206
225
'x-algolia-api-key' : 'API_KEY' ,
207
226
} ) ,
208
227
) ;
209
- } ) ;
210
-
211
- test ( '`init` clients accept different credentials' , async ( ) => {
212
- const abtestingClient = client . initAbtesting ( {
213
- appId : 'appId1' ,
214
- apiKey : 'apiKey1' ,
215
- options : { requester : browserEchoRequester ( ) } ,
216
- } ) ;
217
- const analyticsClient = client . initAnalytics ( {
218
- appId : 'appId2' ,
219
- apiKey : 'apiKey2' ,
220
- options : { requester : browserEchoRequester ( ) } ,
221
- } ) ;
222
- const personalizationClient = client . initPersonalization ( {
223
- appId : 'appId3' ,
224
- apiKey : 'apiKey3' ,
225
- region : 'eu' ,
226
- options : { requester : browserEchoRequester ( ) } ,
227
- } ) ;
228
- const recommendClient = client . initRecommend ( {
229
- appId : 'appId4' ,
230
- apiKey : 'apiKey4' ,
231
- options : { requester : browserEchoRequester ( ) } ,
228
+ expect ( res . url . startsWith ( 'https://data.us.algolia.com/2/tasks/foo/push?watch=true' ) ) . toBeTruthy ( ) ;
229
+ expect ( res . data ) . toEqual ( {
230
+ action : 'partialUpdateObject' ,
231
+ records : [
232
+ {
233
+ baz : 42 ,
234
+ objectID : 'bar' ,
235
+ } ,
236
+ ] ,
232
237
} ) ;
233
238
234
- const res1 = ( await abtestingClient . customGet ( {
235
- path : 'abtestingClient' ,
236
- } ) ) as unknown as EchoResponse ;
237
- const res2 = ( await analyticsClient . customGet ( {
238
- path : 'analyticsClient' ,
239
- } ) ) as unknown as EchoResponse ;
240
- const res3 = ( await personalizationClient . customGet ( {
241
- path : 'personalizationClient' ,
242
- } ) ) as unknown as EchoResponse ;
243
- const res4 = ( await recommendClient . customGet ( {
244
- path : 'recommendClient' ,
239
+ res = ( await ingestionClient . partialUpdateObjectsWithTransformation ( {
240
+ indexName : 'foo' ,
241
+ objects : [ { objectID : 'bar' , baz : 42 } ] ,
242
+ waitForTasks : true ,
245
243
} ) ) as unknown as EchoResponse ;
246
244
247
- expect ( res1 . headers ) . toEqual (
248
- expect . objectContaining ( {
249
- 'x-algolia-application-id' : 'appId1' ,
250
- 'x-algolia-api-key' : 'apiKey1' ,
251
- } ) ,
252
- ) ;
253
- expect ( res2 . headers ) . toEqual (
254
- expect . objectContaining ( {
255
- 'x-algolia-application-id' : 'appId2' ,
256
- 'x-algolia-api-key' : 'apiKey2' ,
257
- } ) ,
258
- ) ;
259
- expect ( res3 . headers ) . toEqual (
245
+ expect ( res . headers ) . toEqual (
260
246
expect . objectContaining ( {
261
- 'x-algolia-application-id' : 'appId3' ,
262
- 'x-algolia-api-key' : 'apiKey3' ,
263
- } ) ,
264
- ) ;
265
- expect ( res4 . headers ) . toEqual (
266
- expect . objectContaining ( {
267
- 'x-algolia-application-id' : 'appId4' ,
268
- 'x-algolia-api-key' : 'apiKey4' ,
247
+ 'x-algolia-application-id' : 'APP_ID' ,
248
+ 'x-algolia-api-key' : 'API_KEY' ,
269
249
} ) ,
270
250
) ;
251
+ expect ( res . url . startsWith ( 'https://data.us.algolia.com/2/tasks/foo/push?watch=true' ) ) . toBeTruthy ( ) ;
252
+ expect ( res . data ) . toEqual ( {
253
+ action : 'partialUpdateObjectNoCreate' ,
254
+ records : [
255
+ {
256
+ baz : 42 ,
257
+ objectID : 'bar' ,
258
+ } ,
259
+ ] ,
260
+ } ) ;
271
261
} ) ;
272
262
} ) ;
273
263
} ) ;
0 commit comments