Skip to content

Commit

Permalink
Merge pull request #239 from Health-Education-England/fix/handleEmpty…
Browse files Browse the repository at this point in the history
…SubmissionDateStringOnAddDoctor

fix: handle empty submission date string on add doctor (for when exce…
  • Loading branch information
JosephKelly authored Oct 17, 2023
2 parents 9aab6a1 + 66f33e1 commit a82f484
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public class GmcClientService {
/**
* add GMC connection for a doctor.
*
* @param gmcId id of doctor to add
* @param changeReason reason for adding doctor
* @param gmcId id of doctor to add
* @param changeReason reason for adding doctor
* @param designatedBodyCode DBC which is going to add for the doctor
*/
public GmcConnectionResponseDto tryAddDoctor(final String gmcId, final String changeReason,
Expand All @@ -74,21 +74,24 @@ public GmcConnectionResponseDto tryAddDoctor(final String gmcId, final String ch

final var tryAddDoctorResponse = submitTryAddDoctor(tryAddDoctor);
final var tryAddDoctorResult = tryAddDoctorResponse.getTryAddDoctorResult();
final var submissionDateString = tryAddDoctorResult.getSubmissionDate();

final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
final LocalDate submissionDate =
submissionDateString.isBlank() ? null : LocalDate.parse(submissionDateString, formatter);
return GmcConnectionResponseDto.builder()
.clientRequestId(tryAddDoctorResult.getClientRequestID())
.gmcRequestId(tryAddDoctorResult.getGMCRequestID())
.submissionDate(LocalDate.parse(tryAddDoctorResult.getSubmissionDate(), formatter))
.submissionDate(submissionDate)
.returnCode(tryAddDoctorResult.getReturnCode())
.build();
}

/**
* remove GMC connection from a doctor.
*
* @param gmcId id of doctor to remove
* @param changeReason reason for removing doctor
* @param gmcId id of doctor to remove
* @param changeReason reason for removing doctor
* @param designatedBodyCode DBC which is going to remove from the doctor
*/
public GmcConnectionResponseDto tryRemoveDoctor(final String gmcId, final String changeReason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -126,6 +127,31 @@ void shouldSubmitTryAddDoctorRequest() {
assertThat(gmcConnectionResponseDto.getReturnCode(), is(returnCode));
}

@Test
void shouldHandleEmptySubmissionDateOnTryAddDoctorRequest() {

final var addDoctorDto = UpdateConnectionDto.builder()
.changeReason(changeReason)
.designatedBodyCode(designatedBodyCode)
.doctors(buildDoctorsList())
.build();

when(webServiceTemplate.marshalSendAndReceive(any(String.class), any(
TryAddDoctor.class), any(SoapActionCallback.class))).thenReturn(tryAddDoctorResponse);
when(tryAddDoctorResponse.getTryAddDoctorResult()).thenReturn(tryAddDoctorResponseCT);
when(tryAddDoctorResponseCT.getClientRequestID()).thenReturn(gmcId);
when(tryAddDoctorResponseCT.getGMCRequestID()).thenReturn(gmcRequestId);
when(tryAddDoctorResponseCT.getSubmissionDate()).thenReturn("");
when(tryAddDoctorResponseCT.getReturnCode()).thenReturn(returnCode);
final var gmcConnectionResponseDto =
gmcClientService.tryAddDoctor(gmcId, changeReason, designatedBodyCode);

assertThat(gmcConnectionResponseDto.getClientRequestId(), is(gmcId));
assertThat(gmcConnectionResponseDto.getGmcRequestId(), is(gmcRequestId));
assertNull(gmcConnectionResponseDto.getSubmissionDate());
assertThat(gmcConnectionResponseDto.getReturnCode(), is(returnCode));
}

@Test
void shouldSubmitTryRemoveDoctorRequest() {

Expand Down

0 comments on commit a82f484

Please sign in to comment.