use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser in project webcert by sklintyg.
the class ArendeServiceTest method testFilterArendeWithAuthFail.
@Test(expected = WebCertServiceException.class)
public void testFilterArendeWithAuthFail() {
WebCertUser webCertUser = createUser();
when(webcertUserService.getUser()).thenReturn(webCertUser);
QueryFragaSvarParameter params = new QueryFragaSvarParameter();
params.setEnhetId("no-auth");
service.filterArende(params);
}
use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser 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.service.user.dto.WebCertUser in project webcert by sklintyg.
the class ArendeServiceTest method testFilterArendeFiltersOutNonVerifiedSekretessPatients.
@Test
@SuppressWarnings("unchecked")
public void testFilterArendeFiltersOutNonVerifiedSekretessPatients() {
WebCertUser webCertUser = createUser();
Map<Personnummer, SekretessStatus> map = mock(Map.class);
when(map.get(any(Personnummer.class))).thenReturn(SekretessStatus.UNDEFINED);
doReturn(map).when(patientDetailsResolver).getSekretessStatusForList(anyList());
when(webcertUserService.getUser()).thenReturn(webCertUser);
when(webcertUserService.isAuthorizedForUnit(any(), eq(true))).thenReturn(true);
List<Arende> queryResults = new ArrayList<>();
queryResults.add(buildArende(UUID.randomUUID().toString(), LocalDateTime.now(), null));
queryResults.add(buildArende(UUID.randomUUID().toString(), LocalDateTime.now().minusDays(1), null));
when(arendeRepository.filterArende(any(Filter.class))).thenReturn(queryResults);
QueryFragaSvarResponse fsResponse = new QueryFragaSvarResponse();
fsResponse.setResults(new ArrayList<>());
fsResponse.setTotalCount(0);
when(fragaSvarService.filterFragaSvar(any(Filter.class))).thenReturn(fsResponse);
QueryFragaSvarParameter params = new QueryFragaSvarParameter();
params.setEnhetId(webCertUser.getValdVardenhet().getId());
QueryFragaSvarResponse response = service.filterArende(params);
verify(patientDetailsResolver, times(1)).getSekretessStatusForList(anyList());
verify(webcertUserService).isAuthorizedForUnit(anyString(), eq(true));
verify(arendeRepository).filterArende(any(Filter.class));
verify(fragaSvarService).filterFragaSvar(any(Filter.class));
assertEquals(0, response.getResults().size());
}
use of se.inera.intyg.webcert.web.service.user.dto.WebCertUser 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.service.user.dto.WebCertUser 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);
}
Aggregations