mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-15 08:00:05 +00:00
test: added for verifySasLogin
This commit is contained in:
37
src/auth/spec/verifySas9Login.spec.ts
Normal file
37
src/auth/spec/verifySas9Login.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
import { verifySas9Login } from '../verifySas9Login'
|
||||||
|
import * as delayModule from '../../utils/delay'
|
||||||
|
|
||||||
|
describe('verifySas9Login', () => {
|
||||||
|
const serverUrl = 'http://test-server.com'
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
jest.mock('../../utils')
|
||||||
|
jest
|
||||||
|
.spyOn(delayModule, 'delay')
|
||||||
|
.mockImplementation(() => Promise.resolve({}))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return isLoggedIn true by checking state of popup', async () => {
|
||||||
|
const popup = {
|
||||||
|
window: {
|
||||||
|
location: { href: serverUrl + `/SASLogon/home` },
|
||||||
|
document: { body: { innerText: '<h3>You have signed in.</h3>' } }
|
||||||
|
}
|
||||||
|
} as unknown as Window
|
||||||
|
|
||||||
|
await expect(verifySas9Login(popup)).resolves.toEqual({
|
||||||
|
isLoggedIn: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return isLoggedIn false if user closed popup, already', async () => {
|
||||||
|
const popup: Window = { closed: true } as unknown as Window
|
||||||
|
|
||||||
|
await expect(verifySas9Login(popup)).resolves.toEqual({
|
||||||
|
isLoggedIn: false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
38
src/auth/spec/verifySasViyaLogin.spec.ts
Normal file
38
src/auth/spec/verifySasViyaLogin.spec.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
* @jest-environment jsdom
|
||||||
|
*/
|
||||||
|
import { verifySasViyaLogin } from '../verifySasViyaLogin'
|
||||||
|
import * as delayModule from '../../utils/delay'
|
||||||
|
|
||||||
|
describe('verifySasViyaLogin', () => {
|
||||||
|
const serverUrl = 'http://test-server.com'
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
jest.mock('../../utils')
|
||||||
|
jest
|
||||||
|
.spyOn(delayModule, 'delay')
|
||||||
|
.mockImplementation(() => Promise.resolve({}))
|
||||||
|
document.cookie = encodeURIComponent('Current-User={"userId":"user-hash"}')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return isLoggedIn true by checking state of popup', async () => {
|
||||||
|
const popup = {
|
||||||
|
window: {
|
||||||
|
location: { href: serverUrl + `/SASLogon/home` },
|
||||||
|
document: { body: { innerText: '<h3>You have signed in.</h3>' } }
|
||||||
|
}
|
||||||
|
} as unknown as Window
|
||||||
|
|
||||||
|
await expect(verifySasViyaLogin(popup)).resolves.toEqual({
|
||||||
|
isLoggedIn: true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return isLoggedIn false if user closed popup, already', async () => {
|
||||||
|
const popup: Window = { closed: true } as unknown as Window
|
||||||
|
|
||||||
|
await expect(verifySasViyaLogin(popup)).resolves.toEqual({
|
||||||
|
isLoggedIn: false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -19,7 +19,7 @@ export async function verifySasViyaLogin(loginPopup: Window): Promise<{
|
|||||||
await delay(1000)
|
await delay(1000)
|
||||||
if (loginPopup.closed) break
|
if (loginPopup.closed) break
|
||||||
isAuthorized =
|
isAuthorized =
|
||||||
!loginPopup.window.location.href.includes('SASLogon') ||
|
loginPopup.window.location.href.includes('SASLogon') ||
|
||||||
loginPopup.window.document.body?.innerText?.includes(
|
loginPopup.window.document.body?.innerText?.includes(
|
||||||
'You have signed in.'
|
'You have signed in.'
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user