Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/clients/src/scw/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/clients/src/scw/client-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -112,11 +112,11 @@ export const assertValidSettings = (obj: Readonly<Settings>): 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`,
)
Expand Down
Loading