Skip to content

Commit ae8e38b

Browse files
committed
Add tests to verify usage of provided headers
Ensures that headers make it through to the resulting HTTP request.
1 parent d81552d commit ae8e38b

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

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)