Skip to content

Commit

Permalink
Refactor and add e2e-tests (#2392)
Browse files Browse the repository at this point in the history
RISDEV-5234

* Move data from CoreData to ManagementData
* Add e2e for scheduled publication
* Add scheduling searches to query test

---------

Co-authored-by: Kim Kern <[email protected]>
  • Loading branch information
anne-ds and kiwikern authored Nov 26, 2024
1 parent 049d55f commit c063145
Show file tree
Hide file tree
Showing 21 changed files with 473 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import de.bund.digitalservice.ris.caselaw.domain.EnsuingDecision;
import de.bund.digitalservice.ris.caselaw.domain.LegalEffect;
import de.bund.digitalservice.ris.caselaw.domain.LongTexts;
import de.bund.digitalservice.ris.caselaw.domain.ManagementData;
import de.bund.digitalservice.ris.caselaw.domain.NormReference;
import de.bund.digitalservice.ris.caselaw.domain.PreviousDecision;
import de.bund.digitalservice.ris.caselaw.domain.ShortTexts;
Expand Down Expand Up @@ -83,7 +84,6 @@ public static DocumentationUnitDTO transformToDTO(
.ecli(StringUtils.normalizeSpace(coreData.ecli()))
.judicialBody(StringUtils.normalizeSpace(coreData.appraisalBody()))
.decisionDate(coreData.decisionDate())
.scheduledPublicationDateTime(coreData.scheduledPublicationDateTime())
.documentType(
coreData.documentType() != null
? DocumentTypeTransformer.transformToDTO(coreData.documentType())
Expand Down Expand Up @@ -145,6 +145,12 @@ public static DocumentationUnitDTO transformToDTO(
.outline(null);
}

if (updatedDomainObject.managementData() != null) {
var managementData = updatedDomainObject.managementData();

builder.scheduledPublicationDateTime(managementData.scheduledPublicationDateTime());
}

addReferences(updatedDomainObject, builder);

return builder.build();
Expand Down Expand Up @@ -582,8 +588,6 @@ public static DocumentationUnit transformToDomain(DocumentationUnitDTO documenta
: documentationUnitDTO.getRegions().get(0).getCode())
.ecli(documentationUnitDTO.getEcli())
.decisionDate(documentationUnitDTO.getDecisionDate())
.lastPublicationDateTime(documentationUnitDTO.getLastPublicationDateTime())
.scheduledPublicationDateTime(documentationUnitDTO.getScheduledPublicationDateTime())
.appraisalBody(documentationUnitDTO.getJudicialBody())
.legalEffect(legalEffect == null ? null : legalEffect.getLabel());

Expand Down Expand Up @@ -711,6 +715,13 @@ public static DocumentationUnit transformToDomain(DocumentationUnitDTO documenta
documentationUnitDTO.getOtherLongText(),
documentationUnitDTO.getDissentingOpinion());

ManagementData managementData =
ManagementData.builder()
.lastPublicationDateTime(documentationUnitDTO.getLastPublicationDateTime())
.scheduledPublicationDateTime(documentationUnitDTO.getScheduledPublicationDateTime())
.borderNumbers(borderNumbers)
.build();

addOriginalFileDocuments(documentationUnitDTO, builder);
addPreviousDecisionsToDomain(documentationUnitDTO, builder);
addEnsuingDecisionsToDomain(documentationUnitDTO, builder);
Expand All @@ -721,8 +732,8 @@ public static DocumentationUnit transformToDomain(DocumentationUnitDTO documenta
.coreData(coreData)
.shortTexts(shortTexts)
.longTexts(longTexts)
.borderNumbers(borderNumbers)
.contentRelatedIndexing(contentRelatedIndexing);
.contentRelatedIndexing(contentRelatedIndexing)
.managementData(managementData);

addStatusToDomain(documentationUnitDTO, builder);
addReferencesToDomain(documentationUnitDTO, builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import de.bund.digitalservice.ris.caselaw.domain.court.Court;
import de.bund.digitalservice.ris.caselaw.domain.lookuptable.documenttype.DocumentType;
import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.PastOrPresent;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Year;
import java.util.List;
import lombok.Builder;
Expand All @@ -24,8 +22,6 @@ public record CoreData(
@UniqueElements List<String> deviatingEclis,
String appraisalBody,
@PastOrPresent LocalDate decisionDate,
@PastOrPresent LocalDateTime lastPublicationDateTime,
@Future LocalDateTime scheduledPublicationDateTime,
@UniqueElements List<LocalDate> deviatingDecisionDates,
String legalEffect,
List<String> inputTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public record DocumentationUnit(
List<EnsuingDecision> ensuingDecisions,
ShortTexts shortTexts,
LongTexts longTexts,
List<String> borderNumbers,
@Valid ManagementData managementData,
Status status,
String note,
ContentRelatedIndexing contentRelatedIndexing,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.bund.digitalservice.ris.caselaw.domain;

import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.PastOrPresent;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Builder;

@Builder(toBuilder = true)
public record ManagementData(
@PastOrPresent LocalDateTime lastPublicationDateTime,
@Future LocalDateTime scheduledPublicationDateTime,
List<String> borderNumbers) {}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import de.bund.digitalservice.ris.caselaw.domain.EnsuingDecision;
import de.bund.digitalservice.ris.caselaw.domain.LegalForce;
import de.bund.digitalservice.ris.caselaw.domain.LongTexts;
import de.bund.digitalservice.ris.caselaw.domain.ManagementData;
import de.bund.digitalservice.ris.caselaw.domain.NormReference;
import de.bund.digitalservice.ris.caselaw.domain.PreviousDecision;
import de.bund.digitalservice.ris.caselaw.domain.PublicationStatus;
Expand All @@ -50,6 +51,7 @@
import de.bund.digitalservice.ris.caselaw.domain.lookuptable.ParticipatingJudge;
import de.bund.digitalservice.ris.caselaw.domain.lookuptable.Region;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.Year;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -897,7 +899,59 @@ void testTransformToDomain_textWithMultipleBorderNumberElements_shouldAddAllBord
DocumentationUnit documentationUnit =
DocumentationUnitTransformer.transformToDomain(documentationUnitDTO);

assertThat(documentationUnit.borderNumbers()).hasSize(2).containsExactly("1", "2");
assertThat(documentationUnit.managementData().borderNumbers())
.hasSize(2)
.containsExactly("1", "2");
}

@Test
void testTransformScheduledPublicationDate_withDate_shouldAddScheduledPublicationDate() {
DocumentationUnitDTO documentationUnitDTO =
generateSimpleDTOBuilder()
.scheduledPublicationDateTime(LocalDateTime.parse("2022-01-23T18:25:14"))
.build();

DocumentationUnit documentationUnit =
DocumentationUnitTransformer.transformToDomain(documentationUnitDTO);

assertThat(documentationUnit.managementData().scheduledPublicationDateTime())
.isEqualTo("2022-01-23T18:25:14");
}

@Test
void testTransformScheduledPublicationDate_withoutDate_shouldNotAddScheduledPublicationDate() {
DocumentationUnitDTO documentationUnitDTO =
generateSimpleDTOBuilder().scheduledPublicationDateTime(null).build();

DocumentationUnit documentationUnit =
DocumentationUnitTransformer.transformToDomain(documentationUnitDTO);

assertThat(documentationUnit.managementData().scheduledPublicationDateTime()).isNull();
}

@Test
void testTransformLastPublicationDate_withDate_shouldAddLastPublicationDate() {
DocumentationUnitDTO documentationUnitDTO =
generateSimpleDTOBuilder()
.lastPublicationDateTime(LocalDateTime.parse("2022-01-23T18:25:14"))
.build();

DocumentationUnit documentationUnit =
DocumentationUnitTransformer.transformToDomain(documentationUnitDTO);

assertThat(documentationUnit.managementData().lastPublicationDateTime())
.isEqualTo("2022-01-23T18:25:14");
}

@Test
void testTransformLastPublicationDate_withoutDate_shouldNotAddLastPublicationDate() {
DocumentationUnitDTO documentationUnitDTO =
generateSimpleDTOBuilder().lastPublicationDateTime(null).build();

DocumentationUnit documentationUnit =
DocumentationUnitTransformer.transformToDomain(documentationUnitDTO);

assertThat(documentationUnit.managementData().lastPublicationDateTime()).isNull();
}

@Test
Expand All @@ -917,7 +971,9 @@ void testTransformToDomain_multipleTextsWithBorderNumberElements_shouldAddAllBor
DocumentationUnit documentationUnit =
DocumentationUnitTransformer.transformToDomain(documentationUnitDTO);

assertThat(documentationUnit.borderNumbers()).hasSize(4).containsExactly("1", "2", "3", "4");
assertThat(documentationUnit.managementData().borderNumbers())
.hasSize(4)
.containsExactly("1", "2", "3", "4");
}

@Test
Expand All @@ -928,7 +984,7 @@ void testTransformToDomain_textWithoutBorderNumberElements_shouldNotAddBorderNum
DocumentationUnit documentationUnit =
DocumentationUnitTransformer.transformToDomain(documentationUnitDTO);

assertThat(documentationUnit.borderNumbers()).isEmpty();
assertThat(documentationUnit.managementData().borderNumbers()).isEmpty();
}

@Test
Expand All @@ -943,7 +999,7 @@ void testTransformToDomain_textWithoutBorderNumberElements_shouldNotAddBorderNum
DocumentationUnit documentationUnit =
DocumentationUnitTransformer.transformToDomain(documentationUnitDTO);

assertThat(documentationUnit.borderNumbers()).hasSize(1).containsExactly("2");
assertThat(documentationUnit.managementData().borderNumbers()).hasSize(1).containsExactly("2");
}

@Test
Expand Down Expand Up @@ -1276,7 +1332,12 @@ private DocumentationUnit.DocumentationUnitBuilder generateSimpleDocumentationUn
.ensuingDecisions(Collections.emptyList())
.shortTexts(ShortTexts.builder().build())
.longTexts(LongTexts.builder().build())
.borderNumbers(Collections.emptyList())
.managementData(
ManagementData.builder()
.scheduledPublicationDateTime(null)
.lastPublicationDateTime(null)
.borderNumbers(Collections.emptyList())
.build())
.attachments(Collections.emptyList())
.contentRelatedIndexing(
ContentRelatedIndexing.builder()
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/components/DocumentUnitList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ function onDelete() {
@close-modal="toggleModal"
@confirm-action="onDelete"
/>
<TableView class="relative table w-full border-separate">
<TableView
class="relative table w-full border-separate"
data-testid="documentUnitList"
>
<TableHeader>
<CellHeaderItem class="w-[1%]"> Dokumentnummer</CellHeaderItem>
<CellHeaderItem> Gerichtstyp</CellHeaderItem>
Expand All @@ -174,7 +177,7 @@ function onDelete() {
<TableRow
v-for="(listEntry, id) in listEntries"
:key="id"
data-testid="listEntry"
:data-testid="`listEntry_${listEntry.documentNumber}`"
>
<CellItem>
<FlexContainer align-items="items-center" class="space-x-8">
Expand Down Expand Up @@ -291,7 +294,10 @@ function onDelete() {
/>
<span v-else>-</span>
</CellItem>
<CellItem v-if="showPublicationDate && schedulingFeatureToggle">
<CellItem
v-if="showPublicationDate && schedulingFeatureToggle"
data-testid="publicationDate"
>
{{ publicationDate(listEntry) }}
</CellItem>
<CellItem class="flex">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/HandoverDocumentationUnitView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ const isDecisionReasonsInvalid = computed<boolean>(
const schedulingFeatureToggle = useFeatureToggle("neuris.scheduledPublishing")
const isScheduled = computed<boolean>(
() => !!store.documentUnit!.coreData.scheduledPublicationDateTime,
() => !!store.documentUnit!.managementData.scheduledPublicationDateTime,
)
const isPublishable = computed<boolean>(
Expand Down
31 changes: 20 additions & 11 deletions frontend/src/components/ScheduledPublishingDateTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,30 @@ dayjs.extend(customParseFormat)
const store = useDocumentUnitStore()
const storedScheduledPublicationDateTime = computed({
get: () => store.documentUnit!.managementData.scheduledPublicationDateTime,
set: (newDate?: string) =>
(store.documentUnit!.managementData.scheduledPublicationDateTime = newDate),
})
// initialize local values with stored date-time
/* eslint-disable vue/no-ref-object-destructure */
const scheduledPublishingDate = ref<string | undefined>(
store.documentUnit!.coreData.scheduledPublicationDateTime &&
storedScheduledPublicationDateTime.value &&
dayjs
.utc(store.documentUnit!.coreData.scheduledPublicationDateTime)
.utc(storedScheduledPublicationDateTime.value)
.tz("Europe/Berlin")
.format("YYYY-MM-DD"),
)
const scheduledPublishingTime = ref<string | undefined>(
(store.documentUnit!.coreData.scheduledPublicationDateTime &&
(storedScheduledPublicationDateTime.value &&
dayjs
.utc(store.documentUnit!.coreData.scheduledPublicationDateTime)
.utc(storedScheduledPublicationDateTime.value)
.tz("Europe/Berlin")
.format("HH:mm")) ||
"05:00",
)
/* eslint-enable vue/no-ref-object-destructure */
const scheduledDateTimeInput = computed(() =>
dayjs.tz(
Expand All @@ -46,7 +55,7 @@ const scheduledDateTimeInput = computed(() =>
)
const isScheduled = computed<boolean>(
() => !!store.documentUnit!.coreData.scheduledPublicationDateTime,
() => !!storedScheduledPublicationDateTime.value,
)
const isDateInFuture = computed<boolean>(
Expand Down Expand Up @@ -82,17 +91,17 @@ const saveScheduling = async () => {
return
}
store.documentUnit!.coreData.scheduledPublicationDateTime =
storedScheduledPublicationDateTime.value =
scheduledDateTimeInput.value.toISOString()
const { error } = await store.updateDocumentUnit()
if (error) {
store.documentUnit!.coreData.scheduledPublicationDateTime = undefined
storedScheduledPublicationDateTime.value = undefined
docUnitSaveError.value = error
} else {
scheduledPublishingDate.value = dayjs(
store.documentUnit!.coreData.scheduledPublicationDateTime,
storedScheduledPublicationDateTime.value,
)
.tz("Europe/Berlin")
.format("YYYY-MM-DD")
Expand All @@ -101,13 +110,13 @@ const saveScheduling = async () => {
const removeScheduling = async () => {
docUnitSaveError.value = null
const previousDate = store.documentUnit!.coreData.scheduledPublicationDateTime
store.documentUnit!.coreData.scheduledPublicationDateTime = undefined
const previousDate = storedScheduledPublicationDateTime.value
storedScheduledPublicationDateTime.value = undefined
const { error } = await store.updateDocumentUnit()
if (error) {
store.documentUnit!.coreData.scheduledPublicationDateTime = previousDate
storedScheduledPublicationDateTime.value = previousDate
docUnitSaveError.value = error
} else {
scheduledPublishingDate.value = undefined
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/preview/DocumentUnitPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ provide(previewLayoutInjectionKey, props.layout || "wide")
<PreviewReferences :references="documentUnit.references as Reference[]" />
<PreviewShortTexts
:short-texts="documentUnit.shortTexts"
:valid-border-numbers="documentUnit.borderNumbers"
:valid-border-numbers="documentUnit.managementData.borderNumbers"
/>
<PreviewLongTexts :long-texts="documentUnit.longTexts as LongTexts" />
</FlexContainer>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/texts/DocumentUnitAdditionalTexts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const otherLongText = computed({
store.documentUnit?.longTexts.otherLongText
? useValidBorderNumberLinks(
store.documentUnit?.longTexts.otherLongText,
store.documentUnit.borderNumbers,
store.documentUnit.managementData.borderNumbers,
)
: undefined,
set: (newValue) => {
Expand All @@ -31,7 +31,7 @@ const dissentingOpinion = computed({
store.documentUnit?.longTexts.dissentingOpinion
? useValidBorderNumberLinks(
store.documentUnit?.longTexts.dissentingOpinion,
store.documentUnit.borderNumbers,
store.documentUnit.managementData.borderNumbers,
)
: undefined,
set: (newValue) => {
Expand All @@ -45,7 +45,7 @@ const outline = computed({
store.documentUnit?.longTexts.outline
? useValidBorderNumberLinks(
store.documentUnit?.longTexts.outline,
store.documentUnit.borderNumbers,
store.documentUnit.managementData.borderNumbers,
)
: undefined,
set: (newValue) => {
Expand Down
Loading

0 comments on commit c063145

Please sign in to comment.