Repository: companieshouse/test-data-generator
Pull request #121: IDVA6-2287 update ACSP profile to take an ACSP number
Author: login: sahmed-ch
Created: 2025-03-12T16:24:58Z | Merged: 2025-03-17T11:49:40Z

Changes made:
- If an ACSP number is provided, ACSP profile is created with that number. If no ACSP number is provided, the randomly generated number is used.
- Updated ACSP membership status to only be `active` or `removed`. 
- Changed the default user role to `owner` for an ACSP membership.
- Changed the default type to `limited-company` for an ACSP profile.


Diff:
diff --git a/README.md b/README.md
index 87cbb2c73..5d290621c 100644
--- a/README.md
+++ b/README.md
@@ -91,13 +91,14 @@ In order to use the generator, there are different possible endpoints that can b
     - `user_role`: This is the role of the ACSP Member. This is optional
     - `status`: Status of the Acsp Member. This is optional
     - `acsp_profile`:
-      - `type`: Company type of the AcspProfile. This is optional with a defaults to `ltd`.
+      - `type`: Company type of the AcspProfile. This is optional with a defaults to `limited-company`.
       - `status`: Status of the Acsp Profile. This is optional with a defaults to`active`.
+      - `acsp_number`: ACSP number of the ACSP Profile. This is optional.
       - `aml_details`:
           - `supervisory_body`: Supervisory body of the Acsp Profile. This is optional.
           - `membership_details`: Membership details of the Acsp Profile. This is optional.
 
-  An usage example looks like this: `{"userId": "rsf3pdwywvse5yz55mfodfx8","userRole": "test","status": "test","acspProfile": {"type": "test","status": "test", "aml_details": [ {"supervisory_body": "association-of-chartered-certified-accountants-acca","membership_details": "test"} ] } }`
+  A usage example looks like this: `{"user_id": "rsf3pdwywvse5yz55mfodfx8","user_role": "test","status": "test","acsp_profile": {"type": "test","status": "test", "acsp_number": "TestACSP", "aml_details": [ {"supervisory_body": "association-of-chartered-certified-accountants-acca","membership_details": "test"} ] } }`
 - DELETE: Sending a DELETE request on the endpoint `{Base URL}/test-data/acsp-members/{acspMemberId}` will delete the test `Acsp Member` and associated `Acsp Profile`. `acspMemberId` is required to delete the Acsp Member.
 
 #### Deleting Appeals
diff --git a/src/main/java/uk/gov/companieshouse/api/testdata/model/rest/AcspMembersSpec.java b/src/main/java/uk/gov/companieshouse/api/testdata/model/rest/AcspMembersSpec.java
index 45a90628e..0d60afda9 100644
--- a/src/main/java/uk/gov/companieshouse/api/testdata/model/rest/AcspMembersSpec.java
+++ b/src/main/java/uk/gov/companieshouse/api/testdata/model/rest/AcspMembersSpec.java
@@ -13,7 +13,7 @@ public class AcspMembersSpec {
     private String userId;
 
     @JsonProperty("status")
-    @Pattern(regexp = "active|suspended|ceased", message = "Invalid acsp member status")
+    @Pattern(regexp = "active|removed", message = "Invalid acsp member status")
     private String status;
 
     @JsonProperty("user_role")
diff --git a/src/main/java/uk/gov/companieshouse/api/testdata/model/rest/AcspProfileSpec.java b/src/main/java/uk/gov/companieshouse/api/testdata/model/rest/AcspProfileSpec.java
index 47642842a..ddb2274db 100644
--- a/src/main/java/uk/gov/companieshouse/api/testdata/model/rest/AcspProfileSpec.java
+++ b/src/main/java/uk/gov/companieshouse/api/testdata/model/rest/AcspProfileSpec.java
@@ -11,6 +11,9 @@ public class AcspProfileSpec {
     @JsonProperty
     private String type;
 
+    @JsonProperty("acsp_number")
+    private String acspNumber;
+
     @JsonProperty("aml_details")
     private List<AmlSpec> amlDetails;
 
@@ -30,6 +33,14 @@ public void setType(String type) {
         this.type = type;
     }
 
+    public String getAcspNumber() {
+        return acspNumber;
+    }
+
+    public void setAcspNumber(String acspNumber) {
+        this.acspNumber = acspNumber;
+    }
+
     public List<AmlSpec> getAmlDetails() {
         return amlDetails;
     }
diff --git a/src/main/java/uk/gov/companieshouse/api/testdata/service/impl/AcspMembersServiceImpl.java b/src/main/java/uk/gov/companieshouse/api/testdata/service/impl/AcspMembersServiceImpl.java
index 99a2fd5ae..186f38783 100644
--- a/src/main/java/uk/gov/companieshouse/api/testdata/service/impl/AcspMembersServiceImpl.java
+++ b/src/main/java/uk/gov/companieshouse/api/testdata/service/impl/AcspMembersServiceImpl.java
@@ -34,7 +34,7 @@ public AcspMembersData create(AcspMembersSpec acspMembersSpec) throws DataExcept
         acspMembers.setAcspNumber(acspMembersSpec.getAcspNumber());
         acspMembers.setUserId(acspMembersSpec.getUserId());
         acspMembers.setUserRole(Objects.requireNonNullElse(acspMembersSpec.getUserRole(),
-                "member"));
+                "owner"));
         acspMembers.setStatus(Objects.requireNonNullElse(acspMembersSpec.getStatus(),
                 "active"));
         acspMembers.setCreatedAt(currentDate);
diff --git a/src/main/java/uk/gov/companieshouse/api/testdata/service/impl/AcspProfileServiceImpl.java b/src/main/java/uk/gov/companieshouse/api/testdata/service/impl/AcspProfileServiceImpl.java
index cbe17c460..05a0b5d60 100644
--- a/src/main/java/uk/gov/companieshouse/api/testdata/service/impl/AcspProfileServiceImpl.java
+++ b/src/main/java/uk/gov/companieshouse/api/testdata/service/impl/AcspProfileServiceImpl.java
@@ -27,15 +27,16 @@ public class AcspProfileServiceImpl implements DataService<AcspProfileData, Acsp
 
     public AcspProfileData create(AcspProfileSpec spec) throws DataException {
         var randomId = randomService.getString(8);
+        var acspNumber = Objects.requireNonNullElse(spec.getAcspNumber(), randomId);
 
         var profile = new AcspProfile();
-        profile.setId(randomId);
+        profile.setId(acspNumber);
         profile.setVersion(0L);
         profile.setStatus(Objects.requireNonNullElse(spec.getStatus(), "active"));
-        profile.setType(Objects.requireNonNullElse(spec.getType(), "ltd"));
-        profile.setAcspNumber(randomId);
-        profile.setName("Test Data Generator " + randomId + " Company Ltd");
-        profile.setLinksSelf(LINK_STEM + randomId);
+        profile.setType(Objects.requireNonNullElse(spec.getType(), "limited-company"));
+        profile.setAcspNumber(acspNumber);
+        profile.setName("Test Data Generator " + acspNumber + " Company Ltd");
+        profile.setLinksSelf(LINK_STEM + acspNumber);
         if (spec.getAmlDetails() != null) {
             List<AmlDetails> amlDetailsList = new ArrayList<>();
             for (AmlSpec amlSpec : spec.getAmlDetails()) {
diff --git a/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/AcspMembersServiceImplTest.java b/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/AcspMembersServiceImplTest.java
index 16825c0ab..1d1fc723b 100644
--- a/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/AcspMembersServiceImplTest.java
+++ b/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/AcspMembersServiceImplTest.java
@@ -100,7 +100,7 @@ void createAcspMemberWithDefaultValues() throws DataException {
         assertEquals("acspNumber", result.getAcspNumber());
         assertEquals("userId", result.getUserId());
         assertEquals("active", result.getStatus());
-        assertEquals("member", result.getUserRole());
+        assertEquals("owner", result.getUserRole());
 
         ArgumentCaptor<AcspMembers> captor = ArgumentCaptor.forClass(AcspMembers.class);
         verify(repository).save(captor.capture());
@@ -110,7 +110,7 @@ void createAcspMemberWithDefaultValues() throws DataException {
         assertEquals("acspNumber", captured.getAcspNumber());
         assertEquals("userId", captured.getUserId());
         assertEquals("active", captured.getStatus());
-        assertEquals("member", captured.getUserRole());
+        assertEquals("owner", captured.getUserRole());
         assertEquals(createdDate, captured.getCreatedAt());
         assertEquals(createdDate, captured.getAddedAt());
         assertEquals(0L, captured.getVersion());
diff --git a/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/AcspProfileServiceImplTest.java b/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/AcspProfileServiceImplTest.java
index f26675317..ee88823f3 100644
--- a/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/AcspProfileServiceImplTest.java
+++ b/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/AcspProfileServiceImplTest.java
@@ -100,7 +100,8 @@ void createAcspProfileWithDefaultValues() throws DataException {
         assertEquals("randomId", captured.getId());
         assertEquals("randomId", captured.getAcspNumber());
         assertEquals("active", captured.getStatus()); // Default value
-        assertEquals("ltd", captured.getType()); // Default value
+        assertEquals("limited-company", captured.getType()); //
+        // Default value
         assertEquals("Test Data Generator randomId Company Ltd", captured.getName());
         assertEquals("/authorised-corporate-service-providers/randomId", captured.getLinksSelf());
         assertEquals(0L, captured.getVersion());
@@ -187,6 +188,23 @@ void createAcspProfileWithEmptyAmlDetails() throws DataException {
         assertEquals("/authorised-corporate-service-providers/randomId", captured.getLinksSelf());
     }
 
+    @Test
+    void createAcspProfileWithProvidedAcspNumber() throws DataException {
+        AcspProfileSpec spec = new AcspProfileSpec();
+        spec.setAcspNumber("TestACSP");
+
+        AcspProfile savedProfile = new AcspProfile();
+        savedProfile.setAcspNumber(spec.getAcspNumber());
+
+        when(repository.save(any(AcspProfile.class))).thenReturn(savedProfile);
+
+        AcspProfileData result = service.create(spec);
+
+        assertNotNull(result);
+        assertEquals("TestACSP", result.getAcspNumber());
+        verify(repository).save(any(AcspProfile.class));
+    }
+
     @Test
     void deleteAcspProfile() {
         AcspProfile acspProfile = new AcspProfile();
diff --git a/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/TestDataServiceImplTest.java b/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/TestDataServiceImplTest.java
index 88f76bdca..3e34178ed 100644
--- a/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/TestDataServiceImplTest.java
+++ b/src/test/java/uk/gov/companieshouse/api/testdata/service/impl/TestDataServiceImplTest.java
@@ -181,9 +181,10 @@ private void verifyCommonCompanyCreation(CompanySpec capturedSpec, CompanyData c
      */
     private AcspMembersData createAcspMembersDataHelper(String userId,
                                                         AcspProfileData profileData,
-                                                        AcspMembersData membersData) throws DataException {
+                                                        AcspMembersData membersData, AcspProfileSpec profileSpec) throws DataException {
         AcspMembersSpec spec = new AcspMembersSpec();
         spec.setUserId(userId);
+        spec.setAcspProfile(profileSpec);
         when(acspProfileService.create(any(AcspProfileSpec.class))).thenReturn(profileData);
         when(acspMembersService.create(any(AcspMembersSpec.class))).thenReturn(membersData);
         return testDataService.createAcspMembersData(spec);
@@ -883,11 +884,18 @@ void deleteIdentityDataThrowsException() {
 
     @Test
     void createAcspMembersData() throws DataException {
-        AcspProfileData acspProfileData = new AcspProfileData("acspNumber");
+        AcspProfileSpec profileSpec = new AcspProfileSpec();
+        profileSpec.setAcspNumber("acspNumber");
+        profileSpec.setStatus("active");
+        profileSpec.setType("limited-company");
+
+        AcspProfileData acspProfileData =
+                new AcspProfileData(profileSpec.getAcspNumber());
         AcspMembersData expectedMembersData =
-                new AcspMembersData("memberId", "acspNumber", "userId", "active", "role");
+                new AcspMembersData("memberId", profileSpec.getAcspNumber(), "userId", "active", "role");
 
-        AcspMembersData result = createAcspMembersDataHelper("userId", acspProfileData, expectedMembersData);
+        AcspMembersData result = createAcspMembersDataHelper(
+                "userId", acspProfileData, expectedMembersData, profileSpec);
 
         verifyAcspMembersData(result, expectedMembersData.getAcspMemberId(), acspProfileData.getAcspNumber(), expectedMembersData.getUserId(), expectedMembersData.getStatus(), expectedMembersData.getUserRole());
         verify(acspMembersService).create(any(AcspMembersSpec.class));


Reviews:
user: login: lyadavalli
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-12T16:50:01Z
user: login: sahmed-ch
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-12T16:58:30Z
user: login: krishna-patel-ch
state: APPROVED
author_association: NONE
submitted_at: 2025-03-17T10:30:47Z
user: login: lyadavalli
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-17T11:48:30Z

Review comments:
diff_hunk: @@ -282,6 +282,10 @@ public AcspMembersData createAcspMembersData(final AcspMembersSpec spec) throws
             acspProfileSpec.setType(spec.getAcspProfile().getType());
         }
 
+        if (spec.getAcspProfile() != null) {
+            acspProfileSpec.setAcspNumber(spec.getAcspProfile().getAcspNumber());
+        }
path: src/main/java/uk/gov/companieshouse/api/testdata/service/impl/TestDataServiceImpl.java
user: login: lyadavalli
body: can we keep all these 3 if conditions in one ? its all checking the same `spec.getAcspProfile() != null`
created_at: 2025-03-12T16:46:20Z
author_association: CONTRIBUTOR
diff_hunk: @@ -282,6 +282,10 @@ public AcspMembersData createAcspMembersData(final AcspMembersSpec spec) throws
             acspProfileSpec.setType(spec.getAcspProfile().getType());
         }
 
+        if (spec.getAcspProfile() != null) {
+            acspProfileSpec.setAcspNumber(spec.getAcspProfile().getAcspNumber());
+        }
path: src/main/java/uk/gov/companieshouse/api/testdata/service/impl/TestDataServiceImpl.java
user: login: sahmed-ch
body: Updated the code.
created_at: 2025-03-12T16:58:30Z
author_association: CONTRIBUTOR

PR comments:
user: login: chsonarqubeprchecks[bot]
created_at: 2025-03-17T11:42:50Z
body: **SonarQube Quality Gate**

[![Quality Gate passed](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](http://code-analysis.platform.aws.chdev.org:9000/dashboard?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121)

[![Bug](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/common/bug-16px.png 'Bug')](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=BUG) [![A](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/checks/RatingBadge/A-16px.png 'A')](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=BUG) [0 Bugs](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=BUG)  
[![Vulnerability](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/common/vulnerability-16px.png 'Vulnerability')](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=VULNERABILITY) [![A](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/checks/RatingBadge/A-16px.png 'A')](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/common/security_hotspot-16px.png 'Security Hotspot')](http://code-analysis.platform.aws.chdev.org:9000/security_hotspots?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121) [![A](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/checks/RatingBadge/A-16px.png 'A')](http://code-analysis.platform.aws.chdev.org:9000/security_hotspots?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121) [0 Security Hotspots](http://code-analysis.platform.aws.chdev.org:9000/security_hotspots?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121)  
[![Code Smell](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/common/code_smell-16px.png 'Code Smell')](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=CODE_SMELL) [![A](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/checks/RatingBadge/A-16px.png 'A')](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=CODE_SMELL) [0 Code Smells](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&resolved=false&types=CODE_SMELL)

[![100.0%](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/checks/CoverageChart/100-16px.png '100.0%')](http://code-analysis.platform.aws.chdev.org:9000/component_measures?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&metric=new_coverage&view=list) [100.0% Coverage](http://code-analysis.platform.aws.chdev.org:9000/component_measures?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&metric=new_coverage&view=list)  
[![0.0%](https://raw.githubusercontent.com/SonarSource/sonarqube-static-resources/master/v86/checks/Duplications/3-16px.png '0.0%')](http://code-analysis.platform.aws.chdev.org:9000/component_measures?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](http://code-analysis.platform.aws.chdev.org:9000/component_measures?id=uk.gov.companieshouse%3Atest-data-generator&pullRequest=121&metric=new_duplicated_lines_density&view=list)


author_association: NONE