-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
587 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { OidcUser } from 'src/auth/oidc-broker'; | ||
import { SignOutPage } from 'src/auth/signout/SignOutPage'; | ||
import { authStore, azureCookieReadyStore, cookieReadyStore, metricStore, oidcStore, userStore } from 'src/libs/state'; | ||
|
||
type NavExports = typeof import('src/libs/nav'); | ||
jest.mock( | ||
'src/libs/nav', | ||
(): NavExports => ({ | ||
...jest.requireActual('src/libs/nav'), | ||
getCurrentUrl: jest.fn().mockReturnValue(new URL('https://app.terra.bio')), | ||
getLink: jest.fn().mockImplementation((_) => _), | ||
goToPath: jest.fn(), | ||
}) | ||
); | ||
|
||
describe('SignOutPage', () => { | ||
it('clears stores after being redirected to', () => { | ||
// Arrange | ||
cookieReadyStore.update(() => true); | ||
azureCookieReadyStore.update((state) => ({ ...state, readyForRuntime: true })); | ||
authStore.update((state) => ({ ...state, cookiesAccepted: true, nihStatusLoaded: true })); | ||
oidcStore.update((state) => ({ ...state, user: {} as OidcUser })); | ||
metricStore.update((state) => ({ ...state, anonymousId: '12345', sessionId: '67890' })); | ||
userStore.update((state) => ({ ...state, enterpriseFeatures: ['github-account-linking'] })); | ||
// Act | ||
render(<SignOutPage />); | ||
// Assert | ||
expect(cookieReadyStore.get()).toBe(false); | ||
expect(azureCookieReadyStore.get().readyForRuntime).toBe(false); | ||
// logout preserves cookiesAccepted | ||
expect(authStore.get().cookiesAccepted).toBe(true); | ||
expect(authStore.get().nihStatusLoaded).toBe(false); | ||
expect(oidcStore.get().user).toBeUndefined(); | ||
// logout preserves the anonymousId | ||
expect(metricStore.get().anonymousId).toBe('12345'); | ||
expect(metricStore.get().sessionId).toBeUndefined(); | ||
expect(userStore.get().enterpriseFeatures).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useEffect } from 'react'; | ||
import { userSignedOut } from 'src/auth/signout/sign-out'; | ||
import * as Nav from 'src/libs/nav'; | ||
|
||
export const signOutCallbackLinkName = 'signout-callback'; | ||
export const SignOutPage = () => { | ||
useEffect(() => { | ||
try { | ||
userSignedOut(); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
Nav.goToPath('root'); | ||
}, []); | ||
return null; | ||
}; | ||
|
||
export const navPaths = [ | ||
{ | ||
name: signOutCallbackLinkName, | ||
path: '/signout', | ||
component: SignOutPage, | ||
title: 'SignOut', | ||
}, | ||
]; |
Oops, something went wrong.