Skip to content

Commit eb2a778

Browse files
authored
Adjust request options.headers (#1348)
* add change to httpURLConnectionClient * changes to untittest * headers adjusted, unittest with headers
1 parent bb0a5de commit eb2a778

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/__tests__/httpClient.spec.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import nock, { Interceptor } from "nock";
22
import Client from "../client";
3+
import { createClient } from "../__mocks__/base";
34
import { BinLookupAPI } from "../services";
45
import ApiException from "../services/exception/apiException";
56
import HttpClientException from "../httpClient/httpClientException";
7+
import { binlookup } from "../typings";
8+
import { ApiConstants } from "../constants/apiConstants";
69

710
beforeEach((): void => {
811
nock.cleanAll();
@@ -60,4 +63,41 @@ describe("HTTP Client", function (): void {
6063
return { errorType, errorMessageContains: contains, errorMessageEquals: equals };
6164
});
6265
});
63-
});
66+
67+
test("should succeed on get 3ds availability", async function (): Promise<void> {
68+
69+
const threeDSAvailabilitySuccessResponse = {
70+
binDetails: {
71+
issuerCountry: "NL"
72+
},
73+
threeDS1Supported: true,
74+
threeDS2CardRangeDetails: [],
75+
threeDS2supported: false
76+
};
77+
78+
const client = createClient();
79+
const binLookupService = new BinLookupAPI(client);
80+
const scope = nock("https://pal-test.adyen.com/pal/servlet/BinLookup/v54", {
81+
reqheaders: {
82+
'Content-Type' : ApiConstants.APPLICATION_JSON_TYPE,
83+
"foo" : "bar"
84+
},
85+
})
86+
.get('/')
87+
.reply(200)
88+
89+
const threeDSAvailabilityRequest: binlookup.ThreeDSAvailabilityRequest = {
90+
merchantAccount: process.env.ADYEN_MERCHANT!,
91+
brands: ["randomBrand"],
92+
cardNumber: "4111111111111111"
93+
};
94+
95+
scope.post("/get3dsAvailability")
96+
.reply(200, threeDSAvailabilitySuccessResponse);
97+
98+
const requestOptions = { headers: { foo : "bar" }}
99+
const response = await binLookupService.get3dsAvailability(threeDSAvailabilityRequest, requestOptions);
100+
expect(response).toEqual< binlookup.ThreeDSAvailabilityResponse>(threeDSAvailabilitySuccessResponse);
101+
});
102+
103+
});

src/httpClient/httpURLConnectionClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class HttpURLConnectionClient implements ClientInterface {
4343
endpoint: string, json: string, config: Config, isApiRequired: boolean,
4444
requestOptions: IRequest.Options,
4545
): Promise<string | HttpClientException | ApiException> {
46-
requestOptions.headers = {};
46+
requestOptions.headers ??= {};
4747
requestOptions.timeout = config.connectionTimeoutMillis;
4848

4949
if (config.certificatePath) {

0 commit comments

Comments
 (0)