diff --git a/components/case/summary/utils/representationEntry.js b/components/case/summary/utils/representationEntry.js index 4c28d5d7..4e06168f 100644 --- a/components/case/summary/utils/representationEntry.js +++ b/components/case/summary/utils/representationEntry.js @@ -4,7 +4,9 @@ import { isRepresentationWindowClosed, canShowRepresentationButtonForAppealType, canStartHouseholderRepresentation, - canStartCpoRepresentation + canStartCpoRepresentation, + canStartRowRepresentation, + canStartAdvertRepresentation } from "../../../../lib/domain/representation-policy"; export function showRepsLocal(startDate, endDate) { @@ -40,25 +42,17 @@ export function canShowRepButtonForAppealType({ return canStartHouseholderRepresentation(appealType, isLPA); case 846040015: - return searchDetailsObj[0].value[0].pinswg_specialistcaseprocess == - 846040001 - ? showRepsLocal( - searchDetailsObj[0].value[0].pinswg_startdate, - searchDetailsObj[0].value[0].pinswg_finalcommentsduedate - ) - : true; + return canStartRowRepresentation( + appealType, + searchDetailsObj[0].value[0] + ); case 846040018: - let shouldShow = - searchDetailsObj[0].value[0].pinswg_speacialistcaseprocess == - 846040000 && isLPA - ? true - : searchDetailsObj[0].value[0] - .pinswg_speacialistcaseprocess == 846040001 - ? true - : false; - - return shouldShow; + return canStartAdvertRepresentation( + appealType, + searchDetailsObj[0].value[0], + isLPA + ); case 846040019: return canStartCpoRepresentation( diff --git a/lib/domain/representation-policy/canStartAdvertRepresentation.js b/lib/domain/representation-policy/canStartAdvertRepresentation.js new file mode 100644 index 00000000..234bbaa6 --- /dev/null +++ b/lib/domain/representation-policy/canStartAdvertRepresentation.js @@ -0,0 +1,17 @@ +const ADVERT_APPEAL_TYPE = 846040018; +const WRITTEN_REPS_SPECIALIST_PROCESS = 846040000; +const HEARING_SPECIALIST_PROCESS = 846040001; + +export function canStartAdvertRepresentation(appealType, caseDetails, isLPA) { + if (Number(appealType) !== ADVERT_APPEAL_TYPE) { + return true; + } + + const specialistProcess = caseDetails?.pinswg_speacialistcaseprocess; + + return specialistProcess == WRITTEN_REPS_SPECIALIST_PROCESS && isLPA + ? true + : specialistProcess == HEARING_SPECIALIST_PROCESS + ? true + : false; +} diff --git a/lib/domain/representation-policy/canStartRowRepresentation.js b/lib/domain/representation-policy/canStartRowRepresentation.js new file mode 100644 index 00000000..721e71cd --- /dev/null +++ b/lib/domain/representation-policy/canStartRowRepresentation.js @@ -0,0 +1,23 @@ +import { isRepresentationWindowOpen } from "./resolveRepresentationWindow"; + +const ROW_APPEAL_TYPE = 846040015; +const HEARING_SPECIALIST_PROCESS = 846040001; + +export function canStartRowRepresentation( + appealType, + caseDetails, + DateCtor = Date +) { + if (Number(appealType) !== ROW_APPEAL_TYPE) { + return true; + } + + return caseDetails?.pinswg_specialistcaseprocess == + HEARING_SPECIALIST_PROCESS + ? isRepresentationWindowOpen( + caseDetails?.pinswg_startdate, + caseDetails?.pinswg_finalcommentsduedate, + DateCtor + ) + : true; +} diff --git a/lib/domain/representation-policy/index.js b/lib/domain/representation-policy/index.js index 150d84be..54cef404 100644 --- a/lib/domain/representation-policy/index.js +++ b/lib/domain/representation-policy/index.js @@ -7,3 +7,5 @@ export { export { canShowRepresentationButtonForAppealType } from "./canShowRepresentationButtonForAppealType"; export { canStartHouseholderRepresentation } from "./canStartHouseholderRepresentation"; export { canStartCpoRepresentation } from "./canStartCpoRepresentation"; +export { canStartRowRepresentation } from "./canStartRowRepresentation"; +export { canStartAdvertRepresentation } from "./canStartAdvertRepresentation";