Skip to content

Commit

Permalink
Merge pull request #660 from ONSdigital/BLAIS5-4401
Browse files Browse the repository at this point in the history
Promote from BLAIS5-4401 to main
  • Loading branch information
lambeb authored Nov 1, 2024
2 parents ee496db + 304b5b5 commit e3b0f29
Show file tree
Hide file tree
Showing 20 changed files with 513 additions and 68 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,19 @@ git clone https://github.com/ONSdigital/blaise-deploy-questionnaire-service.git

Create a new .env file and add the following variables.

| Variable | Description | Var Example |
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
| PORT | **Optional variable**, specify the Port for express server to run on. If not passed in this is set as 5000 by default. <br><br>It's best not to set this as the react project will try and use the variable as well and conflict. By default, React project locally runs on port 3000 | 5009 |
| BLAISE_API_URL | URL that the [Blaise Rest API](https://github.com/ONSdigital/blaise-api-rest) is running on to send calls to | localhost:90 |
| PROJECT_ID | GCP Project ID | ons-blaise-dev-matt55 |
| BUCKET_NAME | GCP Bucket name for the Questionnaire file to be put in | ons-blaise-dev-matt55-dqs |
| SERVER_PARK | Name of Blaise Server Park | gusty |
| BIMS_API_URL | URL that the [BIMS Service](https://github.com/ONSdigital/blaise-instrument-metadata-service) is running on to send calls to set and get the live date | localhost:5011 |
| BIMS_CLIENT_ID | GCP IAP ID for the [BIMS Service](https://github.com/ONSdigital/blaise-instrument-metadata-service) | randomKey0112 |
| BUS_API_CLIENT | Not needed for local development but the config will look for this variables in the .env file and throw an error if it is not found. Hence, give them a random string | FOO |
| BUS_CLIENT_ID | Not needed for local development but the config will look for this variables in the .env file and throw an error if it is not found. Hence, give them a random string | FOO |
| CREATE_DONOR_CASES_CLOUD_FUNCTION_URL | URL to trigger the Create Donor Cases Cloud Function in GCP. This is needed when you want to deploy donor cases for an IPS questionnaire. **The Cloud Function needs to be deployed in GCP**. | https://example-cloud-function-url.com |
| Variable | Description | Var Example |
|-------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
| PORT | **Optional variable**, specify the Port for express server to run on. If not passed in this is set as 5000 by default. <br><br>It's best not to set this as the react project will try and use the variable as well and conflict. By default, React project locally runs on port 3000 | 5009 |
| BLAISE_API_URL | URL that the [Blaise Rest API](https://github.com/ONSdigital/blaise-api-rest) is running on to send calls to | localhost:90 |
| PROJECT_ID | GCP Project ID | ons-blaise-dev-matt55 |
| BUCKET_NAME | GCP Bucket name for the Questionnaire file to be put in | ons-blaise-dev-matt55-dqs |
| SERVER_PARK | Name of Blaise Server Park | gusty |
| BIMS_API_URL | URL that the [BIMS Service](https://github.com/ONSdigital/blaise-instrument-metadata-service) is running on to send calls to set and get the live date | localhost:5011 |
| BIMS_CLIENT_ID | GCP IAP ID for the [BIMS Service](https://github.com/ONSdigital/blaise-instrument-metadata-service) | randomKey0112 |
| BUS_API_CLIENT | Not needed for local development but the config will look for this variables in the .env file and throw an error if it is not found. Hence, give them a random string | FOO |
| BUS_CLIENT_ID | Not needed for local development but the config will look for this variables in the .env file and throw an error if it is not found. Hence, give them a random string | FOO |
| CREATE_DONOR_CASES_CLOUD_FUNCTION_URL | URL to trigger the Create Donor Cases Cloud Function in GCP. This is needed when you want to deploy donor cases for an IPS questionnaire. **The Cloud Function needs to be deployed in GCP**. | https://example-cloud-function-url.com |
| REISSUE_NEW_DONOR_CASE_CLOUD_FUNCTION_URL | URL to trigger the Reissue New Donor Case Cloud Function in GCP. This is needed when you want to reissue a new donor case for an IPS questionnaire. **The Cloud Function needs to be deployed in GCP**. | https://example-cloud-function-url.com |

To find the `X_CLIENT_ID`, navigate to the GCP console, search for `IAP`, click the three dots on right of the service and select `OAuth`. `Client Id` will be on the right.

Expand All @@ -83,7 +84,7 @@ The .env file should be setup as below
Example .env file:

```.env
BLAISE_API_URL=localhost:5011
BLAISE_API_URL=localhost:8011
PROJECT_ID=ons-blaise-v2-dev-<sandbox>
BUCKET_NAME=ons-blaise-v2-dev-<sandbox>-dqs
SERVER_PARK=gusty
Expand All @@ -92,6 +93,7 @@ BIMS_CLIENT_ID=randomKey0778
BUS_API_URL=FOO
BUS_CLIENT_ID=FOO
CREATE_DONOR_CASES_CLOUD_FUNCTION_URL=<cloud-function-url>
REISSUE_NEW_DONOR_CASE_CLOUD_FUNCTION_URL=<cloud-function-url>
```
**NB** DQS environment variables for sandboxes can be found within GCP > App Engine > Versions > DQS service > Config

Expand Down
1 change: 1 addition & 0 deletions appengine_templates/app.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env_variables:
SESSION_SECRET: _SESSION_SECRET
ROLES: _ROLES
CREATE_DONOR_CASES_CLOUD_FUNCTION_URL: _CREATE_DONOR_CASES_CLOUD_FUNCTION_URL
REISSUE_NEW_DONOR_CASE_CLOUD_FUNCTION_URL: _REISSUE_NEW_DONOR_CASE_CLOUD_FUNCTION_URL

automatic_scaling:
min_instances: _MIN_INSTANCES
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ process.env = Object.assign(process.env, {
BIMS_API_URL: "bims-mock-api",
BIMS_CLIENT_ID: "mock-client-id",
CREATE_DONOR_CASES_CLOUD_FUNCTION_URL: "mock-cloud-function-url",
REISSUE_NEW_DONOR_CASE_CLOUD_FUNCTION_URL: "mock-cloud-function-url",
AUTH_TOKEN: "mock-dummy-token"
});
9 changes: 7 additions & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import QuestionnaireDetailsPage from "./components/questionnaireDetailsPage/ques
import ChangeTOStartDate from "./components/questionnaireDetailsPage/changeTOStartDate";
import ChangeTMReleaseDate from "./components/questionnaireDetailsPage/changeTmReleaseDate";
import CreateDonorCasesConfirmation from "./components/createDonorCasePage/createDonorCasesConfirmation";
import ReissueNewDonorCaseConfirmation from "./components/reissueNewDonorCasePage/reissueNewDonorCaseConfirmation";
import "./style.css";
import { isProduction } from "./client/env";
import { Authenticate } from "blaise-login-react/blaise-login-react-client";
Expand Down Expand Up @@ -101,6 +102,10 @@ function App(): ReactElement {
path="/createDonorCasesConfirmation"
element={<CreateDonorCasesConfirmation />}>
</Route>
<Route
path="/reissueNewDonorCaseConfirmation"
element={<ReissueNewDonorCaseConfirmation />}>
</Route>
<Route
path="/"
element={<main id="main-content" className="ons-page__main ons-u-mt-no">
Expand All @@ -122,7 +127,7 @@ function App(): ReactElement {
<Authenticate title="Deploy Questionnaire Service">
{(_user, loggedIn, logOutFunction) => (
<>
<a className="ons-skip-link" href="#main-content">Skip to content</a>
<a className="ons-skip-link">Skip to content</a>
{
isProduction(window.location.hostname) ? <></> : <NotProductionWarning />
}
Expand Down Expand Up @@ -154,4 +159,4 @@ function App(): ReactElement {
);
}

export default App;
export default App;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { MemoryRouter, RouterProvider, createMemoryRouter, useNavigate, useParam
import CreateDonorCasesConfirmation from "./createDonorCasesConfirmation";
import "@testing-library/jest-dom";
import axios from "axios";
import { cloudFunctionAxiosError, ipsQuestionnaire, mockSuccessResponseForDonorCasesCreation } from "../../features/step_definitions/helpers/apiMockObjects";
import {
cloudFunctionAxiosError,
ipsQuestionnaire,
mockSectionForDonorCasesCreation,
mockSuccessResponseForDonorCasesCreation
} from "../../features/step_definitions/helpers/apiMockObjects";

jest.mock("axios");

Expand Down Expand Up @@ -81,15 +86,16 @@ describe("CreateDonorCasesConfirmation navigation", () => {
});

it("should redirect back to the questionnaire details page if user clicks Cancel", async () => {

act(() => {
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
});

expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a", {
state: {
donorCasesResponseMessage: "",
donorCasesStatusCode: 0,
section: "createDonorCases",
responseMessage: "",
statusCode: 0,
role: "",
questionnaire: ipsQuestionnaire,
},
Expand All @@ -113,8 +119,9 @@ describe("CreateDonorCasesConfirmation navigation", () => {
expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a",
{
state: {
donorCasesResponseMessage: mockSuccessResponseForDonorCasesCreation.data,
donorCasesStatusCode: mockSuccessResponseForDonorCasesCreation.status,
section: mockSectionForDonorCasesCreation.data,
responseMessage: mockSuccessResponseForDonorCasesCreation.data,
statusCode: mockSuccessResponseForDonorCasesCreation.status,
questionnaire: ipsQuestionnaire,
role: "IPS Manager"
}
Expand All @@ -141,13 +148,14 @@ describe("CreateDonorCasesConfirmation navigation", () => {
expect(navigate).toHaveBeenCalledWith("/questionnaire/IPS1337a",
{
state: {
donorCasesResponseMessage: (cloudFunctionAxiosError as any).response.data.message,
donorCasesStatusCode: 500,
section: "createDonorCases",
responseMessage: (cloudFunctionAxiosError as any).response.data.message,
statusCode: 500,
questionnaire: ipsQuestionnaire,
role: "IPS Manager"
}
});
});

});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CreateDonorCasesConfirmation(): ReactElement {
};
}
isLoading(false);
navigate(`/questionnaire/${questionnaire.name}`, { state: { donorCasesResponseMessage: res.data, donorCasesStatusCode: res.status, questionnaire: questionnaire, role: role } });
navigate(`/questionnaire/${questionnaire.name}`, { state: { section: "createDonorCases", responseMessage: res.data, statusCode: res.status, questionnaire: questionnaire, role: role } });
}
if (loading) {
return <ONSLoadingPanel />;
Expand Down Expand Up @@ -61,7 +61,7 @@ function CreateDonorCasesConfirmation(): ReactElement {
/>
<ONSButton
label="Cancel"
onClick={() => navigate(`/questionnaire/${questionnaire.name}`, { state: { donorCasesResponseMessage: "", donorCasesStatusCode: 0, questionnaire: questionnaire, role: "" } })} primary={false} />
onClick={() => navigate(`/questionnaire/${questionnaire.name}`, { state: { section: "createDonorCases", responseMessage: "", statusCode: 0, questionnaire: questionnaire, role: "" } })} primary={false} />
</>
)
}
Expand All @@ -70,4 +70,4 @@ function CreateDonorCasesConfirmation(): ReactElement {
);
}

export default CreateDonorCasesConfirmation;
export default CreateDonorCasesConfirmation;
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import { ONSButton, ONSLoadingPanel, ONSPanel } from "blaise-design-system-react
import QuestionnaireDetails from "./sections/questionnaireDetails";
import CreateDonorCases from "./sections/createDonorCases";
import CreateDonorCasesSummary from "../createDonorCasePage/createDonorCasesSummary";
import ReissueNewDonorCase from "./sections/reissueNewDonorCase";
import ReissueNewDonorCaseSummary from "../reissueNewDonorCasePage/reissueNewDonorCaseSummary";

interface State {
section?: string;
questionnaire: Questionnaire | null;
donorCasesResponseMessage?: string;
donorCasesStatusCode?: number;
responseMessage?: string;
statusCode?: number;
role?: string;
}

Expand All @@ -31,7 +34,7 @@ function QuestionnaireDetailsPage(): ReactElement {
const [loaded, setLoaded] = useState<boolean>(false);
const initialState = location || { questionnaire: null };
const { questionnaireName } = useParams();
const { donorCasesResponseMessage, donorCasesStatusCode, role } = location || { donorCasesResponseMessage: "", donorCasesStatusCode: 0, role: "" };
const { section, responseMessage, statusCode, role } = location || { section: "", responseMessage: "", statusCode: 0, role: "" };

useEffect(() => {
if (initialState.questionnaire === null) {
Expand Down Expand Up @@ -115,9 +118,11 @@ function QuestionnaireDetailsPage(): ReactElement {
{questionnaire.name}
</h1>

{donorCasesResponseMessage && donorCasesStatusCode && role && <CreateDonorCasesSummary donorCasesResponseMessage={donorCasesResponseMessage} donorCasesStatusCode={donorCasesStatusCode} role={role} />}
{section === "createDonorCases" && responseMessage && statusCode && role && <CreateDonorCasesSummary donorCasesResponseMessage={responseMessage} donorCasesStatusCode={statusCode} role={role} />}
{section === "reissueNewDonorCase" && responseMessage && statusCode && role && <ReissueNewDonorCaseSummary responseMessage={responseMessage} statusCode={statusCode} role={role} />}
<QuestionnaireDetails questionnaire={questionnaire} modes={modes} />
{questionnaire.name.includes("IPS") && <CreateDonorCases questionnaire={questionnaire} />}
{questionnaire.name.includes("IPS") && <ReissueNewDonorCase questionnaire={questionnaire} />}
<CatiModeDetails questionnaireName={questionnaire.name} modes={modes} />
<CawiModeDetails questionnaire={questionnaire} modes={modes} />
<TotalmobileDetails questionnaireName={questionnaire.name} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function CreateDonorCases({ questionnaire }: Props): ReactElement {
</td>
<td className="ons-summary__values" colSpan={2}>
<Link to="/createDonorCasesConfirmation"
state={{ questionnaire: questionnaire, role: role }}
state={{ section: "createDonorCases", questionnaire: questionnaire, role: role }}
className="ons-summary__button"
aria-label={`Create donor cases for questionnaire ${questionnaire.name}`}>
Create cases
Expand Down
Loading

0 comments on commit e3b0f29

Please sign in to comment.