From a5c9f11c7535720c4bd047477b97130ab4cf7473 Mon Sep 17 00:00:00 2001 From: Yury Shkoda Date: Wed, 14 Jul 2021 14:17:20 +0300 Subject: [PATCH] test(session): cover case when could not get session state --- src/test/SessionManager.spec.ts | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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' + ) + ) + }) + }) })