Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("should send a request and receive a response correctly", async function () {
const connectionStub = stub(new Connection());
const rcvr = new EventEmitter();
let req: any = {};
connectionStub.createSession.resolves({
connection: {
id: "connection-1"
},
createSender: () => {
return Promise.resolve({
send: (request: any) => {
req = request;
}
});
}, createReceiver: () => {
return Promise.resolve(rcvr);
}
});
(!isNode && typeof window !== "undefined" && (window as any).WebSocket)
) {
const socket = parameters.config.webSocket || (window as any).WebSocket;
const host = parameters.config.host;
const endpoint = parameters.config.webSocketEndpointPath || "";
const socketOptions = parameters.config.webSocketConstructorOptions || {};
connectionOptions.webSocketOptions = {
webSocket: socket,
url: `wss://${host}:443/${endpoint}`,
protocol: ["AMQPWSB10"],
options: socketOptions
};
}
const connection = new Connection(connectionOptions);
const connectionLock = `${Constants.establishConnection}-${generate_uuid()}`;
const connectionContextBase: ConnectionContextBase = {
wasConnectionCloseCalled: false,
connectionLock: connectionLock,
negotiateClaimLock: `${Constants.negotiateClaim}-${generate_uuid()}`,
connection: connection,
connectionId: connection.id,
cbsSession: new CbsClient(connection, connectionLock),
config: parameters.config,
tokenCredential:
parameters.tokenCredential ||
new SharedKeyCredential(
parameters.config.sharedAccessKeyName,
parameters.config.sharedAccessKey
),
dataTransformer: parameters.dataTransformer || new DefaultDataTransformer()