Bug 1092954: add tests for forced disconnect handling on room deletion. r=Standard8

This commit is contained in:
Mike de Boer 2014-12-08 17:45:36 +01:00
Родитель 7ca61b12b0
Коммит ca01528808
2 изменённых файлов: 73 добавлений и 3 удалений

Просмотреть файл

@ -34,7 +34,8 @@ describe("loop.store.ActiveRoomStore", function () {
fakeSdkDriver = {
connectSession: sandbox.stub(),
disconnectSession: sandbox.stub()
disconnectSession: sandbox.stub(),
forceDisconnectAll: sandbox.stub().callsArg(0)
};
fakeMultiplexGum = {
@ -740,7 +741,7 @@ describe("loop.store.ActiveRoomStore", function () {
});
it("should dispatch an UpdateRoomInfo action", function() {
sinon.assert.calledOnce(fakeMozLoop.rooms.on);
sinon.assert.calledTwice(fakeMozLoop.rooms.on);
var fakeRoomData = {
roomName: "fakeName",
@ -755,5 +756,30 @@ describe("loop.store.ActiveRoomStore", function () {
new sharedActions.UpdateRoomInfo(fakeRoomData));
});
});
describe("delete:{roomToken}", function() {
var fakeRoomData = {
roomName: "Its a room",
roomOwner: "Me",
roomToken: "fakeToken",
roomUrl: "http://invalid"
};
beforeEach(function() {
store.setupRoomInfo(new sharedActions.SetupRoomInfo(fakeRoomData));
});
it("should disconnect all room connections", function() {
fakeMozLoop.rooms.on.callArgWith(1, "delete:" + fakeRoomData.roomToken, fakeRoomData);
sinon.assert.calledOnce(fakeSdkDriver.forceDisconnectAll);
});
it("should not disconnect anything when another room is deleted", function() {
fakeMozLoop.rooms.on.callArgWith(1, "delete:invalidToken", fakeRoomData);
sinon.assert.calledOnce(fakeSdkDriver.forceDisconnectAll);
});
});
});
});

Просмотреть файл

@ -34,7 +34,8 @@ describe("loop.OTSdkDriver", function () {
connect: sinon.stub(),
disconnect: sinon.stub(),
publish: sinon.stub(),
subscribe: sinon.stub()
subscribe: sinon.stub(),
forceDisconnect: sinon.stub()
}, Backbone.Events);
publisher = _.extend({
@ -175,6 +176,43 @@ describe("loop.OTSdkDriver", function () {
});
});
describe("#forceDisconnectAll", function() {
it("should not disconnect anything when not connected", function() {
driver.session = session;
driver.forceDisconnectAll(function() {});
sinon.assert.notCalled(session.forceDisconnect);
});
it("should disconnect all remote connections when called", function() {
driver.connectSession(sessionData);
sinon.assert.calledOnce(session.connect);
driver._sessionConnected = true;
// Setup the right state in the driver to make `forceDisconnectAll` do
// something.
session.connection = {
id: "localUser"
};
session.trigger("connectionCreated", {
connection: {id: "remoteUser"}
});
expect(driver.connections).to.include.keys("remoteUser");
driver.forceDisconnectAll(function() {});
sinon.assert.calledOnce(session.forceDisconnect);
// Add another remote connection.
session.trigger("connectionCreated", {
connection: {id: "remoteUser2"}
});
expect(driver.connections).to.include.keys("remoteUser", "remoteUser2");
driver.forceDisconnectAll(function() {});
sinon.assert.calledThrice(session.forceDisconnect);
});
});
describe("Events", function() {
beforeEach(function() {
driver.connectSession(sessionData);
@ -275,6 +313,9 @@ describe("loop.OTSdkDriver", function () {
sinon.assert.calledOnce(dispatcher.dispatch);
sinon.assert.calledWithExactly(dispatcher.dispatch,
new sharedActions.RemotePeerConnected());
it("should store the connection details for a remote user", function() {
expect(driver.connections).to.include.keys("remoteUser");
});
});
it("should not dispatch an action if this is for a local user",
@ -284,6 +325,9 @@ describe("loop.OTSdkDriver", function () {
});
sinon.assert.notCalled(dispatcher.dispatch);
it("should not store the connection details for a local user", function() {
expect(driver.connections).to.not.include.keys("localUser");
});
});
});