Skip to content

Commit

Permalink
DIV-5836 - Allow CoRespondent to submit a AosAwaitingSol case (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwakeman authored and hosainnet committed Oct 1, 2019
1 parent 55dcc10 commit 5812b0b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 59 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# div-ccd-definitions
Divorce configuration definitions for CCD

## Setup

### Pre-requirements
Expand Down
2 changes: 1 addition & 1 deletion definitions/divorce/json/CaseEvent.json
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@
"Name": "AOS Received (Co-Respondent)",
"Description": "AOS Received (Co-Respondent)",
"DisplayOrder": 3,
"PreConditionState(s)": "AosAwaiting",
"PreConditionState(s)": "AosAwaiting;AosAwaitingSol",
"PostConditionState": "AosAwaiting",
"CallBackURLAboutToSubmitEvent": "${CCD_DEF_COS_URL}/co-respondent-generate-answers",
"RetriesTimeoutURLAboutToSubmitEvent": "120,120",
Expand Down
89 changes: 32 additions & 57 deletions test/unit/definitions/divorce/UserEventAuthorisation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ function getAuthStateForUserRole(state, userRole, caseType) {
};
}

function checkAuthStateConfig(conditionState, allAuthForEvent, caseType, eventName, acceptedPermissions) {
allAuthForEvent.forEach(authEventEntry => {
const userRole = authEventEntry.UserRole;
const conditionAuthState = AuthorisationCaseState.filter(
getAuthStateForUserRole(conditionState, userRole, caseType));

if (conditionAuthState.length === 0) {
console.log(`"${eventName}" event for "${userRole}" is missing authorisation for state "${conditionState}"`);
}

expect(conditionAuthState.length).to.eql(1);

if (!conditionAuthState[0].CRUD.match(acceptedPermissions)) {
console.log(`"${eventName}" event for "${userRole}" is missing permissions for state "${conditionState}"`);
}
expect(conditionAuthState[0].CRUD).to.match(acceptedPermissions);
});
}

describe('Events authorisation validation', () => {
before(() => {
AuthCaseEventsActive = AuthorisationCaseEvent.filter(entry => {
Expand Down Expand Up @@ -94,60 +113,31 @@ describe('Events authorisation validation', () => {
});
});

it('should give user minimum R access for all post-condition states', () => {
it('should give user minimum RU access for all pre-condition states', () => {
CaseEvent.forEach(event => {
const acceptedPermissions = /C?RU?D?/;
const eventName = event.ID;
const postConditionState = event.PostConditionState;
const basePreConditionStates = event['PreConditionState(s)'];
const preConditionStates = basePreConditionStates ? basePreConditionStates.split(';') : [];
const caseType = event.CaseTypeID;
const allAuthForEvent = AuthCaseEventsActive.filter(getEventsForEventName(eventName, caseType));

if (postConditionState && postConditionState !== '*') {
allAuthForEvent.forEach(authEventEntry => {
const userRole = authEventEntry.UserRole;
const postConditionAuthState = AuthorisationCaseState.filter(
getAuthStateForUserRole(postConditionState, userRole, caseType));

if (postConditionAuthState.length === 0) {
console.log(`"${eventName}" event for "${userRole}" is missing authorisation for PostCondition state "${postConditionState}"`);
}

expect(postConditionAuthState.length).to.eql(1);

if (!postConditionAuthState[0].CRUD.match(acceptedPermissions)) {
console.log(`"${eventName}" event for "${userRole}" is missing permissions for PostCondition state "${postConditionState}"`);
}
expect(postConditionAuthState[0].CRUD).to.match(acceptedPermissions);
});
}
preConditionStates.forEach(preConditionState => {
if (preConditionState && preConditionState !== '*') {
checkAuthStateConfig(preConditionState, allAuthForEvent, caseType, eventName, acceptedPermissions);
}
});
});
});

it('should give user minimum RU access for all pre-condition states', () => {
it('should give user minimum R access for all post-condition states', () => {
CaseEvent.forEach(event => {
const acceptedPermissions = /C?RU?D?/;
const eventName = event.ID;
const preConditionState = event['PreConditionState(s)'];
const postConditionState = event.PostConditionState;
const caseType = event.CaseTypeID;
const allAuthForEvent = AuthCaseEventsActive.filter(getEventsForEventName(eventName, caseType));

if (preConditionState && preConditionState !== '*') {
allAuthForEvent.forEach(authEventEntry => {
const userRole = authEventEntry.UserRole;
const preConditionAuthState = AuthorisationCaseState.filter(
getAuthStateForUserRole(preConditionState, userRole, caseType));

if (preConditionAuthState.length === 0) {
console.log(`"${eventName}" event for "${userRole}" is missing authorisation for PreCondition state "${preConditionState}"`);
}

expect(preConditionAuthState.length).to.eql(1);

if (!preConditionAuthState[0].CRUD.match(acceptedPermissions)) {
console.log(`"${eventName}" event for "${userRole}" is missing permissions for PreCondition state "${preConditionState}"`);
}
expect(preConditionAuthState[0].CRUD).to.match(acceptedPermissions);
});
if (postConditionState && postConditionState !== '*') {
checkAuthStateConfig(postConditionState, allAuthForEvent, caseType, eventName, acceptedPermissions);
}
});
});
Expand All @@ -162,22 +152,7 @@ describe('Events authorisation validation', () => {
const allAuthForEvent = AuthCaseEventsActive.filter(getEventsForEventName(eventName, caseType));

if (!preConditionState && postConditionState && postConditionState !== '*') {
allAuthForEvent.forEach(authEventEntry => {
const userRole = authEventEntry.UserRole;
const postConditionAuthState = AuthorisationCaseState.filter(
getAuthStateForUserRole(postConditionState, userRole, caseType));

if (postConditionAuthState.length === 0) {
console.log(`"${eventName}" event for "${userRole}" is missing authorisation for PostCondition state "${postConditionState}"`);
}

expect(postConditionAuthState.length).to.eql(1);

if (!postConditionAuthState[0].CRUD.match(acceptedPermissions)) {
console.log(`"${eventName}" event for "${userRole}" is missing permissions for PostCondition state "${postConditionState}"`);
}
expect(postConditionAuthState[0].CRUD).to.match(acceptedPermissions);
});
checkAuthStateConfig(postConditionState, allAuthForEvent, caseType, eventName, acceptedPermissions);
}
});
});
Expand Down

0 comments on commit 5812b0b

Please sign in to comment.