use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.
the class ArendeServiceTest method setForwardedTrueTest.
@Test
public void setForwardedTrueTest() {
final Arende arende = buildArende(MEDDELANDE_ID, ENHET_ID);
final Arende vidareBefordrat = arende;
arende.setArendeToVidareBerordrat();
when(arendeRepository.findByIntygsId(INTYG_ID)).thenReturn(ImmutableList.of(arende));
when(webcertUserService.getUser()).thenReturn(createUser());
when(arendeRepository.save(anyList())).thenReturn(ImmutableList.of(vidareBefordrat));
final List<ArendeConversationView> arendeConversationViews = service.setForwarded(INTYG_ID);
assertTrue(arendeConversationViews.stream().allMatch(arendeConversationView -> arendeConversationView.getFraga().getVidarebefordrad()));
verifyZeroInteractions(notificationService);
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView 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()));
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.
the class ArendeServiceTest method answerTest.
@Test
public void answerTest() throws CertificateSenderException {
final String svarPaMeddelandeId = "svarPaMeddelandeId";
Arende fraga = buildArende(svarPaMeddelandeId, null);
fraga.setAmne(ArendeAmne.OVRIGT);
fraga.setSenasteHandelse(LocalDateTime.now());
fraga.setStatus(Status.PENDING_INTERNAL_ACTION);
fraga.setPatientPersonId(PERSON_ID);
when(arendeRepository.findOneByMeddelandeId(svarPaMeddelandeId)).thenReturn(fraga);
when(webcertUserService.isAuthorizedForUnit(isNull(), anyBoolean())).thenReturn(true);
when(webcertUserService.getUser()).thenReturn(new WebCertUser());
ArendeConversationView result = service.answer(svarPaMeddelandeId, "svarstext");
assertNotNull(result.getFraga());
assertNotNull(result.getSvar());
assertEquals(FIXED_TIME_INSTANT, result.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
verify(webcertUserService).isAuthorizedForUnit(isNull(), anyBoolean());
verify(arendeRepository, times(2)).save(any(Arende.class));
verify(monitoringLog).logArendeCreated(anyString(), anyString(), isNull(), any(ArendeAmne.class), anyBoolean());
verify(certificateSenderService).sendMessageToRecipient(anyString(), anyString());
verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
verify(arendeDraftService).delete(INTYG_ID, svarPaMeddelandeId);
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.
the class ArendeServiceTest method createQuestionTest.
@Test
public void createQuestionTest() throws CertificateSenderException {
LocalDateTime now = LocalDateTime.now();
Utkast utkast = buildUtkast();
doReturn(utkast).when(utkastRepository).findOne(anyString());
when(webcertUserService.isAuthorizedForUnit(isNull(), anyBoolean())).thenReturn(true);
when(webcertUserService.getUser()).thenReturn(new WebCertUser());
Arende arende = new Arende();
arende.setSenasteHandelse(now);
ArendeConversationView result = service.createMessage(INTYG_ID, ArendeAmne.KONTKT, "rubrik", "meddelande");
assertNotNull(result.getFraga());
assertNull(result.getSvar());
assertEquals(FIXED_TIME_INSTANT, result.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
verify(webcertUserService).isAuthorizedForUnit(isNull(), anyBoolean());
verify(arendeRepository).save(any(Arende.class));
verify(monitoringLog).logArendeCreated(anyString(), isNull(), isNull(), any(ArendeAmne.class), anyBoolean());
verify(certificateSenderService).sendMessageToRecipient(anyString(), anyString());
verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_QUESTION_FROM_CARE);
verify(arendeDraftService).delete(INTYG_ID, null);
}
use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.
the class ArendeServiceTest method answerUpdatesQuestionTest.
@Test
public void answerUpdatesQuestionTest() throws CertificateSenderException {
final String svarPaMeddelandeId = "svarPaMeddelandeId";
Arende fraga = buildArende(svarPaMeddelandeId, null);
fraga.setAmne(ArendeAmne.OVRIGT);
fraga.setMeddelandeId(svarPaMeddelandeId);
fraga.setStatus(Status.PENDING_INTERNAL_ACTION);
fraga.setPatientPersonId(PERSON_ID);
when(arendeRepository.findOneByMeddelandeId(svarPaMeddelandeId)).thenReturn(fraga);
when(webcertUserService.isAuthorizedForUnit(isNull(), anyBoolean())).thenReturn(true);
when(webcertUserService.getUser()).thenReturn(new WebCertUser());
ArendeConversationView result = service.answer(svarPaMeddelandeId, "svarstext");
assertNotNull(result.getFraga());
assertNotNull(result.getSvar());
assertEquals(FIXED_TIME_INSTANT, result.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
verify(webcertUserService).isAuthorizedForUnit(isNull(), anyBoolean());
verify(monitoringLog).logArendeCreated(anyString(), anyString(), isNull(), any(ArendeAmne.class), anyBoolean());
verify(certificateSenderService).sendMessageToRecipient(anyString(), anyString());
verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.NEW_ANSWER_FROM_CARE);
ArgumentCaptor<Arende> arendeCaptor = ArgumentCaptor.forClass(Arende.class);
verify(arendeRepository, times(2)).save(arendeCaptor.capture());
verify(arendeDraftService).delete(INTYG_ID, svarPaMeddelandeId);
Arende updatedQuestion = arendeCaptor.getAllValues().get(1);
assertEquals(FIXED_TIME_INSTANT, updatedQuestion.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
assertEquals(Status.CLOSED, updatedQuestion.getStatus());
}
Aggregations