Skip to content

Commit

Permalink
Add test for handling null KontaktDato
Browse files Browse the repository at this point in the history
#deploy-test-sykemelding-api

This commit introduces a new test case to verify the correct handling of null values for KontaktDato in the Sykemelding mapping logic. Additionally, it refactors the KontaktMedPasient constructor by removing the redundant start date parameter, streamlining object creation. These changes enhance the reliability and clarity of the codebase with regard to contact date management in health certificates.
  • Loading branch information
krharum committed Dec 10, 2024
1 parent 540b789 commit 619b559
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Dokument {

var prognose = new Prognose(fomIArbeid, dto.getDetaljer());
var helsepersonell = new Helsepersonell(dto.getHelsepersonell());
var kontaktMedPasient = new KontaktMedPasient(dto.getKontaktMedPasient(), fom);
var kontaktMedPasient = new KontaktMedPasient(dto.getKontaktMedPasient());

xmlHelseOpplysningerArbeidsuforhet = new XMLHelseOpplysningerArbeidsuforhet()
.withSyketilfelleStartDato(dto.getStartDato())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
import no.nav.registre.testnorge.sykemelding.external.xmlstds.helseopplysningerarbeidsuforhet._2013_10_01.XMLHelseOpplysningerArbeidsuforhet;
import no.nav.testnav.libs.dto.sykemelding.v1.KontaktMedPasientDTO;

import java.time.LocalDate;

import static java.util.Objects.nonNull;

class KontaktMedPasient {

private final XMLHelseOpplysningerArbeidsuforhet.KontaktMedPasient xmlKontaktMedPasient;

KontaktMedPasient(KontaktMedPasientDTO dto, LocalDate startdato) {
KontaktMedPasient(KontaktMedPasientDTO dto) {
xmlKontaktMedPasient = new XMLHelseOpplysningerArbeidsuforhet.KontaktMedPasient()
.withKontaktDato(dto.getKontaktDato())
.withBegrunnIkkeKontakt(dto.getBegrunnelseIkkeKontakt())
.withBehandletDato(nonNull(startdato) ? startdato.atStartOfDay() : null);
.withBegrunnIkkeKontakt(dto.getBegrunnelseIkkeKontakt());
}

XMLHelseOpplysningerArbeidsuforhet.KontaktMedPasient getXmlObject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,17 @@ void validateNoPerioder_Failure() {
var exception = assertThrows(ResponseStatusException.class, () -> new Sykemelding(sykemeldingDTO, applicationInfo));
assertThat(exception.getMessage(), is(equalTo("400 BAD_REQUEST \"Perioder må angis\"")));
}

@Test
void validateNoKontaktDato_() {

var sykemeldingDTO = getSykemeldingOK();
sykemeldingDTO.getKontaktMedPasient().setKontaktDato(null);

var sykemelding = new Sykemelding(sykemeldingDTO, applicationInfo);
var target = mapperFacade.map(sykemelding, ReceivedSykemeldingDTO.class);

assertThat(target.getSykmelding().getKontaktMedPasient(), allOf(
hasProperty("kontaktDato", is(nullValue()))));
}
}

0 comments on commit 619b559

Please sign in to comment.