Search in sources :

Example 16 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeViewConverterTest method differentMessageThreadsShouldBeSeparatedAndSortedOnSenasteHandelse.

@Test
public void differentMessageThreadsShouldBeSeparatedAndSortedOnSenasteHandelse() {
    // Given
    LocalDateTime startOfFirstThread = LocalDateTime.parse("2016-03-01T11:22:11");
    Arende fraga1 = createValidArendeForLuse("fraga", startOfFirstThread, "fraga1-id", null);
    Arende p11 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusHours(2), "paminnelse-1.1-id", fraga1);
    Arende p12 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusDays(1), "paminnelse-1.2-id", fraga1);
    Arende p13 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusDays(3), "paminnelse-1.3-id", fraga1);
    Arende svar1 = createValidArendeForLuse("svar", startOfFirstThread.plusDays(4), "svar-1-id", fraga1);
    LocalDateTime startOfSecondThread = LocalDateTime.parse("2016-03-02T11:22:11");
    Arende fraga2 = createValidArendeForLuse("fraga", startOfSecondThread, "fraga2-id", null);
    Arende p21 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusHours(2), "paminnelse-2.1-id", fraga2);
    Arende p22 = createValidArendeForLuse("paminnelse", startOfFirstThread.plusDays(1), "paminnelse-2.2-id", fraga2);
    Arende svar2 = createValidArendeForLuse("svar", startOfFirstThread.plusDays(4), "svar-2-id", fraga2);
    List<Arende> mixedThreads = ImmutableList.of(fraga1, fraga2, p11, p21, p12, p22, p13, svar2, svar1);
    // When
    List<ArendeConversationView> createdList = converter.buildArendeConversations(intygsId, mixedThreads, Collections.emptyList(), Collections.emptyList());
    // Then
    List<ArendeView> expectedPaminnelser1Dtos = Stream.of(p13, p12, p11).map(converter::convertToDto).collect(Collectors.toList());
    List<ArendeView> expectedPaminnelser2Dtos = Stream.of(p22, p21).map(converter::convertToDto).collect(Collectors.toList());
    Assertions.assertThat(createdList).hasSize(2).extracting("fraga", "svar", "paminnelser").contains(tuple(converter.convertToDto(fraga1), converter.convertToDto(svar1), expectedPaminnelser1Dtos), tuple(converter.convertToDto(fraga2), converter.convertToDto(svar2), expectedPaminnelser2Dtos));
}
Also used : LocalDateTime(java.time.LocalDateTime) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Test(org.junit.Test)

Example 17 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeViewConverterTest method convertToArendeConversationViewTest.

@Test
public void convertToArendeConversationViewTest() {
    final String fragaMeddelandeId = "fragaId";
    final LocalDateTime senasteHandelseFraga = LocalDateTime.now();
    final String svarMeddelandeId = "svarId";
    final String paminnelse1MeddelandeId = "paminnelse1Id";
    final LocalDateTime paminnelse1Timestamp = LocalDateTime.now();
    final String paminnelse2MeddelandeId = "paminnelse2Id";
    final LocalDateTime paminnelse2Timestamp = paminnelse1Timestamp.minusDays(2);
    ArendeConversationView res = converter.convertToArendeConversationView(buildArende(fragaMeddelandeId, senasteHandelseFraga, LocalDateTime.now()), buildArende(svarMeddelandeId, null, LocalDateTime.now()), null, Arrays.asList(buildArende(paminnelse2MeddelandeId, null, paminnelse2Timestamp), buildArende(paminnelse1MeddelandeId, null, paminnelse1Timestamp)), null);
    assertNotNull(res);
    assertNotNull(res.getFraga());
    assertEquals(fragaMeddelandeId, res.getFraga().getInternReferens());
    assertNotNull(res.getSvar());
    assertEquals(svarMeddelandeId, res.getSvar().getInternReferens());
    assertNotNull(res.getPaminnelser());
    assertEquals(2, res.getPaminnelser().size());
    // assert paminnelser are sorted
    assertEquals(paminnelse1MeddelandeId, res.getPaminnelser().get(0).getInternReferens());
    assertEquals(paminnelse2MeddelandeId, res.getPaminnelser().get(1).getInternReferens());
}
Also used : LocalDateTime(java.time.LocalDateTime) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) Test(org.junit.Test)

Example 18 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeViewConverterTest method emptyListOfKompletterandeIntygIsOk.

@Test
public void emptyListOfKompletterandeIntygIsOk() {
    // Given
    LocalDateTime fragaTimestamp = LocalDateTime.parse("2016-03-01T11:22:11");
    Arende fraga = createValidArendeForLuse("fraga", fragaTimestamp, "unique id of fraga", null);
    Arende svar = createValidArendeForLuse("svar", fragaTimestamp.plusMinutes(10), "unique id of svar", fraga);
    // When
    List<ArendeConversationView> res = converter.buildArendeConversations(fraga.getIntygsId(), ImmutableList.of(fraga, svar), Collections.emptyList(), Collections.emptyList());
    // Then
    Assertions.assertThat(res).hasSize(1).extracting("fraga", "svar", "answeredWithIntyg").contains(tuple(converter.convertToDto(fraga), converter.convertToDto(svar), null));
}
Also used : LocalDateTime(java.time.LocalDateTime) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) Test(org.junit.Test)

Example 19 with ArendeConversationView

use of se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView in project webcert by sklintyg.

the class ArendeViewConverterTest method paminnelserInArendeConversionViewShouldBeReverseSortedOnDate.

@Test
public void paminnelserInArendeConversionViewShouldBeReverseSortedOnDate() {
    // Given
    LocalDateTime fragaTimestamp = LocalDateTime.parse("2016-03-01T11:22:11");
    Arende fraga = createValidArendeForLuse("fraga", fragaTimestamp, "fraga1-id", null);
    Arende p1 = createValidArendeForLuse("paminnelse", fragaTimestamp.plusHours(2), "paminnelse-1.1-id", fraga);
    Arende p2 = createValidArendeForLuse("paminnelse", fragaTimestamp.plusDays(1), "paminnelse-1.2-id", fraga);
    Arende p3 = createValidArendeForLuse("paminnelse", fragaTimestamp.plusDays(3), "paminnelse-1.3-id", fraga);
    Arende svar = createValidArendeForLuse("svar", fragaTimestamp.plusDays(4), "svar-1-id", fraga);
    // When
    ArendeConversationView messageThread = converter.convertToArendeConversationView(fraga, svar, null, ImmutableList.of(p3, p1, p2), null);
    // Then
    List<ArendeView> expectedPaminnelserOrder = Stream.of(p3, p2, p1).map(converter::convertToDto).collect(Collectors.toList());
    Assertions.assertThat(messageThread.getPaminnelser()).hasSize(3).containsExactlyElementsOf(expectedPaminnelserOrder);
}
Also used : LocalDateTime(java.time.LocalDateTime) ArendeConversationView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView) MedicinsktArende(se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende) Arende(se.inera.intyg.webcert.persistence.arende.model.Arende) ArendeView(se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView) Test(org.junit.Test)

Aggregations

ArendeConversationView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeConversationView)19 Arende (se.inera.intyg.webcert.persistence.arende.model.Arende)14 MedicinsktArende (se.inera.intyg.webcert.persistence.arende.model.MedicinsktArende)14 Test (org.junit.Test)12 LocalDateTime (java.time.LocalDateTime)11 WebCertUser (se.inera.intyg.webcert.web.service.user.dto.WebCertUser)8 ArendeAmne (se.inera.intyg.webcert.persistence.arende.model.ArendeAmne)6 Collectors (java.util.stream.Collectors)5 Clock (java.time.Clock)4 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Matchers.anyString (org.mockito.Matchers.anyString)4 AuthoritiesHelper (se.inera.intyg.infra.security.authorities.AuthoritiesHelper)4 Personnummer (se.inera.intyg.schemas.contract.Personnummer)4 ImmutableList (com.google.common.collect.ImmutableList)3 PUT (javax.ws.rs.PUT)3 Utkast (se.inera.intyg.webcert.persistence.utkast.model.Utkast)3 FrageStallare (se.inera.intyg.webcert.web.service.fragasvar.dto.FrageStallare)3 ArendeView (se.inera.intyg.webcert.web.web.controller.api.dto.ArendeView)3