ANCSchedulesService { public void unEnrollFromAllSchedules(String entityId) { List<EnrollmentRecord> openEnrollments = trackingService.search(new EnrollmentsQuery().havingExternalId(entityId).havingState(ACTIVE)); for (EnrollmentRecord enrollment : openEnrollments) { logger.info(format("Un-enrolling ANC with Entity id:{0} from schedule: {1} as Delivery happened.", entityId, enrollment.getScheduleName())); trackingService.unenroll(entityId, asList(enrollment.getScheduleName())); } actionService.markAllAlertsAsInactive(entityId); } @Autowired  ANCSchedulesService(ScheduleTrackingService trackingService, ActionService actionService, ScheduleService scheduleService); void enrollMother(String caseId, LocalDate referenceDateForSchedule); void ancVisitHasHappened(String entityId, String anmId, int visitNumberToFulfill, String visitDate); void deliveryHasBeenPlanned(String entityId, String anmId, String deliveryPlanDate); void ttVisitHasHappened(String entityId, String anmId, String ttDose, String ttDate); void ifaTabletsGiven(String entityId, String anmId, String numberOfIFATabletsGiven, String ifaGivenDate); void hbTestDone(String entityId, String anmId, String date, String anaemicStatus, LocalDate lmp); void forceFulfillMilestone(String externalId, String scheduleName); void unEnrollFromAllSchedules(String entityId); static final int NUMBER_OF_WEEKS_BEFORE_HB_TEST_2_BECOMES_DUE; }
@Test public void shouldUnenrollAMotherFromAllOpenSchedulesAndRaiseDeleteAllAlertActionDuringClose() { EnrollmentRecord record1 = new EnrollmentRecord("Case X", "Schedule 1", null, null, null, null, null, null, null, null); EnrollmentRecord record2 = new EnrollmentRecord("Case X", "Schedule 2", null, null, null, null, null, null, null, null); List<EnrollmentRecord> records = asList(record1, record2); when(trackingService.search(queryFor("Case X"))).thenReturn(records); ancSchedulesService.unEnrollFromAllSchedules("Case X"); verify(trackingService).unenroll("Case X", asList("Schedule 1")); verify(trackingService).unenroll("Case X", asList("Schedule 2")); verify(actionService).markAllAlertsAsInactive("Case X"); }