diff --git a/src/test/RequestClient.spec.ts b/src/test/RequestClient.spec.ts index 6a64e83..9f8ec7d 100644 --- a/src/test/RequestClient.spec.ts +++ b/src/test/RequestClient.spec.ts @@ -5,8 +5,14 @@ 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 { + LoginRequiredError, + AuthorizeError, + NotFoundError, + InternalServerError +} from '../types/errors' import { prefixMessage } from '@sasjs/utils/error' +import { RequestClient } from '../request/RequestClient' const axiosActual = jest.requireActual('axios') @@ -64,6 +70,107 @@ describe('RequestClient', () => { ) ) }) + + describe('handleError', () => { + const requestClient = new RequestClient('https://localhost:8009') + const randomError = 'some error' + + it('should throw an error if could not get confirmUrl', async () => { + const authError = new AuthorizeError('message', 'confirm_url') + + jest + .spyOn(requestClient['httpClient'], 'get') + .mockImplementation(() => Promise.reject(randomError)) + + await expect( + requestClient['handleError'](authError, () => {}) + ).rejects.toEqual(`Error while getting error confirmUrl. ${randomError}`) + }) + + it('should throw an error if authorize form is required', async () => { + const authError = new AuthorizeError('message', 'confirm_url') + + jest + .spyOn(requestClient['httpClient'], 'get') + .mockImplementation(() => + Promise.resolve({ data: '