Skip to content

Commit

Permalink
Merge pull request #649 from ONSdigital/BLAIS5-4463
Browse files Browse the repository at this point in the history
Promote from BLAIS5-4463 to main
  • Loading branch information
kristian4res authored Oct 18, 2024
2 parents 5d1ac9b + 665482a commit 0e4a9cd
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 47 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ 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 |
| 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_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 |

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 @@ -90,7 +91,9 @@ BIMS_API_URL=localhost:5000
BIMS_CLIENT_ID=randomKey0778
BUS_API_URL=FOO
BUS_CLIENT_ID=FOO
CREATE_DONOR_CASES_CLOUD_FUNCTION_URL=<cloud-function-url>
```
**NB** DQS environment variables for sandboxes can be found within GCP > App Engine > Versions > DQS service > Config

Install the project dependencies:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { act } from "react-dom/test-utils";
import React from "react";
import axios from "axios";
import MockAdapter from "axios-mock-adapter";
import { ipsQuestionnaire } from "../../../features/step_definitions/helpers/apiMockObjects";
import { ipsPilotQuestionnaire, ipsQuestionnaire } from "../../../features/step_definitions/helpers/apiMockObjects";
import { Authenticate } from "blaise-login-react/blaise-login-react-client";
import CreateDonorCases from "./createDonorCases";
import { MemoryRouter } from "react-router-dom";
Expand All @@ -21,20 +21,18 @@ const { MockAuthenticate } = jest.requireActual("blaise-login-react/blaise-login
Authenticate.prototype.render = MockAuthenticate.prototype.render;
MockAuthenticate.OverrideReturnValues(null, true);

describe("IPS questionnaire", () => {
beforeEach(() => {
describe("IPS questionnaires", () => {
afterEach(() => {
mock.reset();
});

it("should display the option to create donor cases for IPS Manager and IPS Field Interviewer", async () => {
render(
<MemoryRouter initialEntries={["/questionnaire/"]}>
<CreateDonorCases questionnaire={ipsQuestionnaire} />
</MemoryRouter >
);
});

afterEach(() => {
mock.reset();
});

it("should display the option to create donor cases for IPS Manager and IPS Field Interviewer", async () => {
await act(async () => {
await flushPromises();
});
Expand All @@ -47,4 +45,22 @@ describe("IPS questionnaire", () => {

});
});

it("should display the option to create donor cases for IPS Pilot Interviewer only given it's an IPS Pilot Questionnaire", async () => {
render(
<MemoryRouter initialEntries={["/questionnaire/"]}>
<CreateDonorCases questionnaire={ipsPilotQuestionnaire} />
</MemoryRouter >
);

await act(async () => {
await flushPromises();
});

await waitFor(() => {
expect(screen.getByText("IPS Pilot Interviewer")).toBeDefined();
const createCasesElements = screen.getAllByText("Create cases");
expect(createCasesElements.length).toBe(1);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import React, { ReactElement } from "react";
import dateFormatter from "dayjs";
import QuestionnaireStatus from "../../questionnaireStatus";
import { Questionnaire } from "blaise-api-node-client";
import { Link } from "react-router-dom";

interface Props {
questionnaire: Questionnaire;
}

const VALID_IPS_ROLES = ["IPS Manager", "IPS Field Interviewer", "IPS Pilot Interviewer"];

function CreateDonorCases({ questionnaire }: Props): ReactElement {
const ipsPilotQuestionnairePattern = /^IPS\d{2}00[A-Za-z]$/;
const isIPSPilotQuestionnaire = ipsPilotQuestionnairePattern.test(questionnaire.name);

const rolesToRender = isIPSPilotQuestionnaire
? ["IPS Pilot Interviewer"]
: VALID_IPS_ROLES.filter(role => role !== "IPS Pilot Interviewer");

return (
<>
<div className="ons-summary ons-u-mb-m">
Expand All @@ -21,40 +28,25 @@ function CreateDonorCases({ questionnaire }: Props): ReactElement {
<th>Output</th>
</tr>
</thead>
<tbody className="ons-summary__item">
<tr className="ons-summary__row ons-summary__row--has-values">
<td className="ons-summary__item-title">
<div className="ons-summary__item--text">
IPS Manager
</div>
</td>
<td className="ons-summary__values" colSpan={2}>
<Link to="/createDonorCasesConfirmation"
state={{ questionnaire: questionnaire, role: "IPS Manager" }}
className="ons-summary__button"
aria-label={`Create donor cases for questionnaire ${questionnaire.name}`}>
Create cases
</Link>
</td>
</tr>
</tbody>
<tbody className="ons-summary__item">
<tr className="ons-summary__row ons-summary__row--has-values">
<td className="ons-summary__item-title">
<div className="ons-summary__item--text">
IPS Field Interviewer
</div>
</td>
<td className="ons-summary__values" colSpan={2}>
<Link to="/createDonorCasesConfirmation"
state={{ questionnaire: questionnaire, role: "IPS Field Interviewer" }}
className="ons-summary__button"
aria-label={`Create donor cases for questionnaire ${questionnaire.name}`}>
Create cases
</Link>
</td>
</tr>
</tbody>
{rolesToRender.map((role, index) => (
<tbody key={index} className="ons-summary__item">
<tr className="ons-summary__row ons-summary__row--has-values">
<td className="ons-summary__item-title">
<div className="ons-summary__item--text">
{role}
</div>
</td>
<td className="ons-summary__values" colSpan={2}>
<Link to="/createDonorCasesConfirmation"
state={{ questionnaire: questionnaire, role: role }}
className="ons-summary__button"
aria-label={`Create donor cases for questionnaire ${questionnaire.name}`}>
Create cases
</Link>
</td>
</tr>
</tbody>
))}
</table>
</div>
</div >
Expand Down
6 changes: 6 additions & 0 deletions src/features/step_definitions/helpers/apiMockObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export const ipsQuestionnaire: Questionnaire = {
installDate: "2021-01-15T15:26:43.4233454+00:00"
};

export const ipsPilotQuestionnaire: Questionnaire = {
name: "IPS2500a",
serverParkName: "gusty",
installDate: "2022-01-15T15:26:43.4233454+00:00"
};

export const questionnaireWithName = (questionnaireName: string): Questionnaire => {
return {
name: questionnaireName,
Expand Down

0 comments on commit 0e4a9cd

Please sign in to comment.