Preserving user's queryString

Fixes: #272
This commit is contained in:
moozzyk 2017-04-17 15:01:44 -07:00 committed by Pawel Kadluczka
parent 58e7c1b1fe
commit 39b2990b62
2 changed files with 47 additions and 2 deletions

View File

@ -1,6 +1,8 @@
import { IHttpClient } from "../Microsoft.AspNetCore.SignalR.Client.TS/HttpClient"
import { Connection } from "../Microsoft.AspNetCore.SignalR.Client.TS/Connection"
import { ISignalROptions } from "../Microsoft.AspNetCore.SignalR.Client.TS/ISignalROptions"
import { DataReceived, TransportClosed } from "../Microsoft.AspNetCore.SignalR.Client.TS/Common"
import { ITransport } from "../Microsoft.AspNetCore.SignalR.Client.TS/Transports"
describe("Connection", () => {
@ -122,4 +124,44 @@ describe("Connection", () => {
await connection.stop();
done();
});
it("preserves users connection string", async done => {
let options: ISignalROptions = {
httpClient: <IHttpClient>{
get(url: string): Promise<string> {
if (url.includes("negotiate")) {
return Promise.resolve("42");
}
return Promise.resolve("");
}
}
} as ISignalROptions;
let connectQueryString: string;
let fakeTransport: ITransport = {
connect(url: string, queryString: string): Promise<void> {
connectQueryString = queryString;
return Promise.reject("");
},
send(data: any): Promise<void> {
return Promise.reject("");
},
stop(): void { },
onDataReceived: undefined,
onClosed: undefined
}
var connection = new Connection("http://tempuri.org", "q=myData", options);
try {
await connection.start(fakeTransport);
fail();
done();
}
catch (e) {
}
expect(connectQueryString).toBe("q=myData&id=42");
done();
});
});

View File

@ -22,7 +22,7 @@ export class Connection implements IConnection {
constructor(url: string, queryString: string = "", options: ISignalROptions = {}) {
this.url = url;
this.queryString = queryString;
this.queryString = queryString || "";
this.httpClient = options.httpClient || new HttpClient();
this.connectionState = ConnectionState.Initial;
}
@ -47,7 +47,10 @@ export class Connection implements IConnection {
return;
}
this.queryString = `id=${this.connectionId}`;
if (this.queryString) {
this.queryString += "&";
}
this.queryString += `id=${this.connectionId}`;
this.transport = this.createTransport(transportType);
this.transport.onDataReceived = this.onDataReceived;