You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
eslint ---fix for prefer-const
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
let ContentRepo = require("../../lib/content-repo");
|
||||
let testUtils = require("../test-utils");
|
||||
const ContentRepo = require("../../lib/content-repo");
|
||||
const testUtils = require("../test-utils");
|
||||
|
||||
describe("ContentRepo", function() {
|
||||
let baseUrl = "https://my.home.server";
|
||||
const baseUrl = "https://my.home.server";
|
||||
|
||||
beforeEach(function() {
|
||||
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
|
||||
@ -11,7 +11,7 @@ describe("ContentRepo", function() {
|
||||
|
||||
describe("getHttpUriForMxc", function() {
|
||||
it("should do nothing to HTTP URLs when allowing direct links", function() {
|
||||
let httpUrl = "http://example.com/image.jpeg";
|
||||
const httpUrl = "http://example.com/image.jpeg";
|
||||
expect(
|
||||
ContentRepo.getHttpUriForMxc(
|
||||
baseUrl, httpUrl, undefined, undefined, undefined, true
|
||||
@ -20,13 +20,13 @@ describe("ContentRepo", function() {
|
||||
});
|
||||
|
||||
it("should return the empty string HTTP URLs by default", function() {
|
||||
let httpUrl = "http://example.com/image.jpeg";
|
||||
const httpUrl = "http://example.com/image.jpeg";
|
||||
expect(ContentRepo.getHttpUriForMxc(baseUrl, httpUrl)).toEqual("");
|
||||
});
|
||||
|
||||
it("should return a download URL if no width/height/resize are specified",
|
||||
function() {
|
||||
let mxcUri = "mxc://server.name/resourceid";
|
||||
const mxcUri = "mxc://server.name/resourceid";
|
||||
expect(ContentRepo.getHttpUriForMxc(baseUrl, mxcUri)).toEqual(
|
||||
baseUrl + "/_matrix/media/v1/download/server.name/resourceid"
|
||||
);
|
||||
@ -38,7 +38,7 @@ describe("ContentRepo", function() {
|
||||
|
||||
it("should return a thumbnail URL if a width/height/resize is specified",
|
||||
function() {
|
||||
let mxcUri = "mxc://server.name/resourceid";
|
||||
const mxcUri = "mxc://server.name/resourceid";
|
||||
expect(ContentRepo.getHttpUriForMxc(baseUrl, mxcUri, 32, 64, "crop")).toEqual(
|
||||
baseUrl + "/_matrix/media/v1/thumbnail/server.name/resourceid" +
|
||||
"?width=32&height=64&method=crop"
|
||||
@ -47,7 +47,7 @@ describe("ContentRepo", function() {
|
||||
|
||||
it("should put fragments from mxc:// URIs after any query parameters",
|
||||
function() {
|
||||
let mxcUri = "mxc://server.name/resourceid#automade";
|
||||
const mxcUri = "mxc://server.name/resourceid#automade";
|
||||
expect(ContentRepo.getHttpUriForMxc(baseUrl, mxcUri, 32)).toEqual(
|
||||
baseUrl + "/_matrix/media/v1/thumbnail/server.name/resourceid" +
|
||||
"?width=32#automade"
|
||||
@ -56,7 +56,7 @@ describe("ContentRepo", function() {
|
||||
|
||||
it("should put fragments from mxc:// URIs at the end of the HTTP URI",
|
||||
function() {
|
||||
let mxcUri = "mxc://server.name/resourceid#automade";
|
||||
const mxcUri = "mxc://server.name/resourceid#automade";
|
||||
expect(ContentRepo.getHttpUriForMxc(baseUrl, mxcUri)).toEqual(
|
||||
baseUrl + "/_matrix/media/v1/download/server.name/resourceid#automade"
|
||||
);
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
"use strict";
|
||||
let Crypto = require("../../lib/crypto");
|
||||
let sdk = require("../..");
|
||||
const Crypto = require("../../lib/crypto");
|
||||
const sdk = require("../..");
|
||||
|
||||
describe("Crypto", function() {
|
||||
if (!sdk.CRYPTO_ENABLED) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
let sdk = require("../..");
|
||||
let EventTimeline = sdk.EventTimeline;
|
||||
let utils = require("../test-utils");
|
||||
const sdk = require("../..");
|
||||
const EventTimeline = sdk.EventTimeline;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
function mockRoomStates(timeline) {
|
||||
timeline._startState = utils.mock(sdk.RoomState, "startState");
|
||||
@ -9,16 +9,16 @@ function mockRoomStates(timeline) {
|
||||
}
|
||||
|
||||
describe("EventTimeline", function() {
|
||||
let roomId = "!foo:bar";
|
||||
let userA = "@alice:bar";
|
||||
let userB = "@bertha:bar";
|
||||
const roomId = "!foo:bar";
|
||||
const userA = "@alice:bar";
|
||||
const userB = "@bertha:bar";
|
||||
let timeline;
|
||||
|
||||
beforeEach(function() {
|
||||
utils.beforeEach(this); // eslint-disable-line no-invalid-this
|
||||
|
||||
// XXX: this is a horrid hack; should use sinon or something instead to mock
|
||||
let timelineSet = { room: { roomId: roomId }};
|
||||
const timelineSet = { room: { roomId: roomId }};
|
||||
timelineSet.room.getUnfilteredTimelineSet = function() {
|
||||
return timelineSet;
|
||||
};
|
||||
@ -28,7 +28,7 @@ describe("EventTimeline", function() {
|
||||
|
||||
describe("construction", function() {
|
||||
it("getRoomId should get room id", function() {
|
||||
let v = timeline.getRoomId();
|
||||
const v = timeline.getRoomId();
|
||||
expect(v).toEqual(roomId);
|
||||
});
|
||||
});
|
||||
@ -39,7 +39,7 @@ describe("EventTimeline", function() {
|
||||
});
|
||||
|
||||
it("should copy state events to start and end state", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA,
|
||||
event: true,
|
||||
@ -60,13 +60,13 @@ describe("EventTimeline", function() {
|
||||
});
|
||||
|
||||
it("should raise an exception if called after events are added", function() {
|
||||
let event =
|
||||
const event =
|
||||
utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "Adam stole the plushies",
|
||||
event: true,
|
||||
});
|
||||
|
||||
let state = [
|
||||
const state = [
|
||||
utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA,
|
||||
event: true,
|
||||
@ -105,8 +105,8 @@ describe("EventTimeline", function() {
|
||||
});
|
||||
|
||||
it("setNeighbouringTimeline should set neighbour", function() {
|
||||
let prev = {a: "a"};
|
||||
let next = {b: "b"};
|
||||
const prev = {a: "a"};
|
||||
const next = {b: "b"};
|
||||
timeline.setNeighbouringTimeline(prev, EventTimeline.BACKWARDS);
|
||||
timeline.setNeighbouringTimeline(next, EventTimeline.FORWARDS);
|
||||
expect(timeline.getNeighbouringTimeline(EventTimeline.BACKWARDS)).toBe(prev);
|
||||
@ -114,8 +114,8 @@ describe("EventTimeline", function() {
|
||||
});
|
||||
|
||||
it("setNeighbouringTimeline should throw if called twice", function() {
|
||||
let prev = {a: "a"};
|
||||
let next = {b: "b"};
|
||||
const prev = {a: "a"};
|
||||
const next = {b: "b"};
|
||||
expect(function() {
|
||||
timeline.setNeighbouringTimeline(prev, EventTimeline.BACKWARDS);
|
||||
}).not.toThrow();
|
||||
@ -141,7 +141,7 @@ describe("EventTimeline", function() {
|
||||
mockRoomStates(timeline);
|
||||
});
|
||||
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "hungry hungry hungry",
|
||||
event: true,
|
||||
@ -154,7 +154,7 @@ describe("EventTimeline", function() {
|
||||
|
||||
it("should be able to add events to the end", function() {
|
||||
timeline.addEvent(events[0], false);
|
||||
let initialIndex = timeline.getBaseIndex();
|
||||
const initialIndex = timeline.getBaseIndex();
|
||||
timeline.addEvent(events[1], false);
|
||||
expect(timeline.getBaseIndex()).toEqual(initialIndex);
|
||||
expect(timeline.getEvents().length).toEqual(2);
|
||||
@ -164,7 +164,7 @@ describe("EventTimeline", function() {
|
||||
|
||||
it("should be able to add events to the start", function() {
|
||||
timeline.addEvent(events[0], true);
|
||||
let initialIndex = timeline.getBaseIndex();
|
||||
const initialIndex = timeline.getBaseIndex();
|
||||
timeline.addEvent(events[1], true);
|
||||
expect(timeline.getBaseIndex()).toEqual(initialIndex + 1);
|
||||
expect(timeline.getEvents().length).toEqual(2);
|
||||
@ -173,12 +173,12 @@ describe("EventTimeline", function() {
|
||||
});
|
||||
|
||||
it("should set event.sender for new and old events", function() {
|
||||
let sentinel = {
|
||||
const sentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Alice",
|
||||
};
|
||||
let oldSentinel = {
|
||||
const oldSentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Old Alice",
|
||||
@ -198,11 +198,11 @@ describe("EventTimeline", function() {
|
||||
return null;
|
||||
});
|
||||
|
||||
let newEv = utils.mkEvent({
|
||||
const newEv = utils.mkEvent({
|
||||
type: "m.room.name", room: roomId, user: userA, event: true,
|
||||
content: { name: "New Room Name" },
|
||||
});
|
||||
let oldEv = utils.mkEvent({
|
||||
const oldEv = utils.mkEvent({
|
||||
type: "m.room.name", room: roomId, user: userA, event: true,
|
||||
content: { name: "Old Room Name" },
|
||||
});
|
||||
@ -215,12 +215,12 @@ describe("EventTimeline", function() {
|
||||
|
||||
it("should set event.target for new and old m.room.member events",
|
||||
function() {
|
||||
let sentinel = {
|
||||
const sentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Alice",
|
||||
};
|
||||
let oldSentinel = {
|
||||
const oldSentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Old Alice",
|
||||
@ -240,10 +240,10 @@ describe("EventTimeline", function() {
|
||||
return null;
|
||||
});
|
||||
|
||||
let newEv = utils.mkMembership({
|
||||
const newEv = utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
||||
});
|
||||
let oldEv = utils.mkMembership({
|
||||
const oldEv = utils.mkMembership({
|
||||
room: roomId, mship: "ban", user: userB, skey: userA, event: true,
|
||||
});
|
||||
timeline.addEvent(newEv, false);
|
||||
@ -254,7 +254,7 @@ describe("EventTimeline", function() {
|
||||
|
||||
it("should call setStateEvents on the right RoomState with the right " +
|
||||
"forwardLooking value for new events", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
||||
}),
|
||||
@ -284,7 +284,7 @@ describe("EventTimeline", function() {
|
||||
|
||||
it("should call setStateEvents on the right RoomState with the right " +
|
||||
"forwardLooking value for old events", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
||||
}),
|
||||
@ -313,7 +313,7 @@ describe("EventTimeline", function() {
|
||||
});
|
||||
|
||||
describe("removeEvent", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "hungry hungry hungry",
|
||||
event: true,
|
||||
@ -365,7 +365,7 @@ describe("EventTimeline", function() {
|
||||
function() {
|
||||
timeline.addEvent(events[0], true);
|
||||
timeline.removeEvent(events[0].getId());
|
||||
let initialIndex = timeline.getBaseIndex();
|
||||
const initialIndex = timeline.getBaseIndex();
|
||||
timeline.addEvent(events[1], false);
|
||||
timeline.addEvent(events[2], false);
|
||||
expect(timeline.getBaseIndex()).toEqual(initialIndex);
|
||||
|
@ -1,11 +1,11 @@
|
||||
"use strict";
|
||||
let sdk = require("../..");
|
||||
let Filter = sdk.Filter;
|
||||
let utils = require("../test-utils");
|
||||
const sdk = require("../..");
|
||||
const Filter = sdk.Filter;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
describe("Filter", function() {
|
||||
let filterId = "f1lt3ring15g00d4ursoul";
|
||||
let userId = "@sir_arthur_david:humming.tiger";
|
||||
const filterId = "f1lt3ring15g00d4ursoul";
|
||||
const userId = "@sir_arthur_david:humming.tiger";
|
||||
let filter;
|
||||
|
||||
beforeEach(function() {
|
||||
@ -15,10 +15,10 @@ describe("Filter", function() {
|
||||
|
||||
describe("fromJson", function() {
|
||||
it("create a new Filter from the provided values", function() {
|
||||
let definition = {
|
||||
const definition = {
|
||||
event_fields: ["type", "content"],
|
||||
};
|
||||
let f = Filter.fromJson(userId, filterId, definition);
|
||||
const f = Filter.fromJson(userId, filterId, definition);
|
||||
expect(f.getDefinition()).toEqual(definition);
|
||||
expect(f.userId).toEqual(userId);
|
||||
expect(f.filterId).toEqual(filterId);
|
||||
@ -40,7 +40,7 @@ describe("Filter", function() {
|
||||
|
||||
describe("setDefinition/getDefinition", function() {
|
||||
it("should set and get the filter body", function() {
|
||||
let definition = {
|
||||
const definition = {
|
||||
event_format: "client",
|
||||
};
|
||||
filter.setDefinition(definition);
|
||||
|
@ -15,12 +15,12 @@ limitations under the License.
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
let q = require("q");
|
||||
let sdk = require("../..");
|
||||
let utils = require("../test-utils");
|
||||
const q = require("q");
|
||||
const sdk = require("../..");
|
||||
const utils = require("../test-utils");
|
||||
|
||||
let InteractiveAuth = sdk.InteractiveAuth;
|
||||
let MatrixError = sdk.MatrixError;
|
||||
const InteractiveAuth = sdk.InteractiveAuth;
|
||||
const MatrixError = sdk.MatrixError;
|
||||
|
||||
describe("InteractiveAuth", function() {
|
||||
beforeEach(function() {
|
||||
@ -28,10 +28,10 @@ describe("InteractiveAuth", function() {
|
||||
});
|
||||
|
||||
it("should start an auth stage and complete it", function(done) {
|
||||
let doRequest = jasmine.createSpy('doRequest');
|
||||
let startAuthStage = jasmine.createSpy('startAuthStage');
|
||||
const doRequest = jasmine.createSpy('doRequest');
|
||||
const startAuthStage = jasmine.createSpy('startAuthStage');
|
||||
|
||||
let ia = new InteractiveAuth({
|
||||
const ia = new InteractiveAuth({
|
||||
doRequest: doRequest,
|
||||
startAuthStage: startAuthStage,
|
||||
authData: {
|
||||
@ -60,7 +60,7 @@ describe("InteractiveAuth", function() {
|
||||
});
|
||||
|
||||
// .. which should trigger a call here
|
||||
let requestRes = {"a": "b"};
|
||||
const requestRes = {"a": "b"};
|
||||
doRequest.andCallFake(function(authData) {
|
||||
expect(authData).toEqual({
|
||||
session: "sessionId",
|
||||
@ -78,10 +78,10 @@ describe("InteractiveAuth", function() {
|
||||
});
|
||||
|
||||
it("should make a request if no authdata is provided", function(done) {
|
||||
let doRequest = jasmine.createSpy('doRequest');
|
||||
let startAuthStage = jasmine.createSpy('startAuthStage');
|
||||
const doRequest = jasmine.createSpy('doRequest');
|
||||
const startAuthStage = jasmine.createSpy('startAuthStage');
|
||||
|
||||
let ia = new InteractiveAuth({
|
||||
const ia = new InteractiveAuth({
|
||||
doRequest: doRequest,
|
||||
startAuthStage: startAuthStage,
|
||||
});
|
||||
@ -93,7 +93,7 @@ describe("InteractiveAuth", function() {
|
||||
doRequest.andCallFake(function(authData) {
|
||||
console.log("request1", authData);
|
||||
expect(authData).toBe(null);
|
||||
let err = new MatrixError({
|
||||
const err = new MatrixError({
|
||||
session: "sessionId",
|
||||
flows: [
|
||||
{ stages: ["logintype"] },
|
||||
@ -107,7 +107,7 @@ describe("InteractiveAuth", function() {
|
||||
});
|
||||
|
||||
// .. which should be followed by a call to startAuthStage
|
||||
let requestRes = {"a": "b"};
|
||||
const requestRes = {"a": "b"};
|
||||
startAuthStage.andCallFake(function(stage) {
|
||||
expect(stage).toEqual("logintype");
|
||||
expect(ia.getSessionId()).toEqual("sessionId");
|
||||
|
@ -1,40 +1,40 @@
|
||||
"use strict";
|
||||
let q = require("q");
|
||||
let sdk = require("../..");
|
||||
let MatrixClient = sdk.MatrixClient;
|
||||
let utils = require("../test-utils");
|
||||
const q = require("q");
|
||||
const sdk = require("../..");
|
||||
const MatrixClient = sdk.MatrixClient;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
describe("MatrixClient", function() {
|
||||
let userId = "@alice:bar";
|
||||
let identityServerUrl = "https://identity.server";
|
||||
let identityServerDomain = "identity.server";
|
||||
const userId = "@alice:bar";
|
||||
const identityServerUrl = "https://identity.server";
|
||||
const identityServerDomain = "identity.server";
|
||||
let client;
|
||||
let store;
|
||||
let scheduler;
|
||||
|
||||
let KEEP_ALIVE_PATH = "/_matrix/client/versions";
|
||||
const KEEP_ALIVE_PATH = "/_matrix/client/versions";
|
||||
|
||||
let PUSH_RULES_RESPONSE = {
|
||||
const PUSH_RULES_RESPONSE = {
|
||||
method: "GET",
|
||||
path: "/pushrules/",
|
||||
data: {},
|
||||
};
|
||||
|
||||
let FILTER_PATH = "/user/" + encodeURIComponent(userId) + "/filter";
|
||||
const FILTER_PATH = "/user/" + encodeURIComponent(userId) + "/filter";
|
||||
|
||||
let FILTER_RESPONSE = {
|
||||
const FILTER_RESPONSE = {
|
||||
method: "POST",
|
||||
path: FILTER_PATH,
|
||||
data: { filter_id: "f1lt3r" },
|
||||
};
|
||||
|
||||
let SYNC_DATA = {
|
||||
const SYNC_DATA = {
|
||||
next_batch: "s_5_3",
|
||||
presence: { events: [] },
|
||||
rooms: {},
|
||||
};
|
||||
|
||||
let SYNC_RESPONSE = {
|
||||
const SYNC_RESPONSE = {
|
||||
method: "GET",
|
||||
path: "/sync",
|
||||
data: SYNC_DATA,
|
||||
@ -59,8 +59,8 @@ describe("MatrixClient", function() {
|
||||
if (path === KEEP_ALIVE_PATH && acceptKeepalives) {
|
||||
return q();
|
||||
}
|
||||
let next = httpLookups.shift();
|
||||
let logLine = (
|
||||
const next = httpLookups.shift();
|
||||
const logLine = (
|
||||
"MatrixClient[UT] RECV " + method + " " + path + " " +
|
||||
"EXPECT " + (next ? next.method : next) + " " + (next ? next.path : next)
|
||||
);
|
||||
@ -176,9 +176,9 @@ describe("MatrixClient", function() {
|
||||
httpLookups = [];
|
||||
httpLookups.push(PUSH_RULES_RESPONSE);
|
||||
httpLookups.push(SYNC_RESPONSE);
|
||||
let filterId = "ehfewf";
|
||||
const filterId = "ehfewf";
|
||||
store.getFilterIdByName.andReturn(filterId);
|
||||
let filter = new sdk.Filter(0, filterId);
|
||||
const filter = new sdk.Filter(0, filterId);
|
||||
filter.setDefinition({"room": {"timeline": {"limit": 8}}});
|
||||
store.getFilter.andReturn(filter);
|
||||
client.startClient();
|
||||
@ -220,7 +220,7 @@ describe("MatrixClient", function() {
|
||||
// and they all need to be stored!
|
||||
return "FILTER_SYNC_" + userId + (suffix ? "_" + suffix : "");
|
||||
}
|
||||
let invalidFilterId = 'invalidF1lt3r';
|
||||
const invalidFilterId = 'invalidF1lt3r';
|
||||
httpLookups = [];
|
||||
httpLookups.push({
|
||||
method: "GET",
|
||||
@ -236,9 +236,9 @@ describe("MatrixClient", function() {
|
||||
httpLookups.push(FILTER_RESPONSE);
|
||||
store.getFilterIdByName.andReturn(invalidFilterId);
|
||||
|
||||
let filterName = getFilterName(client.credentials.userId);
|
||||
const filterName = getFilterName(client.credentials.userId);
|
||||
client.store.setFilterIdByName(filterName, invalidFilterId);
|
||||
let filter = new sdk.Filter(client.credentials.userId);
|
||||
const filter = new sdk.Filter(client.credentials.userId);
|
||||
|
||||
client.getOrCreateFilter(filterName, filter).then(function(filterId) {
|
||||
expect(filterId).toEqual(FILTER_RESPONSE.data.filter_id);
|
||||
@ -332,7 +332,7 @@ describe("MatrixClient", function() {
|
||||
describe("emitted sync events", function() {
|
||||
function syncChecker(expectedStates, done) {
|
||||
return function syncListener(state, old) {
|
||||
let expected = expectedStates.shift();
|
||||
const expected = expectedStates.shift();
|
||||
console.log(
|
||||
"'sync' curr=%s old=%s EXPECT=%s", state, old, expected
|
||||
);
|
||||
@ -352,14 +352,14 @@ describe("MatrixClient", function() {
|
||||
}
|
||||
|
||||
it("should transition null -> PREPARED after the first /sync", function(done) {
|
||||
let expectedStates = [];
|
||||
const expectedStates = [];
|
||||
expectedStates.push(["PREPARED", null]);
|
||||
client.on("sync", syncChecker(expectedStates, done));
|
||||
client.startClient();
|
||||
});
|
||||
|
||||
it("should transition null -> ERROR after a failed /filter", function(done) {
|
||||
let expectedStates = [];
|
||||
const expectedStates = [];
|
||||
httpLookups = [];
|
||||
httpLookups.push(PUSH_RULES_RESPONSE);
|
||||
httpLookups.push({
|
||||
@ -372,7 +372,7 @@ describe("MatrixClient", function() {
|
||||
|
||||
it("should transition ERROR -> PREPARED after /sync if prev failed",
|
||||
function(done) {
|
||||
let expectedStates = [];
|
||||
const expectedStates = [];
|
||||
acceptKeepalives = false;
|
||||
httpLookups = [];
|
||||
httpLookups.push(PUSH_RULES_RESPONSE);
|
||||
@ -399,7 +399,7 @@ describe("MatrixClient", function() {
|
||||
});
|
||||
|
||||
it("should transition PREPARED -> SYNCING after /sync", function(done) {
|
||||
let expectedStates = [];
|
||||
const expectedStates = [];
|
||||
expectedStates.push(["PREPARED", null]);
|
||||
expectedStates.push(["SYNCING", "PREPARED"]);
|
||||
client.on("sync", syncChecker(expectedStates, done));
|
||||
@ -408,7 +408,7 @@ describe("MatrixClient", function() {
|
||||
|
||||
it("should transition SYNCING -> ERROR after a failed /sync", function(done) {
|
||||
acceptKeepalives = false;
|
||||
let expectedStates = [];
|
||||
const expectedStates = [];
|
||||
httpLookups.push({
|
||||
method: "GET", path: "/sync", error: { errcode: "NONONONONO" },
|
||||
});
|
||||
@ -427,7 +427,7 @@ describe("MatrixClient", function() {
|
||||
|
||||
xit("should transition ERROR -> SYNCING after /sync if prev failed",
|
||||
function(done) {
|
||||
let expectedStates = [];
|
||||
const expectedStates = [];
|
||||
httpLookups.push({
|
||||
method: "GET", path: "/sync", error: { errcode: "NONONONONO" },
|
||||
});
|
||||
@ -442,7 +442,7 @@ describe("MatrixClient", function() {
|
||||
|
||||
it("should transition SYNCING -> SYNCING on subsequent /sync successes",
|
||||
function(done) {
|
||||
let expectedStates = [];
|
||||
const expectedStates = [];
|
||||
httpLookups.push(SYNC_RESPONSE);
|
||||
httpLookups.push(SYNC_RESPONSE);
|
||||
|
||||
@ -455,7 +455,7 @@ describe("MatrixClient", function() {
|
||||
|
||||
it("should transition ERROR -> ERROR if keepalive keeps failing", function(done) {
|
||||
acceptKeepalives = false;
|
||||
let expectedStates = [];
|
||||
const expectedStates = [];
|
||||
httpLookups.push({
|
||||
method: "GET", path: "/sync", error: { errcode: "NONONONONO" },
|
||||
});
|
||||
@ -479,7 +479,7 @@ describe("MatrixClient", function() {
|
||||
});
|
||||
|
||||
describe("inviteByEmail", function() {
|
||||
let roomId = "!foo:bar";
|
||||
const roomId = "!foo:bar";
|
||||
|
||||
it("should send an invite HTTP POST", function() {
|
||||
httpLookups = [{
|
||||
|
@ -1,18 +1,18 @@
|
||||
"use strict";
|
||||
let PushProcessor = require("../../lib/pushprocessor");
|
||||
let utils = require("../test-utils");
|
||||
const PushProcessor = require("../../lib/pushprocessor");
|
||||
const utils = require("../test-utils");
|
||||
|
||||
describe('NotificationService', function() {
|
||||
let testUserId = "@ali:matrix.org";
|
||||
let testDisplayName = "Alice M";
|
||||
let testRoomId = "!fl1bb13:localhost";
|
||||
const testUserId = "@ali:matrix.org";
|
||||
const testDisplayName = "Alice M";
|
||||
const testRoomId = "!fl1bb13:localhost";
|
||||
|
||||
let testEvent;
|
||||
|
||||
let pushProcessor;
|
||||
|
||||
// These would be better if individual rules were configured in the tests themselves.
|
||||
let matrixClient = {
|
||||
const matrixClient = {
|
||||
getRoom: function() {
|
||||
return {
|
||||
currentState: {
|
||||
@ -213,25 +213,25 @@ describe('NotificationService', function() {
|
||||
|
||||
it('should bing on a user ID.', function() {
|
||||
testEvent.event.content.body = "Hello @ali:matrix.org, how are you?";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on a partial user ID with an @.', function() {
|
||||
testEvent.event.content.body = "Hello @ali, how are you?";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on a partial user ID without @.', function() {
|
||||
testEvent.event.content.body = "Hello ali, how are you?";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on a case-insensitive user ID.', function() {
|
||||
testEvent.event.content.body = "Hello @AlI:matrix.org, how are you?";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
@ -239,13 +239,13 @@ describe('NotificationService', function() {
|
||||
|
||||
it('should bing on a display name.', function() {
|
||||
testEvent.event.content.body = "Hello Alice M, how are you?";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on a case-insensitive display name.', function() {
|
||||
testEvent.event.content.body = "Hello ALICE M, how are you?";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
@ -253,19 +253,19 @@ describe('NotificationService', function() {
|
||||
|
||||
it('should bing on a bing word.', function() {
|
||||
testEvent.event.content.body = "I really like coffee";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on case-insensitive bing words.', function() {
|
||||
testEvent.event.content.body = "Coffee is great";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
it('should bing on wildcard (.*) bing words.', function() {
|
||||
testEvent.event.content.body = "It was foomahbar I think.";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
@ -280,7 +280,7 @@ describe('NotificationService', function() {
|
||||
|
||||
it('should bing on character range ([a-z]) bing words.', function() {
|
||||
testEvent.event.content.body = "I ate 6 pies";
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(true);
|
||||
});
|
||||
|
||||
@ -297,7 +297,7 @@ describe('NotificationService', function() {
|
||||
|
||||
it('should gracefully handle bad input.', function() {
|
||||
testEvent.event.content.body = { "foo": "bar" };
|
||||
let actions = pushProcessor.actionsForEvent(testEvent);
|
||||
const actions = pushProcessor.actionsForEvent(testEvent);
|
||||
expect(actions.tweaks.highlight).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
let callbacks = require("../../lib/realtime-callbacks");
|
||||
let testUtils = require("../test-utils.js");
|
||||
const callbacks = require("../../lib/realtime-callbacks");
|
||||
const testUtils = require("../test-utils.js");
|
||||
|
||||
describe("realtime-callbacks", function() {
|
||||
let clock = jasmine.Clock;
|
||||
const clock = jasmine.Clock;
|
||||
let fakeDate;
|
||||
|
||||
function tick(millis) {
|
||||
@ -28,7 +28,7 @@ describe("realtime-callbacks", function() {
|
||||
|
||||
describe("setTimeout", function() {
|
||||
it("should call the callback after the timeout", function() {
|
||||
let callback = jasmine.createSpy();
|
||||
const callback = jasmine.createSpy();
|
||||
callbacks.setTimeout(callback, 100);
|
||||
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
@ -38,7 +38,7 @@ describe("realtime-callbacks", function() {
|
||||
|
||||
|
||||
it("should default to a zero timeout", function() {
|
||||
let callback = jasmine.createSpy();
|
||||
const callback = jasmine.createSpy();
|
||||
callbacks.setTimeout(callback);
|
||||
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
@ -47,14 +47,14 @@ describe("realtime-callbacks", function() {
|
||||
});
|
||||
|
||||
it("should pass any parameters to the callback", function() {
|
||||
let callback = jasmine.createSpy();
|
||||
const callback = jasmine.createSpy();
|
||||
callbacks.setTimeout(callback, 0, "a", "b", "c");
|
||||
tick(0);
|
||||
expect(callback).toHaveBeenCalledWith("a", "b", "c");
|
||||
});
|
||||
|
||||
it("should set 'this' to the global object", function() {
|
||||
let callback = jasmine.createSpy();
|
||||
const callback = jasmine.createSpy();
|
||||
callback.andCallFake(function() {
|
||||
expect(this).toBe(global); // eslint-disable-line no-invalid-this
|
||||
expect(this.console).toBeDefined(); // eslint-disable-line no-invalid-this
|
||||
@ -65,7 +65,7 @@ describe("realtime-callbacks", function() {
|
||||
});
|
||||
|
||||
it("should handle timeouts of several seconds", function() {
|
||||
let callback = jasmine.createSpy();
|
||||
const callback = jasmine.createSpy();
|
||||
callbacks.setTimeout(callback, 2000);
|
||||
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
@ -76,9 +76,9 @@ describe("realtime-callbacks", function() {
|
||||
});
|
||||
|
||||
it("should call multiple callbacks in the right order", function() {
|
||||
let callback1 = jasmine.createSpy("callback1");
|
||||
let callback2 = jasmine.createSpy("callback2");
|
||||
let callback3 = jasmine.createSpy("callback3");
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
const callback3 = jasmine.createSpy("callback3");
|
||||
callbacks.setTimeout(callback2, 200);
|
||||
callbacks.setTimeout(callback1, 100);
|
||||
callbacks.setTimeout(callback3, 300);
|
||||
@ -101,8 +101,8 @@ describe("realtime-callbacks", function() {
|
||||
});
|
||||
|
||||
it("should treat -ve timeouts the same as a zero timeout", function() {
|
||||
let callback1 = jasmine.createSpy("callback1");
|
||||
let callback2 = jasmine.createSpy("callback2");
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
|
||||
// check that cb1 is called before cb2
|
||||
callback1.andCallFake(function() {
|
||||
@ -120,8 +120,8 @@ describe("realtime-callbacks", function() {
|
||||
});
|
||||
|
||||
it("should not get confused by chained calls", function() {
|
||||
let callback2 = jasmine.createSpy("callback2");
|
||||
let callback1 = jasmine.createSpy("callback1");
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
callback1.andCallFake(function() {
|
||||
callbacks.setTimeout(callback2, 0);
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
@ -136,11 +136,11 @@ describe("realtime-callbacks", function() {
|
||||
});
|
||||
|
||||
it("should be immune to exceptions", function() {
|
||||
let callback1 = jasmine.createSpy("callback1");
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
callback1.andCallFake(function() {
|
||||
throw new Error("prepare to die");
|
||||
});
|
||||
let callback2 = jasmine.createSpy("callback2");
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
callbacks.setTimeout(callback1, 0);
|
||||
callbacks.setTimeout(callback2, 0);
|
||||
|
||||
@ -154,19 +154,19 @@ describe("realtime-callbacks", function() {
|
||||
|
||||
describe("cancelTimeout", function() {
|
||||
it("should cancel a pending timeout", function() {
|
||||
let callback = jasmine.createSpy();
|
||||
let k = callbacks.setTimeout(callback);
|
||||
const callback = jasmine.createSpy();
|
||||
const k = callbacks.setTimeout(callback);
|
||||
callbacks.clearTimeout(k);
|
||||
tick(0);
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not affect sooner timeouts", function() {
|
||||
let callback1 = jasmine.createSpy("callback1");
|
||||
let callback2 = jasmine.createSpy("callback2");
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
|
||||
callbacks.setTimeout(callback1, 100);
|
||||
let k = callbacks.setTimeout(callback2, 200);
|
||||
const k = callbacks.setTimeout(callback2, 200);
|
||||
callbacks.clearTimeout(k);
|
||||
|
||||
tick(100);
|
||||
|
@ -1,13 +1,13 @@
|
||||
"use strict";
|
||||
let sdk = require("../..");
|
||||
let RoomMember = sdk.RoomMember;
|
||||
let utils = require("../test-utils");
|
||||
const sdk = require("../..");
|
||||
const RoomMember = sdk.RoomMember;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
describe("RoomMember", function() {
|
||||
let roomId = "!foo:bar";
|
||||
let userA = "@alice:bar";
|
||||
let userB = "@bertha:bar";
|
||||
let userC = "@clarissa:bar";
|
||||
const roomId = "!foo:bar";
|
||||
const userA = "@alice:bar";
|
||||
const userB = "@bertha:bar";
|
||||
const userC = "@clarissa:bar";
|
||||
let member;
|
||||
|
||||
beforeEach(function() {
|
||||
@ -16,7 +16,7 @@ describe("RoomMember", function() {
|
||||
});
|
||||
|
||||
describe("getAvatarUrl", function() {
|
||||
let hsUrl = "https://my.home.server";
|
||||
const hsUrl = "https://my.home.server";
|
||||
|
||||
it("should return the URL from m.room.member preferentially", function() {
|
||||
member.events.member = utils.mkEvent({
|
||||
@ -30,7 +30,7 @@ describe("RoomMember", function() {
|
||||
avatar_url: "mxc://flibble/wibble",
|
||||
},
|
||||
});
|
||||
let url = member.getAvatarUrl(hsUrl);
|
||||
const url = member.getAvatarUrl(hsUrl);
|
||||
// we don't care about how the mxc->http conversion is done, other
|
||||
// than it contains the mxc body.
|
||||
expect(url.indexOf("flibble/wibble")).not.toEqual(-1);
|
||||
@ -38,20 +38,20 @@ describe("RoomMember", function() {
|
||||
|
||||
it("should return an identicon HTTP URL if allowDefault was set and there " +
|
||||
"was no m.room.member event", function() {
|
||||
let url = member.getAvatarUrl(hsUrl, 64, 64, "crop", true);
|
||||
const url = member.getAvatarUrl(hsUrl, 64, 64, "crop", true);
|
||||
expect(url.indexOf("http")).toEqual(0); // don't care about form
|
||||
});
|
||||
|
||||
it("should return nothing if there is no m.room.member and allowDefault=false",
|
||||
function() {
|
||||
let url = member.getAvatarUrl(hsUrl, 64, 64, "crop", false);
|
||||
const url = member.getAvatarUrl(hsUrl, 64, 64, "crop", false);
|
||||
expect(url).toEqual(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("setPowerLevelEvent", function() {
|
||||
it("should set 'powerLevel' and 'powerLevelNorm'.", function() {
|
||||
let event = utils.mkEvent({
|
||||
const event = utils.mkEvent({
|
||||
type: "m.room.power_levels",
|
||||
room: roomId,
|
||||
user: userA,
|
||||
@ -68,7 +68,7 @@ describe("RoomMember", function() {
|
||||
expect(member.powerLevel).toEqual(20);
|
||||
expect(member.powerLevelNorm).toEqual(10);
|
||||
|
||||
let memberB = new RoomMember(roomId, userB);
|
||||
const memberB = new RoomMember(roomId, userB);
|
||||
memberB.setPowerLevelEvent(event);
|
||||
expect(memberB.powerLevel).toEqual(200);
|
||||
expect(memberB.powerLevelNorm).toEqual(100);
|
||||
@ -76,7 +76,7 @@ describe("RoomMember", function() {
|
||||
|
||||
it("should emit 'RoomMember.powerLevel' if the power level changes.",
|
||||
function() {
|
||||
let event = utils.mkEvent({
|
||||
const event = utils.mkEvent({
|
||||
type: "m.room.power_levels",
|
||||
room: roomId,
|
||||
user: userA,
|
||||
@ -105,7 +105,7 @@ describe("RoomMember", function() {
|
||||
|
||||
it("should honour power levels of zero.",
|
||||
function() {
|
||||
let event = utils.mkEvent({
|
||||
const event = utils.mkEvent({
|
||||
type: "m.room.power_levels",
|
||||
room: roomId,
|
||||
user: userA,
|
||||
@ -138,12 +138,12 @@ describe("RoomMember", function() {
|
||||
describe("setTypingEvent", function() {
|
||||
it("should set 'typing'", function() {
|
||||
member.typing = false;
|
||||
let memberB = new RoomMember(roomId, userB);
|
||||
const memberB = new RoomMember(roomId, userB);
|
||||
memberB.typing = true;
|
||||
let memberC = new RoomMember(roomId, userC);
|
||||
const memberC = new RoomMember(roomId, userC);
|
||||
memberC.typing = true;
|
||||
|
||||
let event = utils.mkEvent({
|
||||
const event = utils.mkEvent({
|
||||
type: "m.typing",
|
||||
user: userA,
|
||||
room: roomId,
|
||||
@ -165,7 +165,7 @@ describe("RoomMember", function() {
|
||||
|
||||
it("should emit 'RoomMember.typing' if the typing state changes",
|
||||
function() {
|
||||
let event = utils.mkEvent({
|
||||
const event = utils.mkEvent({
|
||||
type: "m.typing",
|
||||
room: roomId,
|
||||
content: {
|
||||
@ -190,7 +190,7 @@ describe("RoomMember", function() {
|
||||
});
|
||||
|
||||
describe("setMembershipEvent", function() {
|
||||
let joinEvent = utils.mkMembership({
|
||||
const joinEvent = utils.mkMembership({
|
||||
event: true,
|
||||
mship: "join",
|
||||
user: userA,
|
||||
@ -198,7 +198,7 @@ describe("RoomMember", function() {
|
||||
name: "Alice",
|
||||
});
|
||||
|
||||
let inviteEvent = utils.mkMembership({
|
||||
const inviteEvent = utils.mkMembership({
|
||||
event: true,
|
||||
mship: "invite",
|
||||
user: userB,
|
||||
@ -218,7 +218,7 @@ describe("RoomMember", function() {
|
||||
|
||||
it("should set 'name' based on user_id, displayname and room state",
|
||||
function() {
|
||||
let roomState = {
|
||||
const roomState = {
|
||||
getStateEvents: function(type) {
|
||||
if (type !== "m.room.member") {
|
||||
return [];
|
||||
|
@ -1,13 +1,13 @@
|
||||
"use strict";
|
||||
let sdk = require("../..");
|
||||
let RoomState = sdk.RoomState;
|
||||
let RoomMember = sdk.RoomMember;
|
||||
let utils = require("../test-utils");
|
||||
const sdk = require("../..");
|
||||
const RoomState = sdk.RoomState;
|
||||
const RoomMember = sdk.RoomMember;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
describe("RoomState", function() {
|
||||
let roomId = "!foo:bar";
|
||||
let userA = "@alice:bar";
|
||||
let userB = "@bob:bar";
|
||||
const roomId = "!foo:bar";
|
||||
const userA = "@alice:bar";
|
||||
const userB = "@bob:bar";
|
||||
let state;
|
||||
|
||||
beforeEach(function() {
|
||||
@ -40,7 +40,7 @@ describe("RoomState", function() {
|
||||
});
|
||||
|
||||
it("should return a member for each m.room.member event", function() {
|
||||
let members = state.getMembers();
|
||||
const members = state.getMembers();
|
||||
expect(members.length).toEqual(2);
|
||||
// ordering unimportant
|
||||
expect([userA, userB].indexOf(members[0].userId)).not.toEqual(-1);
|
||||
@ -58,7 +58,7 @@ describe("RoomState", function() {
|
||||
});
|
||||
|
||||
it("should return a member which changes as state changes", function() {
|
||||
let member = state.getMember(userB);
|
||||
const member = state.getMember(userB);
|
||||
expect(member.membership).toEqual("join");
|
||||
expect(member.name).toEqual(userB);
|
||||
|
||||
@ -81,14 +81,14 @@ describe("RoomState", function() {
|
||||
|
||||
it("should return a member which doesn't change when the state is updated",
|
||||
function() {
|
||||
let preLeaveUser = state.getSentinelMember(userA);
|
||||
const preLeaveUser = state.getSentinelMember(userA);
|
||||
state.setStateEvents([
|
||||
utils.mkMembership({
|
||||
room: roomId, user: userA, mship: "leave", event: true,
|
||||
name: "AliceIsGone",
|
||||
}),
|
||||
]);
|
||||
let postLeaveUser = state.getSentinelMember(userA);
|
||||
const postLeaveUser = state.getSentinelMember(userA);
|
||||
|
||||
expect(preLeaveUser.membership).toEqual("join");
|
||||
expect(preLeaveUser.name).toEqual(userA);
|
||||
@ -111,7 +111,7 @@ describe("RoomState", function() {
|
||||
|
||||
it("should return a list of matching events if no state_key was specified",
|
||||
function() {
|
||||
let events = state.getStateEvents("m.room.member");
|
||||
const events = state.getStateEvents("m.room.member");
|
||||
expect(events.length).toEqual(2);
|
||||
// ordering unimportant
|
||||
expect([userA, userB].indexOf(events[0].getStateKey())).not.toEqual(-1);
|
||||
@ -120,7 +120,7 @@ describe("RoomState", function() {
|
||||
|
||||
it("should return a single MatrixEvent if a state_key was specified",
|
||||
function() {
|
||||
let event = state.getStateEvents("m.room.member", userA);
|
||||
const event = state.getStateEvents("m.room.member", userA);
|
||||
expect(event.getContent()).toEqual({
|
||||
membership: "join",
|
||||
});
|
||||
@ -129,7 +129,7 @@ describe("RoomState", function() {
|
||||
|
||||
describe("setStateEvents", function() {
|
||||
it("should emit 'RoomState.members' for each m.room.member event", function() {
|
||||
let memberEvents = [
|
||||
const memberEvents = [
|
||||
utils.mkMembership({
|
||||
user: "@cleo:bar", mship: "invite", room: roomId, event: true,
|
||||
}),
|
||||
@ -149,7 +149,7 @@ describe("RoomState", function() {
|
||||
});
|
||||
|
||||
it("should emit 'RoomState.newMember' for each new member added", function() {
|
||||
let memberEvents = [
|
||||
const memberEvents = [
|
||||
utils.mkMembership({
|
||||
user: "@cleo:bar", mship: "invite", room: roomId, event: true,
|
||||
}),
|
||||
@ -168,7 +168,7 @@ describe("RoomState", function() {
|
||||
});
|
||||
|
||||
it("should emit 'RoomState.events' for each state event", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMembership({
|
||||
user: "@cleo:bar", mship: "invite", room: roomId, event: true,
|
||||
}),
|
||||
@ -198,7 +198,7 @@ describe("RoomState", function() {
|
||||
state.members[userA] = utils.mock(RoomMember);
|
||||
state.members[userB] = utils.mock(RoomMember);
|
||||
|
||||
let powerLevelEvent = utils.mkEvent({
|
||||
const powerLevelEvent = utils.mkEvent({
|
||||
type: "m.room.power_levels", room: roomId, user: userA, event: true,
|
||||
content: {
|
||||
users_default: 10,
|
||||
@ -219,11 +219,11 @@ describe("RoomState", function() {
|
||||
|
||||
it("should call setPowerLevelEvent on a new RoomMember if power levels exist",
|
||||
function() {
|
||||
let userC = "@cleo:bar";
|
||||
let memberEvent = utils.mkMembership({
|
||||
const userC = "@cleo:bar";
|
||||
const memberEvent = utils.mkMembership({
|
||||
mship: "join", user: userC, room: roomId, event: true,
|
||||
});
|
||||
let powerLevelEvent = utils.mkEvent({
|
||||
const powerLevelEvent = utils.mkEvent({
|
||||
type: "m.room.power_levels", room: roomId, user: userA, event: true,
|
||||
content: {
|
||||
users_default: 10,
|
||||
@ -247,7 +247,7 @@ describe("RoomState", function() {
|
||||
state.members[userA] = utils.mock(RoomMember);
|
||||
state.members[userB] = utils.mock(RoomMember);
|
||||
|
||||
let memberEvent = utils.mkMembership({
|
||||
const memberEvent = utils.mkMembership({
|
||||
user: userB, mship: "leave", room: roomId, event: true,
|
||||
});
|
||||
state.setStateEvents([memberEvent]);
|
||||
@ -261,7 +261,7 @@ describe("RoomState", function() {
|
||||
|
||||
describe("setTypingEvent", function() {
|
||||
it("should call setTypingEvent on each RoomMember", function() {
|
||||
let typingEvent = utils.mkEvent({
|
||||
const typingEvent = utils.mkEvent({
|
||||
type: "m.typing", room: roomId, event: true, content: {
|
||||
user_ids: [userA],
|
||||
},
|
||||
@ -296,7 +296,7 @@ describe("RoomState", function() {
|
||||
it("should say members with power >=50 may send state with power level event " +
|
||||
"but no state default",
|
||||
function() {
|
||||
let powerLevelEvent = {
|
||||
const powerLevelEvent = {
|
||||
type: "m.room.power_levels", room: roomId, user: userA, event: true,
|
||||
content: {
|
||||
users_default: 10,
|
||||
@ -316,7 +316,7 @@ describe("RoomState", function() {
|
||||
|
||||
it("should obey state_default",
|
||||
function() {
|
||||
let powerLevelEvent = {
|
||||
const powerLevelEvent = {
|
||||
type: "m.room.power_levels", room: roomId, user: userA, event: true,
|
||||
content: {
|
||||
users_default: 10,
|
||||
@ -337,7 +337,7 @@ describe("RoomState", function() {
|
||||
|
||||
it("should honour explicit event power levels in the power_levels event",
|
||||
function() {
|
||||
let powerLevelEvent = {
|
||||
const powerLevelEvent = {
|
||||
type: "m.room.power_levels", room: roomId, user: userA, event: true,
|
||||
content: {
|
||||
events: {
|
||||
@ -380,7 +380,7 @@ describe("RoomState", function() {
|
||||
|
||||
it("should obey events_default",
|
||||
function() {
|
||||
let powerLevelEvent = {
|
||||
const powerLevelEvent = {
|
||||
type: "m.room.power_levels", room: roomId, user: userA, event: true,
|
||||
content: {
|
||||
users_default: 10,
|
||||
@ -404,7 +404,7 @@ describe("RoomState", function() {
|
||||
|
||||
it("should honour explicit event power levels in the power_levels event",
|
||||
function() {
|
||||
let powerLevelEvent = {
|
||||
const powerLevelEvent = {
|
||||
type: "m.room.power_levels", room: roomId, user: userA, event: true,
|
||||
content: {
|
||||
events: {
|
||||
|
@ -1,18 +1,18 @@
|
||||
"use strict";
|
||||
let sdk = require("../..");
|
||||
let Room = sdk.Room;
|
||||
let RoomState = sdk.RoomState;
|
||||
let MatrixEvent = sdk.MatrixEvent;
|
||||
let EventStatus = sdk.EventStatus;
|
||||
let EventTimeline = sdk.EventTimeline;
|
||||
let utils = require("../test-utils");
|
||||
const sdk = require("../..");
|
||||
const Room = sdk.Room;
|
||||
const RoomState = sdk.RoomState;
|
||||
const MatrixEvent = sdk.MatrixEvent;
|
||||
const EventStatus = sdk.EventStatus;
|
||||
const EventTimeline = sdk.EventTimeline;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
describe("Room", function() {
|
||||
let roomId = "!foo:bar";
|
||||
let userA = "@alice:bar";
|
||||
let userB = "@bertha:bar";
|
||||
let userC = "@clarissa:bar";
|
||||
let userD = "@dorothy:bar";
|
||||
const roomId = "!foo:bar";
|
||||
const userA = "@alice:bar";
|
||||
const userB = "@bertha:bar";
|
||||
const userC = "@clarissa:bar";
|
||||
const userD = "@dorothy:bar";
|
||||
let room;
|
||||
|
||||
beforeEach(function() {
|
||||
@ -26,7 +26,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
describe("getAvatarUrl", function() {
|
||||
let hsUrl = "https://my.home.server";
|
||||
const hsUrl = "https://my.home.server";
|
||||
|
||||
it("should return the URL from m.room.avatar preferentially", function() {
|
||||
room.currentState.getStateEvents.andCallFake(function(type, key) {
|
||||
@ -43,7 +43,7 @@ describe("Room", function() {
|
||||
});
|
||||
}
|
||||
});
|
||||
let url = room.getAvatarUrl(hsUrl);
|
||||
const url = room.getAvatarUrl(hsUrl);
|
||||
// we don't care about how the mxc->http conversion is done, other
|
||||
// than it contains the mxc body.
|
||||
expect(url.indexOf("flibble/wibble")).not.toEqual(-1);
|
||||
@ -51,13 +51,13 @@ describe("Room", function() {
|
||||
|
||||
it("should return an identicon HTTP URL if allowDefault was set and there " +
|
||||
"was no m.room.avatar event", function() {
|
||||
let url = room.getAvatarUrl(hsUrl, 64, 64, "crop", true);
|
||||
const url = room.getAvatarUrl(hsUrl, 64, 64, "crop", true);
|
||||
expect(url.indexOf("http")).toEqual(0); // don't care about form
|
||||
});
|
||||
|
||||
it("should return nothing if there is no m.room.avatar and allowDefault=false",
|
||||
function() {
|
||||
let url = room.getAvatarUrl(hsUrl, 64, 64, "crop", false);
|
||||
const url = room.getAvatarUrl(hsUrl, 64, 64, "crop", false);
|
||||
expect(url).toEqual(null);
|
||||
});
|
||||
});
|
||||
@ -83,7 +83,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
describe("addLiveEvents", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "changing room name", event: true,
|
||||
}),
|
||||
@ -95,7 +95,7 @@ describe("Room", function() {
|
||||
|
||||
it("should call RoomState.setTypingEvent on m.typing events", function() {
|
||||
room.currentState = utils.mock(RoomState);
|
||||
let typing = utils.mkEvent({
|
||||
const typing = utils.mkEvent({
|
||||
room: roomId, type: "m.typing", event: true, content: {
|
||||
user_ids: [userA],
|
||||
},
|
||||
@ -112,7 +112,7 @@ describe("Room", function() {
|
||||
|
||||
it("should replace a timeline event if dupe strategy is 'replace'", function() {
|
||||
// make a duplicate
|
||||
let dupe = utils.mkMessage({
|
||||
const dupe = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "dupe", event: true,
|
||||
});
|
||||
dupe.event.event_id = events[0].getId();
|
||||
@ -124,7 +124,7 @@ describe("Room", function() {
|
||||
|
||||
it("should ignore a given dupe event if dupe strategy is 'ignore'", function() {
|
||||
// make a duplicate
|
||||
let dupe = utils.mkMessage({
|
||||
const dupe = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "dupe", event: true,
|
||||
});
|
||||
dupe.event.event_id = events[0].getId();
|
||||
@ -150,7 +150,7 @@ describe("Room", function() {
|
||||
|
||||
it("should call setStateEvents on the right RoomState with the right " +
|
||||
"forwardLooking value for new events", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
||||
}),
|
||||
@ -174,7 +174,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should synthesize read receipts for the senders of events", function() {
|
||||
let sentinel = {
|
||||
const sentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Alice",
|
||||
@ -190,17 +190,17 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should emit Room.localEchoUpdated when a local echo is updated", function() {
|
||||
let localEvent = utils.mkMessage({
|
||||
const localEvent = utils.mkMessage({
|
||||
room: roomId, user: userA, event: true,
|
||||
});
|
||||
localEvent.status = EventStatus.SENDING;
|
||||
let localEventId = localEvent.getId();
|
||||
const localEventId = localEvent.getId();
|
||||
|
||||
let remoteEvent = utils.mkMessage({
|
||||
const remoteEvent = utils.mkMessage({
|
||||
room: roomId, user: userA, event: true,
|
||||
});
|
||||
remoteEvent.event.unsigned = {transaction_id: "TXN_ID"};
|
||||
let remoteEventId = remoteEvent.getId();
|
||||
const remoteEventId = remoteEvent.getId();
|
||||
|
||||
let callCount = 0;
|
||||
room.on("Room.localEchoUpdated",
|
||||
@ -238,7 +238,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
describe("addEventsToTimeline", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "changing room name", event: true,
|
||||
}),
|
||||
@ -278,12 +278,12 @@ describe("Room", function() {
|
||||
|
||||
describe("event metadata handling", function() {
|
||||
it("should set event.sender for new and old events", function() {
|
||||
let sentinel = {
|
||||
const sentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Alice",
|
||||
};
|
||||
let oldSentinel = {
|
||||
const oldSentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Old Alice",
|
||||
@ -301,11 +301,11 @@ describe("Room", function() {
|
||||
return null;
|
||||
});
|
||||
|
||||
let newEv = utils.mkEvent({
|
||||
const newEv = utils.mkEvent({
|
||||
type: "m.room.name", room: roomId, user: userA, event: true,
|
||||
content: { name: "New Room Name" },
|
||||
});
|
||||
let oldEv = utils.mkEvent({
|
||||
const oldEv = utils.mkEvent({
|
||||
type: "m.room.name", room: roomId, user: userA, event: true,
|
||||
content: { name: "Old Room Name" },
|
||||
});
|
||||
@ -317,12 +317,12 @@ describe("Room", function() {
|
||||
|
||||
it("should set event.target for new and old m.room.member events",
|
||||
function() {
|
||||
let sentinel = {
|
||||
const sentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Alice",
|
||||
};
|
||||
let oldSentinel = {
|
||||
const oldSentinel = {
|
||||
userId: userA,
|
||||
membership: "join",
|
||||
name: "Old Alice",
|
||||
@ -340,10 +340,10 @@ describe("Room", function() {
|
||||
return null;
|
||||
});
|
||||
|
||||
let newEv = utils.mkMembership({
|
||||
const newEv = utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
||||
});
|
||||
let oldEv = utils.mkMembership({
|
||||
const oldEv = utils.mkMembership({
|
||||
room: roomId, mship: "ban", user: userB, skey: userA, event: true,
|
||||
});
|
||||
room.addLiveEvents([newEv]);
|
||||
@ -354,7 +354,7 @@ describe("Room", function() {
|
||||
|
||||
it("should call setStateEvents on the right RoomState with the right " +
|
||||
"forwardLooking value for old events", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMembership({
|
||||
room: roomId, mship: "invite", user: userB, skey: userA, event: true,
|
||||
}),
|
||||
@ -379,8 +379,8 @@ describe("Room", function() {
|
||||
});
|
||||
});
|
||||
|
||||
let resetTimelineTests = function(timelineSupport) {
|
||||
let events = [
|
||||
const resetTimelineTests = function(timelineSupport) {
|
||||
const events = [
|
||||
utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "A message", event: true,
|
||||
}),
|
||||
@ -404,8 +404,8 @@ describe("Room", function() {
|
||||
room.resetLiveTimeline();
|
||||
|
||||
room.addLiveEvents([events[2]]);
|
||||
let oldState = room.getLiveTimeline().getState(EventTimeline.BACKWARDS);
|
||||
let newState = room.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
||||
const oldState = room.getLiveTimeline().getState(EventTimeline.BACKWARDS);
|
||||
const newState = room.getLiveTimeline().getState(EventTimeline.FORWARDS);
|
||||
expect(room.getLiveTimeline().getEvents().length).toEqual(1);
|
||||
expect(oldState.getStateEvents("m.room.name", "")).toEqual(events[1]);
|
||||
expect(newState.getStateEvents("m.room.name", "")).toEqual(events[2]);
|
||||
@ -417,7 +417,7 @@ describe("Room", function() {
|
||||
room.resetLiveTimeline();
|
||||
|
||||
room.addLiveEvents([events[2]]);
|
||||
let newLiveTimeline = room.getLiveTimeline();
|
||||
const newLiveTimeline = room.getLiveTimeline();
|
||||
expect(room.timeline).toEqual(newLiveTimeline.getEvents());
|
||||
expect(room.oldState).toEqual(
|
||||
newLiveTimeline.getState(EventTimeline.BACKWARDS));
|
||||
@ -434,7 +434,7 @@ describe("Room", function() {
|
||||
|
||||
// make sure that the pagination token has been set before the
|
||||
// event is emitted.
|
||||
let tok = emitRoom.getLiveTimeline()
|
||||
const tok = emitRoom.getLiveTimeline()
|
||||
.getPaginationToken(EventTimeline.BACKWARDS);
|
||||
|
||||
expect(tok).toEqual("pagToken");
|
||||
@ -447,10 +447,10 @@ describe("Room", function() {
|
||||
" old timelines", function() {
|
||||
room.addLiveEvents([events[0]]);
|
||||
expect(room.timeline.length).toEqual(1);
|
||||
let firstLiveTimeline = room.getLiveTimeline();
|
||||
const firstLiveTimeline = room.getLiveTimeline();
|
||||
room.resetLiveTimeline();
|
||||
|
||||
let tl = room.getTimelineForEvent(events[0].getId());
|
||||
const tl = room.getTimelineForEvent(events[0].getId());
|
||||
expect(tl).toBe(timelineSupport ? firstLiveTimeline : null);
|
||||
});
|
||||
};
|
||||
@ -465,7 +465,7 @@ describe("Room", function() {
|
||||
room = new Room(roomId, {timelineSupport: true});
|
||||
});
|
||||
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "1111", event: true,
|
||||
}),
|
||||
@ -492,7 +492,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should handle events in adjacent timelines", function() {
|
||||
let oldTimeline = room.addTimeline();
|
||||
const oldTimeline = room.addTimeline();
|
||||
oldTimeline.setNeighbouringTimeline(room.getLiveTimeline(), 'f');
|
||||
room.getLiveTimeline().setNeighbouringTimeline(oldTimeline, 'b');
|
||||
|
||||
@ -508,7 +508,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should return null for events in non-adjacent timelines", function() {
|
||||
let oldTimeline = room.addTimeline();
|
||||
const oldTimeline = room.addTimeline();
|
||||
|
||||
room.addEventsToTimeline([events[0]], false, oldTimeline);
|
||||
room.addLiveEvents([events[1]]);
|
||||
@ -545,7 +545,7 @@ describe("Room", function() {
|
||||
{ userId: "@cleo:bar", membership: "leave" },
|
||||
];
|
||||
});
|
||||
let res = room.getJoinedMembers();
|
||||
const res = room.getJoinedMembers();
|
||||
expect(res.length).toEqual(1);
|
||||
expect(res[0].userId).toEqual("@alice:bar");
|
||||
});
|
||||
@ -556,7 +556,7 @@ describe("Room", function() {
|
||||
{ userId: "@bob:bar", membership: "invite" },
|
||||
];
|
||||
});
|
||||
let res = room.getJoinedMembers();
|
||||
const res = room.getJoinedMembers();
|
||||
expect(res.length).toEqual(0);
|
||||
});
|
||||
});
|
||||
@ -607,14 +607,14 @@ describe("Room", function() {
|
||||
// event.type + "$" event.state_key : MatrixEvent
|
||||
};
|
||||
|
||||
let setJoinRule = function(rule) {
|
||||
const setJoinRule = function(rule) {
|
||||
stateLookup["m.room.join_rules$"] = utils.mkEvent({
|
||||
type: "m.room.join_rules", room: roomId, user: userA, content: {
|
||||
join_rule: rule,
|
||||
}, event: true,
|
||||
});
|
||||
};
|
||||
let setAliases = function(aliases, stateKey) {
|
||||
const setAliases = function(aliases, stateKey) {
|
||||
if (!stateKey) {
|
||||
stateKey = "flibble";
|
||||
}
|
||||
@ -624,14 +624,14 @@ describe("Room", function() {
|
||||
}, event: true,
|
||||
});
|
||||
};
|
||||
let setRoomName = function(name) {
|
||||
const setRoomName = function(name) {
|
||||
stateLookup["m.room.name$"] = utils.mkEvent({
|
||||
type: "m.room.name", room: roomId, user: userA, content: {
|
||||
name: name,
|
||||
}, event: true,
|
||||
});
|
||||
};
|
||||
let addMember = function(userId, state, opts) {
|
||||
const addMember = function(userId, state, opts) {
|
||||
if (!state) {
|
||||
state = "join";
|
||||
}
|
||||
@ -648,9 +648,9 @@ describe("Room", function() {
|
||||
stateLookup = {};
|
||||
room.currentState.getStateEvents.andCallFake(function(type, key) {
|
||||
if (key === undefined) {
|
||||
let prefix = type + "$";
|
||||
let list = [];
|
||||
for (let stateBlob in stateLookup) {
|
||||
const prefix = type + "$";
|
||||
const list = [];
|
||||
for (const stateBlob in stateLookup) {
|
||||
if (!stateLookup.hasOwnProperty(stateBlob)) {
|
||||
continue;
|
||||
}
|
||||
@ -664,8 +664,8 @@ describe("Room", function() {
|
||||
}
|
||||
});
|
||||
room.currentState.getMembers.andCallFake(function() {
|
||||
let memberEvents = room.currentState.getStateEvents("m.room.member");
|
||||
let members = [];
|
||||
const memberEvents = room.currentState.getStateEvents("m.room.member");
|
||||
const members = [];
|
||||
for (let i = 0; i < memberEvents.length; i++) {
|
||||
members.push({
|
||||
name: memberEvents[i].event.content &&
|
||||
@ -679,7 +679,7 @@ describe("Room", function() {
|
||||
return members;
|
||||
});
|
||||
room.currentState.getMember.andCallFake(function(userId) {
|
||||
let memberEvent = room.currentState.getStateEvents(
|
||||
const memberEvent = room.currentState.getStateEvents(
|
||||
"m.room.member", userId
|
||||
);
|
||||
return {
|
||||
@ -696,7 +696,7 @@ describe("Room", function() {
|
||||
describe("Room.recalculate => Stripped State Events", function() {
|
||||
it("should set stripped state events as actual state events if the " +
|
||||
"room is an invite room", function() {
|
||||
let roomName = "flibble";
|
||||
const roomName = "flibble";
|
||||
|
||||
addMember(userA, "invite");
|
||||
stateLookup["m.room.member$" + userA].event.invite_room_state = [
|
||||
@ -712,7 +712,7 @@ describe("Room", function() {
|
||||
room.recalculate(userA);
|
||||
expect(room.currentState.setStateEvents).toHaveBeenCalled();
|
||||
// first call, first arg (which is an array), first element in array
|
||||
let fakeEvent = room.currentState.setStateEvents.calls[0].args[0][0];
|
||||
const fakeEvent = room.currentState.setStateEvents.calls[0].args[0][0];
|
||||
expect(fakeEvent.getContent()).toEqual({
|
||||
name: roomName,
|
||||
});
|
||||
@ -745,9 +745,9 @@ describe("Room", function() {
|
||||
addMember(userC);
|
||||
addMember(userD);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
// we expect at least 1 member to be mentioned
|
||||
let others = [userB, userC, userD];
|
||||
const others = [userB, userC, userD];
|
||||
let found = false;
|
||||
for (let i = 0; i < others.length; i++) {
|
||||
if (name.indexOf(others[i]) !== -1) {
|
||||
@ -766,7 +766,7 @@ describe("Room", function() {
|
||||
addMember(userB);
|
||||
addMember(userC);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userC)).not.toEqual(-1, name);
|
||||
});
|
||||
@ -779,7 +779,7 @@ describe("Room", function() {
|
||||
addMember(userB);
|
||||
addMember(userC);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userC)).not.toEqual(-1, name);
|
||||
});
|
||||
@ -791,7 +791,7 @@ describe("Room", function() {
|
||||
addMember(userA);
|
||||
addMember(userB);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
});
|
||||
|
||||
@ -802,7 +802,7 @@ describe("Room", function() {
|
||||
addMember(userA);
|
||||
addMember(userB);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
});
|
||||
|
||||
@ -812,47 +812,47 @@ describe("Room", function() {
|
||||
addMember(userA, "invite", {user: userB});
|
||||
addMember(userB);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
});
|
||||
|
||||
it("should show the room alias if one exists for private " +
|
||||
"(invite join_rules) rooms if a room name doesn't exist.", function() {
|
||||
let alias = "#room_alias:here";
|
||||
const alias = "#room_alias:here";
|
||||
setJoinRule("invite");
|
||||
setAliases([alias, "#another:one"]);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual(alias);
|
||||
});
|
||||
|
||||
it("should show the room alias if one exists for public " +
|
||||
"(public join_rules) rooms if a room name doesn't exist.", function() {
|
||||
let alias = "#room_alias:here";
|
||||
const alias = "#room_alias:here";
|
||||
setJoinRule("public");
|
||||
setAliases([alias, "#another:one"]);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual(alias);
|
||||
});
|
||||
|
||||
it("should show the room name if one exists for private " +
|
||||
"(invite join_rules) rooms.", function() {
|
||||
let roomName = "A mighty name indeed";
|
||||
const roomName = "A mighty name indeed";
|
||||
setJoinRule("invite");
|
||||
setRoomName(roomName);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual(roomName);
|
||||
});
|
||||
|
||||
it("should show the room name if one exists for public " +
|
||||
"(public join_rules) rooms.", function() {
|
||||
let roomName = "A mighty name indeed";
|
||||
const roomName = "A mighty name indeed";
|
||||
setJoinRule("public");
|
||||
setRoomName(roomName);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual(roomName);
|
||||
});
|
||||
|
||||
@ -861,7 +861,7 @@ describe("Room", function() {
|
||||
setJoinRule("invite");
|
||||
addMember(userA);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual("Empty room");
|
||||
});
|
||||
|
||||
@ -870,7 +870,7 @@ describe("Room", function() {
|
||||
setJoinRule("public");
|
||||
addMember(userA);
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual("Empty room");
|
||||
});
|
||||
|
||||
@ -878,7 +878,7 @@ describe("Room", function() {
|
||||
"alias or members in the room.",
|
||||
function() {
|
||||
room.recalculate(userA);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual("Empty room");
|
||||
});
|
||||
|
||||
@ -889,7 +889,7 @@ describe("Room", function() {
|
||||
addMember(userA, 'join', {name: "Alice"});
|
||||
addMember(userB, "invite", {user: userA});
|
||||
room.recalculate(userB);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual("Invite from Alice");
|
||||
});
|
||||
|
||||
@ -899,20 +899,20 @@ describe("Room", function() {
|
||||
addMember(userA);
|
||||
addMember(userB, "invite", {user: userA});
|
||||
room.recalculate(userB);
|
||||
let name = room.name;
|
||||
const name = room.name;
|
||||
expect(name).toEqual("Invite from " + userA);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("receipts", function() {
|
||||
let eventToAck = utils.mkMessage({
|
||||
const eventToAck = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "PLEASE ACKNOWLEDGE MY EXISTENCE",
|
||||
event: true,
|
||||
});
|
||||
|
||||
function mkReceipt(roomId, records) {
|
||||
let content = {};
|
||||
const content = {};
|
||||
records.forEach(function(r) {
|
||||
if (!content[r.eventId]) {
|
||||
content[r.eventId] = {};
|
||||
@ -944,7 +944,7 @@ describe("Room", function() {
|
||||
describe("addReceipt", function() {
|
||||
it("should store the receipt so it can be obtained via getReceiptsForEvent",
|
||||
function() {
|
||||
let ts = 13787898424;
|
||||
const ts = 13787898424;
|
||||
room.addReceipt(mkReceipt(roomId, [
|
||||
mkRecord(eventToAck.getId(), "m.read", userB, ts),
|
||||
]));
|
||||
@ -959,12 +959,12 @@ describe("Room", function() {
|
||||
|
||||
it("should emit an event when a receipt is added",
|
||||
function() {
|
||||
let listener = jasmine.createSpy('spy');
|
||||
const listener = jasmine.createSpy('spy');
|
||||
room.on("Room.receipt", listener);
|
||||
|
||||
let ts = 13787898424;
|
||||
const ts = 13787898424;
|
||||
|
||||
let receiptEvent = mkReceipt(roomId, [
|
||||
const receiptEvent = mkReceipt(roomId, [
|
||||
mkRecord(eventToAck.getId(), "m.read", userB, ts),
|
||||
]);
|
||||
|
||||
@ -973,15 +973,15 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should clobber receipts based on type and user ID", function() {
|
||||
let nextEventToAck = utils.mkMessage({
|
||||
const nextEventToAck = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "I AM HERE YOU KNOW",
|
||||
event: true,
|
||||
});
|
||||
let ts = 13787898424;
|
||||
const ts = 13787898424;
|
||||
room.addReceipt(mkReceipt(roomId, [
|
||||
mkRecord(eventToAck.getId(), "m.read", userB, ts),
|
||||
]));
|
||||
let ts2 = 13787899999;
|
||||
const ts2 = 13787899999;
|
||||
room.addReceipt(mkReceipt(roomId, [
|
||||
mkRecord(nextEventToAck.getId(), "m.read", userB, ts2),
|
||||
]));
|
||||
@ -996,7 +996,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should persist multiple receipts for a single event ID", function() {
|
||||
let ts = 13787898424;
|
||||
const ts = 13787898424;
|
||||
room.addReceipt(mkReceipt(roomId, [
|
||||
mkRecord(eventToAck.getId(), "m.read", userB, ts),
|
||||
mkRecord(eventToAck.getId(), "m.read", userC, ts),
|
||||
@ -1008,15 +1008,15 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should persist multiple receipts for a single receipt type", function() {
|
||||
let eventTwo = utils.mkMessage({
|
||||
const eventTwo = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "2222",
|
||||
event: true,
|
||||
});
|
||||
let eventThree = utils.mkMessage({
|
||||
const eventThree = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "3333",
|
||||
event: true,
|
||||
});
|
||||
let ts = 13787898424;
|
||||
const ts = 13787898424;
|
||||
room.addReceipt(mkReceipt(roomId, [
|
||||
mkRecord(eventToAck.getId(), "m.read", userB, ts),
|
||||
mkRecord(eventTwo.getId(), "m.read", userC, ts),
|
||||
@ -1059,7 +1059,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should prioritise the most recent event", function() {
|
||||
let events = [
|
||||
const events = [
|
||||
utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "1111",
|
||||
event: true,
|
||||
@ -1075,7 +1075,7 @@ describe("Room", function() {
|
||||
];
|
||||
|
||||
room.addLiveEvents(events);
|
||||
let ts = 13787898424;
|
||||
const ts = 13787898424;
|
||||
|
||||
// check it initialises correctly
|
||||
room.addReceipt(mkReceipt(roomId, [
|
||||
@ -1099,7 +1099,7 @@ describe("Room", function() {
|
||||
|
||||
describe("getUsersReadUpTo", function() {
|
||||
it("should return user IDs read up to the given event", function() {
|
||||
let ts = 13787898424;
|
||||
const ts = 13787898424;
|
||||
room.addReceipt(mkReceipt(roomId, [
|
||||
mkRecord(eventToAck.getId(), "m.read", userB, ts),
|
||||
]));
|
||||
@ -1110,7 +1110,7 @@ describe("Room", function() {
|
||||
|
||||
describe("tags", function() {
|
||||
function mkTags(roomId, tags) {
|
||||
let content = { "tags": tags };
|
||||
const content = { "tags": tags };
|
||||
return new MatrixEvent({
|
||||
content: content,
|
||||
room_id: roomId,
|
||||
@ -1122,7 +1122,7 @@ describe("Room", function() {
|
||||
it("should set tags on rooms from event stream so " +
|
||||
"they can be obtained by the tags property",
|
||||
function() {
|
||||
let tags = { "m.foo": { "order": 0.5 } };
|
||||
const tags = { "m.foo": { "order": 0.5 } };
|
||||
room.addTags(mkTags(roomId, tags));
|
||||
expect(room.tags).toEqual(tags);
|
||||
});
|
||||
@ -1130,11 +1130,11 @@ describe("Room", function() {
|
||||
it("should emit Room.tags event when new tags are " +
|
||||
"received on the event stream",
|
||||
function() {
|
||||
let listener = jasmine.createSpy('spy');
|
||||
const listener = jasmine.createSpy('spy');
|
||||
room.on("Room.tags", listener);
|
||||
|
||||
let tags = { "m.foo": { "order": 0.5 } };
|
||||
let event = mkTags(roomId, tags);
|
||||
const tags = { "m.foo": { "order": 0.5 } };
|
||||
const event = mkTags(roomId, tags);
|
||||
room.addTags(event);
|
||||
expect(listener).toHaveBeenCalledWith(event, room);
|
||||
});
|
||||
@ -1147,17 +1147,17 @@ describe("Room", function() {
|
||||
describe("addPendingEvent", function() {
|
||||
it("should add pending events to the pendingEventList if " +
|
||||
"pendingEventOrdering == 'detached'", function() {
|
||||
let room = new Room(roomId, {
|
||||
const room = new Room(roomId, {
|
||||
pendingEventOrdering: "detached",
|
||||
});
|
||||
let eventA = utils.mkMessage({
|
||||
const eventA = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "remote 1", event: true,
|
||||
});
|
||||
let eventB = utils.mkMessage({
|
||||
const eventB = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "local 1", event: true,
|
||||
});
|
||||
eventB.status = EventStatus.SENDING;
|
||||
let eventC = utils.mkMessage({
|
||||
const eventC = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "remote 2", event: true,
|
||||
});
|
||||
room.addLiveEvents([eventA]);
|
||||
@ -1176,14 +1176,14 @@ describe("Room", function() {
|
||||
room = new Room(roomId, {
|
||||
pendingEventOrdering: "chronological",
|
||||
});
|
||||
let eventA = utils.mkMessage({
|
||||
const eventA = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "remote 1", event: true,
|
||||
});
|
||||
let eventB = utils.mkMessage({
|
||||
const eventB = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "local 1", event: true,
|
||||
});
|
||||
eventB.status = EventStatus.SENDING;
|
||||
let eventC = utils.mkMessage({
|
||||
const eventC = utils.mkMessage({
|
||||
room: roomId, user: userA, msg: "remote 2", event: true,
|
||||
});
|
||||
room.addLiveEvents([eventA]);
|
||||
@ -1197,14 +1197,14 @@ describe("Room", function() {
|
||||
|
||||
describe("updatePendingEvent", function() {
|
||||
it("should remove cancelled events from the pending list", function() {
|
||||
let room = new Room(roomId, {
|
||||
const room = new Room(roomId, {
|
||||
pendingEventOrdering: "detached",
|
||||
});
|
||||
let eventA = utils.mkMessage({
|
||||
const eventA = utils.mkMessage({
|
||||
room: roomId, user: userA, event: true,
|
||||
});
|
||||
eventA.status = EventStatus.SENDING;
|
||||
let eventId = eventA.getId();
|
||||
const eventId = eventA.getId();
|
||||
|
||||
room.addPendingEvent(eventA, "TXN1");
|
||||
expect(room.getPendingEvents()).toEqual(
|
||||
@ -1233,12 +1233,12 @@ describe("Room", function() {
|
||||
|
||||
|
||||
it("should remove cancelled events from the timeline", function() {
|
||||
let room = new Room(roomId);
|
||||
let eventA = utils.mkMessage({
|
||||
const room = new Room(roomId);
|
||||
const eventA = utils.mkMessage({
|
||||
room: roomId, user: userA, event: true,
|
||||
});
|
||||
eventA.status = EventStatus.SENDING;
|
||||
let eventId = eventA.getId();
|
||||
const eventId = eventA.getId();
|
||||
|
||||
room.addPendingEvent(eventA, "TXN1");
|
||||
expect(room.getLiveTimeline().getEvents()).toEqual(
|
||||
|
@ -1,22 +1,22 @@
|
||||
// This file had a function whose name is all caps, which displeases eslint
|
||||
/* eslint new-cap: "off" */
|
||||
|
||||
let q = require("q");
|
||||
let sdk = require("../..");
|
||||
let MatrixScheduler = sdk.MatrixScheduler;
|
||||
let MatrixError = sdk.MatrixError;
|
||||
let utils = require("../test-utils");
|
||||
const q = require("q");
|
||||
const sdk = require("../..");
|
||||
const MatrixScheduler = sdk.MatrixScheduler;
|
||||
const MatrixError = sdk.MatrixError;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
describe("MatrixScheduler", function() {
|
||||
let scheduler;
|
||||
let retryFn;
|
||||
let queueFn;
|
||||
let defer;
|
||||
let roomId = "!foo:bar";
|
||||
let eventA = utils.mkMessage({
|
||||
const roomId = "!foo:bar";
|
||||
const eventA = utils.mkMessage({
|
||||
user: "@alice:bar", room: roomId, event: true,
|
||||
});
|
||||
let eventB = utils.mkMessage({
|
||||
const eventB = utils.mkMessage({
|
||||
user: "@alice:bar", room: roomId, event: true,
|
||||
});
|
||||
|
||||
@ -46,8 +46,8 @@ describe("MatrixScheduler", function() {
|
||||
queueFn = function() {
|
||||
return "one_big_queue";
|
||||
};
|
||||
let deferA = q.defer();
|
||||
let deferB = q.defer();
|
||||
const deferA = q.defer();
|
||||
const deferB = q.defer();
|
||||
let resolvedA = false;
|
||||
scheduler.setProcessFunction(function(event) {
|
||||
if (resolvedA) {
|
||||
@ -70,8 +70,8 @@ describe("MatrixScheduler", function() {
|
||||
|
||||
it("should invoke the retryFn on failure and wait the amount of time specified",
|
||||
function(done) {
|
||||
let waitTimeMs = 1500;
|
||||
let retryDefer = q.defer();
|
||||
const waitTimeMs = 1500;
|
||||
const retryDefer = q.defer();
|
||||
retryFn = function() {
|
||||
retryDefer.resolve();
|
||||
return waitTimeMs;
|
||||
@ -116,8 +116,8 @@ describe("MatrixScheduler", function() {
|
||||
return "yep";
|
||||
};
|
||||
|
||||
let deferA = q.defer();
|
||||
let deferB = q.defer();
|
||||
const deferA = q.defer();
|
||||
const deferB = q.defer();
|
||||
let procCount = 0;
|
||||
scheduler.setProcessFunction(function(ev) {
|
||||
procCount += 1;
|
||||
@ -131,7 +131,7 @@ describe("MatrixScheduler", function() {
|
||||
expect(procCount).toBeLessThan(3);
|
||||
});
|
||||
|
||||
let globalA = scheduler.queueEvent(eventA);
|
||||
const globalA = scheduler.queueEvent(eventA);
|
||||
scheduler.queueEvent(eventB);
|
||||
|
||||
expect(procCount).toEqual(1);
|
||||
@ -149,10 +149,10 @@ describe("MatrixScheduler", function() {
|
||||
// Expect to have processFn invoked for A&B.
|
||||
// Resolve A.
|
||||
// Expect to have processFn invoked for D.
|
||||
let eventC = utils.mkMessage({user: "@a:bar", room: roomId, event: true});
|
||||
let eventD = utils.mkMessage({user: "@b:bar", room: roomId, event: true});
|
||||
const eventC = utils.mkMessage({user: "@a:bar", room: roomId, event: true});
|
||||
const eventD = utils.mkMessage({user: "@b:bar", room: roomId, event: true});
|
||||
|
||||
let buckets = {};
|
||||
const buckets = {};
|
||||
buckets[eventA.getId()] = "queue_A";
|
||||
buckets[eventD.getId()] = "queue_A";
|
||||
buckets[eventB.getId()] = "queue_B";
|
||||
@ -165,12 +165,12 @@ describe("MatrixScheduler", function() {
|
||||
return buckets[event.getId()];
|
||||
};
|
||||
|
||||
let expectOrder = [
|
||||
const expectOrder = [
|
||||
eventA.getId(), eventB.getId(), eventD.getId(),
|
||||
];
|
||||
let deferA = q.defer();
|
||||
const deferA = q.defer();
|
||||
scheduler.setProcessFunction(function(event) {
|
||||
let id = expectOrder.shift();
|
||||
const id = expectOrder.shift();
|
||||
expect(id).toEqual(event.getId());
|
||||
if (expectOrder.length === 0) {
|
||||
done();
|
||||
@ -201,7 +201,7 @@ describe("MatrixScheduler", function() {
|
||||
queueFn = function() {
|
||||
return "yep";
|
||||
};
|
||||
let prom = scheduler.queueEvent(eventA);
|
||||
const prom = scheduler.queueEvent(eventA);
|
||||
expect(prom).toBeDefined();
|
||||
expect(prom.then).toBeDefined();
|
||||
});
|
||||
@ -229,15 +229,15 @@ describe("MatrixScheduler", function() {
|
||||
};
|
||||
scheduler.queueEvent(eventA);
|
||||
scheduler.queueEvent(eventB);
|
||||
let queue = scheduler.getQueueForEvent(eventA);
|
||||
const queue = scheduler.getQueueForEvent(eventA);
|
||||
expect(queue.length).toEqual(2);
|
||||
expect(queue).toEqual([eventA, eventB]);
|
||||
// modify the queue
|
||||
let eventC = utils.mkMessage(
|
||||
const eventC = utils.mkMessage(
|
||||
{user: "@a:bar", room: roomId, event: true}
|
||||
);
|
||||
queue.push(eventC);
|
||||
let queueAgain = scheduler.getQueueForEvent(eventA);
|
||||
const queueAgain = scheduler.getQueueForEvent(eventA);
|
||||
expect(queueAgain.length).toEqual(2);
|
||||
});
|
||||
|
||||
@ -248,9 +248,9 @@ describe("MatrixScheduler", function() {
|
||||
};
|
||||
scheduler.queueEvent(eventA);
|
||||
scheduler.queueEvent(eventB);
|
||||
let queue = scheduler.getQueueForEvent(eventA);
|
||||
const queue = scheduler.getQueueForEvent(eventA);
|
||||
queue[1].event.content.body = "foo";
|
||||
let queueAgain = scheduler.getQueueForEvent(eventA);
|
||||
const queueAgain = scheduler.getQueueForEvent(eventA);
|
||||
expect(queueAgain[1].event.content.body).toEqual("foo");
|
||||
});
|
||||
});
|
||||
@ -320,7 +320,7 @@ describe("MatrixScheduler", function() {
|
||||
|
||||
describe("RETRY_BACKOFF_RATELIMIT", function() {
|
||||
it("should wait at least the time given on M_LIMIT_EXCEEDED", function() {
|
||||
let res = MatrixScheduler.RETRY_BACKOFF_RATELIMIT(
|
||||
const res = MatrixScheduler.RETRY_BACKOFF_RATELIMIT(
|
||||
eventA, 1, new MatrixError({
|
||||
errcode: "M_LIMIT_EXCEEDED", retry_after_ms: 5000,
|
||||
})
|
||||
@ -329,7 +329,7 @@ describe("MatrixScheduler", function() {
|
||||
});
|
||||
|
||||
it("should give up after 5 attempts", function() {
|
||||
let res = MatrixScheduler.RETRY_BACKOFF_RATELIMIT(
|
||||
const res = MatrixScheduler.RETRY_BACKOFF_RATELIMIT(
|
||||
eventA, 5, {}
|
||||
);
|
||||
expect(res).toBe(-1, "Didn't give up.");
|
||||
|
@ -1,14 +1,14 @@
|
||||
"use strict";
|
||||
let q = require("q");
|
||||
let sdk = require("../..");
|
||||
let EventTimeline = sdk.EventTimeline;
|
||||
let TimelineWindow = sdk.TimelineWindow;
|
||||
let TimelineIndex = require("../../lib/timeline-window").TimelineIndex;
|
||||
const q = require("q");
|
||||
const sdk = require("../..");
|
||||
const EventTimeline = sdk.EventTimeline;
|
||||
const TimelineWindow = sdk.TimelineWindow;
|
||||
const TimelineIndex = require("../../lib/timeline-window").TimelineIndex;
|
||||
|
||||
let utils = require("../test-utils");
|
||||
const utils = require("../test-utils");
|
||||
|
||||
let ROOM_ID = "roomId";
|
||||
let USER_ID = "userId";
|
||||
const ROOM_ID = "roomId";
|
||||
const USER_ID = "userId";
|
||||
|
||||
/*
|
||||
* create a timeline with a bunch (default 3) events.
|
||||
@ -23,12 +23,12 @@ function createTimeline(numEvents, baseIndex) {
|
||||
}
|
||||
|
||||
// XXX: this is a horrid hack
|
||||
let timelineSet = { room: { roomId: ROOM_ID }};
|
||||
const timelineSet = { room: { roomId: ROOM_ID }};
|
||||
timelineSet.room.getUnfilteredTimelineSet = function() {
|
||||
return timelineSet;
|
||||
};
|
||||
|
||||
let timeline = new EventTimeline(timelineSet);
|
||||
const timeline = new EventTimeline(timelineSet);
|
||||
|
||||
// add the events after the baseIndex first
|
||||
addEventsToTimeline(timeline, numEvents - baseIndex, false);
|
||||
@ -56,8 +56,8 @@ function addEventsToTimeline(timeline, numEvents, atStart) {
|
||||
* create a pair of linked timelines
|
||||
*/
|
||||
function createLinkedTimelines() {
|
||||
let tl1 = createTimeline();
|
||||
let tl2 = createTimeline();
|
||||
const tl1 = createTimeline();
|
||||
const tl2 = createTimeline();
|
||||
tl1.setNeighbouringTimeline(tl2, EventTimeline.FORWARDS);
|
||||
tl2.setNeighbouringTimeline(tl1, EventTimeline.BACKWARDS);
|
||||
return [tl1, tl2];
|
||||
@ -71,42 +71,42 @@ describe("TimelineIndex", function() {
|
||||
|
||||
describe("minIndex", function() {
|
||||
it("should return the min index relative to BaseIndex", function() {
|
||||
let timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
const timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
expect(timelineIndex.minIndex()).toEqual(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("maxIndex", function() {
|
||||
it("should return the max index relative to BaseIndex", function() {
|
||||
let timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
const timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
expect(timelineIndex.maxIndex()).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("advance", function() {
|
||||
it("should advance up to the end of the timeline", function() {
|
||||
let timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
let result = timelineIndex.advance(3);
|
||||
const timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
const result = timelineIndex.advance(3);
|
||||
expect(result).toEqual(2);
|
||||
expect(timelineIndex.index).toEqual(2);
|
||||
});
|
||||
|
||||
it("should retreat back to the start of the timeline", function() {
|
||||
let timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
let result = timelineIndex.advance(-2);
|
||||
const timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
const result = timelineIndex.advance(-2);
|
||||
expect(result).toEqual(-1);
|
||||
expect(timelineIndex.index).toEqual(-1);
|
||||
});
|
||||
|
||||
it("should advance into the next timeline", function() {
|
||||
let timelines = createLinkedTimelines();
|
||||
let tl1 = timelines[0];
|
||||
let tl2 = timelines[1];
|
||||
const timelines = createLinkedTimelines();
|
||||
const tl1 = timelines[0];
|
||||
const tl2 = timelines[1];
|
||||
|
||||
// initialise the index pointing at the end of the first timeline
|
||||
let timelineIndex = new TimelineIndex(tl1, 2);
|
||||
const timelineIndex = new TimelineIndex(tl1, 2);
|
||||
|
||||
let result = timelineIndex.advance(1);
|
||||
const result = timelineIndex.advance(1);
|
||||
expect(result).toEqual(1);
|
||||
expect(timelineIndex.timeline).toBe(tl2);
|
||||
|
||||
@ -117,15 +117,15 @@ describe("TimelineIndex", function() {
|
||||
});
|
||||
|
||||
it("should retreat into the previous timeline", function() {
|
||||
let timelines = createLinkedTimelines();
|
||||
let tl1 = timelines[0];
|
||||
let tl2 = timelines[1];
|
||||
const timelines = createLinkedTimelines();
|
||||
const tl1 = timelines[0];
|
||||
const tl2 = timelines[1];
|
||||
|
||||
// initialise the index pointing at the start of the second
|
||||
// timeline
|
||||
let timelineIndex = new TimelineIndex(tl2, -1);
|
||||
const timelineIndex = new TimelineIndex(tl2, -1);
|
||||
|
||||
let result = timelineIndex.advance(-1);
|
||||
const result = timelineIndex.advance(-1);
|
||||
expect(result).toEqual(-1);
|
||||
expect(timelineIndex.timeline).toBe(tl1);
|
||||
expect(timelineIndex.index).toEqual(1);
|
||||
@ -134,8 +134,8 @@ describe("TimelineIndex", function() {
|
||||
|
||||
describe("retreat", function() {
|
||||
it("should retreat up to the start of the timeline", function() {
|
||||
let timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
let result = timelineIndex.retreat(2);
|
||||
const timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||
const result = timelineIndex.retreat(2);
|
||||
expect(result).toEqual(1);
|
||||
expect(timelineIndex.index).toEqual(-1);
|
||||
});
|
||||
@ -167,50 +167,50 @@ describe("TimelineWindow", function() {
|
||||
|
||||
describe("load", function() {
|
||||
it("should initialise from the live timeline", function(done) {
|
||||
let liveTimeline = createTimeline();
|
||||
let room = {};
|
||||
const liveTimeline = createTimeline();
|
||||
const room = {};
|
||||
room.getLiveTimeline = function() {
|
||||
return liveTimeline;
|
||||
};
|
||||
|
||||
let timelineWindow = new TimelineWindow(undefined, room);
|
||||
const timelineWindow = new TimelineWindow(undefined, room);
|
||||
timelineWindow.load(undefined, 2).then(function() {
|
||||
let expectedEvents = liveTimeline.getEvents().slice(1);
|
||||
const expectedEvents = liveTimeline.getEvents().slice(1);
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
}).catch(utils.failTest).done(done);
|
||||
});
|
||||
|
||||
it("should initialise from a specific event", function(done) {
|
||||
let timeline = createTimeline();
|
||||
let eventId = timeline.getEvents()[1].getId();
|
||||
const timeline = createTimeline();
|
||||
const eventId = timeline.getEvents()[1].getId();
|
||||
|
||||
let timelineSet = {};
|
||||
let client = {};
|
||||
const timelineSet = {};
|
||||
const client = {};
|
||||
client.getEventTimeline = function(timelineSet0, eventId0) {
|
||||
expect(timelineSet0).toBe(timelineSet);
|
||||
expect(eventId0).toEqual(eventId);
|
||||
return q(timeline);
|
||||
};
|
||||
|
||||
let timelineWindow = new TimelineWindow(client, timelineSet);
|
||||
const timelineWindow = new TimelineWindow(client, timelineSet);
|
||||
timelineWindow.load(eventId, 3).then(function() {
|
||||
let expectedEvents = timeline.getEvents();
|
||||
const expectedEvents = timeline.getEvents();
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
}).catch(utils.failTest).done(done);
|
||||
});
|
||||
|
||||
it("canPaginate should return false until load has returned",
|
||||
function(done) {
|
||||
let timeline = createTimeline();
|
||||
const timeline = createTimeline();
|
||||
timeline.setPaginationToken("toktok1", EventTimeline.BACKWARDS);
|
||||
timeline.setPaginationToken("toktok2", EventTimeline.FORWARDS);
|
||||
|
||||
let eventId = timeline.getEvents()[1].getId();
|
||||
const eventId = timeline.getEvents()[1].getId();
|
||||
|
||||
let timelineSet = {};
|
||||
let client = {};
|
||||
const timelineSet = {};
|
||||
const client = {};
|
||||
|
||||
let timelineWindow = new TimelineWindow(client, timelineSet);
|
||||
const timelineWindow = new TimelineWindow(client, timelineSet);
|
||||
|
||||
client.getEventTimeline = function(timelineSet0, eventId0) {
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -221,7 +221,7 @@ describe("TimelineWindow", function() {
|
||||
};
|
||||
|
||||
timelineWindow.load(eventId, 3).then(function() {
|
||||
let expectedEvents = timeline.getEvents();
|
||||
const expectedEvents = timeline.getEvents();
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
.toBe(true);
|
||||
@ -234,12 +234,12 @@ describe("TimelineWindow", function() {
|
||||
describe("pagination", function() {
|
||||
it("should be able to advance across the initial timeline",
|
||||
function(done) {
|
||||
let timeline = createTimeline();
|
||||
let eventId = timeline.getEvents()[1].getId();
|
||||
let timelineWindow = createWindow(timeline);
|
||||
const timeline = createTimeline();
|
||||
const eventId = timeline.getEvents()[1].getId();
|
||||
const timelineWindow = createWindow(timeline);
|
||||
|
||||
timelineWindow.load(eventId, 1).then(function() {
|
||||
let expectedEvents = [timeline.getEvents()[1]];
|
||||
const expectedEvents = [timeline.getEvents()[1]];
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -250,7 +250,7 @@ describe("TimelineWindow", function() {
|
||||
return timelineWindow.paginate(EventTimeline.FORWARDS, 2);
|
||||
}).then(function(success) {
|
||||
expect(success).toBe(true);
|
||||
let expectedEvents = timeline.getEvents().slice(1);
|
||||
const expectedEvents = timeline.getEvents().slice(1);
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -265,7 +265,7 @@ describe("TimelineWindow", function() {
|
||||
return timelineWindow.paginate(EventTimeline.BACKWARDS, 2);
|
||||
}).then(function(success) {
|
||||
expect(success).toBe(true);
|
||||
let expectedEvents = timeline.getEvents();
|
||||
const expectedEvents = timeline.getEvents();
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -279,12 +279,12 @@ describe("TimelineWindow", function() {
|
||||
});
|
||||
|
||||
it("should advance into next timeline", function(done) {
|
||||
let tls = createLinkedTimelines();
|
||||
let eventId = tls[0].getEvents()[1].getId();
|
||||
let timelineWindow = createWindow(tls[0], {windowLimit: 5});
|
||||
const tls = createLinkedTimelines();
|
||||
const eventId = tls[0].getEvents()[1].getId();
|
||||
const timelineWindow = createWindow(tls[0], {windowLimit: 5});
|
||||
|
||||
timelineWindow.load(eventId, 3).then(function() {
|
||||
let expectedEvents = tls[0].getEvents();
|
||||
const expectedEvents = tls[0].getEvents();
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -295,7 +295,7 @@ describe("TimelineWindow", function() {
|
||||
return timelineWindow.paginate(EventTimeline.FORWARDS, 2);
|
||||
}).then(function(success) {
|
||||
expect(success).toBe(true);
|
||||
let expectedEvents = tls[0].getEvents()
|
||||
const expectedEvents = tls[0].getEvents()
|
||||
.concat(tls[1].getEvents().slice(0, 2));
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
@ -309,7 +309,7 @@ describe("TimelineWindow", function() {
|
||||
expect(success).toBe(true);
|
||||
// the windowLimit should have made us drop an event from
|
||||
// tls[0]
|
||||
let expectedEvents = tls[0].getEvents().slice(1)
|
||||
const expectedEvents = tls[0].getEvents().slice(1)
|
||||
.concat(tls[1].getEvents());
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
@ -324,12 +324,12 @@ describe("TimelineWindow", function() {
|
||||
});
|
||||
|
||||
it("should retreat into previous timeline", function(done) {
|
||||
let tls = createLinkedTimelines();
|
||||
let eventId = tls[1].getEvents()[1].getId();
|
||||
let timelineWindow = createWindow(tls[1], {windowLimit: 5});
|
||||
const tls = createLinkedTimelines();
|
||||
const eventId = tls[1].getEvents()[1].getId();
|
||||
const timelineWindow = createWindow(tls[1], {windowLimit: 5});
|
||||
|
||||
timelineWindow.load(eventId, 3).then(function() {
|
||||
let expectedEvents = tls[1].getEvents();
|
||||
const expectedEvents = tls[1].getEvents();
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -340,7 +340,7 @@ describe("TimelineWindow", function() {
|
||||
return timelineWindow.paginate(EventTimeline.BACKWARDS, 2);
|
||||
}).then(function(success) {
|
||||
expect(success).toBe(true);
|
||||
let expectedEvents = tls[0].getEvents().slice(1, 3)
|
||||
const expectedEvents = tls[0].getEvents().slice(1, 3)
|
||||
.concat(tls[1].getEvents());
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
@ -354,7 +354,7 @@ describe("TimelineWindow", function() {
|
||||
expect(success).toBe(true);
|
||||
// the windowLimit should have made us drop an event from
|
||||
// tls[1]
|
||||
let expectedEvents = tls[0].getEvents()
|
||||
const expectedEvents = tls[0].getEvents()
|
||||
.concat(tls[1].getEvents().slice(0, 2));
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
@ -369,11 +369,11 @@ describe("TimelineWindow", function() {
|
||||
});
|
||||
|
||||
it("should make forward pagination requests", function(done) {
|
||||
let timeline = createTimeline();
|
||||
const timeline = createTimeline();
|
||||
timeline.setPaginationToken("toktok", EventTimeline.FORWARDS);
|
||||
|
||||
let timelineWindow = createWindow(timeline, {windowLimit: 5});
|
||||
let eventId = timeline.getEvents()[1].getId();
|
||||
const timelineWindow = createWindow(timeline, {windowLimit: 5});
|
||||
const eventId = timeline.getEvents()[1].getId();
|
||||
|
||||
client.paginateEventTimeline = function(timeline0, opts) {
|
||||
expect(timeline0).toBe(timeline);
|
||||
@ -385,7 +385,7 @@ describe("TimelineWindow", function() {
|
||||
};
|
||||
|
||||
timelineWindow.load(eventId, 3).then(function() {
|
||||
let expectedEvents = timeline.getEvents();
|
||||
const expectedEvents = timeline.getEvents();
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -395,18 +395,18 @@ describe("TimelineWindow", function() {
|
||||
return timelineWindow.paginate(EventTimeline.FORWARDS, 2);
|
||||
}).then(function(success) {
|
||||
expect(success).toBe(true);
|
||||
let expectedEvents = timeline.getEvents().slice(0, 5);
|
||||
const expectedEvents = timeline.getEvents().slice(0, 5);
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
}).catch(utils.failTest).done(done);
|
||||
});
|
||||
|
||||
|
||||
it("should make backward pagination requests", function(done) {
|
||||
let timeline = createTimeline();
|
||||
const timeline = createTimeline();
|
||||
timeline.setPaginationToken("toktok", EventTimeline.BACKWARDS);
|
||||
|
||||
let timelineWindow = createWindow(timeline, {windowLimit: 5});
|
||||
let eventId = timeline.getEvents()[1].getId();
|
||||
const timelineWindow = createWindow(timeline, {windowLimit: 5});
|
||||
const eventId = timeline.getEvents()[1].getId();
|
||||
|
||||
client.paginateEventTimeline = function(timeline0, opts) {
|
||||
expect(timeline0).toBe(timeline);
|
||||
@ -418,7 +418,7 @@ describe("TimelineWindow", function() {
|
||||
};
|
||||
|
||||
timelineWindow.load(eventId, 3).then(function() {
|
||||
let expectedEvents = timeline.getEvents();
|
||||
const expectedEvents = timeline.getEvents();
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -428,18 +428,18 @@ describe("TimelineWindow", function() {
|
||||
return timelineWindow.paginate(EventTimeline.BACKWARDS, 2);
|
||||
}).then(function(success) {
|
||||
expect(success).toBe(true);
|
||||
let expectedEvents = timeline.getEvents().slice(1, 6);
|
||||
const expectedEvents = timeline.getEvents().slice(1, 6);
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
}).catch(utils.failTest).done(done);
|
||||
});
|
||||
|
||||
it("should limit the number of unsuccessful pagination requests",
|
||||
function(done) {
|
||||
let timeline = createTimeline();
|
||||
const timeline = createTimeline();
|
||||
timeline.setPaginationToken("toktok", EventTimeline.FORWARDS);
|
||||
|
||||
let timelineWindow = createWindow(timeline, {windowLimit: 5});
|
||||
let eventId = timeline.getEvents()[1].getId();
|
||||
const timelineWindow = createWindow(timeline, {windowLimit: 5});
|
||||
const eventId = timeline.getEvents()[1].getId();
|
||||
|
||||
let paginateCount = 0;
|
||||
client.paginateEventTimeline = function(timeline0, opts) {
|
||||
@ -451,7 +451,7 @@ describe("TimelineWindow", function() {
|
||||
};
|
||||
|
||||
timelineWindow.load(eventId, 3).then(function() {
|
||||
let expectedEvents = timeline.getEvents();
|
||||
const expectedEvents = timeline.getEvents();
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
@ -462,7 +462,7 @@ describe("TimelineWindow", function() {
|
||||
}).then(function(success) {
|
||||
expect(success).toBe(false);
|
||||
expect(paginateCount).toEqual(3);
|
||||
let expectedEvents = timeline.getEvents().slice(0, 3);
|
||||
const expectedEvents = timeline.getEvents().slice(0, 3);
|
||||
expect(timelineWindow.getEvents()).toEqual(expectedEvents);
|
||||
|
||||
expect(timelineWindow.canPaginate(EventTimeline.BACKWARDS))
|
||||
|
@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
let sdk = require("../..");
|
||||
let User = sdk.User;
|
||||
let utils = require("../test-utils");
|
||||
const sdk = require("../..");
|
||||
const User = sdk.User;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
describe("User", function() {
|
||||
let userId = "@alice:bar";
|
||||
const userId = "@alice:bar";
|
||||
let user;
|
||||
|
||||
beforeEach(function() {
|
||||
@ -13,7 +13,7 @@ describe("User", function() {
|
||||
});
|
||||
|
||||
describe("setPresenceEvent", function() {
|
||||
let event = utils.mkEvent({
|
||||
const event = utils.mkEvent({
|
||||
type: "m.presence", content: {
|
||||
presence: "online",
|
||||
user_id: userId,
|
||||
|
@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
let utils = require("../../lib/utils");
|
||||
let testUtils = require("../test-utils");
|
||||
const utils = require("../../lib/utils");
|
||||
const testUtils = require("../test-utils");
|
||||
|
||||
describe("utils", function() {
|
||||
beforeEach(function() {
|
||||
@ -9,7 +9,7 @@ describe("utils", function() {
|
||||
|
||||
describe("encodeParams", function() {
|
||||
it("should url encode and concat with &s", function() {
|
||||
let params = {
|
||||
const params = {
|
||||
foo: "bar",
|
||||
baz: "beer@",
|
||||
};
|
||||
@ -21,8 +21,8 @@ describe("utils", function() {
|
||||
|
||||
describe("encodeUri", function() {
|
||||
it("should replace based on object keys and url encode", function() {
|
||||
let path = "foo/bar/%something/%here";
|
||||
let vals = {
|
||||
const path = "foo/bar/%something/%here";
|
||||
const vals = {
|
||||
"%something": "baz",
|
||||
"%here": "beer@",
|
||||
};
|
||||
@ -34,7 +34,7 @@ describe("utils", function() {
|
||||
|
||||
describe("forEach", function() {
|
||||
it("should be invoked for each element", function() {
|
||||
let arr = [];
|
||||
const arr = [];
|
||||
utils.forEach([55, 66, 77], function(element) {
|
||||
arr.push(element);
|
||||
});
|
||||
@ -44,50 +44,50 @@ describe("utils", function() {
|
||||
|
||||
describe("findElement", function() {
|
||||
it("should find only 1 element if there is a match", function() {
|
||||
let matchFn = function() {
|
||||
const matchFn = function() {
|
||||
return true;
|
||||
};
|
||||
let arr = [55, 66, 77];
|
||||
const arr = [55, 66, 77];
|
||||
expect(utils.findElement(arr, matchFn)).toEqual(55);
|
||||
});
|
||||
it("should be able to find in reverse order", function() {
|
||||
let matchFn = function() {
|
||||
const matchFn = function() {
|
||||
return true;
|
||||
};
|
||||
let arr = [55, 66, 77];
|
||||
const arr = [55, 66, 77];
|
||||
expect(utils.findElement(arr, matchFn, true)).toEqual(77);
|
||||
});
|
||||
it("should find nothing if the function never returns true", function() {
|
||||
let matchFn = function() {
|
||||
const matchFn = function() {
|
||||
return false;
|
||||
};
|
||||
let arr = [55, 66, 77];
|
||||
const arr = [55, 66, 77];
|
||||
expect(utils.findElement(arr, matchFn)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeElement", function() {
|
||||
it("should remove only 1 element if there is a match", function() {
|
||||
let matchFn = function() {
|
||||
const matchFn = function() {
|
||||
return true;
|
||||
};
|
||||
let arr = [55, 66, 77];
|
||||
const arr = [55, 66, 77];
|
||||
utils.removeElement(arr, matchFn);
|
||||
expect(arr).toEqual([66, 77]);
|
||||
});
|
||||
it("should be able to remove in reverse order", function() {
|
||||
let matchFn = function() {
|
||||
const matchFn = function() {
|
||||
return true;
|
||||
};
|
||||
let arr = [55, 66, 77];
|
||||
const arr = [55, 66, 77];
|
||||
utils.removeElement(arr, matchFn, true);
|
||||
expect(arr).toEqual([55, 66]);
|
||||
});
|
||||
it("should remove nothing if the function never returns true", function() {
|
||||
let matchFn = function() {
|
||||
const matchFn = function() {
|
||||
return false;
|
||||
};
|
||||
let arr = [55, 66, 77];
|
||||
const arr = [55, 66, 77];
|
||||
utils.removeElement(arr, matchFn);
|
||||
expect(arr).toEqual(arr);
|
||||
});
|
||||
@ -104,7 +104,7 @@ describe("utils", function() {
|
||||
expect(utils.isFunction(555)).toBe(false);
|
||||
|
||||
expect(utils.isFunction(function() {})).toBe(true);
|
||||
let s = { foo: function() {} };
|
||||
const s = { foo: function() {} };
|
||||
expect(utils.isFunction(s.foo)).toBe(true);
|
||||
});
|
||||
});
|
||||
@ -154,7 +154,7 @@ describe("utils", function() {
|
||||
});
|
||||
|
||||
describe("deepCompare", function() {
|
||||
let assert = {
|
||||
const assert = {
|
||||
isTrue: function(x) {
|
||||
expect(x).toBe(true);
|
||||
},
|
||||
@ -174,7 +174,7 @@ describe("utils", function() {
|
||||
it("should handle regexps", function() {
|
||||
assert.isTrue(utils.deepCompare(/abc/, /abc/));
|
||||
assert.isFalse(utils.deepCompare(/abc/, /123/));
|
||||
let r = /abc/;
|
||||
const r = /abc/;
|
||||
assert.isTrue(utils.deepCompare(r, r));
|
||||
});
|
||||
|
||||
@ -216,10 +216,10 @@ describe("utils", function() {
|
||||
// no two different function is equal really, they capture their
|
||||
// context variables so even if they have same toString(), they
|
||||
// won't have same functionality
|
||||
let func = function(x) {
|
||||
const func = function(x) {
|
||||
return true;
|
||||
};
|
||||
let func2 = function(x) {
|
||||
const func2 = function(x) {
|
||||
return true;
|
||||
};
|
||||
assert.isTrue(utils.deepCompare(func, func));
|
||||
@ -231,17 +231,17 @@ describe("utils", function() {
|
||||
|
||||
|
||||
describe("extend", function() {
|
||||
let SOURCE = { "prop2": 1, "string2": "x", "newprop": "new" };
|
||||
const SOURCE = { "prop2": 1, "string2": "x", "newprop": "new" };
|
||||
|
||||
it("should extend", function() {
|
||||
let target = {
|
||||
const target = {
|
||||
"prop1": 5, "prop2": 7, "string1": "baz", "string2": "foo",
|
||||
};
|
||||
let merged = {
|
||||
const merged = {
|
||||
"prop1": 5, "prop2": 1, "string1": "baz", "string2": "x",
|
||||
"newprop": "new",
|
||||
};
|
||||
let sourceOrig = JSON.stringify(SOURCE);
|
||||
const sourceOrig = JSON.stringify(SOURCE);
|
||||
|
||||
utils.extend(target, SOURCE);
|
||||
expect(JSON.stringify(target)).toEqual(JSON.stringify(merged));
|
||||
@ -251,14 +251,14 @@ describe("utils", function() {
|
||||
});
|
||||
|
||||
it("should ignore null", function() {
|
||||
let target = {
|
||||
const target = {
|
||||
"prop1": 5, "prop2": 7, "string1": "baz", "string2": "foo",
|
||||
};
|
||||
let merged = {
|
||||
const merged = {
|
||||
"prop1": 5, "prop2": 1, "string1": "baz", "string2": "x",
|
||||
"newprop": "new",
|
||||
};
|
||||
let sourceOrig = JSON.stringify(SOURCE);
|
||||
const sourceOrig = JSON.stringify(SOURCE);
|
||||
|
||||
utils.extend(target, null, SOURCE);
|
||||
expect(JSON.stringify(target)).toEqual(JSON.stringify(merged));
|
||||
@ -268,7 +268,7 @@ describe("utils", function() {
|
||||
});
|
||||
|
||||
it("should handle properties created with defineProperties", function() {
|
||||
let source = Object.defineProperties({}, {
|
||||
const source = Object.defineProperties({}, {
|
||||
"enumerableProp": {
|
||||
get: function() {
|
||||
return true;
|
||||
@ -282,7 +282,7 @@ describe("utils", function() {
|
||||
},
|
||||
});
|
||||
|
||||
let target = {};
|
||||
const target = {};
|
||||
utils.extend(target, source);
|
||||
expect(target.enumerableProp).toBe(true);
|
||||
expect(target.nonenumerableProp).toBe(undefined);
|
||||
|
Reference in New Issue
Block a user