Skip to content
This repository was archived by the owner on Dec 1, 2017. It is now read-only.
Open
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions server/presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ api = {
var isAnon = !req.session.email;
var user;

logger.debug({firstRequest: firstRequest, email: !!req.session.email},
"/stream connection made");

if (isAnon)
user = api._setupUser(anons, api._genId());
user = api._setupUser(anons, api._genId(), firstRequest);
else
user = api._setupUser(users, req.session.email);
user = api._setupUser(users, req.session.email, firstRequest);

user.touch();

Expand Down
17 changes: 12 additions & 5 deletions static/spa/talkilla/js/spa.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var TalkillaSPA = (function() {
this.server.on("reconnection",
this._onServerEvent.bind(this,"reconnection"));
this.server.on("message", this._onServerMessage.bind(this));

}

TalkillaSPA.prototype = {
Expand All @@ -38,11 +39,17 @@ var TalkillaSPA = (function() {
else if (type === "reconnection")
this.port.post("reconnection", (new payloads.Reconnection(event)));
else if (type === "connected") {
this.port.post(type, {
addresses: [{type: "email", value: this.email}],
capabilities: this.capabilities
});
this.server.presenceRequest();
if ("email" in this) {
this.port.post(type, {
addresses: [{type: "email", value: this.email}],
capabilities: this.capabilities
});
this.server.presenceRequest();
} else {
this.port.post(type, {
capabilities: this.capabilities
});
}
}
else
this.port.post(type, event);
Expand Down
80 changes: 66 additions & 14 deletions test/frontend/spa/talkilla_spa_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global sinon, SPAPort, Server, TalkillaSPA, expect, payloads */
/* jshint unused:false */

"use strict";

describe("TalkillaSPA", function() {
Expand All @@ -12,6 +12,8 @@ describe("TalkillaSPA", function() {
sandbox = sinon.sandbox.create();
port = new SPAPort();
server = new Server();

sandbox.stub(server, "connect");
spa = new TalkillaSPA(port, server, {capabilities: ["call", "move"]});
});

Expand All @@ -20,24 +22,75 @@ describe("TalkillaSPA", function() {
expect(spa.capabilities).to.be.a("array");
expect(spa.capabilities).eql(["call", "move"]);
});

});

describe("#_onServerEvent", function() {

it("should post a connect event to the port", function() {
spa.email = "foo";
sandbox.stub(spa.port, "post");
describe("connected", function () {

spa.server.trigger("connected");
// XXX email shouldn't be a public member of the API, I don't think,
// and as a result, and we should be avoiding using it to do the tests
// I suspect we really want to be testing the connect and connected
// events as a pair.

it("should post a connected event containing the email address " +
"to the worker port if spa.email is set", function() {

spa.email = "foo";
sandbox.stub(spa.port, "post");

spa.server.trigger("connected");

sinon.assert.calledOnce(spa.port.post);
sinon.assert.calledWithExactly(
spa.port.post, "connected", {
addresses: [{type: "email", value: "foo"}],
capabilities: ["call", "move"]
}
);
});

it("should post a connected event to the worker port if " +
"not containing an email address is spa.email is not set", function() {

delete spa.email;
sandbox.stub(spa.port, "post");

spa.server.trigger("connected");

sinon.assert.calledOnce(spa.port.post);
sinon.assert.calledWithExactly(
spa.port.post, "connected", {
capabilities: ["call", "move"]
});
});

it("should post a presenceRequest to the server if spa.email is set",
function() {
spa.email = "foo";
sandbox.stub(spa.port, "post");
sandbox.stub(spa.server, "presenceRequest");

spa.server.trigger("connected");

sinon.assert.calledOnce(spa.server.presenceRequest);
sinon.assert.calledWithExactly(spa.server.presenceRequest);
});


it("should not post a presenceRequest to the server if spa.email" +
" is not set", function() {

delete spa.email;

sandbox.stub(spa.port, "post");
sandbox.stub(spa.server, "presenceRequest");

spa.server.trigger("connected");

sinon.assert.notCalled(spa.server.presenceRequest);
});

sinon.assert.calledOnce(spa.port.post);
sinon.assert.calledWithExactly(
spa.port.post, "connected", {
addresses: [{type: "email", value: "foo"}],
capabilities: ["call", "move"]
}
);
});

it("should post a reconnection event to the port", function() {
Expand Down Expand Up @@ -80,7 +133,6 @@ describe("TalkillaSPA", function() {
describe("#_onConnect", function() {

it("should connect to the server", function() {
sandbox.stub(spa.server, "connect");

// The Talkilla SPA doesn't need any credentials. This is
// handled via cookies.
Expand Down
2 changes: 1 addition & 1 deletion test/server/presence_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe("presence", function() {
// away from testing the impl with stubs and instead look at the
// side effect on anons for this specific test
sinon.assert.calledOnce(api._setupUser);
sinon.assert.calledWithExactly(api._setupUser, anons, fakeId);
sinon.assert.calledWithExactly(api._setupUser, anons, fakeId, false);
});

});
Expand Down