Skip to content
Snippets Groups Projects
Commit 6a8c44b9 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6179 set sentAt to now if missing

parent 085dc916
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,7 @@ interface AntragraumNachrichtMapper {
default ZonedDateTime mapZonedDateTime(String sentAt) {
if (StringUtils.isBlank(sentAt)) {
return null;
return ZonedDateTime.now();
}
return ZonedDateTime.parse(sentAt);
}
......
......@@ -27,6 +27,7 @@ import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
......@@ -45,40 +46,40 @@ class AntragraumNachrichtMapperTest {
@Test
void shouldMapVorgangId() {
var result = map();
var result = toGrpc();
assertThat(result.getVorgangId()).isEqualTo(RueckfrageHeadTestFactory.VORGANG_ID);
}
@Test
void shouldMapId() {
var result = map();
var result = toGrpc();
assertThat(result.getId()).isEqualTo(RueckfrageHeadTestFactory.ID);
}
@Test
void shouldMapVorgangName() {
var result = map();
var result = toGrpc();
assertThat(result.getVorgangName()).isEqualTo(RueckfrageHeadTestFactory.VORGANG_NAME);
}
@Test
void shouldMapStatus() {
var result = map();
var result = toGrpc();
assertThat(result.getStatus()).isEqualTo(RueckfrageStatus.NEW.name());
}
@Test
void shouldMapSentAt() {
var result = map();
var result = toGrpc();
assertThat(result.getSentAt()).isEqualTo(PostfachNachrichtTestFactory.SENT_AT.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
private GrpcRueckfrageHead map() {
private GrpcRueckfrageHead toGrpc() {
return mapper.toGrpc(RueckfrageHeadTestFactory.create());
}
......@@ -88,63 +89,64 @@ class AntragraumNachrichtMapperTest {
class TestMapAnswerToPostfachNachricht {
@Test
void shouldMapText() {
var result = map();
var result = fromRueckfrageAnswer();
assertThat(result.getMailBody()).isEqualTo(GrpcRueckfrageAnswerTestFactory.TEXT);
}
@Test
void shouldMapMessageId() {
var result = map();
var result = fromRueckfrageAnswer();
assertThat(result.getMessageId()).isEqualTo(GrpcRueckfrageAnswerTestFactory.RUECKFRAGE_ID);
}
@Test
void shouldMapAttachmentIds() {
var result = map();
var result = fromRueckfrageAnswer();
assertThat(result.getAttachments()).isEqualTo(GrpcRueckfrageAnswerTestFactory.ATTACHMENT_ID_LIST);
}
@Test
void shouldSetDirection() {
var result = map();
var result = fromRueckfrageAnswer();
assertThat(result.getDirection()).isEqualTo(Direction.IN);
}
@Test
void shouldSetReplyOption() {
var result = map();
var result = fromRueckfrageAnswer();
assertThat(result.getReplyOption()).isEqualTo(ReplyOption.FORBIDDEN);
}
@Test
void shouldSetCreateAt() {
var result = map();
var result = fromRueckfrageAnswer();
assertThat(result.getCreatedAt()).isCloseTo(ZonedDateTime.now(), within(2, ChronoUnit.SECONDS));
}
@Test
void shouldSetSentAt() {
var result = map();
var result = fromRueckfrageAnswer();
assertThat(result.getSentAt()).isCloseTo(PostfachNachrichtTestFactory.SENT_AT, within(2, ChronoUnit.SECONDS));
}
@DisplayName("should set sentAt to now if value is missing")
@Test
void shouldHandleEmptySentAt() {
void shouldSetSentAtIfMissing() {
var rueckfrage = GrpcRueckfrageAnswerTestFactory.createBuilder().setSentAt(StringUtils.EMPTY).build();
var result = mapper.fromRueckfrageAnswer(rueckfrage);
assertThat(result.getSentAt()).isNull();
assertThat(result.getSentAt()).isCloseTo(ZonedDateTime.now(), within(2, ChronoUnit.SECONDS));
}
private PostfachNachricht map() {
private PostfachNachricht fromRueckfrageAnswer() {
return mapper.fromRueckfrageAnswer(GrpcRueckfrageAnswerTestFactory.create());
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment