Repository: companieshouse/api-sdk-node
Pull request #762: lp550-create general partner usual residential  choice page
Author: login: HatiDev
Created: 2025-03-12T12:21:35Z | Merged: 2025-03-12T14:04:17Z

JIRA link
https://companieshouse.atlassian.net/browse/LP-550

Change description
add getGeneralPartner method to limited partnership service


Diff:
diff --git a/src/services/limited-partnerships/service.ts b/src/services/limited-partnerships/service.ts
index 095bce9f..a79d3611 100644
--- a/src/services/limited-partnerships/service.ts
+++ b/src/services/limited-partnerships/service.ts
@@ -1,5 +1,10 @@
 import { HttpResponse, IHttpClient } from "../../http";
-import { LimitedPartnership, LimitedPartnershipResourceCreated, LimitedPartnershipIncorporation, GeneralPartner } from "./types";
+import {
+    LimitedPartnership,
+    LimitedPartnershipResourceCreated,
+    LimitedPartnershipIncorporation,
+    GeneralPartner
+} from "./types";
 import Resource, { ApiErrorResponse } from "../resource";
 
 export default class LimitedPartnershipsService {
@@ -50,7 +55,8 @@ export default class LimitedPartnershipsService {
      */
 
     public async postLimitedPartnershipIncorporation (
-        transactionId: string): Promise<Resource<LimitedPartnershipResourceCreated> | ApiErrorResponse> {
+        transactionId: string
+    ): Promise<Resource<LimitedPartnershipResourceCreated> | ApiErrorResponse> {
         const URL = `/transactions/${transactionId}/incorporation/limited-partnership`;
         const response: HttpResponse = await this.client.httpPost(URL);
 
@@ -63,8 +69,11 @@ export default class LimitedPartnershipsService {
     public async getLimitedPartnershipIncorporation (
         transactionId: string,
         filingResourceId: string,
-        includeSubResources?: boolean): Promise<Resource<LimitedPartnershipIncorporation> | ApiErrorResponse> {
-        const subResourcesQuery: string = (includeSubResources ? ("?include_sub_resources=" + includeSubResources) : "");
+        includeSubResources?: boolean
+    ): Promise<Resource<LimitedPartnershipIncorporation> | ApiErrorResponse> {
+        const subResourcesQuery: string = includeSubResources
+            ? "?include_sub_resources=" + includeSubResources
+            : "";
         const URL = `/transactions/${transactionId}/incorporation/limited-partnership/${filingResourceId}${subResourcesQuery}`;
 
         const response: HttpResponse = await this.client.httpGet(URL);
@@ -81,7 +90,8 @@ export default class LimitedPartnershipsService {
 
     public async postGeneralPartner (
         transactionId: string,
-        body: GeneralPartner): Promise<Resource<LimitedPartnershipResourceCreated> | ApiErrorResponse> {
+        body: GeneralPartner
+    ): Promise<Resource<LimitedPartnershipResourceCreated> | ApiErrorResponse> {
         const URL = `/transactions/${transactionId}/limited-partnership/general-partner`;
         const response: HttpResponse = await this.client.httpPost(URL, body);
 
@@ -90,4 +100,17 @@ export default class LimitedPartnershipsService {
             resource: { ...response.body }
         };
     }
+
+    public async getGeneralPartner (
+        transactionId: string,
+        generalPartnerId: string
+    ): Promise<Resource<GeneralPartner> | ApiErrorResponse> {
+        const URL = `/transactions/${transactionId}/limited-partnership/general-partner/${generalPartnerId}`;
+        const response: HttpResponse = await this.client.httpGet(URL);
+
+        return {
+            httpStatusCode: response.status,
+            resource: { ...response.body }
+        };
+    }
 }
diff --git a/test/services/limited-partnerships/limited.partnerships.mock.ts b/test/services/limited-partnerships/limited.partnerships.mock.ts
index 1f41938f..d23d7bbf 100644
--- a/test/services/limited-partnerships/limited.partnerships.mock.ts
+++ b/test/services/limited-partnerships/limited.partnerships.mock.ts
@@ -156,3 +156,9 @@ export const mockPostGeneralPartnerResponse = {
     400: { status: 400, body: { error: BAD_REQUEST } },
     401: { status: 401, body: { error: UNAUTHORISED } }
 };
+
+export const mockGetGeneralPartnerResponse = {
+    200: { status: 200, body: GENERAL_PARTNER_OBJECT_MOCK },
+    404: { status: 404, body: { error: NOT_FOUND } },
+    401: { status: 401, body: { error: UNAUTHORISED } }
+};
diff --git a/test/services/limited-partnerships/limited.partnerships.spec.ts b/test/services/limited-partnerships/limited.partnerships.spec.ts
index fd6bbdc4..8c384c4b 100644
--- a/test/services/limited-partnerships/limited.partnerships.spec.ts
+++ b/test/services/limited-partnerships/limited.partnerships.spec.ts
@@ -8,7 +8,8 @@ import {
     LimitedPartnershipResourceCreated,
     LimitedPartnershipsService,
     LimitedPartnershipIncorporation,
-    NameEndingType
+    NameEndingType,
+    GeneralPartner
 } from "../../../src/services/limited-partnerships";
 import Resource from "../../../src/services/resource";
 
@@ -194,6 +195,7 @@ describe("LimitedPartnershipsService", () => {
                         "/transactions/12345/limited-partnership/partnership/09876"
                     )
                 ).to.be.true;
+
                 expect(response.httpStatusCode).to.equal(200);
                 expect(response?.resource).to.eql(mockValues.LIMITED_PARTNERSHIP_OBJECT_MOCK);
             });
@@ -498,4 +500,78 @@ describe("LimitedPartnershipsService", () => {
             });
         })
     });
+
+    describe("getGeneralPartner", () => {
+        it("should return a status 200 and the generalPartner object", async () => {
+            const mockRequest = sinon
+                .stub(mockValues.requestClient, "httpGet")
+                .resolves(mockValues.mockGetGeneralPartnerResponse[200]);
+
+            const service = new LimitedPartnershipsService(
+                mockValues.requestClient
+            );
+
+            const response = await service.getGeneralPartner(
+                mockValues.TRANSACTION_ID,
+                mockValues.SUBMISSION_ID
+            ) as Resource<GeneralPartner>;
+
+            expect(mockRequest).to.have.been.calledOnce;
+            expect(
+                mockRequest.calledWith(
+                    "/transactions/12345/limited-partnership/general-partner/09876"
+                )
+            ).to.be.true;
+            expect(response.httpStatusCode).to.equal(200);
+            expect(response?.resource).to.eql(mockValues.GENERAL_PARTNER_OBJECT_MOCK);
+        });
+
+        it("should return error 401 (Unauthorised)", async () => {
+            const mockRequest = sinon
+                .stub(mockValues.requestClient, "httpGet")
+                .resolves(mockValues.mockGetGeneralPartnerResponse[401]);
+
+            const service = new LimitedPartnershipsService(
+                mockValues.requestClient
+            );
+            const response = (await service.getGeneralPartner(
+                mockValues.TRANSACTION_ID,
+                mockValues.SUBMISSION_ID
+            )) as Resource<any>;
+
+            expect(mockRequest).to.have.been.calledOnce;
+            expect(
+                mockRequest.calledWith(
+                    "/transactions/12345/limited-partnership/general-partner/09876"
+                )
+            ).to.be.true;
+
+            expect(response.httpStatusCode).to.equal(401);
+            expect(response.resource.error).to.equal(mockValues.UNAUTHORISED);
+        });
+
+        it("should return error 404 (Not Found)", async () => {
+            const mockRequest = sinon
+                .stub(mockValues.requestClient, "httpGet")
+                .resolves(mockValues.mockGetGeneralPartnerResponse[404]);
+
+            const service = new LimitedPartnershipsService(
+                mockValues.requestClient
+            );
+            const response = (await service.getGeneralPartner(
+                mockValues.TRANSACTION_ID,
+                "wrong-id"
+            )) as Resource<any>;
+
+            expect(mockRequest).to.have.been.calledOnce;
+            expect(
+                mockRequest.calledWith(
+                    "/transactions/12345/limited-partnership/general-partner/wrong-id"
+                )
+            ).to.be.true;
+
+            expect(response.httpStatusCode).to.equal(404);
+            expect(response.resource.error).to.equal(mockValues.NOT_FOUND);
+        });
+    })
 });


Reviews:
user: login: lduranteau
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-12T13:29:35Z
user: login: HatiDev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-12T13:41:13Z
user: login: lduranteau
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-12T13:58:18Z

Review comments:
diff_hunk: @@ -90,4 +100,17 @@ export default class LimitedPartnershipsService {
             resource: { ...response.body }
         };
     }
+
+    public async getGeneralPartner (
+        transactionId: string,
+        submissionId: string
path: src/services/limited-partnerships/service.ts
user: login: lduranteau
body: can you change submissionId by generalPartnerId
created_at: 2025-03-12T13:29:28Z
author_association: CONTRIBUTOR
diff_hunk: @@ -90,4 +100,17 @@ export default class LimitedPartnershipsService {
             resource: { ...response.body }
         };
     }
+
+    public async getGeneralPartner (
+        transactionId: string,
+        submissionId: string
path: src/services/limited-partnerships/service.ts
user: login: HatiDev
body: renamed
created_at: 2025-03-12T13:41:13Z
author_association: CONTRIBUTOR

PR comments:
user: login: chsonarqubeprchecks[bot]
created_at: 2025-03-12T13:59:12Z
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=api-sdk-node&pullRequest=762)

[![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=api-sdk-node&pullRequest=762&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=api-sdk-node&pullRequest=762&resolved=false&types=BUG) [0 Bugs](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=api-sdk-node&pullRequest=762&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=api-sdk-node&pullRequest=762&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=api-sdk-node&pullRequest=762&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=api-sdk-node&pullRequest=762&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=api-sdk-node&pullRequest=762) [![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=api-sdk-node&pullRequest=762) [0 Security Hotspots](http://code-analysis.platform.aws.chdev.org:9000/security_hotspots?id=api-sdk-node&pullRequest=762)  
[![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=api-sdk-node&pullRequest=762&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=api-sdk-node&pullRequest=762&resolved=false&types=CODE_SMELL) [0 Code Smells](http://code-analysis.platform.aws.chdev.org:9000/project/issues?id=api-sdk-node&pullRequest=762&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=api-sdk-node&pullRequest=762&metric=new_coverage&view=list) [100.0% Coverage](http://code-analysis.platform.aws.chdev.org:9000/component_measures?id=api-sdk-node&pullRequest=762&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=api-sdk-node&pullRequest=762&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](http://code-analysis.platform.aws.chdev.org:9000/component_measures?id=api-sdk-node&pullRequest=762&metric=new_duplicated_lines_density&view=list)


author_association: NONE