Skip to content

Commit

Permalink
fix: tests and DBC api return
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenRobertsHEE committed Jul 10, 2024
1 parent c3c7990 commit deba798
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.nhs.tis.sync.service;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.reference.api.dto.DBCDTO;
import com.transformuk.hee.tis.reference.client.impl.ReferenceServiceImpl;
import com.transformuk.hee.tis.tcs.api.dto.PersonDTO;
import com.transformuk.hee.tis.tcs.api.dto.PlacementDetailsDTO;
Expand All @@ -16,6 +17,7 @@
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import uk.nhs.tis.sync.dto.CurriculumMembershipWrapperDto;

Expand Down Expand Up @@ -85,9 +87,11 @@ public List<Object> retrieveDtos(Map<String, String> message) {
String name = message.get("name");
return createNonNullList(profileServiceImpl.getSingleAdminUser(name));
}

if(table.equals(TABLE_DBC) && message.containsKey("dbc")) {
String dbc = message.get("dbc");
return createNonNullList(referenceServiceImpl.getDBCByCode(dbc));
ResponseEntity<DBCDTO> responseEntity = referenceServiceImpl.getDBCByCode(dbc);
return createNonNullList(responseEntity.getBody());
}

if (message.containsKey("id")) {
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package uk.nhs.tis.sync.mapper;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.transformuk.hee.tis.profile.dto.RoleDTO;
import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO;
import com.transformuk.hee.tis.profile.service.dto.UserProgrammeDTO;
import com.transformuk.hee.tis.profile.service.dto.UserTrustDTO;
import java.util.HashSet;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import uk.nhs.tis.sync.dto.HeeUserDmsDto;

public class HeeUserMapperTest {

private HeeUserMapper mapper;

private HeeUserDTO heeUserDto;

@Before
public void setUp() {
mapper = new HeeUserMapperImpl();

heeUserDto = new HeeUserDTO();
heeUserDto.setActive(true);
HashSet<UserProgrammeDTO> assocProgrammes = new HashSet<>();
assocProgrammes.add(new UserProgrammeDTO());
heeUserDto.setAssociatedProgrammes(assocProgrammes);
HashSet<UserTrustDTO> userTrusts = new HashSet<>();
userTrusts.add(new UserTrustDTO());
heeUserDto.setAssociatedTrusts(userTrusts);
heeUserDto.setFirstName("first name");
heeUserDto.setName("name");
Set<String> dbcs = new HashSet<>();
dbcs.add("dbc1");
heeUserDto.setDesignatedBodyCodes(dbcs);
heeUserDto.setEmailAddress("email");
heeUserDto.setGmcId("gmc");
heeUserDto.setLastName("last name");
heeUserDto.setPassword("password");
heeUserDto.setPhoneNumber("phone");
HashSet<RoleDTO> roles = new HashSet<>();
roles.add(new RoleDTO());
heeUserDto.setRoles(roles);
heeUserDto.setTemporaryPassword(true);
}

@Test
public void shouldMapAHeeUserDtoToADataDmsDto() {
HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto);

assertEquals("1", heeUserDmsDto.getActive());
assertEquals("name", heeUserDmsDto.getName());
assertEquals("first name", heeUserDmsDto.getFirstName());
assertEquals("gmc", heeUserDmsDto.getGmcId());
assertEquals("last name", heeUserDmsDto.getLastName());
assertEquals("email", heeUserDmsDto.getEmailAddress());
assertEquals("phone", heeUserDmsDto.getPhoneNumber());
//other HeeUserDto properties are ignored
}
}
63 changes: 63 additions & 0 deletions src/test/java/uk/nhs/tis/sync/service/DataRequestServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import static org.mockito.Mockito.when;

import com.transformuk.hee.tis.profile.client.service.impl.ProfileServiceImpl;
import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO;
import com.transformuk.hee.tis.reference.api.dto.DBCDTO;
import com.transformuk.hee.tis.reference.api.dto.GradeDTO;
import com.transformuk.hee.tis.reference.api.dto.SiteDTO;
import com.transformuk.hee.tis.reference.api.dto.TrustDTO;
Expand Down Expand Up @@ -45,13 +47,16 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;
import uk.nhs.tis.sync.dto.CurriculumMembershipWrapperDto;

class DataRequestServiceTest {

private static final String FORENAMES = "Joe";
private static final String SURNAME = "Bloggs";
private static final String HEE_USER_NAME = "the user name";
private static final String DBC_VALUE = "theDBC";

private static final String GDC_NUMBER = "gdc123";
private static final String GMC_NUMBER = "gmc123";
Expand Down Expand Up @@ -795,4 +800,62 @@ void shouldReturnEmptyWhenFindGradesIdInThrowsException() {

assertThat("Unexpected DTO count.", grades.size(), is(0));
}

@Test
void shouldReturnHeeUserWhenHeeUserFound() {
HeeUserDTO expectedDto = new HeeUserDTO();
when(profileService.getSingleAdminUser(HEE_USER_NAME)).thenReturn(expectedDto);

Map<String, String> message = new HashMap<String, String>() {{
put("table", "HeeUser");
put("name", HEE_USER_NAME);
}};
List<Object> retrievedDtos = service.retrieveDtos(message);

assertThat("Unexpected DTO count.", retrievedDtos.size(), is(1));
assertThat("Unexpected DTO.", retrievedDtos.get(0), sameInstance(expectedDto));
}

@Test
void shouldReturnEmptyWhenHeeUserNotFound() {
when(profileService.getSingleAdminUser(HEE_USER_NAME)).thenReturn(null);

Map<String, String> message = new HashMap<String, String>() {{
put("table", "HeeUser");
put("name", HEE_USER_NAME);
}};
List<Object> heeUsers = service.retrieveDtos(message);

assertThat("Unexpected DTO count.", heeUsers.size(), is(0));
}

@Test
void shouldReturnDbcWhenDbcFound() {
DBCDTO expectedDto = new DBCDTO();
ResponseEntity<DBCDTO> responseEntity = new ResponseEntity<>(expectedDto, HttpStatus.OK);
when(referenceService.getDBCByCode(DBC_VALUE)).thenReturn(responseEntity);

Map<String, String> message = new HashMap<String, String>() {{
put("table", "DBC");
put("dbc", DBC_VALUE);
}};
List<Object> retrievedDtos = service.retrieveDtos(message);

assertThat("Unexpected DTO count.", retrievedDtos.size(), is(1));
assertThat("Unexpected DTO.", retrievedDtos.get(0), sameInstance(expectedDto));
}

@Test
void shouldReturnEmptyWhenDbcNotFound() {
ResponseEntity<DBCDTO> responseEntity = new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
when(referenceService.getDBCByCode(DBC_VALUE)).thenReturn(responseEntity);

Map<String, String> message = new HashMap<String, String>() {{
put("table", "DBC");
put("dbc", DBC_VALUE);
}};
List<Object> dbcs = service.retrieveDtos(message);

assertThat("Unexpected DTO count.", dbcs.size(), is(0));
}
}

0 comments on commit deba798

Please sign in to comment.