Skip to content

Commit

Permalink
CIV-15169 Hearing Notice API Tests (#4821)
Browse files Browse the repository at this point in the history
* Added spec and unspec hearing notice scheduler tests
* Updated spec hearing notice tests
* Unskip 1v2 diff transfer case offline test
---------

Co-authored-by: GarethLancaster <[email protected]>
Co-authored-by: vasudevganesanhmcts <[email protected]>
  • Loading branch information
3 people authored Oct 3, 2024
1 parent 525e6a8 commit d5bc4a9
Show file tree
Hide file tree
Showing 15 changed files with 742 additions and 158 deletions.
1 change: 1 addition & 0 deletions codecept.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports.config = {
'./e2e/tests/api_tests/lrspec_cui/*_test.js',
'./e2e/tests/api_tests/multiIntermediateTrack/*_test.js',
'./e2e/tests/api_tests/settle-discontinue/*_test.js',
'./e2e/tests/api_tests/automated_hearing_notice/*_test.js'
],
output: process.env.REPORT_DIR || 'test-results/functional',
helpers: {
Expand Down
20 changes: 19 additions & 1 deletion e2e/api/dataHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,25 @@ module.exports = {
dateTime: (days = 0) => {
return getDateTimeISOString(days);
},

incrementDate: (date = new Date(), dayIncrement, monthIncrement, yearIncrement) => {
const newDate = new Date(date);
if(dayIncrement) {
newDate.setDate(newDate.getDate() + dayIncrement);
}
if(monthIncrement) {
newDate.setMonth(newDate.getMonth() + monthIncrement);
}
if(yearIncrement) {
newDate.setYear(newDate.getFullYear() + yearIncrement);
}
return newDate;
},
appendTime: (date = new Date(), hours, minutes) => {
const newDate = new Date(date);
newDate.setHours(hours ? hours : date.getHours());
newDate.setMinutes(minutes ? minutes : date.getMinutes());
return newDate;
},
document: filename => {
const documentId = uuid.v1();
return {
Expand Down
24 changes: 24 additions & 0 deletions e2e/api/serviceAuthorisationHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const restHelper = require('./restHelper');
const config = require('../config');
const totp = require('totp-generator');
const {s2sForXUI, s2s} = require('../config');

const getS2sToken = async ({microservice, secret}) => {
return restHelper.retriedRequest(
`${config.url.authProviderApi}/lease`,
{'Content-Type': 'application/json'},
{
microservice: microservice,
oneTimePassword: totp(secret)
})
.then(response => response.text());
};

module.exports = {
civilServiceAuth: () => {
return getS2sToken(s2s);
},
xuiAuth: () => {
return getS2sToken(s2sForXUI);
},
};
53 changes: 52 additions & 1 deletion e2e/api/steps_hearings.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
const {checkCaseFlagsEnabled, checkCaseFlagsAndHmcEnabled} = require('./testingSupport');
const {checkCaseFlagsEnabled, checkCaseFlagsAndHmcEnabled, triggerCamundaProcess, waitForCompletedCamundaProcess} = require('./testingSupport');
const apiRequest = require('./apiRequest.js');
const {addAndAssertCaseFlag} = require('./caseFlagsHelper');
const {getHearingsPayload} = require('./apiRequest');
const chai = require('chai');
const {expect} = chai;
const {date} = require('../api/dataHelper');
const config = require('../config');
const {listedHearing} = require('./wiremock/data/hearings');
const {createUpdateStub} = require('./wiremock/wiremock');
const {hearingStubRequestBody, unnotifiedHearingStubRequestBody, getpartiesNotifiedStubRequestBody,
putPartiesNotifiedStubRequestBody
} = require('./wiremock/requests/hearings');
const {
AUTOMATED_HEARING_NOTICE,
UNSPEC_AUTOMATED_HEARING_NOTICE_SCHEDULER,
SPEC_AUTOMATED_HEARING_NOTICE_SCHEDULER
} = require('../fixtures/camundaProcesses');

const specServiceId = 'AAA6';
const unspecServiceId = 'AAA7';

const runningOnLocal = () => !['aat', 'demo', 'preview'].includes(config.runningEnv);
const locationId = () => runningOnLocal() ? '000000' : '424213';

const createHearingId = () => `${Math.floor(1000000000 + Math.random() * 9000000000)}`;
const getUILink = (process)=> `${process.links[0].href.replace('engine-rest', 'app/cockpit/default/#')}`;

const getExpectedPayload = (serviceId) => {
if (serviceId === specServiceId) {
return {
Expand Down Expand Up @@ -840,6 +853,28 @@ const getExpectedPayload = (serviceId) => {
}
;

const createHearing = async (caseId, hearingType, serviceCode) => {
const hearingId = createHearingId();
const hearing = listedHearing(caseId, hearingId, hearingType, serviceCode);
await createUpdateStub(hearingStubRequestBody(hearing, hearingId));
console.log(`Created new hearing mock: [${hearingId} - ${hearingType}]`);
return hearingId;
};

const triggerHearingNoticeScheduler = async (expectedHearingId, definitionKey) => {
//Update unnotified hearings stub
await createUpdateStub(unnotifiedHearingStubRequestBody([expectedHearingId]));

const process = await triggerCamundaProcess(definitionKey);
console.log(`Started hearing notice scheduler process: ${getUILink(process)}`);

// Wait for the hearing notice scheduler process
await waitForCompletedCamundaProcess(null, process.id, null);

// Wait for hearing notice process
await waitForCompletedCamundaProcess(AUTOMATED_HEARING_NOTICE, null, `hearingId_eq_${expectedHearingId}`);
};

module.exports = {
createCaseFlags: async (user, caseId, flagLocation, flag) => {
if (!(await checkCaseFlagsEnabled())) {
Expand Down Expand Up @@ -882,5 +917,21 @@ module.exports = {
expect(actualPayload).deep.equal(expectedPayload);
expect(caseDeepLink).deep.contain(`/cases/case-details/${caseId}`);
},
setupStaticMocks: async () => {
await createUpdateStub(getpartiesNotifiedStubRequestBody());
await createUpdateStub(putPartiesNotifiedStubRequestBody());
},
createUnspecTrialHearing: async (caseId) => createHearing(caseId, 'TRI', 'AAA7'),
createUnspecDisposalHearing: async (caseId) => createHearing(caseId, 'DIS', 'AAA7'),
createUnspecDisputeResolutionHearing: async (caseId) => createHearing(caseId, 'DRH', 'AAA7'),
createSpecTrialHearing: async (caseId) => createHearing(caseId, 'TRI', 'AAA6'),
createSpecDisposalHearing: async (caseId) => createHearing(caseId, 'DIS', 'AAA6'),
createSpecDisputeResolutionHearing: async (caseId) => createHearing(caseId, 'DRH', 'AAA6'),
triggerUnspecAutomatedHearingNoticeScheduler: async (expectedHearingId) => {
return await triggerHearingNoticeScheduler(expectedHearingId, UNSPEC_AUTOMATED_HEARING_NOTICE_SCHEDULER);
},
triggerSpecAutomatedHearingNoticeScheduler: async (expectedHearingId) => {
return await triggerHearingNoticeScheduler(expectedHearingId, SPEC_AUTOMATED_HEARING_NOTICE_SCHEDULER);
}
};

Loading

0 comments on commit d5bc4a9

Please sign in to comment.