use of se.inera.intyg.webcert.persistence.arende.repository.ArendeRepository in project webcert by sklintyg.
the class ArendeServiceTest method answerKompltQuestionClosesAllCompletionsAsHandled.
@Test
public void answerKompltQuestionClosesAllCompletionsAsHandled() throws CertificateSenderException {
final String svarPaMeddelandeId = "svarPaMeddelandeId";
Arende fraga = buildArende(svarPaMeddelandeId, ENHET_ID);
fraga.setStatus(Status.PENDING_INTERNAL_ACTION);
fraga.setAmne(ArendeAmne.KOMPLT);
fraga.setPatientPersonId(PERSON_ID);
Arende komplt1 = buildArende(UUID.randomUUID().toString(), ENHET_ID);
komplt1.setStatus(Status.PENDING_INTERNAL_ACTION);
komplt1.setAmne(ArendeAmne.KOMPLT);
komplt1.setPatientPersonId(PERSON_ID);
Arende komplt2 = buildArende(UUID.randomUUID().toString(), ENHET_ID);
komplt2.setStatus(Status.PENDING_INTERNAL_ACTION);
komplt2.setAmne(ArendeAmne.KOMPLT);
komplt2.setPatientPersonId(PERSON_ID);
Arende otherSubject = buildArende(UUID.randomUUID().toString(), ENHET_ID);
otherSubject.setStatus(Status.PENDING_INTERNAL_ACTION);
otherSubject.setAmne(ArendeAmne.AVSTMN);
otherSubject.setPatientPersonId(PERSON_ID);
when(arendeRepository.findByIntygsId(INTYG_ID)).thenReturn(Arrays.asList(fraga, komplt1, otherSubject, komplt2));
when(webcertUserService.isAuthorizedForUnit(anyString(), anyBoolean())).thenReturn(true);
WebCertUser webcertUser = createUser();
when(webcertUserService.getUser()).thenReturn(webcertUser);
List<ArendeConversationView> result = service.answerKomplettering(INTYG_ID, "svarstext");
verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
verify(arendeRepository).findByIntygsId(INTYG_ID);
verify(arendeDraftService, times(3)).delete(eq(INTYG_ID), anyString());
assertTrue(result.stream().map(ArendeConversationView::getFraga).filter(f -> f.getAmne() == ArendeAmne.KOMPLT).allMatch(f -> f.getStatus() == Status.CLOSED));
assertNotNull(result.stream().map(ArendeConversationView::getSvar).filter(Objects::nonNull).map(ArendeView::getInternReferens).collect(MoreCollectors.onlyElement()));
}
Aggregations