Skip to content

Commit

Permalink
835 Set response_expires_at in eq payload (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamHawtin authored Mar 20, 2023
1 parent d7dc641 commit efe4fbd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -55,12 +57,19 @@ public Map<String, Object> buildEqPayloadMap(
eqTokenPayload.put("language_code", languageCode);
eqTokenPayload.put("version", EQ_SCHEMA_VERSION);
eqTokenPayload.put("response_id", encryptResponseId(uacUpdateDTO.getQid()));
// TODO: this is a tactical hack, we'd believed that the prefered schemaUrl field would be
// TODO: this is a tactical hack, we'd believed that the preferred schemaUrl field would be
// populated
// TODO: ticket to do this properly: https://trello.com/c/XEEIGcJW
eqTokenPayload.put("schema_name", uacUpdateDTO.getCollectionInstrumentUrl());
eqTokenPayload.put("survey_metadata", getSurveyMetaData(uacUpdateDTO));

// TODO: As a short term work around we are always setting response_expires_at to a year in the
// future. This is to prevent eQ from deleting the partial which is their default behaviour if
// no response_expires_at is set
OffsetDateTime oneYearInTheFuture = java.time.OffsetDateTime.now().plusYears(1);
eqTokenPayload.put(
"response_expires_at", oneYearInTheFuture.format(DateTimeFormatter.ISO_DATE_TIME));

return eqTokenPayload;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import uk.gov.ons.ssdc.rhservice.service.UacService;

@ExtendWith(MockitoExtension.class)
public class EqLaunchEndpointTest {
class EqLaunchEndpointTest {

@Mock private UacService uacService;

Expand All @@ -42,7 +42,7 @@ public class EqLaunchEndpointTest {
@InjectMocks private EqLaunchEndpoint underTest;

@Test
public void testCallingEndpointGetsToken() {
void testCallingEndpointGetsToken() {
// Given
Map<String, Object> eqPayload = new HashMap<>();
JWSObject jwsObject = Mockito.mock(JWSObject.class);
Expand Down Expand Up @@ -79,7 +79,7 @@ public void testCallingEndpointGetsToken() {
}

@Test
public void testCallingEndpointGetsResponseEntityReturned() {
void testCallingEndpointGetsResponseEntityReturned() {
// Given
Map<String, Object> payload = new HashMap<>();
JWSObject jwsObject = Mockito.mock(JWSObject.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ void testBuildEqPayloadWithoutUACLaunchData() {
Map<String, Object> actualData = (Map<String, Object>) actualSurveyMetaData.get("data");
assertThat(actualData.get("qid")).isEqualTo(uacUpdateDTO.getQid());
assertThat(actualSurveyMetaData.get("receipting_keys")).isEqualTo(List.of("qid"));

// TODO test the workaround of setting response_expires_at to a year in the future
// As a quick way of testing it, check the value is greater than one year in the
// future, minus one minute
String actualResponseExpiresAtString = eqPayload.get("response_expires_at").toString();
OffsetDateTime actualResponseExpiresAt = OffsetDateTime.parse(actualResponseExpiresAtString);
OffsetDateTime oneYearInFuture = OffsetDateTime.now().plusYears(1).minusMinutes(1);
assertThat(actualResponseExpiresAt).isAfter(oneYearInFuture);
}

@Test
Expand Down

0 comments on commit efe4fbd

Please sign in to comment.