Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story: [CCMSPUI 370] Add isPrimary flag for provider firms #117

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading