diff --git a/src/test/SessionManager.spec.ts b/src/test/SessionManager.spec.ts index 2af3855..c818d4f 100644 --- a/src/test/SessionManager.spec.ts +++ b/src/test/SessionManager.spec.ts @@ -1,7 +1,9 @@ import { SessionManager } from '../SessionManager' -import * as dotenv from 'dotenv' import { RequestClient } from '../request/RequestClient' +import { NoSessionStateError } from '../types/errors' +import * as dotenv from 'dotenv' import axios from 'axios' + jest.mock('axios') const mockedAxios = axios as jest.Mocked @@ -43,4 +45,38 @@ describe('SessionManager', () => { ).resolves.toEqual(expectedResponse) }) }) + + describe('waitForSession', () => { + it('should reject with NoSessionStateError if SAS server did not provide session state', async () => { + const responseStatus = 304 + + mockedAxios.get.mockImplementation(() => + Promise.resolve({ data: '', status: responseStatus }) + ) + + await expect( + sessionManager['waitForSession']( + { + id: 'id', + state: '', + links: [ + { rel: 'state', href: '', uri: '', type: '', method: 'GET' } + ], + attributes: { + sessionInactiveTimeout: 0 + }, + creationTimeStamp: '' + }, + null, + 'access_token' + ) + ).rejects.toEqual( + new NoSessionStateError( + responseStatus, + process.env.SERVER_URL as string, + 'logUrl' + ) + ) + }) + }) })