1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-03 18:50:05 +00:00

test(RequestClient): fix error handling

This commit is contained in:
Yury Shkoda
2021-12-21 11:40:59 +03:00
parent 2ebd6e11ba
commit 4197ad5aa8
3 changed files with 21 additions and 7 deletions

View File

@@ -5,6 +5,8 @@ import { app, mockedAuthResponse } from './SAS_server_app'
import { ServerType } from '@sasjs/utils'
import SASjs from '../SASjs'
import * as axiosModules from '../utils/createAxiosInstance'
import { LoginRequiredError } from '../types/errors'
import { prefixMessage } from '@sasjs/utils/error'
const axiosActual = jest.requireActual('axios')
@@ -55,8 +57,11 @@ describe('RequestClient', () => {
it('should response the POST method with Unauthorized', async () => {
await expect(
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
).rejects.toThrow(
'Error while getting access token. Request failed with status code 401'
).rejects.toEqual(
prefixMessage(
new LoginRequiredError(),
'Error while getting access token. '
)
)
})
})
@@ -132,8 +137,11 @@ describe('RequestClient - Self Signed Server', () => {
it('should response the POST method with Unauthorized', async () => {
await expect(
adapter.getAccessToken('clientId', 'clientSecret', 'incorrect')
).rejects.toThrow(
'Error while getting access token. Request failed with status code 401'
).rejects.toEqual(
prefixMessage(
new LoginRequiredError(),
'Error while getting access token. '
)
)
})
})