Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@

import java.math.BigDecimal;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -45,6 +46,8 @@
@Log4j2
public class OrderEmailContextMapper {

private static final DateTimeFormatter CREATED_AT_FORMATTER = new DateTimeFormatterBuilder().appendInstant(3).toFormatter();

private final IdentifierTypeService identifierTypeService;
private final ContributorNameTypeService contributorNameTypeService;
private final ConfigurationService configurationService;
Expand All @@ -60,12 +63,16 @@ public OrderEmailContext buildContext(List<CompositePurchaseOrder> orders) {
.toList()))
.toList();
return OrderEmailContext.builder()
.createdAt(Instant.now().truncatedTo(ChronoUnit.MILLIS).toString())
.createdAt(formatCreatedAt(Instant.now()))
.organization(mapOrganization(orders))
.orders(orderWrappers)
.build();
}

static String formatCreatedAt(Instant instant) {
return CREATED_AT_FORMATTER.format(instant);
}

private OrganizationContext mapOrganization(List<CompositePurchaseOrder> orders) {
return orders.stream()
.map(CompositePurchaseOrder::getVendor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.UUID;

Expand Down Expand Up @@ -176,6 +177,11 @@ void buildContext_setsCreatedAt() {
assertThat(ctx.getCreatedAt()).matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z");
}

@Test
void formatCreatedAt_wholeSecond_keepsMilliseconds() {
assertThat(OrderEmailContextMapper.formatCreatedAt(Instant.parse("2026-08-12T10:15:30Z"))).isEqualTo("2026-08-12T10:15:30.000Z");
}

@Test
void buildContext_mapsOrganizationFields() throws IOException {
var org = new Organization();
Expand Down
Loading