Skip to content

feat: add Api Base URL option to client #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2021
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
4 changes: 3 additions & 1 deletion src/create-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const clientConstructor = ({ token, ...options }: Typeform.ClientArg = {}
...otherArgs
} = args

const requestUrl = buildUrlWithParams(`${API_BASE_URL}${url}`, params)
const { apiBaseUrl } = options
const requestApiBaseUrl = apiBaseUrl || API_BASE_URL
const requestUrl = buildUrlWithParams(`${requestApiBaseUrl}${url}`, params)

const { headers = {} } = options
const authorization = token ? { Authorization: `bearer ${token}` } : {}
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/create-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ test('falsy values should be passed', () => {
}
expect(buildUrlWithParams(url, params)).toBe('http://typeform.com?a=0&b=0')
})

test('Specify apiBaseUrl', async () => {


const rainbowApi = 'https://api.rainbow.typeform.com'

const clientWithApiBaseUrl = clientConstructor({
token: 'abc',
apiBaseUrl: rainbowApi
})

await clientWithApiBaseUrl.request({
url: '/forms',
method: 'get',
headers: {
Accepts: 'application/json'
}
})
expect(axios.history.get[0].url).toBe(`${rainbowApi}/forms`)
})