use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testCloseQuestionToFKAsHandledOK.
@Test
public void testCloseQuestionToFKAsHandledOK() {
FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar.setFrageStallare(FrageStallare.WEBCERT.getKod());
fragaSvar.setFrageText("Fråga till FK");
fragaSvar.setStatus(Status.PENDING_EXTERNAL_ACTION);
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_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 testSaveFragaNotAuthorizedForUnit.
@Test(expected = WebCertServiceException.class)
public void testSaveFragaNotAuthorizedForUnit() {
FragaSvar fraga = buildFraga(1L, "frageText", Amne.OVRIGT, LocalDateTime.now());
// create mocked Utlatande from intygstjansten
when(intygServiceMock.fetchIntygData(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), false)).thenReturn(getIntygContentHolder());
when(webCertUserService.getUser()).thenReturn(createUser());
when(webCertUserService.isAuthorizedForUnit(any(String.class), eq(false))).thenReturn(false);
// test call
try {
service.saveNewQuestion(fraga.getIntygsReferens().getIntygsId(), fraga.getIntygsReferens().getIntygsTyp(), fraga.getAmne(), fraga.getFrageText());
} finally {
verifyZeroInteractions(fragasvarRepositoryMock);
verifyZeroInteractions(notificationServiceMock);
verifyZeroInteractions(arendeDraftService);
}
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testExceptionThrownWhenIntygIsUnsentToFK.
@Test(expected = WebCertServiceException.class)
public void testExceptionThrownWhenIntygIsUnsentToFK() {
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(getUnsentIntygContentHolder());
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);
verifyZeroInteractions(fragasvarRepositoryMock);
}
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method buildFragaSvar.
private FragaSvar buildFragaSvar(Long id, LocalDateTime fragaSkickadDatum, LocalDateTime svarSkickadDatum) {
FragaSvar f = new FragaSvar();
f.setStatus(Status.PENDING_INTERNAL_ACTION);
f.setAmne(Amne.OVRIGT);
f.setExternReferens("<fk-extern-referens>");
f.setInternReferens(id);
f.setFrageSkickadDatum(fragaSkickadDatum);
f.setFrageText("frageText");
f.setSvarSkickadDatum(svarSkickadDatum);
IntygsReferens intygsReferens = new IntygsReferens();
intygsReferens.setIntygsId(INTYG_ID);
intygsReferens.setIntygsTyp("fk7263");
intygsReferens.setPatientId(PNR);
f.setIntygsReferens(intygsReferens);
f.setKompletteringar(new HashSet<>());
f.setVardperson(new Vardperson());
f.getVardperson().setEnhetsId("enhet");
return f;
}
use of se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar in project webcert by sklintyg.
the class FragaSvarServiceImplTest method testOpenAsUnhandledInvalidState.
@Test(expected = WebCertServiceException.class)
public void testOpenAsUnhandledInvalidState() {
FragaSvar fragaSvar = buildFragaSvar(1L, LocalDateTime.now(), LocalDateTime.now());
fragaSvar.setFrageStallare(FrageStallare.FORSAKRINGSKASSAN.getKod());
fragaSvar.setFrageText("Fråga från FK");
fragaSvar.setSvarsText("Svar till FK från WC");
fragaSvar.setStatus(Status.CLOSED);
when(fragasvarRepositoryMock.findOne(1L)).thenReturn(fragaSvar);
try {
service.openQuestionAsUnhandled(1L);
} finally {
verify(fragasvarRepositoryMock, never()).save(any(FragaSvar.class));
verifyZeroInteractions(notificationServiceMock);
}
}
Aggregations