Skip to content

Commit

Permalink
disallowed null country in billing address in member service
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcaprice committed Jun 12, 2024
1 parent b8bf14c commit 670b42a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ public ResponseEntity<Void> updateMemberDefaultLanguage(@PathVariable String sal
public ResponseEntity<Boolean> updatePublicMemberDetails(@RequestBody MemberUpdateData memberUpdateData,
@PathVariable String salesforceId) {
LOG.info("REST request to update member public details for salesforce id {}", salesforceId);
if (StringUtils.isBlank(memberUpdateData.getPublicName())) {
LOG.info("Null name in request to update public details");
if (!memberDetailsUpdateValid(memberUpdateData)) {
return ResponseEntity.badRequest().build();
}
try {
Expand Down Expand Up @@ -388,4 +387,18 @@ public ResponseEntity<Void> requestRemoveConsortiumMember(
memberService.requestRemoveConsortiumMember(removeConsortiumMember);
return ResponseEntity.ok().build();
}

private boolean memberDetailsUpdateValid(MemberUpdateData data) {
if (StringUtils.isBlank(data.getPublicName())) {
LOG.info("Null name in request to update public details");
return false;
}

// allow null billing address but if present, country must be specified
if (data.getBillingAddress() != null && StringUtils.isBlank(data.getBillingAddress().getCountry())) {
LOG.info("Null billing country in request to update public details");
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.orcid.memberportal.service.member.client.model.Country;
import org.orcid.memberportal.service.member.client.model.MemberContact;
import org.orcid.memberportal.service.member.client.model.MemberContacts;
import org.orcid.memberportal.service.member.client.model.MemberDetails;
import org.orcid.memberportal.service.member.client.model.MemberOrgId;
import org.orcid.memberportal.service.member.client.model.MemberOrgIds;
import org.orcid.memberportal.service.member.client.model.MemberUpdateData;
import org.orcid.memberportal.service.member.client.model.State;
import org.orcid.memberportal.service.member.client.model.*;
import org.orcid.memberportal.service.member.domain.Member;
import org.orcid.memberportal.service.member.services.MemberService;
import org.orcid.memberportal.service.member.validation.MemberValidation;
Expand Down Expand Up @@ -105,6 +98,24 @@ public void testUpdatePublicMemberDetails() throws UnauthorizedMemberAccessExcep
Mockito.verify(memberService).updateMemberData(Mockito.any(MemberUpdateData.class), Mockito.eq("salesforceId"));
}

@Test
public void testUpdatePublicMemberDetailsWithBillingAddress() throws UnauthorizedMemberAccessException {
Mockito.when(memberService.updateMemberData(Mockito.any(MemberUpdateData.class), Mockito.eq("salesforceId"))).thenReturn(Boolean.TRUE);
MemberUpdateData memberUpdateData = getPublicMemberDetailsWithBillingAddress();
ResponseEntity<Boolean> response = memberResource.updatePublicMemberDetails(memberUpdateData, "salesforceId");
assertEquals(200, response.getStatusCodeValue());
Mockito.verify(memberService).updateMemberData(Mockito.any(MemberUpdateData.class), Mockito.eq("salesforceId"));
}

@Test
public void testUpdatePublicMemberDetailsWithBillingAddressAndNullCountry() throws UnauthorizedMemberAccessException {
Mockito.when(memberService.updateMemberData(Mockito.any(MemberUpdateData.class), Mockito.eq("salesforceId"))).thenReturn(Boolean.TRUE);
MemberUpdateData memberUpdateData = getPublicMemberDetailsWithBillingAddressAndNullCountry();
ResponseEntity<Boolean> response = memberResource.updatePublicMemberDetails(memberUpdateData, "salesforceId");
assertEquals(400, response.getStatusCodeValue());
Mockito.verify(memberService, Mockito.never()).updateMemberData(Mockito.any(MemberUpdateData.class), Mockito.eq("salesforceId"));
}

@Test
public void testUpdatePublicMemberDetails_unauthorised() throws UnauthorizedMemberAccessException {
Mockito.when(memberService.updateMemberData(Mockito.any(MemberUpdateData.class), Mockito.eq("salesforceId"))).thenThrow(new UnauthorizedMemberAccessException("blah", "blah"));
Expand Down Expand Up @@ -301,6 +312,35 @@ private MemberUpdateData getPublicMemberDetails() {
return memberUpdateData;
}

private MemberUpdateData getPublicMemberDetailsWithBillingAddress() {
MemberUpdateData memberUpdateData = new MemberUpdateData();
memberUpdateData.setPublicName("test member details");
memberUpdateData.setWebsite("https://website.com");
memberUpdateData.setOrgName("orgName");
memberUpdateData.setDescription("test");
memberUpdateData.setEmail("[email protected]");

BillingAddress billingAddress = new BillingAddress();
billingAddress.setCity("new york");
billingAddress.setCountry("USA");
memberUpdateData.setBillingAddress(billingAddress);
return memberUpdateData;
}

private MemberUpdateData getPublicMemberDetailsWithBillingAddressAndNullCountry() {
MemberUpdateData memberUpdateData = new MemberUpdateData();
memberUpdateData.setPublicName("test member details");
memberUpdateData.setWebsite("https://website.com");
memberUpdateData.setOrgName("orgName");
memberUpdateData.setDescription("test");
memberUpdateData.setEmail("[email protected]");

BillingAddress billingAddress = new BillingAddress();
billingAddress.setCity("new york");
memberUpdateData.setBillingAddress(billingAddress);
return memberUpdateData;
}

private MemberContacts getMemberContacts() {
MemberContacts memberContacts = new MemberContacts();

Expand Down

0 comments on commit 670b42a

Please sign in to comment.