AlertCreationAction implements Action { @Override public void invoke(MilestoneEvent event, Map<String, String> extraData) { BeneficiaryType beneficiaryType = BeneficiaryType.from(extraData.get("beneficiaryType")); if (WindowName.late.toString().equals(event.windowName())) { actionService.alertForBeneficiary(beneficiaryType, event.externalId(), event.scheduleName(), event.milestoneName(), urgent, event.startOfLateWindow(), event.startOfMaxWindow()); } else if (WindowName.earliest.toString().equals(event.windowName())) { actionService.alertForBeneficiary(beneficiaryType, event.externalId(), event.scheduleName(), event.milestoneName(), upcoming, event.startOfDueWindow(), event.startOfLateWindow()); } else { actionService.alertForBeneficiary(beneficiaryType, event.externalId(), event.scheduleName(), event.milestoneName(), normal, event.startOfDueWindow(), event.startOfLateWindow()); } } @Autowired  AlertCreationAction(ActionService actionService); @Override void invoke(MilestoneEvent event, Map<String, String> extraData);  }
@Test public void shouldRaiseUpcomingAlertActionsForDueWindowAlerts() throws Exception { HashMap<String, String> extraData = new HashMap<>(); extraData.put("beneficiaryType", "mother"); reminderAction.invoke(event("Case 1", "Schedule 1", "Milestone 1", WindowName.earliest, dueWindowStart, lateWindowStart, maxWindowStart), extraData); verify(actionService).alertForBeneficiary(mother, "Case 1", "Schedule 1", "Milestone 1", upcoming, dueWindowStart, lateWindowStart); }
@Test public void shouldRaiseNormalAlertActionsForDueWindowAlerts() throws Exception { HashMap<String, String> extraData = new HashMap<>(); extraData.put("beneficiaryType", "mother"); reminderAction.invoke(event("Case 1", "Schedule 1", "Milestone 1", WindowName.due, dueWindowStart, lateWindowStart, maxWindowStart), extraData); verify(actionService).alertForBeneficiary(mother, "Case 1", "Schedule 1", "Milestone 1", normal, dueWindowStart, lateWindowStart); }
@Test public void shouldRaiseUrgentAlertActionsForLateWindowAlerts() throws Exception { HashMap<String, String> extraData = new HashMap<>(); extraData.put("beneficiaryType", "child"); reminderAction.invoke(event("Case 1", "Schedule 1", "Milestone 1", WindowName.late, dueWindowStart, lateWindowStart, maxWindowStart), extraData); verify(actionService).alertForBeneficiary(child, "Case 1", "Schedule 1", "Milestone 1", urgent, lateWindowStart, maxWindowStart); }