mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 12:30:06 +00:00
test: AuthManager specs are updated/removed
This commit is contained in:
@@ -101,46 +101,20 @@ describe('AuthManager', () => {
|
|||||||
loginForm: null
|
loginForm: null
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
jest
|
jest.spyOn(authManager, 'logOut')
|
||||||
.spyOn(authManager, 'logOut')
|
|
||||||
.mockImplementation(() => Promise.resolve(true))
|
|
||||||
|
|
||||||
jest
|
jest.spyOn<any, any>(authManager, 'getNewLoginForm')
|
||||||
.spyOn<any, any>(authManager, 'getNewLoginForm')
|
jest.spyOn<any, any>(authManager, 'sendLoginRequest')
|
||||||
.mockImplementation(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
name: 'test'
|
|
||||||
})
|
|
||||||
)
|
|
||||||
mockedAxios.post.mockImplementation(() =>
|
|
||||||
Promise.resolve({ data: mockLoginSuccessResponse })
|
|
||||||
)
|
|
||||||
|
|
||||||
const loginResponse = await authManager.logIn(userName, password)
|
const loginResponse = await authManager.logIn(userName, password)
|
||||||
|
|
||||||
expect(loginResponse.isLoggedIn).toBeTruthy()
|
expect(loginResponse.isLoggedIn).toBeTruthy()
|
||||||
expect(loginResponse.userName).toEqual(userName)
|
expect(loginResponse.userName).toEqual(userName)
|
||||||
|
|
||||||
const loginParams = serialize({
|
|
||||||
_service: 'default',
|
|
||||||
username: userName,
|
|
||||||
password,
|
|
||||||
name: 'test'
|
|
||||||
})
|
|
||||||
expect(authCallback).toHaveBeenCalledTimes(1)
|
expect(authCallback).toHaveBeenCalledTimes(1)
|
||||||
expect(authManager.logOut).toHaveBeenCalledTimes(1)
|
expect(authManager.logOut).toHaveBeenCalledTimes(0)
|
||||||
expect(authManager['getNewLoginForm']).toHaveBeenCalledTimes(1)
|
expect(authManager['getNewLoginForm']).toHaveBeenCalledTimes(0)
|
||||||
expect(mockedAxios.post).toHaveBeenCalledWith(
|
expect(authManager['sendLoginRequest']).toHaveBeenCalledTimes(0)
|
||||||
`/SASLogon/login`,
|
|
||||||
loginParams,
|
|
||||||
{
|
|
||||||
withCredentials: true,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
Accept: '*/*'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
expect(authCallback).toHaveBeenCalledTimes(1)
|
expect(authCallback).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -567,43 +541,8 @@ describe('AuthManager', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('return session information when logged in - SAS9', async () => {
|
|
||||||
// username cannot have `-` and cannot be uppercased
|
|
||||||
const username = 'testusername'
|
|
||||||
const serverType = ServerType.Sas9
|
|
||||||
const authManager = new AuthManager(
|
|
||||||
serverUrl,
|
|
||||||
serverType,
|
|
||||||
requestClient,
|
|
||||||
authCallback
|
|
||||||
)
|
|
||||||
mockedAxios.get.mockImplementation(() =>
|
|
||||||
Promise.resolve({
|
|
||||||
data: `"title":"Log Off ${username}","url":"javascript: clearFrame(\"/SASStoredProcess/do?_action=logoff\")"' })`
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
const response = await authManager.checkSession()
|
|
||||||
expect(response.isLoggedIn).toBeTruthy()
|
|
||||||
expect(response.userName).toEqual(username)
|
|
||||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
|
||||||
1,
|
|
||||||
`http://test-server.com/SASStoredProcess`,
|
|
||||||
{
|
|
||||||
withCredentials: true,
|
|
||||||
responseType: 'text',
|
|
||||||
transformResponse: undefined,
|
|
||||||
headers: {
|
|
||||||
Accept: '*/*',
|
|
||||||
'Content-Type': 'text/plain'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('return session information when logged in - SAS9 - having full name in html', async () => {
|
it('return session information when logged in - SAS9 - having full name in html', async () => {
|
||||||
const fullname = 'FirstName LastName'
|
const fullname = 'FirstName LastName'
|
||||||
const username = 'firlas'
|
|
||||||
const serverType = ServerType.Sas9
|
const serverType = ServerType.Sas9
|
||||||
const authManager = new AuthManager(
|
const authManager = new AuthManager(
|
||||||
serverUrl,
|
serverUrl,
|
||||||
@@ -619,7 +558,8 @@ describe('AuthManager', () => {
|
|||||||
|
|
||||||
const response = await authManager.checkSession()
|
const response = await authManager.checkSession()
|
||||||
expect(response.isLoggedIn).toBeTruthy()
|
expect(response.isLoggedIn).toBeTruthy()
|
||||||
expect(response.userName).toEqual(username)
|
expect(response.userName).toEqual('')
|
||||||
|
expect(response.userLongName).toEqual(fullname)
|
||||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
`http://test-server.com/SASStoredProcess`,
|
`http://test-server.com/SASStoredProcess`,
|
||||||
|
|||||||
Reference in New Issue
Block a user