use of se.inera.intyg.webcert.persistence.arende.model.Arende 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.persistence.arende.model.Arende in project webcert by sklintyg.
the class ArendeServiceTest method openArendeAsUnhandledQuestionFromFK.
@Test
public void openArendeAsUnhandledQuestionFromFK() {
Arende arende = buildArende(MEDDELANDE_ID, null);
arende.setSkickatAv(FrageStallare.FORSAKRINGSKASSAN.getKod());
arende.setStatus(Status.CLOSED);
when(arendeRepository.findOneByMeddelandeId(MEDDELANDE_ID)).thenReturn(arende);
service.openArendeAsUnhandled(MEDDELANDE_ID);
ArgumentCaptor<Arende> arendeCaptor = ArgumentCaptor.forClass(Arende.class);
verify(arendeRepository).save(arendeCaptor.capture());
assertEquals(Status.PENDING_INTERNAL_ACTION, arendeCaptor.getValue().getStatus());
verify(notificationService).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_RECIPIENT_UNHANDLED);
}
use of se.inera.intyg.webcert.persistence.arende.model.Arende in project webcert by sklintyg.
the class ArendeServiceTest method testCloseCompletionsAsHandled.
@Test
public void testCloseCompletionsAsHandled() {
final String intygId = "intygId";
Arende arende1 = buildArende(UUID.randomUUID().toString(), INTYG_ID, LocalDateTime.now(), LocalDateTime.now(), ENHET_ID);
arende1.setAmne(ArendeAmne.KOMPLT);
arende1.setSkickatAv(FrageStallare.FORSAKRINGSKASSAN.getKod());
Arende arende2 = buildArende(UUID.randomUUID().toString(), INTYG_ID, LocalDateTime.now(), LocalDateTime.now(), ENHET_ID);
arende2.setAmne(ArendeAmne.KONTKT);
arende2.setSkickatAv(FrageStallare.FORSAKRINGSKASSAN.getKod());
Arende arende3 = buildArende(UUID.randomUUID().toString(), INTYG_ID, LocalDateTime.now(), LocalDateTime.now(), ENHET_ID);
arende3.setAmne(ArendeAmne.KOMPLT);
arende3.setSkickatAv(FrageStallare.FORSAKRINGSKASSAN.getKod());
Arende arende4 = buildArende(UUID.randomUUID().toString(), INTYG_ID, LocalDateTime.now(), LocalDateTime.now(), ENHET_ID);
arende4.setAmne(ArendeAmne.KOMPLT);
// already closed
arende4.setStatus(Status.CLOSED);
arende4.setSkickatAv(FrageStallare.FORSAKRINGSKASSAN.getKod());
when(arendeRepository.findByIntygsId(intygId)).thenReturn(Arrays.asList(arende1, arende2, arende3, arende4));
ArgumentCaptor<Arende> arendeCaptor = ArgumentCaptor.forClass(Arende.class);
service.closeCompletionsAsHandled(intygId, "luse");
verify(arendeRepository).findByIntygsId(intygId);
verify(arendeRepository, times(2)).save(arendeCaptor.capture());
assertEquals(arende1.getMeddelandeId(), arendeCaptor.getAllValues().get(0).getMeddelandeId());
assertEquals(Status.CLOSED, arendeCaptor.getAllValues().get(0).getStatus());
assertEquals(arende3.getMeddelandeId(), arendeCaptor.getAllValues().get(1).getMeddelandeId());
assertEquals(Status.CLOSED, arendeCaptor.getAllValues().get(1).getStatus());
assertEquals(FIXED_TIME_INSTANT, arendeCaptor.getAllValues().get(0).getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
assertEquals(FIXED_TIME_INSTANT, arendeCaptor.getAllValues().get(1).getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
verify(notificationService, times(2)).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_RECIPIENT_HANDLED);
}
use of se.inera.intyg.webcert.persistence.arende.model.Arende 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.persistence.arende.model.Arende in project webcert by sklintyg.
the class ArendeServiceTest method testProcessIncomingMessage.
@Test
public void testProcessIncomingMessage() throws WebCertServiceException {
final String signeratAvName = "signeratAvName";
Arende arende = new Arende();
arende.setIntygsId(INTYG_ID);
Utkast utkast = buildUtkast();
utkast.getSkapadAv().setNamn(signeratAvName);
when(utkastRepository.findOne(INTYG_ID)).thenReturn(utkast);
Arende res = service.processIncomingMessage(arende);
assertNotNull(res);
assertEquals(FIXED_TIME_INSTANT, res.getTimestamp().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
assertEquals(FIXED_TIME_INSTANT, res.getSenasteHandelse().toInstant(ZoneId.systemDefault().getRules().getOffset(FIXED_TIME_INSTANT)));
assertEquals(utkast.getSignatur().getSigneradAv(), res.getSigneratAv());
assertEquals(signeratAvName, res.getSigneratAvName());
verify(utkastRepository).findOne(INTYG_ID);
verify(notificationService).sendNotificationForQuestionReceived(any(Arende.class));
verifyZeroInteractions(arendeDraftService);
}
Aggregations