File tree 3 files changed +41
-4
lines changed
client-common/src/__tests__
3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,34 @@ describe('default preset', () => {
146
146
expect ( recommendation . transporter . userAgent ) . toBe ( client . transporter . userAgent ) ;
147
147
} ) ;
148
148
149
+ test ( 'allows clients to override credentials' , ( ) => {
150
+ const clientWithOptions = algoliasearch ( 'appId' , 'apiKey' ) ;
151
+
152
+ expect ( clientWithOptions . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'apiKey' ) ;
153
+
154
+ const analytics = clientWithOptions . initAnalytics ( {
155
+ apiKey : 'analytics' ,
156
+ } ) ;
157
+ const recommendation = clientWithOptions . initRecommendation ( {
158
+ apiKey : 'recommendation' ,
159
+ } ) ;
160
+
161
+ expect ( analytics . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'analytics' ) ;
162
+ expect ( recommendation . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'recommendation' ) ;
163
+ } ) ;
164
+
165
+ test ( 'allows clients to keep default credentials' , ( ) => {
166
+ const clientWithOptions = algoliasearch ( 'appId' , 'apiKey' ) ;
167
+
168
+ expect ( clientWithOptions . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'apiKey' ) ;
169
+
170
+ const analytics = clientWithOptions . initAnalytics ( ) ;
171
+ const recommendation = clientWithOptions . initRecommendation ( ) ;
172
+
173
+ expect ( analytics . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'apiKey' ) ;
174
+ expect ( recommendation . transporter . headers [ 'x-algolia-api-key' ] ) . toBe ( 'apiKey' ) ;
175
+ } ) ;
176
+
149
177
it ( 'can be destroyed' , ( ) => {
150
178
if ( ! testing . isBrowser ( ) ) {
151
179
expect ( client ) . toHaveProperty ( 'destroy' ) ;
Original file line number Diff line number Diff line change @@ -3,13 +3,22 @@ import { ClientTransporterOptions } from '@algolia/client-common';
3
3
import { RecommendationClientOptions } from '@algolia/client-recommendation' ;
4
4
import { SearchClientOptions } from '@algolia/client-search' ;
5
5
6
- export type WithoutCredentials < TClient > = Omit < TClient , 'appId' | 'apiKey' > ;
6
+ type Credentials = { readonly appId : string ; readonly apiKey : string } ;
7
+ export type WithoutCredentials < TClientOptions extends Credentials > = Omit <
8
+ TClientOptions ,
9
+ keyof Credentials
10
+ > ;
11
+ export type OptionalCredentials < TClientOptions extends Credentials > = Omit <
12
+ TClientOptions ,
13
+ keyof Credentials
14
+ > &
15
+ Pick < Partial < TClientOptions > , keyof Credentials > ;
7
16
8
17
export type AlgoliaSearchOptions = Partial < ClientTransporterOptions > &
9
18
WithoutCredentials < SearchClientOptions > ;
10
19
11
20
export type InitAnalyticsOptions = Partial < ClientTransporterOptions > &
12
- WithoutCredentials < AnalyticsClientOptions > ;
21
+ OptionalCredentials < AnalyticsClientOptions > ;
13
22
14
23
export type InitRecommendationOptions = Partial < ClientTransporterOptions > &
15
- WithoutCredentials < RecommendationClientOptions > ;
24
+ OptionalCredentials < RecommendationClientOptions > ;
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ export class TestSuite {
49
49
client . transporter . hosts = [ client . transporter . hosts [ 2 ] ] ;
50
50
51
51
// Also, since we are targeting always the same host, the
52
- // server may take a litle more than expected to answer.
52
+ // server may take a little more than expected to answer.
53
53
// To avoid timeouts we increase the timeouts duration
54
54
// @ts -ignore
55
55
client . transporter . timeouts = {
You can’t perform that action at this time.
0 commit comments