Skip to content

Commit

Permalink
PRMDR-701: Add feature flag checks to enable ARF workflow (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
abbas-khan10 authored Feb 28, 2024
1 parent dd5c3b0 commit ef57feb
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ describe('GP Workflow: Patient search and verify', () => {
active: false,
};

const featureFlags = {
uploadArfWorkflowEnabled: 'true',
uploadLambdaEnabled: 'true',
};

gpRoles.forEach((role) => {
beforeEach(() => {
cy.intercept('GET', '/FeatureFlags*', {
statusCode: 200,
body: featureFlags,
}).as('featureFlags');

cy.login(role);
cy.visit(searchPatientUrl);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const patient = {
active: false,
};

const featureFlags = {
uploadArfWorkflowEnabled: 'true',
uploadLambdaEnabled: 'true',
};

const bucketUrlIdentifer = 'document-store.s3.amazonaws.com';
const serverError = 500;
const successNoContent = 204;
Expand Down Expand Up @@ -91,6 +96,11 @@ const gpRoles = [Roles.GP_ADMIN, Roles.GP_CLINICAL];
describe('GP Workflow: Upload docs and verify', () => {
gpRoles.forEach((role) => {
beforeEach(() => {
cy.intercept('GET', '**/FeatureFlags**', {
statusCode: 200,
body: featureFlags,
}).as('featureFlags');

cy.login(role);
navigateToUploadPage();
});
Expand Down
82 changes: 68 additions & 14 deletions app/src/pages/uploadDocumentsPage/UploadDocumentsPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import UploadDocumentsPage from './UploadDocumentsPage';
import usePatient from '../../helpers/hooks/usePatient';
import { buildPatientDetails } from '../../helpers/test/testBuilders';
import { buildConfig } from '../../helpers/test/testBuilders';
import { UPLOAD_STAGE } from '../../types/pages/UploadDocumentsPage/types';
import { useState } from 'react';
jest.mock('../../helpers/hooks/useBaseAPIHeaders');
jest.mock('../../helpers/hooks/useBaseAPIUrl');
jest.mock('../../helpers/hooks/usePatient');
jest.mock('react-router');
const mockedUsePatient = usePatient as jest.Mock;
import useConfig from '../../helpers/hooks/useConfig';
import { routes } from '../../types/generic/routes';

const mockUseState = useState as jest.Mock;
const mockConfigContext = useConfig as jest.Mock;
const mockedUseNavigate = jest.fn();

const mockPatient = buildPatientDetails();
jest.mock('react-router', () => ({
useNavigate: () => mockedUseNavigate,
useLocation: () => jest.fn(),
}));
jest.mock('react', () => ({
...jest.requireActual('react'),
useState: jest.fn(),
Expand All @@ -25,39 +27,91 @@ jest.mock('../../components/blocks/_arf/uploadingStage/UploadingStage', () => ()
jest.mock('../../components/blocks/_arf/completeStage/CompleteStage', () => () => (
<h1>Mock complete stage</h1>
));
jest.mock('../../helpers/hooks/useConfig');

describe('UploadDocumentsPage', () => {
beforeEach(() => {
process.env.REACT_APP_ENVIRONMENT = 'jest';
mockedUsePatient.mockReturnValue(mockPatient);
mockConfigContext.mockReturnValue(
buildConfig({}, { uploadArfWorkflowEnabled: true, uploadLambdaEnabled: true }),
);
mockUseState.mockImplementation(() => [UPLOAD_STAGE.Selecting, jest.fn()]);
});
afterEach(() => {
jest.clearAllMocks();
});
describe('Rendering', () => {
it('renders initial file input stage', () => {
it('renders initial file input stage', async () => {
render(<UploadDocumentsPage />);

expect(
screen.getByRole('heading', { name: 'Mock file input stage' }),
).toBeInTheDocument();
await waitFor(() => {
expect(mockedUseNavigate).not.toHaveBeenCalledWith(routes.UNAUTHORISED);
});
});

it('renders uploading stage when state is set', () => {
it('renders uploading stage when state is set', async () => {
mockUseState.mockImplementation(() => [UPLOAD_STAGE.Uploading, jest.fn()]);

render(<UploadDocumentsPage />);

expect(
screen.getByRole('heading', { name: 'Mock files are uploading stage' }),
).toBeInTheDocument();
await waitFor(() => {
expect(mockedUseNavigate).not.toHaveBeenCalledWith(routes.UNAUTHORISED);
});
});

it('renders upload complete stage when state is set', () => {
it('renders upload complete stage when state is set', async () => {
mockUseState.mockImplementation(() => [UPLOAD_STAGE.Complete, jest.fn()]);

render(<UploadDocumentsPage />);

expect(
screen.getByRole('heading', { name: 'Mock complete stage' }),
).toBeInTheDocument();
await waitFor(() => {
expect(mockedUseNavigate).not.toHaveBeenCalledWith(routes.UNAUTHORISED);
});
});
});

describe('Navigation', () => {
it('redirects to unauthorised page if arf workflow feature toggled off', async () => {
mockConfigContext.mockReturnValue(
buildConfig({}, { uploadArfWorkflowEnabled: true, uploadLambdaEnabled: false }),
);

render(<UploadDocumentsPage />);

await waitFor(() => {
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.UNAUTHORISED);
});
});
it('redirects to unauthorised page if upload lambda feature toggled off', async () => {
mockConfigContext.mockReturnValue(
buildConfig({}, { uploadArfWorkflowEnabled: true, uploadLambdaEnabled: false }),
);

render(<UploadDocumentsPage />);

await waitFor(() => {
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.UNAUTHORISED);
});
});
it('redirects to unauthorised page if both features toggled off', async () => {
mockConfigContext.mockReturnValue(
buildConfig({}, { uploadArfWorkflowEnabled: false, uploadLambdaEnabled: false }),
);

render(<UploadDocumentsPage />);

await waitFor(() => {
expect(mockedUseNavigate).toHaveBeenCalledWith(routes.UNAUTHORISED);
});
});
});
describe('Navigation', () => {});
});
24 changes: 23 additions & 1 deletion app/src/pages/uploadDocumentsPage/UploadDocumentsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import React, { useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { UPLOAD_STAGE, UploadDocument } from '../../types/pages/UploadDocumentsPage/types';
import SelectStage from '../../components/blocks/_arf/selectStage/SelectStage';
import UploadingStage from '../../components/blocks/_arf/uploadingStage/UploadingStage';
import CompleteStage from '../../components/blocks/_arf/completeStage/CompleteStage';
import { routes } from '../../types/generic/routes';
import { useNavigate } from 'react-router';
import useConfig from '../../helpers/hooks/useConfig';

function UploadDocumentsPage() {
const [stage, setStage] = useState<UPLOAD_STAGE>(UPLOAD_STAGE.Selecting);
const [documents, setDocuments] = useState<Array<UploadDocument>>([]);
const config = useConfig();
const navigate = useNavigate();

const mounted = useRef(false);
useEffect(() => {
const onPageLoad = () => {
if (
!config.featureFlags.uploadArfWorkflowEnabled ||
!config.featureFlags.uploadLambdaEnabled
) {
navigate(routes.UNAUTHORISED);
}
};

if (!mounted.current) {
mounted.current = true;
onPageLoad();
}
}, [navigate, config]);

if (stage === UPLOAD_STAGE.Selecting) {
return (
Expand Down

0 comments on commit ef57feb

Please sign in to comment.