Skip to content

Commit

Permalink
full test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tlangs committed Mar 20, 2024
1 parent c2ec60e commit 9d34969
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 197 deletions.
12 changes: 6 additions & 6 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
28 changes: 14 additions & 14 deletions config/dev.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
{
"agoraUrlRoot": "https://agora.dsde-dev.broadinstitute.org",
"agoraUrlRoot": "https://agora.sehsan-oauth-logout.bee.envs-terra.bio",
"bardRoot": "https://terra-bard-dev.appspot.com",
"billingProfileManagerUrlRoot": "https://bpm.dsde-dev.broadinstitute.org",
"bondUrlRoot": "https://bond.dsde-dev.broadinstitute.org",
"calhounUrlRoot": "https://calhoun.dsde-dev.broadinstitute.org",
"catalogUrlRoot": "https://catalog.dsde-dev.broadinstitute.org",
"billingProfileManagerUrlRoot": "https://bpm.sehsan-oauth-logout.bee.envs-terra.bio",
"bondUrlRoot": "https://bond.sehsan-oauth-logout.bee.envs-terra.bio",
"calhounUrlRoot": "https://calhoun.sehsan-oauth-logout.bee.envs-terra.bio",
"catalogUrlRoot": "https://catalog.sehsan-oauth-logout.bee.envs-terra.bio",
"dataRepoUrlRoot": "https://jade.datarepo-dev.broadinstitute.org",
"devUrlRoot": "https://bvdp-saturn-dev.appspot.com",
"dockstoreUrlRoot": "https://staging.dockstore.org",
"drsHubUrlRoot": "https://drshub.dsde-dev.broadinstitute.org",
"drsHubUrlRoot": "https://drshub.sehsan-oauth-logout.bee.envs-terra.bio",
"externalCreds": {
"providers": ["ras", "github"],
"urlRoot": "https://externalcreds.dsde-dev.broadinstitute.org"
"urlRoot": "https://externalcreds.sehsan-oauth-logout.bee.envs-terra.bio"
},
"firecloudBucketRoot": "https://storage.googleapis.com/firecloud-alerts-dev",
"firecloudUrlRoot": "https://firecloud.dsde-dev.broadinstitute.org",
"firecloudUrlRoot": "https://firecloud.sehsan-oauth-logout.bee.envs-terra.bio",
"isProd": false,
"jobManagerUrlRoot": "https://job-manager.dsde-dev.broadinstitute.org/jobs",
"leoUrlRoot": "https://leonardo.dsde-dev.broadinstitute.org",
"orchestrationUrlRoot": "https://firecloud-orchestration.dsde-dev.broadinstitute.org",
"rawlsUrlRoot": "https://rawls.dsde-dev.broadinstitute.org",
"jobManagerUrlRoot": "https://job-manager.sehsan-oauth-logout.bee.envs-terra.bio/jobs",
"leoUrlRoot": "https://leonardo.sehsan-oauth-logout.bee.envs-terra.bio",
"orchestrationUrlRoot": "https://firecloudorch.sehsan-oauth-logout.bee.envs-terra.bio",
"rawlsUrlRoot": "https://rawls.sehsan-oauth-logout.bee.envs-terra.bio",
"rexUrlRoot": "https://terra-rex-dev.appspot.com",
"samUrlRoot": "https://sam.dsde-dev.broadinstitute.org",
"samUrlRoot": "https://sam.sehsan-oauth-logout.bee.envs-terra.bio",
"shibbolethUrlRoot": "https://broad-shibboleth-prod.appspot.com/dev",
"workspaceManagerUrlRoot": "https://workspace.dsde-dev.broadinstitute.org",
"workspaceManagerUrlRoot": "https://workspace.sehsan-oauth-logout.bee.envs-terra.bio",
"tCell": {
"appId": "saturnnonprod-O9lUP",
"apiKey": "AQEBBAEkx4iE2KxNyI7Wx08EwU1ycTM7E4FMSmaibbMUQxNU6uQvuAJt7fyABAtFYSYfgEE"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"keycode-js": "^3.1.0",
"lodash": "^4.17.21",
"marked": "^4.0.10",
"oidc-client-ts": "^2.0.4",
"oidc-client-ts": "^2.4.0",
"outdated-browser-rework": "^3.0.1",
"path-to-regexp": "^5.0.0",
"pluralize": "^8.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/auth/AuthContainer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ReactNode } from 'react';
import { h } from 'react-hyperscript-helpers';
import { Logout } from 'src/auth/Logout';
import { fixedSpinnerOverlay } from 'src/components/common';
import { useRoute } from 'src/libs/nav';
import { useStore } from 'src/libs/react-utils';
Expand All @@ -22,6 +23,7 @@ const AuthContainer = ({ children }) => {
const authspinner = () => fixedSpinnerOverlay;

return Utils.cond<ReactNode>(
[name === 'logout-callback', () => h(Logout)],
[signInStatus === 'uninitialized' && !isPublic, authspinner],
[signInStatus === 'signedOut' && !isPublic, () => h(SignIn)],
[userMustRegister, () => h(Register)],
Expand Down
41 changes: 41 additions & 0 deletions src/auth/Logout.test.tsx
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 { Logout } from 'src/auth/Logout';
import { OidcUser } from 'src/auth/oidc-broker';
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('Logout', () => {
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(<Logout />);
// 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([]);
});
});
20 changes: 10 additions & 10 deletions src/auth/Logout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import FooterWrapper from 'src/components/FooterWrapper';
import TopBar from 'src/components/TopBar';
import { userSignedOut } from 'src/auth/auth-events/signout';
import * as Nav from 'src/libs/nav';

export const logoutCallbackLinkName = 'logout-callback';
const Logout = () => {
return (
<FooterWrapper>
<TopBar title="Logout" href={undefined}>
<div />
</TopBar>
</FooterWrapper>
);
export const Logout = () => {
try {
userSignedOut();
} catch (e) {
console.error(e);
}
Nav.goToPath('root');
return <div />;
};

export const navPaths = [
Expand Down
119 changes: 0 additions & 119 deletions src/auth/auth-events/logout.test.ts

This file was deleted.

Loading

0 comments on commit 9d34969

Please sign in to comment.