From 7bdab0578527c059ba791277cbb25d593c48d751 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 21 Jan 2016 17:34:12 +0000 Subject: [PATCH] Unbreak tests --- lib/http-api.js | 11 ++++++++--- lib/models/room.js | 2 +- lib/sync.js | 8 +++++--- spec/unit/matrix-client.spec.js | 6 ++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/http-api.js b/lib/http-api.js index 3a600ef9c..7420c5c02 100644 --- a/lib/http-api.js +++ b/lib/http-api.js @@ -43,6 +43,9 @@ module.exports.PREFIX_V2_ALPHA = "/_matrix/client/v2_alpha"; */ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1"; +/** + * A constant representing the URI path for release 0 of the Client-Server HTTP API. + */ module.exports.PREFIX_R0 = "/_matrix/client/r0"; /** @@ -443,9 +446,11 @@ module.exports.MatrixHttpApi.prototype = { handlerFn(err, response, body); } ); - // FIXME: This is EVIL, but I can't think of a better way to expose - // abort() operations on underlying HTTP requests :( - reqPromise.abort = req.abort.bind(req); + if (req && req.abort) { + // FIXME: This is EVIL, but I can't think of a better way to expose + // abort() operations on underlying HTTP requests :( + reqPromise.abort = req.abort.bind(req); + } } catch (ex) { defer.reject(ex); diff --git a/lib/models/room.js b/lib/models/room.js index 2369fbbd0..04b5599f8 100644 --- a/lib/models/room.js +++ b/lib/models/room.js @@ -137,7 +137,7 @@ Room.prototype.getUnreadNotificationCount = function(type) { /** * Set one of the notification counts for this room * @param {String} type The type of notification count to set. - * @param {Number} type The new count + * @param {Number} count The new count */ Room.prototype.setUnreadNotificationCount = function(type, count) { this._notificationCounts[type] = count; diff --git a/lib/sync.js b/lib/sync.js index cdee768dc..7f7171613 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -540,9 +540,11 @@ SyncApi.prototype._sync = function(syncOptions, attempt) { if (!self._syncConnectionLost) { return; } - // kill the current sync request - debuglog("Aborting current /sync."); - self._currentSyncRequest.abort(); + if (self._currentSyncRequest.abort) { + // kill the current sync request + debuglog("Aborting current /sync."); + self._currentSyncRequest.abort(); + } }); } console.error("/sync error (%s attempts): %s", attempt, err); diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index badbabf74..076a4297b 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -10,6 +10,8 @@ describe("MatrixClient", function() { var identityServerDomain = "identity.server"; var client, store, scheduler; + var KEEP_ALIVE_PATH = "/"; + var PUSH_RULES_RESPONSE = { method: "GET", path: "/pushrules/", @@ -51,6 +53,9 @@ describe("MatrixClient", function() { ]; var pendingLookup = null; function httpReq(cb, method, path, qp, data, prefix) { + if (path === KEEP_ALIVE_PATH) { + return q(); + } var next = httpLookups.shift(); var logLine = ( "MatrixClient[UT] RECV " + method + " " + path + " " + @@ -137,6 +142,7 @@ describe("MatrixClient", function() { ]); client._http.authedRequest.andCallFake(httpReq); client._http.authedRequestWithPrefix.andCallFake(httpReq); + client._http.requestWithPrefix.andCallFake(httpReq); // set reasonable working defaults pendingLookup = null;