Skip to content

Commit

Permalink
add isPrimary flag for base provider
Browse files Browse the repository at this point in the history
  • Loading branch information
farrell-m committed Oct 29, 2024
1 parent f9c5a3a commit 0986f8b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
2 changes: 2 additions & 0 deletions data-api/open-api-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,8 @@ components:
type: 'array'
items:
$ref: "#/components/schemas/baseOffice"
is_primary:
type: 'boolean'
providerDetail:
allOf:
- $ref: "#/components/schemas/baseProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class Firm implements Serializable {
@Column(name = "PROVIDER_NAME")
private String name;

/**
* Whether this is the primary provider firm.
*/
@Column(name = "PRIMARY_FLAG")
private Boolean isPrimary;

/**
* The end date of the user associated with the firm.
* This field is ignored during JSON serialization/deserialization.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.gov.laa.ccms.data.mapper;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import uk.gov.laa.ccms.data.entity.FeeEarner;
import uk.gov.laa.ccms.data.entity.Office;
import uk.gov.laa.ccms.data.entity.Provider;
Expand All @@ -24,6 +25,7 @@
@Mapper(componentModel = "spring")
public interface ProviderMapper {

@Mapping(target = "isPrimary", ignore = true)
ProviderDetail toProviderDetail(Provider provider);

OfficeDetail toOfficeDetail(Office office);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.mapstruct.Mapping;
import org.springframework.data.domain.Page;
import uk.gov.laa.ccms.data.entity.Firm;
import uk.gov.laa.ccms.data.entity.Provider;
import uk.gov.laa.ccms.data.entity.User;
import uk.gov.laa.ccms.data.model.BaseProvider;
import uk.gov.laa.ccms.data.model.BaseUser;
Expand All @@ -28,6 +29,9 @@ public interface UserMapper {

BaseUser toBaseUser(User user);

@Mapping(target = "isPrimary", ignore = true)
BaseProvider toBaseProvider(Provider provider);

@Mapping(target = "offices", ignore = true)
BaseProvider toBaseProvider(Firm firm);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
Expand All @@ -13,6 +14,7 @@
import uk.gov.laa.ccms.data.entity.Firm;
import uk.gov.laa.ccms.data.entity.Office;
import uk.gov.laa.ccms.data.entity.Provider;
import uk.gov.laa.ccms.data.entity.ProviderContact;
import uk.gov.laa.ccms.data.entity.User;
import uk.gov.laa.ccms.data.model.BaseOffice;
import uk.gov.laa.ccms.data.model.BaseProvider;
Expand Down Expand Up @@ -54,7 +56,7 @@ private UserDetail createUserDetail(User user) {
userDetail.setLoginId(user.getLoginId());
userDetail.setUsername(user.getUsername());
userDetail.setUserType(user.getUserType());
userDetail.setProvider(mapper.providerToBaseProvider(user.getProvider()));
userDetail.setProvider(mapper.toBaseProvider(user.getProvider()));
userDetail.setFirms(mapper.firmListToBaseProviderList(user.getFirms()));
userDetail.setFunctions(new ArrayList<>(user.getFunctions()));
return userDetail;
Expand All @@ -74,6 +76,41 @@ private BaseOffice createBaseOffice(Office office) {
return baseOffice;
}

private Provider createProvider() {
Provider provider = new Provider();
provider.setId(12345);
provider.setOffices(List.of(new Office()));
provider.setContactNames(List.of(new ProviderContact()));
provider.setName("provider");
return provider;
}

private BaseProvider createBaseProvider(Provider provider) {
BaseProvider baseProvider = new BaseProvider();
baseProvider.setId(provider.getId());
baseProvider.setName(provider.getName());
baseProvider.setOffices(mapper.officeListToBaseOfficeList(provider.getOffices()));
return baseProvider;
}

private BaseProvider createBaseProvider(Firm firm) {
BaseProvider baseProvider = new BaseProvider();
baseProvider.setId(firm.getId());
baseProvider.setName(firm.getName());
baseProvider.setIsPrimary(firm.getIsPrimary());
return baseProvider;
}

private Firm createFirm(Boolean isPrimary) {
Firm firm = new Firm();
firm.setId(12345);
firm.setName("firm");
firm.setUserEndDate(LocalDateTime.now());
firm.setIsPrimary(isPrimary);
return firm;
}


// Tests

@Test
Expand All @@ -99,6 +136,30 @@ void toProviderDetails() {
assertEquals(expectedProvider, actualProvider);
}

@Test
void providerToBaseProvider() {
Provider provider = createProvider();
BaseProvider expectedProvider = createBaseProvider(provider);
BaseProvider actualBaseProvider = mapper.toBaseProvider(provider);
assertEquals(expectedProvider, actualBaseProvider);
}

@Test
void primaryFirmToBaseProvider() {
Firm firm = createFirm(true);
BaseProvider expectedProvider = createBaseProvider(firm);
BaseProvider actualBaseProvider = mapper.toBaseProvider(firm);
assertEquals(expectedProvider, actualBaseProvider);
}

@Test
void nonPrimaryFirmToBaseProvider() {
Firm firm = createFirm(false);
BaseProvider expectedProvider = createBaseProvider(firm);
BaseProvider actualBaseProvider = mapper.toBaseProvider(firm);
assertEquals(expectedProvider, actualBaseProvider);
}

@Test
void firmListToBaseProviderList() {
List<Firm> firms = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ void getEvidenceDocumentTypeLookupValues_returnsPageOEvidenceDocumentTypeValues(
assertEquals(expectedResponse, actualResponse);
}

@SuppressWarnings("unchecked")
@Test
void getAssessmentSummaryAttributes_withParentSummaryType_returnsFilteredResults() {
String summaryType = "PARENT";
Expand All @@ -619,6 +620,7 @@ void getAssessmentSummaryAttributes_withParentSummaryType_returnsFilteredResults
assertEquals(expectedResponse, actualResponse);
}

@SuppressWarnings("unchecked")
@Test
void getAssessmentSummaryAttributes_withChildSummaryType_returnsFilteredResults() {
String summaryType = "CHILD";
Expand All @@ -640,6 +642,7 @@ void getAssessmentSummaryAttributes_withChildSummaryType_returnsFilteredResults(
assertEquals(expectedResponse, actualResponse);
}

@SuppressWarnings("unchecked")
@Test
void getAssessmentSummaryAttributes_withNullSummaryType_returnsAllResults() {
String summaryType = null;
Expand Down

0 comments on commit 0986f8b

Please sign in to comment.