Skip to content

Commit 5633e47

Browse files
authored
Merge pull request #800 from companieshouse/feature/psc-verification-web-persist-request-id
IDVA3-3300 Add optional headers parameter to psc-verification-web api calls
2 parents 4563002 + ae8e38b commit 5633e47

File tree

8 files changed

+107
-20
lines changed

8 files changed

+107
-20
lines changed

src/services/company-profile/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IHttpClient } from "../../http";
1+
import { Headers, IHttpClient } from "../../http";
22
import {
33
CompanyProfile, CompanyProfileResource, RegisteredOfficeAddressResource, AccountsResource,
44
NextAccountsResource, ConfirmationStatementResource, LinksResource, ForeignCompanyDetailsResource, ServiceAddressResource
@@ -16,8 +16,8 @@ export default class CompanyProfileService {
1616
*
1717
* @param number the company number to look up
1818
*/
19-
public async getCompanyProfile (number: string): Promise<Resource<CompanyProfile>> {
20-
const resp = await this.client.httpGet(`/company/${number}`);
19+
public async getCompanyProfile (number: string, headers?: Headers): Promise<Resource<CompanyProfile>> {
20+
const resp = await this.client.httpGet(`/company/${number}`, headers);
2121

2222
const resource: Resource<CompanyProfile> = {
2323
httpStatusCode: resp.status

src/services/company-psc/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IHttpClient } from "../../http";
1+
import { Headers, IHttpClient } from "../../http";
22
import { CompanyPersonsWithSignificantControlResource, CompanyPersonsWithSignificantControl } from "./types";
33
import Resource from "../resource";
44
import Mapping from "../../mapping/mapping";
@@ -14,8 +14,8 @@ export default class CompanyPscService {
1414
*
1515
* @param number the company number to look up
1616
*/
17-
public async getCompanyPsc (number: string, startIndex: number = 0, itemsPerPage: number = 25): Promise<Resource<CompanyPersonsWithSignificantControl>> {
18-
const resp = await this.client.httpGet(`/company/${number}/persons-with-significant-control?start_index=${startIndex}&items_per_page=${itemsPerPage}`);
17+
public async getCompanyPsc (number: string, startIndex: number = 0, itemsPerPage: number = 25, headers?: Headers): Promise<Resource<CompanyPersonsWithSignificantControl>> {
18+
const resp = await this.client.httpGet(`/company/${number}/persons-with-significant-control?start_index=${startIndex}&items_per_page=${itemsPerPage}`, headers);
1919

2020
const resource: Resource<CompanyPersonsWithSignificantControl> = {
2121
httpStatusCode: resp.status

src/services/psc-verification-link/service.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { PlannedMaintenance, PscVerification, PscVerificationData, ValidationStatusResponse, ValidationStatusResponseResource } from "./types"
22

3-
import { HttpResponse, IHttpClient } from "../../http";
3+
import { Headers, HttpResponse, IHttpClient } from "../../http";
44
import Resource, { ApiErrorResponse, ApiResponse } from "../resource";
55
import Mapping from "../../mapping/mapping";
66
import { PersonWithSignificantControlResource } from "../psc/types";
@@ -22,10 +22,10 @@ export default class PscVerificationService {
2222
* - A `Resource<PscVerification>` object containing the created PSC verification details.
2323
* - An `ApiErrorResponse` object if an error occurs during the request.
2424
*/
25-
public async postPscVerification (transactionId: string, pscVerification: PscVerificationData): Promise<Resource<PscVerification> | ApiErrorResponse> {
25+
public async postPscVerification (transactionId: string, pscVerification: PscVerificationData, headers?: Headers): Promise<Resource<PscVerification> | ApiErrorResponse> {
2626
const resourceUri = `/transactions/${transactionId}/persons-with-significant-control-verification`;
2727
const pscVerificationResource = Mapping.snakeCaseKeys(pscVerification);
28-
const response = await this.client.httpPost(resourceUri, pscVerificationResource);
28+
const response = await this.client.httpPost(resourceUri, pscVerificationResource, headers);
2929

3030
if (response.error) {
3131
return this.handleErrorResponse(response);
@@ -43,9 +43,9 @@ export default class PscVerificationService {
4343
* - A `Resource<PscVerification>` object containing the PSC verification details.
4444
* - An `ApiErrorResponse` object if an error occurs during the request.
4545
*/
46-
public async getPscVerification (transactionId: string, pscVerificationId: string): Promise<Resource<PscVerification> | ApiErrorResponse> {
46+
public async getPscVerification (transactionId: string, pscVerificationId: string, headers?: Headers): Promise<Resource<PscVerification> | ApiErrorResponse> {
4747
const resourceUri = `/transactions/${transactionId}/persons-with-significant-control-verification/${pscVerificationId}`;
48-
const response = await this.client.httpGet(resourceUri);
48+
const response = await this.client.httpGet(resourceUri, headers);
4949

5050
if (response.error) {
5151
return this.handleErrorResponse(response);
@@ -64,8 +64,11 @@ export default class PscVerificationService {
6464
* - A `Resource<PscVerification>` object containing the updated PSC verification details.
6565
* - An `ApiErrorResponse` object if an error occurs during the request.
6666
*/
67-
public async patchPscVerification (transactionId: string, pscVerificationId: string, pscVerificationPatch: PscVerificationData): Promise<Resource<PscVerification> | ApiErrorResponse> {
68-
const additionalHeaders = { "Content-Type": "application/merge-patch+json" };
67+
public async patchPscVerification (transactionId: string, pscVerificationId: string, pscVerificationPatch: PscVerificationData, headers?: Headers): Promise<Resource<PscVerification> | ApiErrorResponse> {
68+
const additionalHeaders = {
69+
...headers,
70+
"Content-Type": "application/merge-patch+json"
71+
};
6972
const resourceUri = `/transactions/${transactionId}/persons-with-significant-control-verification/${pscVerificationId}`;
7073
const pscVerificationPatchResource = Mapping.snakeCaseKeys(pscVerificationPatch);
7174
const response = await this.client.httpPatch(resourceUri, pscVerificationPatchResource, additionalHeaders);
@@ -91,9 +94,9 @@ export default class PscVerificationService {
9194
* using the `handleErrorResponse` method. Otherwise, the response body is mapped to camelCase keys
9295
* and returned as part of the resource.
9396
*/
94-
public async getValidationStatus (transactionId: string, pscVerificationId: string): Promise<Resource<PscVerification> | ApiErrorResponse> {
97+
public async getValidationStatus (transactionId: string, pscVerificationId: string, headers?: Headers): Promise<Resource<PscVerification> | ApiErrorResponse> {
9598
const resourceUri = `/transactions/${transactionId}/persons-with-significant-control-verification/${pscVerificationId}/validation_status`;
96-
const response = await this.client.httpGet(resourceUri);
99+
const response = await this.client.httpGet(resourceUri, headers);
97100

98101
if (response.error) {
99102
return this.handleErrorResponse(response);
@@ -115,9 +118,9 @@ export default class PscVerificationService {
115118
* - An `ApiResponse<PlannedMaintenance>` object containing maintenance details.
116119
* - An `ApiErrorResponse` object if an error occurs during the request.
117120
*/
118-
public async checkPlannedMaintenance (): Promise<ApiResponse<PlannedMaintenance> | ApiErrorResponse> {
121+
public async checkPlannedMaintenance (headers?: Headers): Promise<ApiResponse<PlannedMaintenance> | ApiErrorResponse> {
119122
const maintenanceUri = `/persons-with-significant-control-verification/maintenance`;
120-
const response = await this.client.httpGet(maintenanceUri);
123+
const response = await this.client.httpGet(maintenanceUri, headers);
121124

122125
if (response.error) {
123126
return this.handleErrorResponse(response);

src/services/psc/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IHttpClient } from "../../http";
1+
import { Headers, IHttpClient } from "../../http";
22
import Mapping from "../../mapping/mapping";
33
import Resource, { ApiErrorResponse } from "../resource";
44
import { PersonWithSignificantControl, PersonWithSignificantControlResource } from "./types";
@@ -15,9 +15,9 @@ export default class PscService {
1515
* @param companyNumber the Company Number to look up
1616
* @param pscNotificationId the PSC Notification ID to retrieve
1717
*/
18-
public async getPscIndividual (companyNumber: string, pscNotificationId: string): Promise<Resource<PersonWithSignificantControl> | ApiErrorResponse> {
18+
public async getPscIndividual (companyNumber: string, pscNotificationId: string, headers?: Headers): Promise<Resource<PersonWithSignificantControl> | ApiErrorResponse> {
1919
const resourceUri = `/company/${companyNumber}/persons-with-significant-control/individual/${pscNotificationId}/verification-state`;
20-
const response = await this.client.httpGet(resourceUri);
20+
const response = await this.client.httpGet(resourceUri, headers);
2121

2222
if (response.error) {
2323
return {

test/services/company-profile/service.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,21 @@ describe("company-profile", () => {
231231
expect(resource.links.filingHistory).to.be.undefined;
232232
expect(resource.hasSuperSecurePscs).to.be.undefined;
233233
});
234+
235+
it("uses provided headers", async () => {
236+
const mockResponseBody : CompanyProfileResource = fullCompanyProfileMock;
237+
const headers = { "X-Request-Id": "random-uuid" };
238+
239+
const mockGetResponse = {
240+
status: 200,
241+
body: mockResponseBody
242+
};
243+
244+
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetResponse);
245+
const companyProfile: CompanyProfileService = new CompanyProfileService(requestClient);
246+
await companyProfile.getCompanyProfile("NUMBER-NOT-IMPORTANT", headers);
247+
248+
expect(mockRequest.calledOnce).to.be.true;
249+
expect(mockRequest.firstCall.args[1]).to.deep.equal(headers);
250+
});
234251
});

test/services/company-psc/service.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,10 @@ describe("company-psc", () => {
157157
await companyPsc.getCompanyPsc("123", 10);
158158
expect(mockRequest.calledWith("/company/123/persons-with-significant-control?start_index=10&items_per_page=25")).to.be.true;
159159
});
160+
161+
it("uses provided headers", async () => {
162+
const headers = { "X-Request-Id": "random-uuid" };
163+
await companyPsc.getCompanyPsc("123", 10, 20, headers);
164+
expect(mockRequest.calledWith("/company/123/persons-with-significant-control?start_index=10&items_per_page=20", headers)).to.be.true;
165+
});
160166
});

test/services/psc-verification-link/service.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ describe("PSC Verification Link", () => {
5151
expect(data.httpStatusCode).to.equal(StatusCodes.INTERNAL_SERVER_ERROR);
5252
expect(data.errors?.[0]).to.equal(ReasonPhrases.INTERNAL_SERVER_ERROR);
5353
});
54+
55+
it("uses provided headers", async () => {
56+
const mockRequest = sinon.stub(requestClient, "httpPost").resolves(mockPscVerificationCreatedResponse[201]);
57+
58+
const headers = { "X-Request-Id": "random-uuid" };
59+
await pscService.postPscVerification(TRANSACTION_ID, PSC_VERIFICATION_CREATED, headers);
60+
61+
expect(mockRequest.calledOnce).to.be.true;
62+
expect(mockRequest.firstCall.args[2]).to.deep.equal(headers);
63+
});
5464
});
5565

5666
describe("GET endpoint", () => {
@@ -92,6 +102,16 @@ describe("PSC Verification Link", () => {
92102
expect(response.httpStatusCode).to.equal(StatusCodes.INTERNAL_SERVER_ERROR);
93103
expect(response.errors?.[0]).to.equal(ReasonPhrases.INTERNAL_SERVER_ERROR);
94104
});
105+
106+
it("uses provided headers", async () => {
107+
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockPscVerificationIndResponse[200]);
108+
109+
const headers = { "X-Request-Id": "random-uuid" };
110+
await pscService.getPscVerification(TRANSACTION_ID, PSC_NOTIFICATION_ID, headers);
111+
112+
expect(mockRequest.calledOnce).to.be.true;
113+
expect(mockRequest.firstCall.args[1]).to.deep.equal(headers);
114+
});
95115
});
96116

97117
describe("PATCH endpoint", () => {
@@ -135,6 +155,17 @@ describe("PSC Verification Link", () => {
135155
expect(response.httpStatusCode).to.equal(StatusCodes.INTERNAL_SERVER_ERROR);
136156
expect(response.errors?.[0]).to.equal(ReasonPhrases.INTERNAL_SERVER_ERROR);
137157
});
158+
159+
it("uses provided headers", async () => {
160+
const mockRequest = sinon.stub(requestClient, "httpPatch").resolves(mockPscVerificationPatchIndResponse[200]);
161+
162+
const testHeaders = { "X-Request-Id": "random-uuid" };
163+
const existingHeaders = { "Content-Type": "application/merge-patch+json" }; // These are inserted by patchPscVerification
164+
await pscService.patchPscVerification(TRANSACTION_ID, FILING_ID, PSC_VERIFICATION_IND, testHeaders);
165+
166+
expect(mockRequest.calledOnce).to.be.true;
167+
expect(mockRequest.firstCall.args[2]).to.deep.equal({ ...existingHeaders, ...testHeaders });
168+
});
138169
});
139170

140171
describe("Validation status GET endpoint", () => {
@@ -192,6 +223,16 @@ describe("PSC Verification Link", () => {
192223
expect(response.httpStatusCode).to.equal(StatusCodes.INTERNAL_SERVER_ERROR);
193224
expect(response.errors?.[0]).to.equal(ReasonPhrases.INTERNAL_SERVER_ERROR);
194225
});
226+
227+
it("uses provided headers", async () => {
228+
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockGetValidationStatusResponse[200]);
229+
230+
const headers = { "X-Request-Id": "random-uuid" };
231+
await pscService.getValidationStatus(TRANSACTION_ID, PSC_NOTIFICATION_ID, headers);
232+
233+
expect(mockRequest.calledOnce).to.be.true;
234+
expect(mockRequest.firstCall.args[1]).to.deep.equal(headers);
235+
});
195236
});
196237

197238
describe("checkPlannedMaintenance endpoint", () => {
@@ -223,5 +264,15 @@ describe("PSC Verification Link", () => {
223264
expect(response.httpStatusCode).to.equal(StatusCodes.INTERNAL_SERVER_ERROR);
224265
expect(response.errors?.[0]).to.equal(ReasonPhrases.INTERNAL_SERVER_ERROR);
225266
});
267+
268+
it("uses provided headers", async () => {
269+
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockPlannedMaintenanceResponse[200]);
270+
271+
const headers = { "X-Request-Id": "random-uuid" };
272+
await pscService.checkPlannedMaintenance(headers);
273+
274+
expect(mockRequest.calledOnce).to.be.true;
275+
expect(mockRequest.firstCall.args[1]).to.deep.equal(headers);
276+
});
226277
});
227278
});

test/services/psc/service.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,15 @@ describe("PSC details", () => {
6666
expect(response.httpStatusCode).to.equal(StatusCodes.INTERNAL_SERVER_ERROR);
6767
expect(response.errors?.[0]).to.equal(ReasonPhrases.INTERNAL_SERVER_ERROR);
6868
});
69+
70+
it("uses provided headers", async () => {
71+
const mockRequest = sinon.stub(requestClient, "httpGet").resolves(mockIndividualResponse[200]);
72+
const headers = { "X-Request-Id": "random-uuid" };
73+
74+
await pscService.getPscIndividual(COMPANY_NUMBER, PSC_NOTIFICATION_ID, headers);
75+
76+
expect(mockRequest.calledOnce).to.be.true;
77+
expect(mockRequest.firstCall.args[1]).to.deep.equal(headers);
78+
});
6979
});
7080
});

0 commit comments

Comments
 (0)