mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 12:30:06 +00:00
test(checkSession): extract username from server response
This commit is contained in:
@@ -3,6 +3,7 @@ import * as dotenv from 'dotenv'
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import {
|
import {
|
||||||
|
mockedCurrentUserApi,
|
||||||
mockLoginAuthoriseRequiredResponse,
|
mockLoginAuthoriseRequiredResponse,
|
||||||
mockLoginSuccessResponse
|
mockLoginSuccessResponse
|
||||||
} from './mockResponses'
|
} from './mockResponses'
|
||||||
@@ -89,6 +90,7 @@ describe('AuthManager', () => {
|
|||||||
jest.spyOn(authManager, 'checkSession').mockImplementation(() =>
|
jest.spyOn(authManager, 'checkSession').mockImplementation(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
|
userName: '',
|
||||||
loginForm: { name: 'test' }
|
loginForm: { name: 'test' }
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -167,11 +169,12 @@ describe('AuthManager', () => {
|
|||||||
authCallback
|
authCallback
|
||||||
)
|
)
|
||||||
mockedAxios.get.mockImplementation(() =>
|
mockedAxios.get.mockImplementation(() =>
|
||||||
Promise.resolve({ data: '<button onClick="logout">' })
|
Promise.resolve({ data: mockedCurrentUserApi(userName) })
|
||||||
)
|
)
|
||||||
|
|
||||||
const response = await authManager.checkSession()
|
const response = await authManager.checkSession()
|
||||||
expect(response.isLoggedIn).toBeTruthy()
|
expect(response.isLoggedIn).toBeTruthy()
|
||||||
|
expect(response.userName).toEqual(userName)
|
||||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
`http://test-server.com/identities/users/@currentUser`,
|
`http://test-server.com/identities/users/@currentUser`,
|
||||||
|
|||||||
@@ -22,3 +22,28 @@ export const generateToken = (timeToLiveSeconds: number): string => {
|
|||||||
const token = `${header}.${payload}.${signature}`
|
const token = `${header}.${payload}.${signature}`
|
||||||
return token
|
return token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const mockedCurrentUserApi = (username: string) => ({
|
||||||
|
creationTimeStamp: '2021-04-17T14:13:14.000Z',
|
||||||
|
modifiedTimeStamp: '2021-08-31T22:08:07.000Z',
|
||||||
|
id: username,
|
||||||
|
type: 'user',
|
||||||
|
name: 'Full User Name',
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
rel: 'self',
|
||||||
|
href: `/identities/users/${username}`,
|
||||||
|
uri: `/identities/users/${username}`,
|
||||||
|
type: 'user'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
method: 'GET',
|
||||||
|
rel: 'alternate',
|
||||||
|
href: `/identities/users/${username}`,
|
||||||
|
uri: `/identities/users/${username}`,
|
||||||
|
type: 'application/vnd.sas.summary'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
version: 2
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user