mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-08 04:50:06 +00:00
test(session): added test to cover 304 response
This commit is contained in:
@@ -3,6 +3,7 @@ import { RequestClient } from '../request/RequestClient'
|
|||||||
import { NoSessionStateError } from '../types/errors'
|
import { NoSessionStateError } from '../types/errors'
|
||||||
import * as dotenv from 'dotenv'
|
import * as dotenv from 'dotenv'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import { Logger, LogLevel } from '@sasjs/utils'
|
||||||
|
|
||||||
jest.mock('axios')
|
jest.mock('axios')
|
||||||
const mockedAxios = axios as jest.Mocked<typeof axios>
|
const mockedAxios = axios as jest.Mocked<typeof axios>
|
||||||
@@ -47,12 +48,26 @@ describe('SessionManager', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('waitForSession', () => {
|
describe('waitForSession', () => {
|
||||||
it('should reject with NoSessionStateError if SAS server did not provide session state', async () => {
|
beforeEach(() => {
|
||||||
const responseStatus = 304
|
;(process as any).logger = new Logger(LogLevel.Off)
|
||||||
|
})
|
||||||
|
|
||||||
mockedAxios.get.mockImplementation(() =>
|
it('should reject with NoSessionStateError if SAS server did not provide session state', async () => {
|
||||||
Promise.resolve({ data: '', status: responseStatus })
|
let requestAttempt = 0
|
||||||
)
|
|
||||||
|
mockedAxios.get.mockImplementation(() => {
|
||||||
|
requestAttempt += 1
|
||||||
|
|
||||||
|
if (requestAttempt > 10) {
|
||||||
|
return Promise.resolve({ data: 'idle', status: 200 })
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve({ data: '', status: 304 })
|
||||||
|
})
|
||||||
|
|
||||||
|
mockedAxios
|
||||||
|
|
||||||
|
jest.spyOn((process as any).logger, 'info')
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
sessionManager['waitForSession'](
|
sessionManager['waitForSession'](
|
||||||
@@ -70,12 +85,11 @@ describe('SessionManager', () => {
|
|||||||
null,
|
null,
|
||||||
'access_token'
|
'access_token'
|
||||||
)
|
)
|
||||||
).rejects.toEqual(
|
).resolves.toEqual('idle')
|
||||||
new NoSessionStateError(
|
|
||||||
responseStatus,
|
expect((process as any).logger.info).toHaveBeenCalledTimes(1)
|
||||||
process.env.SERVER_URL as string,
|
expect((process as any).logger.info).toHaveBeenLastCalledWith(
|
||||||
'logUrl'
|
`Could not get session state. Server responded with 304 whilst checking state: ${process.env.SERVER_URL}`
|
||||||
)
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user