UNPKG

@vulog/aima-client

Version:

```bash npm i @vulog/aima-client ```

48 lines (43 loc) 1.57 kB
import { describe, test, vi, beforeEach, expect } from 'vitest'; import getClient from './getClient'; import { ClientOptions } from './types'; describe('getClient', () => { beforeEach(() => { vi.resetAllMocks(); }); test('create client', () => { const options: ClientOptions = { fleetId: 'fleetId', baseUrl: 'baseUrl', clientId: 'clientId', clientSecret: 'clientSecret', apiKey: 'apiKey', }; const client = getClient(options); expect(client.defaults.baseURL).toEqual(options.baseUrl); }); test('User-Agent should contain package version', () => { const options: ClientOptions = { fleetId: 'fleetId', baseUrl: 'baseUrl', clientId: 'clientId', clientSecret: 'clientSecret', apiKey: 'apiKey', }; const client = getClient(options); expect(client.defaults.headers['User-Agent']).toEqual(`aima-node/1.1.98 ${options.fleetId}`); }); test('User-Agent should use custom value when provided', () => { const customUserAgent = 'custom-user-agent/1.0'; const options: ClientOptions = { fleetId: 'fleetId', baseUrl: 'baseUrl', clientId: 'clientId', clientSecret: 'clientSecret', apiKey: 'apiKey', userAgent: customUserAgent, }; const client = getClient(options); expect(client.defaults.headers['User-Agent']).toEqual(customUserAgent); }); });