use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testSetVidareBefordradOK.
@Test
public void testSetVidareBefordradOK() {
FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now());
when(webCertUserService.getUser()).thenReturn(createUser());
when(fragasvarRepositoryMock.findByIntygsReferensIntygsId(any(String.class))).thenReturn(ImmutableList.of(fraga));
assertFalse(fraga.getVidarebefordrad());
List<FragaSvar> fragaSvarList = service.setVidareBefordrad(fraga.getIntygsReferens().getIntygsId());
verify(fragasvarRepositoryMock).save(anyList());
verifyZeroInteractions(notificationServiceMock);
assertTrue(fragaSvarList.stream().allMatch(FragaSvar::getVidarebefordrad));
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testCloseCompletionsAsHandled.
@Test
public void testCloseCompletionsAsHandled() {
final String intygId = "intygId";
FragaSvar fragaSvar1 = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar1.setAmne(Amne.KOMPLETTERING_AV_LAKARINTYG);
fragaSvar1.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
FragaSvar fragaSvar2 = buildFragaSvar(2L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar2.setAmne(Amne.KONTAKT);
fragaSvar2.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
FragaSvar fragaSvar3 = buildFragaSvar(3L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar3.setAmne(Amne.KOMPLETTERING_AV_LAKARINTYG);
fragaSvar3.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
FragaSvar fragaSvar4 = buildFragaSvar(4L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar4.setAmne(Amne.KOMPLETTERING_AV_LAKARINTYG);
// already closed
fragaSvar4.setStatus(Status.CLOSED);
fragaSvar4.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
when(fragasvarRepositoryMock.findByIntygsReferensIntygsId(intygId)).thenReturn(Arrays.asList(fragaSvar1, fragaSvar2, fragaSvar3, fragaSvar4));
ArgumentCaptor<FragaSvar> fsCapture = ArgumentCaptor.forClass(FragaSvar.class);
when(fragasvarRepositoryMock.save(fsCapture.capture())).thenAnswer(invocation -> invocation.getArguments()[0]);
service.closeCompletionsAsHandled(intygId);
verify(fragasvarRepositoryMock).findByIntygsReferensIntygsId(intygId);
verify(fragasvarRepositoryMock, times(2)).save(any(FragaSvar.class));
assertEquals(fragaSvar1.getInternReferens(), fsCapture.getAllValues().get(0).getInternReferens());
assertEquals(Status.CLOSED, fsCapture.getAllValues().get(0).getStatus());
assertEquals(fragaSvar3.getInternReferens(), fsCapture.getAllValues().get(1).getInternReferens());
assertEquals(Status.CLOSED, fsCapture.getAllValues().get(1).getStatus());
verify(notificationServiceMock, times(2)).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_RECIPIENT_HANDLED);
verify(arendeDraftService, times(2)).delete(eq(INTYG_ID), anyString());
verifyNoMoreInteractions(arendeDraftService);
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testSaveSvarNotAuthorizedForunit.
@Test(expected = WebCertServiceException.class)
public void testSaveSvarNotAuthorizedForunit() {
FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(false);
try {
service.saveSvar(1L, "svarsText");
} finally {
verify(fragasvarRepositoryMock, never()).save(any(FragaSvar.class));
verifyZeroInteractions(notificationServiceMock);
verifyZeroInteractions(arendeDraftService);
}
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testCloseAnsweredQuestionToFKAsHandledOK.
@Test
public void testCloseAnsweredQuestionToFKAsHandledOK() {
// This is a question that we sent to FK that has been answered so we now have to close it
FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar.setFrageStallare(FrageStallare.WEBCERT.getKod());
fragaSvar.setFrageText("Fråga från WC till FK");
fragaSvar.setStatus(Status.ANSWERED);
fragaSvar.setSvarsText("Med ett svar från FK");
ArgumentCaptor<FragaSvar> fsCapture = ArgumentCaptor.forClass(FragaSvar.class);
when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
when(fragasvarRepositoryMock.save(fsCapture.capture())).thenReturn(fragaSvar);
service.closeQuestionAsHandled(1L);
verify(notificationServiceMock).sendNotificationForQAs(INTYG_ID, NotificationEvent.QUESTION_FROM_CARE_WITH_ANSWER_HANDLED);
verify(fragasvarRepositoryMock).findOne(1L);
verify(fragasvarRepositoryMock).save(any(FragaSvar.class));
assertEquals(Status.CLOSED, fsCapture.getValue().getStatus());
verifyZeroInteractions(arendeDraftService);
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testExceptionThrownWhenIntygIsRevoked.
@Test(expected = WebCertServiceException.class)
public void testExceptionThrownWhenIntygIsRevoked() {
FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now());
String intygsId = fraga.getIntygsReferens().getIntygsId();
// Setup when - given -then
when(intygServiceMock.fetchIntygData(intygsId, fraga.getIntygsReferens().getIntygsTyp(), false)).thenReturn(getRevokedIntygContentHolder());
when(webCertUserService.getUser()).thenReturn(createUser());
when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(true);
// test call
try {
service.saveNewQuestion(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), fraga.getAmne(), fraga.getFrageText());
} finally {
verifyZeroInteractions(sendQuestionToFKClientMock);
verifyZeroInteractions(notificationServiceMock);
verify(fragasvarRepositoryMock, times(0)).save(any(FragaSvar.class));
}
}
Aggregations