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

Added logging to debug file delete issues #1536

Draft
wants to merge 12 commits into
base: ithc
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion Jenkinsfile_CNP
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def secrets = [
]

def yarnBuilder = new uk.gov.hmcts.contino.YarnBuilder(this)
def branchesToSync = ['demo', 'ithc', 'perftest']
def branchesToSync = ['demo', 'perftest']

def pipelineConf = new AppPipelineConfig()
pipelineConf.vaultSecrets = secrets
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,9 @@ ADOP_WEB_URL=https://adoption-web.aat.platform.hmcts.net/ SHOW_BROWSER_WINDOW=fa
```$bash
ADOP_WEB_URL=https://adoption-web-pr-146.service.core-compute-preview.internal/ SHOW_BROWSER_WINDOW=false CITIZEN_PASSWORD=Adoption12 yarn test:local --grep 'Verify apply my own option'
```

## Step controllers
src/main/app/controller contains default controllers. These will be used if no controllers are specified alongside content in the steps folders.
If a step needs additional functionality, add a controller alongside the content.ts, which inherits the default controller. Get and post controllers
need 'get' or 'post' in their filenames.

5 changes: 5 additions & 0 deletions infrastructure/ithc.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sku_name = "Premium"
family = "P"
capacity = "1"
rdb_backup_enabled = true
redis_backup_frequency = "15"
28 changes: 16 additions & 12 deletions infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ data "azurerm_subnet" "core_infra_redis_subnet" {
}

module "adoption-web-session-storage" {
source = "git@github.com:hmcts/cnp-module-redis?ref=master"
product = "${var.product}-${var.component}-session-storage"
location = var.location
env = var.env
private_endpoint_enabled = true
redis_version = "6"
business_area = "cft"
public_network_access_enabled = false
common_tags = var.common_tags
sku_name = var.sku_name
family = var.family
capacity = var.capacity
source = "git@github.com:hmcts/cnp-module-redis?ref=DTSPO-17012-data-persistency"
product = "${var.product}-${var.component}-session-storage"
location = var.location
env = var.env
private_endpoint_enabled = true
redis_version = "6"
business_area = "cft"
public_network_access_enabled = false
common_tags = var.common_tags
sku_name = var.sku_name
family = var.family
capacity = var.capacity
rdb_backup_enabled = var.rdb_backup_enabled
rdb_backup_frequency = var.redis_backup_frequency
rdb_backup_max_snapshot_count = var.rdb_backup_max_snapshot_count
rdb_storage_account_name_prefix = var.raw_product
}

data "azurerm_key_vault" "adoption_key_vault" {
Expand Down
16 changes: 16 additions & 0 deletions infrastructure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ variable "capacity" {
default = "1"
description = "The size of the Redis cache to deploy. Valid values are 1, 2, 3, 4, 5"
}

variable "rdb_backup_enabled" {
type = bool
default = false
description = "The maximum number of snapshots to create as a backup. Only supported for Premium SKUs."
}

variable "rdb_backup_max_snapshot_count" {
type = string
default = "1"
}

variable "redis_backup_frequency" {
default = "360"
description = "The Backup Frequency in Minutes. Only supported on Premium SKUs. Possible values are: 15, 30, 60, 360, 720 and 1440"
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@axe-core/playwright": "^4.9.0",
"@hmcts/cookie-manager": "^1.0.0",
"@hmcts/frontend": "^0.0.50-alpha",
"@hmcts/nodejs-healthcheck": "^1.7.3",
"@hmcts/nodejs-healthcheck": "^1.8.4",
"@hmcts/nodejs-logging": "^4.0.4",
"@hmcts/properties-volume": "^1.0.0",
"@types/autobind-decorator": "^2.1.0",
Expand Down Expand Up @@ -170,7 +170,8 @@
"minimist": "^1.2.6",
"config/json5": ">=2.2.2",
"tsconfig-paths/json5": ">=2.2.2",
"cookiejar": ">=2.1.4"
"cookiejar": ">=2.1.4",
"formidable": "^3.2.4"
},
"packageManager": "yarn@3.6.4"
}
9 changes: 9 additions & 0 deletions src/main/app/document/DocumentManagementClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { Logger } from '@hmcts/nodejs-logging';
import Axios, { AxiosInstance, AxiosResponse } from 'axios';
import FormData from 'form-data';

import { CASE_TYPE, JURISDICTION, UserRole } from '../../app/case/definition';
import type { UserDetails } from '../controller/AppRequest';

const logger = Logger.getLogger('DocumentManagementClient');

export class DocumentManagementClient {
client: AxiosInstance;
serviceToken: string;
userToken: string;

constructor(baseURL: string, authToken: string, private readonly user: UserDetails) {
this.serviceToken = authToken;
this.userToken = `Bearer ${user.accessToken}`;

this.client = Axios.create({
baseURL,
maxBodyLength: 20971520,
Expand Down Expand Up @@ -42,6 +50,7 @@ export class DocumentManagementClient {
}

async delete({ url }: { url: string }): Promise<AxiosResponse> {
logger.info(`service header is ${this.serviceToken}, usertoken is ${this.userToken}`);
return this.client.delete(url, { headers: { 'user-id': this.user.id } });
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/app/document/DocumentManagementController.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Logger } from '@hmcts/nodejs-logging';
import autobind from 'autobind-decorator';
import config from 'config';
import type { Response } from 'express';
Expand All @@ -20,6 +21,8 @@ import type { AppRequest, UserDetails } from '../controller/AppRequest';

import { Classification, DocumentManagementClient } from './DocumentManagementClient';

const logger = Logger.getLogger('DocumentManagementController');

@autobind
export class DocumentManagerController {
private getDocumentManagementClient(user: UserDetails) {
Expand Down Expand Up @@ -108,6 +111,8 @@ export class DocumentManagerController {
return res.redirect(documentInput ? documentInput.documentRedirectUrl : UPLOAD_YOUR_DOCUMENTS);
}
const documentUrlToDelete = documentToDelete.value.documentLink.document_url;
req.session.userCase.id;
logger.info(`Deleting document from case ${req.session.userCase.id}. Document URL: ${documentUrlToDelete}`);

documentsUploaded[documentIndexToDelete].value = null;

Expand All @@ -122,6 +127,9 @@ export class DocumentManagerController {

req.session.save(err => {
if (err) {
logger.error(
`Error deleting document from case ${req.session.userCase.id}. Document URL: ${documentUrlToDelete}`
);
throw err;
}
return res.redirect(documentInput ? documentInput.documentRedirectUrl : UPLOAD_YOUR_DOCUMENTS);
Expand Down
4 changes: 2 additions & 2 deletions src/main/steps/application/submitted/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const enContent = {
'You should contact your social worker for updates on your application. The adoption service cannot provide these.',
multipleChildren: 'Adopting more than one child',
line6:
'If you are applying for more than one child, you must complete and submit a new application for each child. This must be done before midnight on the day you submitted your first application or you will be charged an additional court fee of £183.',
'If you are applying for more than one child, you must complete and submit a new application for each child. This must be done before midnight on the day you submitted your first application or you will be charged an additional court fee of £undefined.',
line7: 'You will be asked the same questions. This is because each application is treated separately.',
line8:
'You might find it useful to take a note of each new reference number next to the name of the child you are applying to adopt. The emails you receive will only contain the reference number.',
Expand Down Expand Up @@ -53,7 +53,7 @@ const cyContent = {
'Dylech gysylltu â’ch gweithiwr cymdeithasol i gael diweddariadau am eich cais. Ni all y gwasanaeth mabwysiadu roi diweddariadau i chi.',
multipleChildren: 'Mabwysiadu mwy nag un plentyn',
line6:
'Os ydych chi’n gwneud cais i fabwysiadu mwy nag un plentyn, mae’n rhaid i chi gwblhau a chyflwyno cais newydd ar gyfer pob plentyn. Rhaid gwneud hyn cyn hanner nos ar y dyddiad y byddwch yn cyflwyno eich cais cyntaf neu fe godir ffi llys ychwanegol arnoch o £183.',
'Os ydych chi’n gwneud cais i fabwysiadu mwy nag un plentyn, mae’n rhaid i chi gwblhau a chyflwyno cais newydd ar gyfer pob plentyn. Rhaid gwneud hyn cyn hanner nos ar y dyddiad y byddwch yn cyflwyno eich cais cyntaf neu fe godir ffi llys ychwanegol arnoch o £undefined.',
line7: 'Fe ofynnir yr un cwestiynau i chi. Mae hyn oherwydd fe ymdrinnir â phob cais ar wahân.',
line8:
'Efallai y byddai’n eich helpu i nodi pob cyfeirnod newydd wrth enw’r plentyn rydych yn gwneud cais i’w fabwysiadu. Dim ond y cyfeirnod fydd wedi’i nodi ar y negeseuon e-bost a anfonir atoch.',
Expand Down
6 changes: 2 additions & 4 deletions src/main/steps/application/submitted/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const en = content => ({
line5:
'You should contact your social worker for updates on your application. The adoption service cannot provide these.',
multipleChildren: 'Adopting more than one child',
line6:
'If you are applying for more than one child, you must complete and submit a new application for each child. This must be done before midnight on the day you submitted your first application or you will be charged an additional court fee of £183.',
line6: `If you are applying for more than one child, you must complete and submit a new application for each child. This must be done before midnight on the day you submitted your first application or you will be charged an additional court fee of £${content.fee?.FeeAmount}.`,
line7: 'You will be asked the same questions. This is because each application is treated separately.',
line8:
'You might find it useful to take a note of each new reference number next to the name of the child you are applying to adopt. The emails you receive will only contain the reference number.',
Expand Down Expand Up @@ -47,8 +46,7 @@ const cy: typeof en = content => ({
line5:
'Dylech gysylltu â’ch gweithiwr cymdeithasol i gael diweddariadau am eich cais. Ni all y gwasanaeth mabwysiadu roi diweddariadau i chi.',
multipleChildren: 'Mabwysiadu mwy nag un plentyn',
line6:
'Os ydych chi’n gwneud cais i fabwysiadu mwy nag un plentyn, mae’n rhaid i chi gwblhau a chyflwyno cais newydd ar gyfer pob plentyn. Rhaid gwneud hyn cyn hanner nos ar y dyddiad y byddwch yn cyflwyno eich cais cyntaf neu fe godir ffi llys ychwanegol arnoch o £183.',
line6: `Os ydych chi’n gwneud cais i fabwysiadu mwy nag un plentyn, mae’n rhaid i chi gwblhau a chyflwyno cais newydd ar gyfer pob plentyn. Rhaid gwneud hyn cyn hanner nos ar y dyddiad y byddwch yn cyflwyno eich cais cyntaf neu fe godir ffi llys ychwanegol arnoch o £${content.fee?.FeeAmount}.`,
line7: 'Fe ofynnir yr un cwestiynau i chi. Mae hyn oherwydd fe ymdrinnir â phob cais ar wahân.',
line8:
'Efallai y byddai’n eich helpu i nodi pob cyfeirnod newydd wrth enw’r plentyn rydych yn gwneud cais i’w fabwysiadu. Dim ond y cyfeirnod fydd wedi’i nodi ar y negeseuon e-bost a anfonir atoch.',
Expand Down
19 changes: 0 additions & 19 deletions src/main/steps/application/submitted/get.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const mockGetFee = jest.fn();
jest.mock('../../../app/fee/fee-lookup-api', () => ({
getFee: mockGetFee,
}));

import { mockRequest } from '../../../../test/unit/utils/mockRequest';
import { mockResponse } from '../../../../test/unit/utils/mockResponse';
import { Case } from '../../../app/case/case';
import { State } from '../../../app/case/definition';
import { AppRequest } from '../../../app/controller/AppRequest';
import { TASK_LIST_URL } from '../../urls';

import GetSubmittedController from './getSubmittedController';

describe('GetSubmittedController', () => {
const controller = new GetSubmittedController();
const res = mockResponse();
let req: AppRequest<Partial<Case>>;

beforeEach(() => {
req = mockRequest({
session: { userCase: { state: State.Submitted }, user: { email: 'test@example.com' } },
});
});

afterEach(() => {
mockGetFee.mockClear();
});

it('returns user to task list when state is not Submitted', async () => {
req.session.userCase.state = State.AwaitingDocuments;
controller.get(req, res);
expect(res.redirect).toHaveBeenCalledWith(TASK_LIST_URL);
});

it('should call the fee lookup api', async () => {
mockGetFee.mockResolvedValue({ FeeAmount: 'a fee amount' });
await controller.get(req, res);
expect(mockGetFee).toHaveBeenCalledWith(req.locals.logger);
});

it('should save the fee response in session', async () => {
mockGetFee.mockResolvedValue({
FeeCode: 'MOCK_CODE',
FeeDescription: 'MOCK_DESCRIPTION',
FeeVersion: 'MOCK_VERSION',
FeeAmount: 'MOCK_AMOUNT',
});
await controller.get(req, res);
expect(req.session.fee).toEqual({
FeeCode: 'MOCK_CODE',
FeeDescription: 'MOCK_DESCRIPTION',
FeeVersion: 'MOCK_VERSION',
FeeAmount: 'MOCK_AMOUNT',
});
});

it('should throw error when feel lookup api fails', async () => {
mockGetFee.mockReturnValue(undefined);
try {
await controller.get(req, res);
} catch (err) {
/* eslint-disable jest/no-conditional-expect */
expect(err).toEqual(new Error('GetSubmittedController unable to get fee from fee-register API'));
expect(mockGetFee).toHaveBeenCalledWith(req.locals.logger);
/* eslint-enable jest/no-conditional-expect */
}
});
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { Logger } from '@hmcts/nodejs-logging';
import autobind from 'autobind-decorator';
import { Response } from 'express';

import { State } from '../../../app/case/definition';
import { AppRequest } from '../../../app/controller/AppRequest';
import { GetController } from '../../../app/controller/GetController';
import { getFee } from '../../../app/fee/fee-lookup-api';
import { TASK_LIST_URL } from '../../urls';

import { generateContent } from './content';

const logger = Logger.getLogger('GetSubmittedController');

@autobind
export default class ApplicationSubmittedGetController extends GetController {
export default class GetSubmittedController extends GetController {
constructor() {
super(__dirname + '/template', generateContent);
}
Expand All @@ -19,6 +23,15 @@ export default class ApplicationSubmittedGetController extends GetController {
if (req.session.userCase.state !== State.Submitted) {
return res.redirect(TASK_LIST_URL);
}
await super.get(req, res);
const feeResponse = await getFee(req.locals.logger);
if (feeResponse) {
req.session.fee = feeResponse;

const callback = () => super.get(req, res);
super.saveSessionAndRedirect(req, res, callback);
} else {
logger.error('GetSubmittedController unable to get fee from fee-register API');
throw new Error('GetSubmittedController unable to get fee from fee-register API');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const enContent = {
line1:
'If you are applying for more than one child, you will need to complete an application for each child in turn. Once you have submitted your first application, you can continue and start your next application.',
line2:
'You will only be charged one fee if you submit additional applications before midnight on the day you submit your first application. If you submit after the day of the first application, you will be charged another £183.',
'You will only be charged one fee if you submit additional applications before midnight on the day you submit your first application. If you submit after the day of the first application, you will be charged another £undefined.',
line3:
'If you sign out, you must sign in again using the same email address and password used in your first application.',
continue: 'Continue',
Expand All @@ -18,7 +18,7 @@ const cyContent = {
line1:
'Os ydych chi’n gwneud cais i fabwysiadu mwy nag un plentyn, bydd angen i chi gyflwyno cais newydd ar gyfer pob plentyn. Unwaith y byddwch wedi cyflwyno eich cais cyntaf, gallwch barhau a chychwyn eich cais nesaf.',
line2:
'Codir un ffi arnoch os byddwch yn cyflwyno unrhyw geisiadau ychwanegol cyn hanner nos ar ddyddiad cyflwyno’ch cais cyntaf. Os byddwch yn eu cyflwyno ar ôl dyddiad cyflwyno’r cais cyntaf, yna bydd rhaid i chi dalu £183 arall.',
'Codir un ffi arnoch os byddwch yn cyflwyno unrhyw geisiadau ychwanegol cyn hanner nos ar ddyddiad cyflwyno’ch cais cyntaf. Os byddwch yn eu cyflwyno ar ôl dyddiad cyflwyno’r cais cyntaf, yna bydd rhaid i chi dalu £undefined arall.',
line3:
'Os byddwch yn allgofnodi, bydd rhaid ichi fewngofnodi eto gan ddefnyddio’r un cyfeiriad e-bost a chyfrinair a ddefnyddiwyd ar gyfer eich cais cyntaf.',
continue: 'Parhau',
Expand Down
8 changes: 3 additions & 5 deletions src/main/steps/eligibility/multiple-children-desc/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ const en = content => ({
title: 'Applying for more than one child',
line1:
'If you are applying for more than one child, you will need to complete an application for each child in turn. Once you have submitted your first application, you can continue and start your next application.',
line2:
'You will only be charged one fee if you submit additional applications before midnight on the day you submit your first application. If you submit after the day of the first application, you will be charged another £183.',
line2: `You will only be charged one fee if you submit additional applications before midnight on the day you submit your first application. If you submit after the day of the first application, you will be charged another £${content.fee?.FeeAmount}.`,
line3:
'If you sign out, you must sign in again using the same email address and password used in your first application.',
continue: 'Continue',
});

const cy: typeof en = () => ({
const cy: typeof en = content => ({
title: 'Gwneud cais i fabwysiadu mwy nag un plentyn',
line1:
'Os ydych chi’n gwneud cais i fabwysiadu mwy nag un plentyn, bydd angen i chi gyflwyno cais newydd ar gyfer pob plentyn. Unwaith y byddwch wedi cyflwyno eich cais cyntaf, gallwch barhau a chychwyn eich cais nesaf.',
line2:
'Codir un ffi arnoch os byddwch yn cyflwyno unrhyw geisiadau ychwanegol cyn hanner nos ar ddyddiad cyflwyno’ch cais cyntaf. Os byddwch yn eu cyflwyno ar ôl dyddiad cyflwyno’r cais cyntaf, yna bydd rhaid i chi dalu £183 arall.',
line2: `Codir un ffi arnoch os byddwch yn cyflwyno unrhyw geisiadau ychwanegol cyn hanner nos ar ddyddiad cyflwyno’ch cais cyntaf. Os byddwch yn eu cyflwyno ar ôl dyddiad cyflwyno’r cais cyntaf, yna bydd rhaid i chi dalu £${content.fee?.FeeAmount} arall.`,
line3:
'Os byddwch yn allgofnodi, bydd rhaid ichi fewngofnodi eto gan ddefnyddio’r un cyfeiriad e-bost a chyfrinair a ddefnyddiwyd ar gyfer eich cais cyntaf.',
continue: 'Parhau',
Expand Down
Loading