Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements URO-211 part B - link creation #221

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/app/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@ import {
useLocation,
} from 'react-router-dom';
import {
CollectionsList,
useAppSelector,
useFilteredParams,
usePageTracking,
} from '../common/hooks';
import {
CollectionDetail,
detailPath,
CollectionsList,
detailDataProductPath,
detailPath,
} from '../features/collections/Collections';
import Legacy, { LEGACY_BASE_ROUTE } from '../features/legacy/Legacy';
import PageNotFound from '../features/layout/PageNotFound';
import { Fallback } from '../features/legacy/IFrameFallback';
import Legacy, { LEGACY_BASE_ROUTE } from '../features/legacy/Legacy';
import Navigator, {
navigatorPath,
navigatorPathWithCategory,
} from '../features/navigator/Navigator';
import PageNotFound from '../features/layout/PageNotFound';
import ORCIDLinkConfirmLink from '../features/orcidlink/ConfirmLink';
import ORCIDLinkCreateLink from '../features/orcidlink/CreateLink';
import ORCIDLinkHome from '../features/orcidlink/Home';
import ORCIDLinkServiceError from '../features/orcidlink/ServiceError';
import ProfileWrapper from '../features/profile/Profile';
import Status from '../features/status/Status';
import {
useAppSelector,
useFilteredParams,
usePageTracking,
} from '../common/hooks';
import ORCIDLinkFeature from '../features/orcidlink';
import ORCIDLinkCreateLink from '../features/orcidlink/CreateLink';

export const LOGIN_ROUTE = '/legacy/login';
export const ROOT_REDIRECT_ROUTE = '/narratives';
Expand Down Expand Up @@ -82,11 +84,17 @@ const Routes: FC = () => {

{/* orcidlink */}
<Route path="/orcidlink">
<Route index element={<Authed element={<ORCIDLinkFeature />} />} />
<Route index element={<Authed element={<ORCIDLinkHome />} />} />
</Route>
<Route path="/orcidlink/link">
<Route index element={<Authed element={<ORCIDLinkCreateLink />} />} />
</Route>
<Route path="/orcidlink/linkcontinue/:sessionId">
<Route index element={<Authed element={<ORCIDLinkConfirmLink />} />} />
</Route>
<Route path="/orcidlink/error">
<Route index element={<Authed element={<ORCIDLinkServiceError />} />} />
</Route>

{/* IFrame Fallback Routes */}
<Route path="/fallback">
Expand Down
2 changes: 1 addition & 1 deletion src/common/api/utils/kbaseBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface JSONRPC20Body {
export interface JSONRPC20Error {
code: number;
message: string;
data: unknown;
data?: unknown;
}

export type JSONRPCBody = JSONRPC11Body | JSONRPC20Body;
Expand Down
94 changes: 94 additions & 0 deletions src/features/orcidlink/ConfirmLink/index.mockedapi.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { render, waitFor } from '@testing-library/react';
import { Provider } from 'react-redux';
import { MemoryRouter, Route, Routes } from 'react-router-dom';
import { createTestStore } from '../../../app/store';
import ORCIDLinkAPI from '../common/api/ORCIDLInkAPI';
import { INITIAL_STORE_STATE } from '../test/data';
import CreateLinkController from './index';

/**
* This set of tests focuses on artifically constructed error conditions. They
* use a jest spy to mock api methods. It seems that jest, at least the version
* in this codebase, does not or cannot reset the module level mocks, so these
* tests need to be separated from the others.
*/

describe('The ConfirmLink controller component (api mocks for errors)', () => {
beforeEach(() => {
// jest.resetAllMocks();
});
afterEach(() => {
jest.clearAllMocks();
});

it('renders the expected error message if the loading api calls return a non-JSON-RPC error', async () => {
// NB need to mock each call made, otherwise will get network errors in the
// test output (though tests will still pass).
// The calls are made in parallel (Promise.all), so there is no ensuring
// which one is called or completes first and triggers the Promise.all
// error. (Though in practice the first one, or perhaps the mocked one,
// fails first, as it does not invoke an actual network call, which consumes
// time.)
jest
.spyOn(ORCIDLinkAPI.prototype, 'getLinkingSession')
.mockImplementation(async () => {
throw new Error('Test Error');
});

jest.spyOn(ORCIDLinkAPI.prototype, 'info').mockImplementation(async () => {
throw new Error('Test Error');
});

const { container } = render(
<Provider store={createTestStore(INITIAL_STORE_STATE)}>
<MemoryRouter
initialEntries={['/orcidlink/linkcontinue/foo_session_error_1']}
>
<Routes>
<Route
path="/orcidlink/linkcontinue/:sessionId"
element={<CreateLinkController />}
/>{' '}
</Routes>
</MemoryRouter>
</Provider>
);

await waitFor(() => {
expect(container).toHaveTextContent('Test Error');
});
});

it('renders the expected error message if the loading api calls return a non-Error error', async () => {
jest
.spyOn(ORCIDLinkAPI.prototype, 'getLinkingSession')
.mockImplementation(async () => {
// eslint-disable-next-line no-throw-literal
throw 'Not A Real Error';
});

jest.spyOn(ORCIDLinkAPI.prototype, 'info').mockImplementation(async () => {
// eslint-disable-next-line no-throw-literal
throw 'Not A Real Error';
});

const { container } = render(
<Provider store={createTestStore(INITIAL_STORE_STATE)}>
<MemoryRouter
initialEntries={['/orcidlink/linkcontinue/foo_session_error_1']}
>
<Routes>
<Route
path="/orcidlink/linkcontinue/:sessionId"
element={<CreateLinkController />}
/>{' '}
</Routes>
</MemoryRouter>
</Provider>
);

await waitFor(() => {
expect(container).toHaveTextContent('Unknown error');
});
});
});
Loading
Loading