Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TNT-46700 Add proxy configuration #116

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/target-nodejs-sdk/test/proxy.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Agent } from "https";

const { getFetchWithTelemetry } = require("@adobe/target-tools");
const TargetClient = require("../src/index.server").default;

describe("Target Client supports proxy configuration", () => {
it("By overriding the fetchApi during client initialization", async () => {
const proxyAgentSpy = jest.spyOn(Agent.prototype, "createConnection");

const fetchImpl = (url, options) => {
const fetchOptions = options || {};
fetchOptions.agent = new Agent({
keepAlive: true
});
const telemetryFetch = getFetchWithTelemetry();
return telemetryFetch(url, fetchOptions);
};

const client = TargetClient.create({
client: "adobesummit2018",
organizationId: "65453EA95A70434F0A495D34@AdobeOrg",
decisioningMethod: "server-side",
fetchApi: fetchImpl
});

const TARGET_REQUEST = {
prefetch: {
mboxes: [
{
name: "mbox-droptop",
index: 1
}
]
}
};

await client.getOffers({
request: TARGET_REQUEST,
sessionId: "dummy_session"
});

const proxyAgentSpyCall = proxyAgentSpy.mock.calls[0][0];

expect(proxyAgentSpyCall.keepAlive).toEqual(true);
expect(proxyAgentSpyCall.servername).toEqual(
"adobesummit2018.tt.omtrdc.net"
);
expect(proxyAgentSpyCall.headers["X-EXC-SDK"]).toEqual("AdobeTargetNode");
});
});