diff --git a/packages/clients/src/scw/__tests__/api.test.ts b/packages/clients/src/scw/__tests__/api.test.ts index 360b3d37b..7c8726045 100644 --- a/packages/clients/src/scw/__tests__/api.test.ts +++ b/packages/clients/src/scw/__tests__/api.test.ts @@ -3,13 +3,19 @@ import { API } from '../api' import { createClient } from '../client' class CustomAPI extends API { - getBaseURL = (): string => this.client.settings.apiURL + getBaseURL = (): string => { + if (!this.client.settings.apiURL) { + throw new Error('API URL is missing') + } + + return this.client.settings.apiURL + } } describe('API', () => { it('binds methods properly', () => { const api = new CustomAPI(createClient()) - // eslint-disable-next-line @typescript-eslint/unbound-method + const unboundMethod = api.getBaseURL expect(() => { unboundMethod() diff --git a/packages/clients/src/scw/__tests__/client-ini-factory.test.ts b/packages/clients/src/scw/__tests__/client-ini-factory.test.ts index 71f3029ea..3c90661fa 100644 --- a/packages/clients/src/scw/__tests__/client-ini-factory.test.ts +++ b/packages/clients/src/scw/__tests__/client-ini-factory.test.ts @@ -169,6 +169,9 @@ describe('withProfile', () => { }) it('modifies authentication', async () => { + if (!DEFAULT_SETTINGS.apiURL) { + throw new Error('API URL is missing') + } const request = new Request(DEFAULT_SETTINGS.apiURL) const reqInterceptor = withProfile({ accessKey: FILLED_PROFILE.accessKey, diff --git a/packages/clients/src/scw/client-settings.ts b/packages/clients/src/scw/client-settings.ts index f2fe7f49b..47b10fc94 100644 --- a/packages/clients/src/scw/client-settings.ts +++ b/packages/clients/src/scw/client-settings.ts @@ -10,14 +10,14 @@ import { isURL, isZone, } from '../internal/validations/string-validation' -import type { ProfileDefaultValues } from './client-ini-profile' +import type { Profile } from './client-ini-profile' /** * Holds default values of settings. * * @public */ -export type DefaultValues = ProfileDefaultValues & { +export type DefaultValues = Profile & { /** * The default number of results when requesting a paginated resource. */ @@ -112,11 +112,11 @@ export const assertValidSettings = (obj: Readonly): void => { } // API URL. - if (!isURL(obj.apiURL)) { + if (obj.apiURL && !isURL(obj.apiURL)) { throw new Error(`Invalid URL ${obj.apiURL}`) } - if (obj.apiURL.endsWith('/')) { + if (obj.apiURL?.endsWith('/')) { throw new Error( `Invalid URL ${obj.apiURL}: it should not have a trailing slash`, )