1
- import { test , expect } from 'vitest' ;
1
+ /* eslint no-console: 0 */
2
2
3
- import { algoliasearch , apiClientVersion } from '../builds/node ' ;
3
+ import { vi , test , expect } from 'vitest ' ;
4
4
5
- const client = algoliasearch ( 'APP_ID' , 'API_KEY' ) ;
5
+ import { LogLevelEnum } from '../../client-common/src/types' ;
6
+ import { createConsoleLogger } from '../../logger-console/src/logger' ;
7
+ import { algoliasearch , apiClientVersion } from '../builds/node' ;
6
8
7
9
test ( 'sets the ua' , ( ) => {
10
+ const client = algoliasearch ( 'APP_ID' , 'API_KEY' ) ;
8
11
expect ( client . transporter . algoliaAgent ) . toEqual ( {
9
12
add : expect . any ( Function ) ,
10
13
value : expect . stringContaining (
@@ -14,10 +17,28 @@ test('sets the ua', () => {
14
17
} ) ;
15
18
16
19
test ( 'forwards node search helpers' , ( ) => {
20
+ const client = algoliasearch ( 'APP_ID' , 'API_KEY' ) ;
17
21
expect ( client . generateSecuredApiKey ) . not . toBeUndefined ( ) ;
18
22
expect ( client . getSecuredApiKeyRemainingValidity ) . not . toBeUndefined ( ) ;
19
23
expect ( ( ) => {
20
24
const resp = client . generateSecuredApiKey ( { parentApiKey : 'foo' , restrictions : { validUntil : 200 } } ) ;
21
25
client . getSecuredApiKeyRemainingValidity ( { securedApiKey : resp } ) ;
22
26
} ) . not . toThrow ( ) ;
23
27
} ) ;
28
+
29
+ test ( 'with logger' , ( ) => {
30
+ vi . spyOn ( console , 'debug' ) ;
31
+ vi . spyOn ( console , 'info' ) ;
32
+ vi . spyOn ( console , 'error' ) ;
33
+
34
+ const client = algoliasearch ( 'APP_ID' , 'API_KEY' , {
35
+ logger : createConsoleLogger ( LogLevelEnum . Debug ) ,
36
+ } ) ;
37
+
38
+ expect ( async ( ) => {
39
+ await client . setSettings ( { indexName : 'foo' , indexSettings : { } } ) ;
40
+ expect ( console . debug ) . toHaveBeenCalledTimes ( 1 ) ;
41
+ expect ( console . info ) . toHaveBeenCalledTimes ( 1 ) ;
42
+ expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
43
+ } ) . not . toThrow ( ) ;
44
+ } ) ;
0 commit comments