-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(javascript): add logger-console package from v4 (generated)
algolia/api-clients-automation#3823 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
- Loading branch information
1 parent
7213be0
commit f3650d5
Showing
53 changed files
with
513 additions
and
34 deletions.
There are no files selected for viewing
27 changes: 24 additions & 3 deletions
27
packages/algoliasearch/__tests__/algoliasearch.browser.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
import { test, expect } from 'vitest'; | ||
/* eslint no-console: 0 */ | ||
|
||
import { algoliasearch, apiClientVersion } from '../builds/browser'; | ||
import { vi, test, expect } from 'vitest'; | ||
|
||
const client = algoliasearch('APP_ID', 'API_KEY'); | ||
import { LogLevelEnum } from '../../client-common/src/types'; | ||
import { createConsoleLogger } from '../../logger-console/src/logger'; | ||
import { algoliasearch, apiClientVersion } from '../builds/browser'; | ||
|
||
test('sets the ua', () => { | ||
const client = algoliasearch('APP_ID', 'API_KEY'); | ||
|
||
expect(client.transporter.algoliaAgent).toEqual({ | ||
add: expect.any(Function), | ||
value: expect.stringContaining( | ||
`Algolia for JavaScript (${apiClientVersion}); Search (${apiClientVersion}); Browser`, | ||
), | ||
}); | ||
}); | ||
|
||
test('with logger', () => { | ||
vi.spyOn(console, 'debug'); | ||
vi.spyOn(console, 'info'); | ||
vi.spyOn(console, 'error'); | ||
|
||
const client = algoliasearch('APP_ID', 'API_KEY', { | ||
logger: createConsoleLogger(LogLevelEnum.Debug), | ||
}); | ||
|
||
expect(async () => { | ||
await client.setSettings({ indexName: 'foo', indexSettings: {} }); | ||
expect(console.debug).toHaveBeenCalledTimes(1); | ||
expect(console.info).toHaveBeenCalledTimes(1); | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
}).not.toThrow(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 24 additions & 3 deletions
27
packages/algoliasearch/__tests__/algoliasearch.fetch.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
import { test, expect } from 'vitest'; | ||
/* eslint no-console: 0 */ | ||
|
||
import { algoliasearch, apiClientVersion } from '../builds/fetch'; | ||
import { vi, test, expect } from 'vitest'; | ||
|
||
const client = algoliasearch('APP_ID', 'API_KEY'); | ||
import { LogLevelEnum } from '../../client-common/src/types'; | ||
import { createConsoleLogger } from '../../logger-console/src/logger'; | ||
import { algoliasearch, apiClientVersion } from '../builds/fetch'; | ||
|
||
test('sets the ua', () => { | ||
const client = algoliasearch('APP_ID', 'API_KEY'); | ||
expect(client.transporter.algoliaAgent).toEqual({ | ||
add: expect.any(Function), | ||
value: expect.stringContaining(`Algolia for JavaScript (${apiClientVersion}); Search (${apiClientVersion}); Fetch`), | ||
}); | ||
}); | ||
|
||
test('forwards node search helpers', () => { | ||
const client = algoliasearch('APP_ID', 'API_KEY'); | ||
expect(client.generateSecuredApiKey).not.toBeUndefined(); | ||
expect(client.getSecuredApiKeyRemainingValidity).not.toBeUndefined(); | ||
expect(() => { | ||
const resp = client.generateSecuredApiKey({ parentApiKey: 'foo', restrictions: { validUntil: 200 } }); | ||
client.getSecuredApiKeyRemainingValidity({ securedApiKey: resp }); | ||
}).not.toThrow(); | ||
}); | ||
|
||
test('with logger', () => { | ||
vi.spyOn(console, 'debug'); | ||
vi.spyOn(console, 'info'); | ||
vi.spyOn(console, 'error'); | ||
|
||
const client = algoliasearch('APP_ID', 'API_KEY', { | ||
logger: createConsoleLogger(LogLevelEnum.Debug), | ||
}); | ||
|
||
expect(async () => { | ||
await client.setSettings({ indexName: 'foo', indexSettings: {} }); | ||
expect(console.debug).toHaveBeenCalledTimes(1); | ||
expect(console.info).toHaveBeenCalledTimes(1); | ||
expect(console.error).toHaveBeenCalledTimes(1); | ||
}).not.toThrow(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
export * from './src/createAuth'; | ||
export * from './src/createIterablePromise'; | ||
export * from './src/cache'; | ||
export * from './src/transporter'; | ||
export * from './src/constants'; | ||
export * from './src/createAlgoliaAgent'; | ||
export * from './src/createAuth'; | ||
export * from './src/createIterablePromise'; | ||
export * from './src/getAlgoliaAgent'; | ||
export * from './src/logger'; | ||
export * from './src/transporter'; | ||
export * from './src/types'; | ||
export * from './src/constants'; |
24 changes: 24 additions & 0 deletions
24
packages/client-common/src/__tests__/logger/null-logger.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint no-console: 0 */ | ||
|
||
import { vi, describe, test, expect } from 'vitest'; | ||
|
||
import { createNullLogger } from '../../logger'; | ||
|
||
describe('null logger', () => { | ||
test('has a null behavior', async () => { | ||
vi.resetAllMocks(); | ||
vi.spyOn(console, 'debug'); | ||
vi.spyOn(console, 'info'); | ||
vi.spyOn(console, 'error'); | ||
|
||
const logger = createNullLogger(); | ||
|
||
await logger.debug('foo', {}); | ||
await logger.info('foo', {}); | ||
await logger.error('foo', {}); | ||
|
||
expect(console.debug).toHaveBeenCalledTimes(0); | ||
expect(console.info).toHaveBeenCalledTimes(0); | ||
expect(console.error).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
Oops, something went wrong.