Skip to content

Commit

Permalink
DMP-4813 Change update metadata from OffsetDateTime to String so date…
Browse files Browse the repository at this point in the history
… is in expected format

Changed the update metadata request from OffsetDateTime to a formatted string so the output is in the expected format
  • Loading branch information
karen-hedges committed Mar 3, 2025
1 parent 8e9dbb2 commit 26f99a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public String getArmBearerToken() {
return String.format("Bearer %s", accessToken);
}

private String formatDateTime(OffsetDateTime offsetDateTime) {
String formatDateTime(OffsetDateTime offsetDateTime) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(armDataManagementConfiguration.getDateTimeFormat());
String dateTime = null;
if (nonNull(offsetDateTime)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.darts.arm.service;
package uk.gov.hmcts.darts.arm.service.impl;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -15,13 +15,13 @@
import uk.gov.hmcts.darts.arm.client.model.rpo.EmptyRpoRequest;
import uk.gov.hmcts.darts.arm.config.ArmApiConfigurationProperties;
import uk.gov.hmcts.darts.arm.config.ArmDataManagementConfiguration;
import uk.gov.hmcts.darts.arm.service.impl.ArmApiServiceImpl;
import uk.gov.hmcts.darts.retention.enums.RetentionConfidenceScoreEnum;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -138,8 +138,34 @@ void updateMetadata_WithNullRetentionConfidenceScoreAndReason() {
verify(armApiClient, times(1)).updateMetadata(eq("Bearer " + bearerToken), eq(expectedMetadataRequest));
}

@Test
void formatDateTime_ShouldReturnFormattedDateTime_WhenOffsetDateTimeIsNotNull() {
// given
OffsetDateTime offsetDateTime = OffsetDateTime.parse("2023-01-01T12:00:00Z");
when(armDataManagementConfiguration.getDateTimeFormat()).thenReturn(DATE_TIME_FORMAT);

String expectedFormattedDateTime = "2023-01-01T12:00:00.000Z";

// when
String formattedDateTime = armApiService.formatDateTime(offsetDateTime);

// then
assertEquals(expectedFormattedDateTime, formattedDateTime);
}

@Test
void formatDateTime_ShouldReturnNull_WhenOffsetDateTimeIsNull() {
// given
when(armDataManagementConfiguration.getDateTimeFormat()).thenReturn(DATE_TIME_FORMAT);

// when
String formattedDateTime = armApiService.formatDateTime(null);

// then
assertEquals(null, formattedDateTime);
}

private String formatDateTime(OffsetDateTime offsetDateTime) {
//"event_date": "1925-02-24T13:52:40.338Z
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX");
return offsetDateTime.format(dateTimeFormatter);
}
Expand Down

0 comments on commit 26f99a5

Please sign in to comment.