You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
migrate to jest from mocha+expect+istanbul
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -12,10 +12,12 @@ module.exports = {
|
|||||||
// babel's transform-runtime converts references to ES6 globals such as
|
// babel's transform-runtime converts references to ES6 globals such as
|
||||||
// Promise and Map to core-js polyfills, so we can use ES6 globals.
|
// Promise and Map to core-js polyfills, so we can use ES6 globals.
|
||||||
es6: true,
|
es6: true,
|
||||||
|
jest: true,
|
||||||
},
|
},
|
||||||
extends: ["eslint:recommended", "google"],
|
extends: ["eslint:recommended", "google"],
|
||||||
plugins: [
|
plugins: [
|
||||||
"babel",
|
"babel",
|
||||||
|
"jest",
|
||||||
],
|
],
|
||||||
rules: {
|
rules: {
|
||||||
// rules we've always adhered to or now do
|
// rules we've always adhered to or now do
|
||||||
|
|||||||
11
package.json
11
package.json
@@ -4,9 +4,8 @@
|
|||||||
"description": "Matrix Client-Server SDK for Javascript",
|
"description": "Matrix Client-Server SDK for Javascript",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:build": "babel -s -d specbuild spec",
|
"test:run": "jest spec/ --coverage --testEnvironment node",
|
||||||
"test:run": "istanbul cover --report text --report cobertura --config .istanbul.yml -i \"lib/**/*.js\" node_modules/mocha/bin/_mocha -- --recursive specbuild --colors",
|
"test:watch": "jest spec/ --coverage --testEnvironment node --watch",
|
||||||
"test:watch": "mocha --watch --compilers js:babel-core/register --recursive spec --colors",
|
|
||||||
"test": "yarn test:build && yarn test:run",
|
"test": "yarn test:build && yarn test:run",
|
||||||
"check": "yarn test:build && _mocha --recursive specbuild --colors",
|
"check": "yarn test:build && _mocha --recursive specbuild --colors",
|
||||||
"gendoc": "babel --no-babelrc --plugins transform-class-properties -d .jsdocbuild src && jsdoc -r .jsdocbuild -P package.json -R README.md -d .jsdoc",
|
"gendoc": "babel --no-babelrc --plugins transform-class-properties -d .jsdocbuild src && jsdoc -r .jsdocbuild -P package.json -R README.md -d .jsdoc",
|
||||||
@@ -65,6 +64,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.18.0",
|
"babel-cli": "^6.18.0",
|
||||||
"babel-eslint": "^10.0.1",
|
"babel-eslint": "^10.0.1",
|
||||||
|
"babel-jest": "^23.6.0",
|
||||||
"babel-plugin-transform-async-to-bluebird": "^1.1.1",
|
"babel-plugin-transform-async-to-bluebird": "^1.1.1",
|
||||||
"babel-plugin-transform-class-properties": "^6.24.1",
|
"babel-plugin-transform-class-properties": "^6.24.1",
|
||||||
"babel-plugin-transform-runtime": "^6.23.0",
|
"babel-plugin-transform-runtime": "^6.23.0",
|
||||||
@@ -75,13 +75,12 @@
|
|||||||
"eslint": "^5.12.0",
|
"eslint": "^5.12.0",
|
||||||
"eslint-config-google": "^0.7.1",
|
"eslint-config-google": "^0.7.1",
|
||||||
"eslint-plugin-babel": "^5.3.0",
|
"eslint-plugin-babel": "^5.3.0",
|
||||||
|
"eslint-plugin-jest": "^23.0.4",
|
||||||
"exorcist": "^1.0.1",
|
"exorcist": "^1.0.1",
|
||||||
"expect": "^1.20.2",
|
"jest": "^23.6.0",
|
||||||
"istanbul": "^0.4.5",
|
|
||||||
"jsdoc": "^3.5.5",
|
"jsdoc": "^3.5.5",
|
||||||
"lolex": "^1.5.2",
|
"lolex": "^1.5.2",
|
||||||
"matrix-mock-request": "^1.2.3",
|
"matrix-mock-request": "^1.2.3",
|
||||||
"mocha": "^6.2.1",
|
|
||||||
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
|
"olm": "https://packages.matrix.org/npm/olm/olm-3.1.4.tgz",
|
||||||
"rimraf": "^3.0.0",
|
"rimraf": "^3.0.0",
|
||||||
"source-map-support": "^0.5.13",
|
"source-map-support": "^0.5.13",
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
env: {
|
|
||||||
mocha: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,6 @@ import './olm-loader';
|
|||||||
import sdk from '..';
|
import sdk from '..';
|
||||||
import testUtils from './test-utils';
|
import testUtils from './test-utils';
|
||||||
import MockHttpBackend from 'matrix-mock-request';
|
import MockHttpBackend from 'matrix-mock-request';
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
import LocalStorageCryptoStore from '../lib/crypto/store/localStorage-crypto-store';
|
import LocalStorageCryptoStore from '../lib/crypto/store/localStorage-crypto-store';
|
||||||
import logger from '../src/logger';
|
import logger from '../src/logger';
|
||||||
@@ -159,7 +158,7 @@ TestClient.prototype.awaitOneTimeKeyUpload = function() {
|
|||||||
.respond(200, (path, content) => {
|
.respond(200, (path, content) => {
|
||||||
expect(content.device_keys).toBe(undefined);
|
expect(content.device_keys).toBe(undefined);
|
||||||
expect(content.one_time_keys).toBeTruthy();
|
expect(content.one_time_keys).toBeTruthy();
|
||||||
expect(content.one_time_keys).toNotEqual({});
|
expect(content.one_time_keys).not.toEqual({});
|
||||||
logger.log('%s: received %i one-time keys', this,
|
logger.log('%s: received %i one-time keys', this,
|
||||||
Object.keys(content.one_time_keys).length);
|
Object.keys(content.one_time_keys).length);
|
||||||
this.oneTimeKeys = content.one_time_keys;
|
this.oneTimeKeys = content.one_time_keys;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
import TestClient from '../TestClient';
|
import TestClient from '../TestClient';
|
||||||
@@ -88,8 +87,6 @@ describe("DeviceList management:", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
|
|
||||||
// we create our own sessionStoreBackend so that we can use it for
|
// we create our own sessionStoreBackend so that we can use it for
|
||||||
// another TestClient.
|
// another TestClient.
|
||||||
sessionStoreBackend = new testUtils.MockStorageApi();
|
sessionStoreBackend = new testUtils.MockStorageApi();
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import 'source-map-support/register';
|
|||||||
// load olm before the sdk if possible
|
// load olm before the sdk if possible
|
||||||
import '../olm-loader';
|
import '../olm-loader';
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
const sdk = require("../..");
|
const sdk = require("../..");
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
const utils = require("../../lib/utils");
|
const utils = require("../../lib/utils");
|
||||||
@@ -56,7 +55,7 @@ function bobUploadsDeviceKeys() {
|
|||||||
bobTestClient.client.uploadKeys(),
|
bobTestClient.client.uploadKeys(),
|
||||||
bobTestClient.httpBackend.flush(),
|
bobTestClient.httpBackend.flush(),
|
||||||
]).then(() => {
|
]).then(() => {
|
||||||
expect(Object.keys(bobTestClient.deviceKeys).length).toNotEqual(0);
|
expect(Object.keys(bobTestClient.deviceKeys).length).not.toEqual(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,8 +405,6 @@ describe("MatrixClient crypto", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
|
|
||||||
aliTestClient = new TestClient(aliUserId, aliDeviceId, aliAccessToken);
|
aliTestClient = new TestClient(aliUserId, aliDeviceId, aliAccessToken);
|
||||||
await aliTestClient.client.initCrypto();
|
await aliTestClient.client.initCrypto();
|
||||||
|
|
||||||
@@ -548,7 +545,7 @@ describe("MatrixClient crypto", function() {
|
|||||||
.then(() => bobTestClient.awaitOneTimeKeyUpload())
|
.then(() => bobTestClient.awaitOneTimeKeyUpload())
|
||||||
.then((keys) => {
|
.then((keys) => {
|
||||||
expect(Object.keys(keys).length).toEqual(5);
|
expect(Object.keys(keys).length).toEqual(5);
|
||||||
expect(Object.keys(bobTestClient.deviceKeys).length).toNotEqual(0);
|
expect(Object.keys(bobTestClient.deviceKeys).length).not.toEqual(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -753,9 +750,9 @@ describe("MatrixClient crypto", function() {
|
|||||||
.then(() => httpBackend.when("POST", "/keys/upload")
|
.then(() => httpBackend.when("POST", "/keys/upload")
|
||||||
.respond(200, (path, content) => {
|
.respond(200, (path, content) => {
|
||||||
expect(content.one_time_keys).toBeTruthy();
|
expect(content.one_time_keys).toBeTruthy();
|
||||||
expect(content.one_time_keys).toNotEqual({});
|
expect(content.one_time_keys).not.toEqual({});
|
||||||
expect(Object.keys(content.one_time_keys).length)
|
expect(Object.keys(content.one_time_keys).length)
|
||||||
.toBeGreaterThanOrEqualTo(1);
|
.toBeGreaterThanOrEqual(1);
|
||||||
logger.log('received %i one-time keys',
|
logger.log('received %i one-time keys',
|
||||||
Object.keys(content.one_time_keys).length);
|
Object.keys(content.one_time_keys).length);
|
||||||
// cancel futher calls by telling the client
|
// cancel futher calls by telling the client
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const sdk = require("../..");
|
|||||||
const HttpBackend = require("matrix-mock-request");
|
const HttpBackend = require("matrix-mock-request");
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
describe("MatrixClient events", function() {
|
describe("MatrixClient events", function() {
|
||||||
@@ -15,7 +14,6 @@ describe("MatrixClient events", function() {
|
|||||||
const selfAccessToken = "aseukfgwef";
|
const selfAccessToken = "aseukfgwef";
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new HttpBackend();
|
httpBackend = new HttpBackend();
|
||||||
sdk.request(httpBackend.requestFn);
|
sdk.request(httpBackend.requestFn);
|
||||||
client = sdk.createClient({
|
client = sdk.createClient({
|
||||||
@@ -219,7 +217,7 @@ describe("MatrixClient events", function() {
|
|||||||
client.on("RoomState.events", function(event, state) {
|
client.on("RoomState.events", function(event, state) {
|
||||||
eventsInvokeCount++;
|
eventsInvokeCount++;
|
||||||
const index = roomStateEventTypes.indexOf(event.getType());
|
const index = roomStateEventTypes.indexOf(event.getType());
|
||||||
expect(index).toNotEqual(
|
expect(index).not.toEqual(
|
||||||
-1, "Unexpected room state event type: " + event.getType(),
|
-1, "Unexpected room state event type: " + event.getType(),
|
||||||
);
|
);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ describe("getEventTimeline support", function() {
|
|||||||
let client;
|
let client;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new HttpBackend();
|
httpBackend = new HttpBackend();
|
||||||
sdk.request(httpBackend.requestFn);
|
sdk.request(httpBackend.requestFn);
|
||||||
});
|
});
|
||||||
@@ -145,7 +144,7 @@ describe("getEventTimeline support", function() {
|
|||||||
const timelineSet = room.getTimelineSets()[0];
|
const timelineSet = room.getTimelineSets()[0];
|
||||||
expect(function() {
|
expect(function() {
|
||||||
client.getEventTimeline(timelineSet, "event");
|
client.getEventTimeline(timelineSet, "event");
|
||||||
}).toNotThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -221,14 +220,11 @@ describe("getEventTimeline support", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("MatrixClient event timelines", function() {
|
describe("MatrixClient event timelines", function() {
|
||||||
let client = null;
|
let client = null;
|
||||||
let httpBackend = null;
|
let httpBackend = null;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new HttpBackend();
|
httpBackend = new HttpBackend();
|
||||||
sdk.request(httpBackend.requestFn);
|
sdk.request(httpBackend.requestFn);
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ const Filter = publicGlobals.Filter;
|
|||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
const MockStorageApi = require("../MockStorageApi");
|
const MockStorageApi = require("../MockStorageApi");
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("MatrixClient", function() {
|
describe("MatrixClient", function() {
|
||||||
const baseUrl = "http://localhost.or.something";
|
const baseUrl = "http://localhost.or.something";
|
||||||
let client = null;
|
let client = null;
|
||||||
@@ -21,7 +19,6 @@ describe("MatrixClient", function() {
|
|||||||
const accessToken = "aseukfgwef";
|
const accessToken = "aseukfgwef";
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new HttpBackend();
|
httpBackend = new HttpBackend();
|
||||||
store = new MemoryStore();
|
store = new MemoryStore();
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const MatrixClient = sdk.MatrixClient;
|
|||||||
const HttpBackend = require("matrix-mock-request");
|
const HttpBackend = require("matrix-mock-request");
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
describe("MatrixClient opts", function() {
|
describe("MatrixClient opts", function() {
|
||||||
@@ -58,7 +57,6 @@ describe("MatrixClient opts", function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new HttpBackend();
|
httpBackend = new HttpBackend();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -101,7 +99,7 @@ describe("MatrixClient opts", function() {
|
|||||||
"m.room.create",
|
"m.room.create",
|
||||||
];
|
];
|
||||||
client.on("event", function(event) {
|
client.on("event", function(event) {
|
||||||
expect(expectedEventTypes.indexOf(event.getType())).toNotEqual(
|
expect(expectedEventTypes.indexOf(event.getType())).not.toEqual(
|
||||||
-1, "Recv unexpected event type: " + event.getType(),
|
-1, "Recv unexpected event type: " + event.getType(),
|
||||||
);
|
);
|
||||||
expectedEventTypes.splice(
|
expectedEventTypes.splice(
|
||||||
|
|||||||
@@ -4,11 +4,8 @@ import Promise from 'bluebird';
|
|||||||
|
|
||||||
const sdk = require("../..");
|
const sdk = require("../..");
|
||||||
const HttpBackend = require("matrix-mock-request");
|
const HttpBackend = require("matrix-mock-request");
|
||||||
const utils = require("../test-utils");
|
|
||||||
const EventStatus = sdk.EventStatus;
|
const EventStatus = sdk.EventStatus;
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("MatrixClient retrying", function() {
|
describe("MatrixClient retrying", function() {
|
||||||
const baseUrl = "http://localhost.or.something";
|
const baseUrl = "http://localhost.or.something";
|
||||||
let client = null;
|
let client = null;
|
||||||
@@ -20,7 +17,6 @@ describe("MatrixClient retrying", function() {
|
|||||||
let room;
|
let room;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new HttpBackend();
|
httpBackend = new HttpBackend();
|
||||||
sdk.request(httpBackend.requestFn);
|
sdk.request(httpBackend.requestFn);
|
||||||
scheduler = new sdk.MatrixScheduler();
|
scheduler = new sdk.MatrixScheduler();
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const HttpBackend = require("matrix-mock-request");
|
|||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("MatrixClient room timelines", function() {
|
describe("MatrixClient room timelines", function() {
|
||||||
const baseUrl = "http://localhost.or.something";
|
const baseUrl = "http://localhost.or.something";
|
||||||
@@ -104,7 +103,6 @@ describe("MatrixClient room timelines", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function(done) {
|
beforeEach(function(done) {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new HttpBackend();
|
httpBackend = new HttpBackend();
|
||||||
sdk.request(httpBackend.requestFn);
|
sdk.request(httpBackend.requestFn);
|
||||||
client = sdk.createClient({
|
client = sdk.createClient({
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const utils = require("../test-utils");
|
|||||||
const MatrixEvent = sdk.MatrixEvent;
|
const MatrixEvent = sdk.MatrixEvent;
|
||||||
const EventTimeline = sdk.EventTimeline;
|
const EventTimeline = sdk.EventTimeline;
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
describe("MatrixClient syncing", function() {
|
describe("MatrixClient syncing", function() {
|
||||||
@@ -23,7 +22,6 @@ describe("MatrixClient syncing", function() {
|
|||||||
const roomTwo = "!bar:localhost";
|
const roomTwo = "!bar:localhost";
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new HttpBackend();
|
httpBackend = new HttpBackend();
|
||||||
sdk.request(httpBackend.requestFn);
|
sdk.request(httpBackend.requestFn);
|
||||||
client = sdk.createClient({
|
client = sdk.createClient({
|
||||||
@@ -528,7 +526,7 @@ describe("MatrixClient syncing", function() {
|
|||||||
awaitSyncEvent(),
|
awaitSyncEvent(),
|
||||||
]).then(function() {
|
]).then(function() {
|
||||||
const room = client.getRoom(roomTwo);
|
const room = client.getRoom(roomTwo);
|
||||||
expect(room).toExist();
|
expect(room).toBeDefined();
|
||||||
const tok = room.getLiveTimeline()
|
const tok = room.getLiveTimeline()
|
||||||
.getPaginationToken(EventTimeline.BACKWARDS);
|
.getPaginationToken(EventTimeline.BACKWARDS);
|
||||||
expect(tok).toEqual("roomtwotok");
|
expect(tok).toEqual("roomtwotok");
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ limitations under the License.
|
|||||||
|
|
||||||
const anotherjson = require('another-json');
|
const anotherjson = require('another-json');
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
const utils = require('../../lib/utils');
|
const utils = require('../../lib/utils');
|
||||||
const testUtils = require('../test-utils');
|
const testUtils = require('../test-utils');
|
||||||
@@ -283,8 +282,6 @@ describe("megolm", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
|
|
||||||
aliceTestClient = new TestClient(
|
aliceTestClient = new TestClient(
|
||||||
"@alice:localhost", "xzcvb", "akjgkrgjs",
|
"@alice:localhost", "xzcvb", "akjgkrgjs",
|
||||||
);
|
);
|
||||||
@@ -713,7 +710,7 @@ describe("megolm", function() {
|
|||||||
'PUT', '/send/',
|
'PUT', '/send/',
|
||||||
).respond(200, function(path, content) {
|
).respond(200, function(path, content) {
|
||||||
logger.log('/send:', content);
|
logger.log('/send:', content);
|
||||||
expect(content.session_id).toNotEqual(megolmSessionId);
|
expect(content.session_id).not.toEqual(megolmSessionId);
|
||||||
return {
|
return {
|
||||||
event_id: '$event_id',
|
event_id: '$event_id',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
// load olm before the sdk if possible
|
// load olm before the sdk if possible
|
||||||
@@ -41,18 +40,6 @@ module.exports.syncPromise = function(client, count) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform common actions before each test case, e.g. printing the test case
|
|
||||||
* name to stdout.
|
|
||||||
* @param {Mocha.Context} context The test context
|
|
||||||
*/
|
|
||||||
module.exports.beforeEach = function(context) {
|
|
||||||
const desc = context.currentTest.fullTitle();
|
|
||||||
|
|
||||||
logger.log(desc);
|
|
||||||
logger.log(new Array(1 + desc.length).join("="));
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a spy for an object and automatically spy its methods.
|
* Create a spy for an object and automatically spy its methods.
|
||||||
* @param {*} constr The class constructor (used with 'new')
|
* @param {*} constr The class constructor (used with 'new')
|
||||||
@@ -71,7 +58,7 @@ module.exports.mock = function(constr, name) {
|
|||||||
for (const key in constr.prototype) { // eslint-disable-line guard-for-in
|
for (const key in constr.prototype) { // eslint-disable-line guard-for-in
|
||||||
try {
|
try {
|
||||||
if (constr.prototype[key] instanceof Function) {
|
if (constr.prototype[key] instanceof Function) {
|
||||||
result[key] = expect.createSpy();
|
result[key] = jest.fn();
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// Direct access to some non-function fields of DOM prototypes may
|
// Direct access to some non-function fields of DOM prototypes may
|
||||||
@@ -377,9 +364,9 @@ module.exports.setHttpResponses = function setHttpResponses(
|
|||||||
client._http = [
|
client._http = [
|
||||||
"authedRequest", "authedRequestWithPrefix", "getContentUri",
|
"authedRequest", "authedRequestWithPrefix", "getContentUri",
|
||||||
"request", "requestWithPrefix", "uploadContent",
|
"request", "requestWithPrefix", "uploadContent",
|
||||||
].reduce((r, k) => {r[k] = expect.createSpy(); return r;}, {});
|
].reduce((r, k) => {r[k] = jest.fn(); return r;}, {});
|
||||||
client._http.authedRequest.andCall(httpReq);
|
client._http.authedRequest.mockImplementation(httpReq);
|
||||||
client._http.authedRequestWithPrefix.andCall(httpReq);
|
client._http.authedRequestWithPrefix.mockImplementation(httpReq);
|
||||||
client._http.requestWithPrefix.andCall(httpReq);
|
client._http.requestWithPrefix.mockImplementation(httpReq);
|
||||||
client._http.request.andCall(httpReq);
|
client._http.request.mockImplementation(httpReq);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,11 +18,9 @@ limitations under the License.
|
|||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
const sdk = require("../..");
|
const sdk = require("../..");
|
||||||
const utils = require("../test-utils");
|
|
||||||
|
|
||||||
const AutoDiscovery = sdk.AutoDiscovery;
|
const AutoDiscovery = sdk.AutoDiscovery;
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import MockHttpBackend from "matrix-mock-request";
|
import MockHttpBackend from "matrix-mock-request";
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +28,6 @@ describe("AutoDiscovery", function() {
|
|||||||
let httpBackend = null;
|
let httpBackend = null;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
httpBackend = new MockHttpBackend();
|
httpBackend = new MockHttpBackend();
|
||||||
sdk.request(httpBackend.requestFn);
|
sdk.request(httpBackend.requestFn);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
const ContentRepo = require("../../lib/content-repo");
|
const ContentRepo = require("../../lib/content-repo");
|
||||||
const testUtils = require("../test-utils");
|
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("ContentRepo", function() {
|
describe("ContentRepo", function() {
|
||||||
const baseUrl = "https://my.home.server";
|
const baseUrl = "https://my.home.server";
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("getHttpUriForMxc", function() {
|
describe("getHttpUriForMxc", function() {
|
||||||
it("should do nothing to HTTP URLs when allowing direct links", function() {
|
it("should do nothing to HTTP URLs when allowing direct links", function() {
|
||||||
const httpUrl = "http://example.com/image.jpeg";
|
const httpUrl = "http://example.com/image.jpeg";
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import 'source-map-support/register';
|
|||||||
import '../olm-loader';
|
import '../olm-loader';
|
||||||
|
|
||||||
import Crypto from '../../lib/crypto';
|
import Crypto from '../../lib/crypto';
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
import WebStorageSessionStore from '../../lib/store/session/webstorage';
|
import WebStorageSessionStore from '../../lib/store/session/webstorage';
|
||||||
import MemoryCryptoStore from '../../lib/crypto/store/memory-crypto-store.js';
|
import MemoryCryptoStore from '../../lib/crypto/store/memory-crypto-store.js';
|
||||||
@@ -12,7 +11,6 @@ import TestClient from '../TestClient';
|
|||||||
import {MatrixEvent} from '../../lib/models/event';
|
import {MatrixEvent} from '../../lib/models/event';
|
||||||
import Room from '../../lib/models/room';
|
import Room from '../../lib/models/room';
|
||||||
import olmlib from '../../lib/crypto/olmlib';
|
import olmlib from '../../lib/crypto/olmlib';
|
||||||
import lolex from 'lolex';
|
|
||||||
|
|
||||||
const EventEmitter = require("events").EventEmitter;
|
const EventEmitter = require("events").EventEmitter;
|
||||||
|
|
||||||
@@ -20,6 +18,8 @@ const sdk = require("../..");
|
|||||||
|
|
||||||
const Olm = global.Olm;
|
const Olm = global.Olm;
|
||||||
|
|
||||||
|
jest.useFakeTimers();
|
||||||
|
|
||||||
describe("Crypto", function() {
|
describe("Crypto", function() {
|
||||||
if (!sdk.CRYPTO_ENABLED) {
|
if (!sdk.CRYPTO_ENABLED) {
|
||||||
return;
|
return;
|
||||||
@@ -76,9 +76,9 @@ describe("Crypto", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mockBaseApis = {
|
mockBaseApis = {
|
||||||
sendToDevice: expect.createSpy(),
|
sendToDevice: jest.fn(),
|
||||||
getKeyBackupVersion: expect.createSpy(),
|
getKeyBackupVersion: jest.fn(),
|
||||||
isGuest: expect.createSpy(),
|
isGuest: jest.fn(),
|
||||||
};
|
};
|
||||||
mockRoomList = {};
|
mockRoomList = {};
|
||||||
|
|
||||||
@@ -110,15 +110,15 @@ describe("Crypto", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
fakeEmitter.emit('toDeviceEvent', {
|
fakeEmitter.emit('toDeviceEvent', {
|
||||||
getType: expect.createSpy().andReturn('m.room.message'),
|
getType: jest.fn().mockReturnValue('m.room.message'),
|
||||||
getContent: expect.createSpy().andReturn({
|
getContent: jest.fn().mockReturnValue({
|
||||||
msgtype: 'm.bad.encrypted',
|
msgtype: 'm.bad.encrypted',
|
||||||
}),
|
}),
|
||||||
getWireContent: expect.createSpy().andReturn({
|
getWireContent: jest.fn().mockReturnValue({
|
||||||
algorithm: 'm.olm.v1.curve25519-aes-sha2',
|
algorithm: 'm.olm.v1.curve25519-aes-sha2',
|
||||||
sender_key: 'this is a key',
|
sender_key: 'this is a key',
|
||||||
}),
|
}),
|
||||||
getSender: expect.createSpy().andReturn('@bob:home.server'),
|
getSender: jest.fn().mockReturnValue('@bob:home.server'),
|
||||||
});
|
});
|
||||||
|
|
||||||
await prom;
|
await prom;
|
||||||
@@ -245,7 +245,7 @@ describe("Crypto", function() {
|
|||||||
await bobDecryptor.onRoomKeyEvent(ksEvent);
|
await bobDecryptor.onRoomKeyEvent(ksEvent);
|
||||||
await eventPromise;
|
await eventPromise;
|
||||||
expect(events[0].getContent().msgtype).toBe("m.bad.encrypted");
|
expect(events[0].getContent().msgtype).toBe("m.bad.encrypted");
|
||||||
expect(events[1].getContent().msgtype).toNotBe("m.bad.encrypted");
|
expect(events[1].getContent().msgtype).not.toBe("m.bad.encrypted");
|
||||||
|
|
||||||
const cryptoStore = bobClient._cryptoStore;
|
const cryptoStore = bobClient._cryptoStore;
|
||||||
const eventContent = events[0].getWireContent();
|
const eventContent = events[0].getWireContent();
|
||||||
@@ -260,7 +260,7 @@ describe("Crypto", function() {
|
|||||||
// the room key request should still be there, since we haven't
|
// the room key request should still be there, since we haven't
|
||||||
// decrypted everything
|
// decrypted everything
|
||||||
expect(await cryptoStore.getOutgoingRoomKeyRequest(roomKeyRequestBody))
|
expect(await cryptoStore.getOutgoingRoomKeyRequest(roomKeyRequestBody))
|
||||||
.toExist();
|
.toBeDefined();
|
||||||
|
|
||||||
// keyshare the session key starting at the first message, so
|
// keyshare the session key starting at the first message, so
|
||||||
// that it can now be decrypted
|
// that it can now be decrypted
|
||||||
@@ -268,10 +268,10 @@ describe("Crypto", function() {
|
|||||||
ksEvent = await keyshareEventForEvent(events[0], 0);
|
ksEvent = await keyshareEventForEvent(events[0], 0);
|
||||||
await bobDecryptor.onRoomKeyEvent(ksEvent);
|
await bobDecryptor.onRoomKeyEvent(ksEvent);
|
||||||
await eventPromise;
|
await eventPromise;
|
||||||
expect(events[0].getContent().msgtype).toNotBe("m.bad.encrypted");
|
expect(events[0].getContent().msgtype).not.toBe("m.bad.encrypted");
|
||||||
// the room key request should be gone since we've now decypted everything
|
// the room key request should be gone since we've now decypted everything
|
||||||
expect(await cryptoStore.getOutgoingRoomKeyRequest(roomKeyRequestBody))
|
expect(await cryptoStore.getOutgoingRoomKeyRequest(roomKeyRequestBody))
|
||||||
.toNotExist();
|
.toBeFalsy();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ describe("Crypto", function() {
|
|||||||
sender_key: "senderkey",
|
sender_key: "senderkey",
|
||||||
};
|
};
|
||||||
expect(await cryptoStore.getOutgoingRoomKeyRequest(roomKeyRequestBody))
|
expect(await cryptoStore.getOutgoingRoomKeyRequest(roomKeyRequestBody))
|
||||||
.toExist();
|
.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses a new txnid for re-requesting keys", async function() {
|
it("uses a new txnid for re-requesting keys", async function() {
|
||||||
@@ -329,38 +329,32 @@ describe("Crypto", function() {
|
|||||||
|
|
||||||
aliceClient.startClient();
|
aliceClient.startClient();
|
||||||
|
|
||||||
const clock = lolex.install();
|
let promise;
|
||||||
|
// make a room key request, and record the transaction ID for the
|
||||||
|
// sendToDevice call
|
||||||
|
({promise, func: aliceClient.sendToDevice} = awaitFunctionCall());
|
||||||
|
await aliceClient.cancelAndResendEventRoomKeyRequest(event);
|
||||||
|
jest.runAllTimers();
|
||||||
|
let args = await promise;
|
||||||
|
const txnId = args[2];
|
||||||
|
jest.runAllTimers();
|
||||||
|
|
||||||
try {
|
// give the room key request manager time to update the state
|
||||||
let promise;
|
// of the request
|
||||||
// make a room key request, and record the transaction ID for the
|
await Promise.resolve();
|
||||||
// sendToDevice call
|
|
||||||
({promise, func: aliceClient.sendToDevice} = awaitFunctionCall());
|
|
||||||
await aliceClient.cancelAndResendEventRoomKeyRequest(event);
|
|
||||||
clock.runToLast();
|
|
||||||
let args = await promise;
|
|
||||||
const txnId = args[2];
|
|
||||||
clock.runToLast();
|
|
||||||
|
|
||||||
// give the room key request manager time to update the state
|
// cancel and resend the room key request
|
||||||
// of the request
|
({promise, func: aliceClient.sendToDevice} = awaitFunctionCall());
|
||||||
await Promise.resolve();
|
await aliceClient.cancelAndResendEventRoomKeyRequest(event);
|
||||||
|
jest.runAllTimers();
|
||||||
// cancel and resend the room key request
|
// the first call to sendToDevice will be the cancellation
|
||||||
({promise, func: aliceClient.sendToDevice} = awaitFunctionCall());
|
args = await promise;
|
||||||
await aliceClient.cancelAndResendEventRoomKeyRequest(event);
|
// the second call to sendToDevice will be the key request
|
||||||
clock.runToLast();
|
({promise, func: aliceClient.sendToDevice} = awaitFunctionCall());
|
||||||
// the first call to sendToDevice will be the cancellation
|
jest.runAllTimers();
|
||||||
args = await promise;
|
args = await promise;
|
||||||
// the second call to sendToDevice will be the key request
|
jest.runAllTimers();
|
||||||
({promise, func: aliceClient.sendToDevice} = awaitFunctionCall());
|
expect(args[2]).not.toBe(txnId);
|
||||||
clock.runToLast();
|
|
||||||
args = await promise;
|
|
||||||
clock.runToLast();
|
|
||||||
expect(args[2]).toNotBe(txnId);
|
|
||||||
} finally {
|
|
||||||
clock.uninstall();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,11 +17,9 @@ limitations under the License.
|
|||||||
|
|
||||||
import DeviceList from '../../../lib/crypto/DeviceList';
|
import DeviceList from '../../../lib/crypto/DeviceList';
|
||||||
import MemoryCryptoStore from '../../../lib/crypto/store/memory-crypto-store.js';
|
import MemoryCryptoStore from '../../../lib/crypto/store/memory-crypto-store.js';
|
||||||
import testUtils from '../../test-utils';
|
|
||||||
import utils from '../../../lib/utils';
|
import utils from '../../../lib/utils';
|
||||||
import logger from '../../../src/logger';
|
import logger from '../../../src/logger';
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
const signedDeviceList = {
|
const signedDeviceList = {
|
||||||
@@ -60,11 +58,9 @@ describe('DeviceList', function() {
|
|||||||
let deviceLists = [];
|
let deviceLists = [];
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
|
|
||||||
deviceLists = [];
|
deviceLists = [];
|
||||||
|
|
||||||
downloadSpy = expect.createSpy();
|
downloadSpy = jest.fn();
|
||||||
cryptoStore = new MemoryCryptoStore();
|
cryptoStore = new MemoryCryptoStore();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,7 +88,7 @@ describe('DeviceList', function() {
|
|||||||
dl.startTrackingDeviceList('@test1:sw1v.org');
|
dl.startTrackingDeviceList('@test1:sw1v.org');
|
||||||
|
|
||||||
const queryDefer1 = Promise.defer();
|
const queryDefer1 = Promise.defer();
|
||||||
downloadSpy.andReturn(queryDefer1.promise);
|
downloadSpy.mockReturnValue(queryDefer1.promise);
|
||||||
|
|
||||||
const prom1 = dl.refreshOutdatedDeviceLists();
|
const prom1 = dl.refreshOutdatedDeviceLists();
|
||||||
expect(downloadSpy).toHaveBeenCalledWith(['@test1:sw1v.org'], {});
|
expect(downloadSpy).toHaveBeenCalledWith(['@test1:sw1v.org'], {});
|
||||||
@@ -111,15 +107,15 @@ describe('DeviceList', function() {
|
|||||||
dl.startTrackingDeviceList('@test1:sw1v.org');
|
dl.startTrackingDeviceList('@test1:sw1v.org');
|
||||||
|
|
||||||
const queryDefer1 = Promise.defer();
|
const queryDefer1 = Promise.defer();
|
||||||
downloadSpy.andReturn(queryDefer1.promise);
|
downloadSpy.mockReturnValue(queryDefer1.promise);
|
||||||
|
|
||||||
const prom1 = dl.refreshOutdatedDeviceLists();
|
const prom1 = dl.refreshOutdatedDeviceLists();
|
||||||
expect(downloadSpy).toHaveBeenCalledWith(['@test1:sw1v.org'], {});
|
expect(downloadSpy).toHaveBeenCalledWith(['@test1:sw1v.org'], {});
|
||||||
downloadSpy.reset();
|
downloadSpy.mockReset();
|
||||||
|
|
||||||
// outdated notif arrives while the request is in flight.
|
// outdated notif arrives while the request is in flight.
|
||||||
const queryDefer2 = Promise.defer();
|
const queryDefer2 = Promise.defer();
|
||||||
downloadSpy.andReturn(queryDefer2.promise);
|
downloadSpy.mockReturnValue(queryDefer2.promise);
|
||||||
|
|
||||||
dl.invalidateUserDeviceList('@test1:sw1v.org');
|
dl.invalidateUserDeviceList('@test1:sw1v.org');
|
||||||
dl.refreshOutdatedDeviceLists();
|
dl.refreshOutdatedDeviceLists();
|
||||||
@@ -136,10 +132,10 @@ describe('DeviceList', function() {
|
|||||||
// uh-oh; user restarts before second request completes. The new instance
|
// uh-oh; user restarts before second request completes. The new instance
|
||||||
// should know we never got a complete device list.
|
// should know we never got a complete device list.
|
||||||
logger.log("Creating new devicelist to simulate app reload");
|
logger.log("Creating new devicelist to simulate app reload");
|
||||||
downloadSpy.reset();
|
downloadSpy.mockReset();
|
||||||
const dl2 = createTestDeviceList();
|
const dl2 = createTestDeviceList();
|
||||||
const queryDefer3 = Promise.defer();
|
const queryDefer3 = Promise.defer();
|
||||||
downloadSpy.andReturn(queryDefer3.promise);
|
downloadSpy.mockReturnValue(queryDefer3.promise);
|
||||||
|
|
||||||
const prom3 = dl2.refreshOutdatedDeviceLists();
|
const prom3 = dl2.refreshOutdatedDeviceLists();
|
||||||
expect(downloadSpy).toHaveBeenCalledWith(['@test1:sw1v.org'], {});
|
expect(downloadSpy).toHaveBeenCalledWith(['@test1:sw1v.org'], {});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import '../../../olm-loader';
|
import '../../../olm-loader';
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
import sdk from '../../../..';
|
import sdk from '../../../..';
|
||||||
@@ -32,8 +31,6 @@ describe("MegolmDecryption", function() {
|
|||||||
let mockBaseApis;
|
let mockBaseApis;
|
||||||
|
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
|
|
||||||
await Olm.init();
|
await Olm.init();
|
||||||
|
|
||||||
mockCrypto = testUtils.mock(Crypto, 'Crypto');
|
mockCrypto = testUtils.mock(Crypto, 'Crypto');
|
||||||
@@ -55,9 +52,9 @@ describe("MegolmDecryption", function() {
|
|||||||
|
|
||||||
// we stub out the olm encryption bits
|
// we stub out the olm encryption bits
|
||||||
mockOlmLib = {};
|
mockOlmLib = {};
|
||||||
mockOlmLib.ensureOlmSessionsForDevices = expect.createSpy();
|
mockOlmLib.ensureOlmSessionsForDevices = jest.fn();
|
||||||
mockOlmLib.encryptMessageForDevice =
|
mockOlmLib.encryptMessageForDevice =
|
||||||
expect.createSpy().andReturn(Promise.resolve());
|
jest.fn().mockReturnValue(Promise.resolve());
|
||||||
megolmDecryption.olmlib = mockOlmLib;
|
megolmDecryption.olmlib = mockOlmLib;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -135,22 +132,22 @@ describe("MegolmDecryption", function() {
|
|||||||
|
|
||||||
// set up some pre-conditions for the share call
|
// set up some pre-conditions for the share call
|
||||||
const deviceInfo = {};
|
const deviceInfo = {};
|
||||||
mockCrypto.getStoredDevice.andReturn(deviceInfo);
|
mockCrypto.getStoredDevice.mockReturnValue(deviceInfo);
|
||||||
|
|
||||||
mockOlmLib.ensureOlmSessionsForDevices.andReturn(
|
mockOlmLib.ensureOlmSessionsForDevices.mockReturnValue(
|
||||||
Promise.resolve({'@alice:foo': {'alidevice': {
|
Promise.resolve({'@alice:foo': {'alidevice': {
|
||||||
sessionId: 'alisession',
|
sessionId: 'alisession',
|
||||||
}}}),
|
}}}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const awaitEncryptForDevice = new Promise((res, rej) => {
|
const awaitEncryptForDevice = new Promise((res, rej) => {
|
||||||
mockOlmLib.encryptMessageForDevice.andCall(() => {
|
mockOlmLib.encryptMessageForDevice.mockImplementation(() => {
|
||||||
res();
|
res();
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
mockBaseApis.sendToDevice = expect.createSpy();
|
mockBaseApis.sendToDevice = jest.fn();
|
||||||
|
|
||||||
// do the share
|
// do the share
|
||||||
megolmDecryption.shareKeysWithDevice(keyRequest);
|
megolmDecryption.shareKeysWithDevice(keyRequest);
|
||||||
@@ -160,21 +157,20 @@ describe("MegolmDecryption", function() {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
// check that it called encryptMessageForDevice with
|
// check that it called encryptMessageForDevice with
|
||||||
// appropriate args.
|
// appropriate args.
|
||||||
expect(mockOlmLib.encryptMessageForDevice.calls.length)
|
expect(mockOlmLib.encryptMessageForDevice).toBeCalledTimes(1);
|
||||||
.toEqual(1);
|
|
||||||
|
|
||||||
const call = mockOlmLib.encryptMessageForDevice.calls[0];
|
const call = mockOlmLib.encryptMessageForDevice.mock.calls[0];
|
||||||
const payload = call.arguments[6];
|
const payload = call[6];
|
||||||
|
|
||||||
expect(payload.type).toEqual("m.forwarded_room_key");
|
expect(payload.type).toEqual("m.forwarded_room_key");
|
||||||
expect(payload.content).toInclude({
|
expect(payload.content).toMatchObject({
|
||||||
sender_key: "SENDER_CURVE25519",
|
sender_key: "SENDER_CURVE25519",
|
||||||
sender_claimed_ed25519_key: "SENDER_ED25519",
|
sender_claimed_ed25519_key: "SENDER_ED25519",
|
||||||
session_id: groupSession.session_id(),
|
session_id: groupSession.session_id(),
|
||||||
chain_index: 0,
|
chain_index: 0,
|
||||||
forwarding_curve25519_key_chain: [],
|
forwarding_curve25519_key_chain: [],
|
||||||
});
|
});
|
||||||
expect(payload.content.session_key).toExist();
|
expect(payload.content.session_key).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -201,13 +197,12 @@ describe("MegolmDecryption", function() {
|
|||||||
origin_server_ts: 1507753886000,
|
origin_server_ts: 1507753886000,
|
||||||
});
|
});
|
||||||
|
|
||||||
const successHandler = expect.createSpy();
|
const successHandler = jest.fn();
|
||||||
const failureHandler = expect.createSpy()
|
const failureHandler = jest.fn((err) => {
|
||||||
.andCall((err) => {
|
expect(err.toString()).toMatch(
|
||||||
expect(err.toString()).toMatch(
|
/Duplicate message index, possible replay attack/,
|
||||||
/Duplicate message index, possible replay attack/,
|
);
|
||||||
);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return megolmDecryption.decryptEvent(event1).then((res) => {
|
return megolmDecryption.decryptEvent(event1).then((res) => {
|
||||||
const event2 = new MatrixEvent({
|
const event2 = new MatrixEvent({
|
||||||
@@ -228,7 +223,7 @@ describe("MegolmDecryption", function() {
|
|||||||
successHandler,
|
successHandler,
|
||||||
failureHandler,
|
failureHandler,
|
||||||
).then(() => {
|
).then(() => {
|
||||||
expect(successHandler).toNotHaveBeenCalled();
|
expect(successHandler).not.toHaveBeenCalled();
|
||||||
expect(failureHandler).toHaveBeenCalled();
|
expect(failureHandler).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -266,10 +261,10 @@ describe("MegolmDecryption", function() {
|
|||||||
const cryptoStore = new MemoryCryptoStore(mockStorage);
|
const cryptoStore = new MemoryCryptoStore(mockStorage);
|
||||||
|
|
||||||
const olmDevice = new OlmDevice(cryptoStore);
|
const olmDevice = new OlmDevice(cryptoStore);
|
||||||
olmDevice.verifySignature = expect.createSpy();
|
olmDevice.verifySignature = jest.fn();
|
||||||
await olmDevice.init();
|
await olmDevice.init();
|
||||||
|
|
||||||
mockBaseApis.claimOneTimeKeys = expect.createSpy().andReturn(Promise.resolve({
|
mockBaseApis.claimOneTimeKeys = jest.fn().mockReturnValue(Promise.resolve({
|
||||||
one_time_keys: {
|
one_time_keys: {
|
||||||
'@alice:home.server': {
|
'@alice:home.server': {
|
||||||
aliceDevice: {
|
aliceDevice: {
|
||||||
@@ -285,18 +280,18 @@ describe("MegolmDecryption", function() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
mockBaseApis.sendToDevice = expect.createSpy().andReturn(Promise.resolve());
|
mockBaseApis.sendToDevice = jest.fn().mockReturnValue(Promise.resolve());
|
||||||
|
|
||||||
mockCrypto.downloadKeys.andReturn(Promise.resolve({
|
mockCrypto.downloadKeys.mockReturnValue(Promise.resolve({
|
||||||
'@alice:home.server': {
|
'@alice:home.server': {
|
||||||
aliceDevice: {
|
aliceDevice: {
|
||||||
deviceId: 'aliceDevice',
|
deviceId: 'aliceDevice',
|
||||||
isBlocked: expect.createSpy().andReturn(false),
|
isBlocked: jest.fn().mockReturnValue(false),
|
||||||
isUnverified: expect.createSpy().andReturn(false),
|
isUnverified: jest.fn().mockReturnValue(false),
|
||||||
getIdentityKey: expect.createSpy().andReturn(
|
getIdentityKey: jest.fn().mockReturnValue(
|
||||||
'YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWE',
|
'YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWE',
|
||||||
),
|
),
|
||||||
getFingerprint: expect.createSpy().andReturn(''),
|
getFingerprint: jest.fn().mockReturnValue(''),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -312,10 +307,10 @@ describe("MegolmDecryption", function() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const mockRoom = {
|
const mockRoom = {
|
||||||
getEncryptionTargetMembers: expect.createSpy().andReturn(
|
getEncryptionTargetMembers: jest.fn().mockReturnValue(
|
||||||
[{userId: "@alice:home.server"}],
|
[{userId: "@alice:home.server"}],
|
||||||
),
|
),
|
||||||
getBlacklistUnverifiedDevices: expect.createSpy().andReturn(false),
|
getBlacklistUnverifiedDevices: jest.fn().mockReturnValue(false),
|
||||||
};
|
};
|
||||||
const ct1 = await megolmEncryption.encryptMessage(mockRoom, "a.fake.type", {
|
const ct1 = await megolmEncryption.encryptMessage(mockRoom, "a.fake.type", {
|
||||||
body: "Some text",
|
body: "Some text",
|
||||||
@@ -323,25 +318,25 @@ describe("MegolmDecryption", function() {
|
|||||||
expect(mockRoom.getEncryptionTargetMembers).toHaveBeenCalled();
|
expect(mockRoom.getEncryptionTargetMembers).toHaveBeenCalled();
|
||||||
|
|
||||||
// this should have claimed a key for alice as it's starting a new session
|
// this should have claimed a key for alice as it's starting a new session
|
||||||
expect(mockBaseApis.claimOneTimeKeys).toHaveBeenCalled(
|
expect(mockBaseApis.claimOneTimeKeys).toHaveBeenCalledWith(
|
||||||
[['@alice:home.server', 'aliceDevice']], 'signed_curve25519',
|
[['@alice:home.server', 'aliceDevice']], 'signed_curve25519',
|
||||||
);
|
);
|
||||||
expect(mockCrypto.downloadKeys).toHaveBeenCalledWith(
|
expect(mockCrypto.downloadKeys).toHaveBeenCalledWith(
|
||||||
['@alice:home.server'], false,
|
['@alice:home.server'], false,
|
||||||
);
|
);
|
||||||
expect(mockBaseApis.sendToDevice).toHaveBeenCalled();
|
expect(mockBaseApis.sendToDevice).toHaveBeenCalled();
|
||||||
expect(mockBaseApis.claimOneTimeKeys).toHaveBeenCalled(
|
expect(mockBaseApis.claimOneTimeKeys).toHaveBeenCalledWith(
|
||||||
[['@alice:home.server', 'aliceDevice']], 'signed_curve25519',
|
[['@alice:home.server', 'aliceDevice']], 'signed_curve25519',
|
||||||
);
|
);
|
||||||
|
|
||||||
mockBaseApis.claimOneTimeKeys.reset();
|
mockBaseApis.claimOneTimeKeys.mockReset();
|
||||||
|
|
||||||
const ct2 = await megolmEncryption.encryptMessage(mockRoom, "a.fake.type", {
|
const ct2 = await megolmEncryption.encryptMessage(mockRoom, "a.fake.type", {
|
||||||
body: "Some more text",
|
body: "Some more text",
|
||||||
});
|
});
|
||||||
|
|
||||||
// this should *not* have claimed a key as it should be using the same session
|
// this should *not* have claimed a key as it should be using the same session
|
||||||
expect(mockBaseApis.claimOneTimeKeys).toNotHaveBeenCalled();
|
expect(mockBaseApis.claimOneTimeKeys).not.toHaveBeenCalled();
|
||||||
|
|
||||||
// likewise they should show the same session ID
|
// likewise they should show the same session ID
|
||||||
expect(ct2.session_id).toEqual(ct1.session_id);
|
expect(ct2.session_id).toEqual(ct1.session_id);
|
||||||
|
|||||||
@@ -16,10 +16,8 @@ limitations under the License.
|
|||||||
|
|
||||||
import '../../../olm-loader';
|
import '../../../olm-loader';
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import MemoryCryptoStore from '../../../../lib/crypto/store/memory-crypto-store.js';
|
import MemoryCryptoStore from '../../../../lib/crypto/store/memory-crypto-store.js';
|
||||||
import MockStorageApi from '../../../MockStorageApi';
|
import MockStorageApi from '../../../MockStorageApi';
|
||||||
import testUtils from '../../../test-utils';
|
|
||||||
import logger from '../../../../src/logger';
|
import logger from '../../../../src/logger';
|
||||||
|
|
||||||
import OlmDevice from '../../../../lib/crypto/OlmDevice';
|
import OlmDevice from '../../../../lib/crypto/OlmDevice';
|
||||||
@@ -54,8 +52,6 @@ describe("OlmDecryption", function() {
|
|||||||
let bobOlmDevice;
|
let bobOlmDevice;
|
||||||
|
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
|
|
||||||
await global.Olm.init();
|
await global.Olm.init();
|
||||||
|
|
||||||
aliceOlmDevice = makeOlmDevice();
|
aliceOlmDevice = makeOlmDevice();
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ limitations under the License.
|
|||||||
|
|
||||||
import '../../olm-loader';
|
import '../../olm-loader';
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
|
|
||||||
import sdk from '../../..';
|
import sdk from '../../..';
|
||||||
@@ -98,16 +97,16 @@ function makeTestClient(sessionStore, cryptoStore) {
|
|||||||
const scheduler = [
|
const scheduler = [
|
||||||
"getQueueForEvent", "queueEvent", "removeEventFromQueue",
|
"getQueueForEvent", "queueEvent", "removeEventFromQueue",
|
||||||
"setProcessFunction",
|
"setProcessFunction",
|
||||||
].reduce((r, k) => {r[k] = expect.createSpy(); return r;}, {});
|
].reduce((r, k) => {r[k] = jest.fn(); return r;}, {});
|
||||||
const store = [
|
const store = [
|
||||||
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
||||||
"save", "wantsSave", "setSyncToken", "storeEvents", "storeRoom",
|
"save", "wantsSave", "setSyncToken", "storeEvents", "storeRoom",
|
||||||
"storeUser", "getFilterIdByName", "setFilterIdByName", "getFilter",
|
"storeUser", "getFilterIdByName", "setFilterIdByName", "getFilter",
|
||||||
"storeFilter", "getSyncAccumulator", "startup", "deleteAllData",
|
"storeFilter", "getSyncAccumulator", "startup", "deleteAllData",
|
||||||
].reduce((r, k) => {r[k] = expect.createSpy(); return r;}, {});
|
].reduce((r, k) => {r[k] = jest.fn(); return r;}, {});
|
||||||
store.getSavedSync = expect.createSpy().andReturn(Promise.resolve(null));
|
store.getSavedSync = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.getSavedSyncToken = expect.createSpy().andReturn(Promise.resolve(null));
|
store.getSavedSyncToken = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.setSyncData = expect.createSpy().andReturn(Promise.resolve(null));
|
store.setSyncData = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
return new MatrixClient({
|
return new MatrixClient({
|
||||||
baseUrl: "https://my.home.server",
|
baseUrl: "https://my.home.server",
|
||||||
idBaseUrl: "https://identity.server",
|
idBaseUrl: "https://identity.server",
|
||||||
@@ -138,8 +137,6 @@ describe("MegolmBackup", function() {
|
|||||||
let megolmDecryption;
|
let megolmDecryption;
|
||||||
beforeEach(async function() {
|
beforeEach(async function() {
|
||||||
await Olm.init();
|
await Olm.init();
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
|
|
||||||
mockCrypto = testUtils.mock(Crypto, 'Crypto');
|
mockCrypto = testUtils.mock(Crypto, 'Crypto');
|
||||||
mockCrypto.backupKey = new Olm.PkEncryption();
|
mockCrypto.backupKey = new Olm.PkEncryption();
|
||||||
mockCrypto.backupKey.set_recipient_key(
|
mockCrypto.backupKey.set_recipient_key(
|
||||||
@@ -155,9 +152,9 @@ describe("MegolmBackup", function() {
|
|||||||
|
|
||||||
// we stub out the olm encryption bits
|
// we stub out the olm encryption bits
|
||||||
mockOlmLib = {};
|
mockOlmLib = {};
|
||||||
mockOlmLib.ensureOlmSessionsForDevices = expect.createSpy();
|
mockOlmLib.ensureOlmSessionsForDevices = jest.fn();
|
||||||
mockOlmLib.encryptMessageForDevice =
|
mockOlmLib.encryptMessageForDevice =
|
||||||
expect.createSpy().andReturn(Promise.resolve());
|
jest.fn().mockReturnValue(Promise.resolve());
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("backup", function() {
|
describe("backup", function() {
|
||||||
@@ -218,7 +215,7 @@ describe("MegolmBackup", function() {
|
|||||||
};
|
};
|
||||||
mockCrypto.cancelRoomKeyRequest = function() {};
|
mockCrypto.cancelRoomKeyRequest = function() {};
|
||||||
|
|
||||||
mockCrypto.backupGroupSession = expect.createSpy();
|
mockCrypto.backupGroupSession = jest.fn();
|
||||||
|
|
||||||
return event.attemptDecryption(mockCrypto).then(() => {
|
return event.attemptDecryption(mockCrypto).then(() => {
|
||||||
return megolmDecryption.onRoomKeyEvent(event);
|
return megolmDecryption.onRoomKeyEvent(event);
|
||||||
@@ -288,8 +285,8 @@ describe("MegolmBackup", function() {
|
|||||||
expect(method).toBe("PUT");
|
expect(method).toBe("PUT");
|
||||||
expect(path).toBe("/room_keys/keys");
|
expect(path).toBe("/room_keys/keys");
|
||||||
expect(queryParams.version).toBe(1);
|
expect(queryParams.version).toBe(1);
|
||||||
expect(data.rooms[ROOM_ID].sessions).toExist();
|
expect(data.rooms[ROOM_ID].sessions).toBeDefined();
|
||||||
expect(data.rooms[ROOM_ID].sessions).toIncludeKey(
|
expect(data.rooms[ROOM_ID].sessions).toHaveProperty(
|
||||||
groupSession.session_id(),
|
groupSession.session_id(),
|
||||||
);
|
);
|
||||||
resolve();
|
resolve();
|
||||||
@@ -382,16 +379,16 @@ describe("MegolmBackup", function() {
|
|||||||
const scheduler = [
|
const scheduler = [
|
||||||
"getQueueForEvent", "queueEvent", "removeEventFromQueue",
|
"getQueueForEvent", "queueEvent", "removeEventFromQueue",
|
||||||
"setProcessFunction",
|
"setProcessFunction",
|
||||||
].reduce((r, k) => {r[k] = expect.createSpy(); return r;}, {});
|
].reduce((r, k) => {r[k] = jest.fn(); return r;}, {});
|
||||||
const store = [
|
const store = [
|
||||||
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
||||||
"save", "wantsSave", "setSyncToken", "storeEvents", "storeRoom",
|
"save", "wantsSave", "setSyncToken", "storeEvents", "storeRoom",
|
||||||
"storeUser", "getFilterIdByName", "setFilterIdByName", "getFilter",
|
"storeUser", "getFilterIdByName", "setFilterIdByName", "getFilter",
|
||||||
"storeFilter", "getSyncAccumulator", "startup", "deleteAllData",
|
"storeFilter", "getSyncAccumulator", "startup", "deleteAllData",
|
||||||
].reduce((r, k) => {r[k] = expect.createSpy(); return r;}, {});
|
].reduce((r, k) => {r[k] = jest.fn(); return r;}, {});
|
||||||
store.getSavedSync = expect.createSpy().andReturn(Promise.resolve(null));
|
store.getSavedSync = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.getSavedSyncToken = expect.createSpy().andReturn(Promise.resolve(null));
|
store.getSavedSyncToken = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.setSyncData = expect.createSpy().andReturn(Promise.resolve(null));
|
store.setSyncData = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
const client = new MatrixClient({
|
const client = new MatrixClient({
|
||||||
baseUrl: "https://my.home.server",
|
baseUrl: "https://my.home.server",
|
||||||
idBaseUrl: "https://identity.server",
|
idBaseUrl: "https://identity.server",
|
||||||
@@ -458,8 +455,8 @@ describe("MegolmBackup", function() {
|
|||||||
expect(method).toBe("PUT");
|
expect(method).toBe("PUT");
|
||||||
expect(path).toBe("/room_keys/keys");
|
expect(path).toBe("/room_keys/keys");
|
||||||
expect(queryParams.version).toBe(1);
|
expect(queryParams.version).toBe(1);
|
||||||
expect(data.rooms[ROOM_ID].sessions).toExist();
|
expect(data.rooms[ROOM_ID].sessions).toBeDefined();
|
||||||
expect(data.rooms[ROOM_ID].sessions).toIncludeKey(
|
expect(data.rooms[ROOM_ID].sessions).toHaveProperty(
|
||||||
groupSession.session_id(),
|
groupSession.session_id(),
|
||||||
);
|
);
|
||||||
if (numCalls > 1) {
|
if (numCalls > 1) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
|
|
||||||
import '../../olm-loader';
|
import '../../olm-loader';
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import anotherjson from 'another-json';
|
import anotherjson from 'another-json';
|
||||||
|
|
||||||
import olmlib from '../../../lib/crypto/olmlib';
|
import olmlib from '../../../lib/crypto/olmlib';
|
||||||
@@ -64,13 +63,12 @@ describe("Cross Signing", function() {
|
|||||||
const alice = await makeTestClient(
|
const alice = await makeTestClient(
|
||||||
{userId: "@alice:example.com", deviceId: "Osborne2"},
|
{userId: "@alice:example.com", deviceId: "Osborne2"},
|
||||||
);
|
);
|
||||||
alice.uploadDeviceSigningKeys = expect.createSpy()
|
alice.uploadDeviceSigningKeys = jest.fn(async (auth, keys) => {
|
||||||
.andCall(async (auth, keys) => {
|
await olmlib.verifySignature(
|
||||||
await olmlib.verifySignature(
|
alice._crypto._olmDevice, keys.master_key, "@alice:example.com",
|
||||||
alice._crypto._olmDevice, keys.master_key, "@alice:example.com",
|
"Osborne2", alice._crypto._olmDevice.deviceEd25519Key,
|
||||||
"Osborne2", alice._crypto._olmDevice.deviceEd25519Key,
|
);
|
||||||
);
|
});
|
||||||
});
|
|
||||||
alice.uploadKeySignatures = async () => {};
|
alice.uploadKeySignatures = async () => {};
|
||||||
// set Alice's cross-signing key
|
// set Alice's cross-signing key
|
||||||
await alice.resetCrossSigningKeys();
|
await alice.resetCrossSigningKeys();
|
||||||
@@ -146,7 +144,7 @@ describe("Cross Signing", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const uploadSigsPromise = new Promise((resolve, reject) => {
|
const uploadSigsPromise = new Promise((resolve, reject) => {
|
||||||
alice.uploadKeySignatures = expect.createSpy().andCall(async (content) => {
|
alice.uploadKeySignatures = jest.fn(async (content) => {
|
||||||
await olmlib.verifySignature(
|
await olmlib.verifySignature(
|
||||||
alice._crypto._olmDevice,
|
alice._crypto._olmDevice,
|
||||||
content["@alice:example.com"][
|
content["@alice:example.com"][
|
||||||
@@ -732,7 +730,7 @@ describe("Cross Signing", function() {
|
|||||||
{
|
{
|
||||||
cryptoCallbacks: {
|
cryptoCallbacks: {
|
||||||
shouldUpgradeDeviceVerifications: (verifs) => {
|
shouldUpgradeDeviceVerifications: (verifs) => {
|
||||||
expect(verifs.users["@bob:example.com"]).toExist();
|
expect(verifs.users["@bob:example.com"]).toBeDefined();
|
||||||
upgradeResolveFunc();
|
upgradeResolveFunc();
|
||||||
return ["@bob:example.com"];
|
return ["@bob:example.com"];
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ limitations under the License.
|
|||||||
|
|
||||||
import '../../olm-loader';
|
import '../../olm-loader';
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import { MatrixEvent } from '../../../lib/models/event';
|
import { MatrixEvent } from '../../../lib/models/event';
|
||||||
import { SECRET_STORAGE_ALGORITHM_V1 } from '../../../lib/crypto/SecretStorage';
|
import { SECRET_STORAGE_ALGORITHM_V1 } from '../../../lib/crypto/SecretStorage';
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ describe("Secrets", function() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const getKey = expect.createSpy().andCall(e => {
|
const getKey = jest.fn(e => {
|
||||||
expect(Object.keys(e.keys)).toEqual(["abc"]);
|
expect(Object.keys(e.keys)).toEqual(["abc"]);
|
||||||
return ['abc', privkey];
|
return ['abc', privkey];
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ try {
|
|||||||
logger.warn("unable to run device verification tests: libolm not available");
|
logger.warn("unable to run device verification tests: libolm not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import DeviceInfo from '../../../../lib/crypto/deviceinfo';
|
import DeviceInfo from '../../../../lib/crypto/deviceinfo';
|
||||||
|
|
||||||
import {ShowQRCode, ScanQRCode} from '../../../../lib/crypto/verification/QRCode';
|
import {ShowQRCode, ScanQRCode} from '../../../../lib/crypto/verification/QRCode';
|
||||||
@@ -47,7 +46,7 @@ describe("QR code verification", function() {
|
|||||||
return "device+ed25519+key";
|
return "device+ed25519+key";
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const spy = expect.createSpy().andCall((e) => {
|
const spy = jest.fn((e) => {
|
||||||
qrCode.done();
|
qrCode.done();
|
||||||
});
|
});
|
||||||
qrCode.on("show_qr_code", spy);
|
qrCode.on("show_qr_code", spy);
|
||||||
@@ -77,8 +76,8 @@ describe("QR code verification", function() {
|
|||||||
"ABCDEFG",
|
"ABCDEFG",
|
||||||
);
|
);
|
||||||
const client = {
|
const client = {
|
||||||
getStoredDevice: expect.createSpy().andReturn(device),
|
getStoredDevice: jest.fn().mockReturnValue(device),
|
||||||
setDeviceVerified: expect.createSpy(),
|
setDeviceVerified: jest.fn(),
|
||||||
};
|
};
|
||||||
const qrCode = new ScanQRCode(client);
|
const qrCode = new ScanQRCode(client);
|
||||||
qrCode.on("confirm_user_id", ({userId, confirm}) => {
|
qrCode.on("confirm_user_id", ({userId, confirm}) => {
|
||||||
@@ -100,18 +99,18 @@ describe("QR code verification", function() {
|
|||||||
|
|
||||||
it("should error when the user ID doesn't match", async function() {
|
it("should error when the user ID doesn't match", async function() {
|
||||||
const client = {
|
const client = {
|
||||||
getStoredDevice: expect.createSpy(),
|
getStoredDevice: jest.fn(),
|
||||||
setDeviceVerified: expect.createSpy(),
|
setDeviceVerified: jest.fn(),
|
||||||
};
|
};
|
||||||
const qrCode = new ScanQRCode(client, "@bob:example.com", "ABCDEFG");
|
const qrCode = new ScanQRCode(client, "@bob:example.com", "ABCDEFG");
|
||||||
qrCode.on("scan", ({done}) => {
|
qrCode.on("scan", ({done}) => {
|
||||||
done(QR_CODE_URL);
|
done(QR_CODE_URL);
|
||||||
});
|
});
|
||||||
const spy = expect.createSpy();
|
const spy = jest.fn();
|
||||||
await qrCode.verify().catch(spy);
|
await qrCode.verify().catch(spy);
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
expect(client.getStoredDevice).toNotHaveBeenCalled();
|
expect(client.getStoredDevice).not.toHaveBeenCalled();
|
||||||
expect(client.setDeviceVerified).toNotHaveBeenCalled();
|
expect(client.setDeviceVerified).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should error if the key doesn't match", async function() {
|
it("should error if the key doesn't match", async function() {
|
||||||
@@ -129,18 +128,18 @@ describe("QR code verification", function() {
|
|||||||
"ABCDEFG",
|
"ABCDEFG",
|
||||||
);
|
);
|
||||||
const client = {
|
const client = {
|
||||||
getStoredDevice: expect.createSpy().andReturn(device),
|
getStoredDevice: jest.fn().mockReturnValue(device),
|
||||||
setDeviceVerified: expect.createSpy(),
|
setDeviceVerified: jest.fn(),
|
||||||
};
|
};
|
||||||
const qrCode = new ScanQRCode(client, "@alice:example.com", "ABCDEFG");
|
const qrCode = new ScanQRCode(client, "@alice:example.com", "ABCDEFG");
|
||||||
qrCode.on("scan", ({done}) => {
|
qrCode.on("scan", ({done}) => {
|
||||||
done(QR_CODE_URL);
|
done(QR_CODE_URL);
|
||||||
});
|
});
|
||||||
const spy = expect.createSpy();
|
const spy = jest.fn();
|
||||||
await qrCode.verify().catch(spy);
|
await qrCode.verify().catch(spy);
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
expect(client.getStoredDevice).toHaveBeenCalled();
|
expect(client.getStoredDevice).toHaveBeenCalled();
|
||||||
expect(client.setDeviceVerified).toNotHaveBeenCalled();
|
expect(client.setDeviceVerified).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ try {
|
|||||||
logger.warn("unable to run device verification tests: libolm not available");
|
logger.warn("unable to run device verification tests: libolm not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
import {verificationMethods} from '../../../../lib/crypto';
|
import {verificationMethods} from '../../../../lib/crypto';
|
||||||
|
|
||||||
import SAS from '../../../../lib/crypto/verification/SAS';
|
import SAS from '../../../../lib/crypto/verification/SAS';
|
||||||
@@ -74,7 +72,7 @@ describe("verification request", function() {
|
|||||||
bobVerifier._endTimer();
|
bobVerifier._endTimer();
|
||||||
});
|
});
|
||||||
const aliceVerifier = await alice.client.requestVerification("@bob:example.com");
|
const aliceVerifier = await alice.client.requestVerification("@bob:example.com");
|
||||||
expect(aliceVerifier).toBeAn(SAS);
|
expect(aliceVerifier).toBeInstanceOf(SAS);
|
||||||
|
|
||||||
// XXX: Private function access (but it's a test, so we're okay)
|
// XXX: Private function access (but it's a test, so we're okay)
|
||||||
aliceVerifier._endTimer();
|
aliceVerifier._endTimer();
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ try {
|
|||||||
logger.warn("unable to run device verification tests: libolm not available");
|
logger.warn("unable to run device verification tests: libolm not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import olmlib from '../../../../lib/crypto/olmlib';
|
import olmlib from '../../../../lib/crypto/olmlib';
|
||||||
|
|
||||||
import sdk from '../../../..';
|
import sdk from '../../../..';
|
||||||
@@ -57,9 +56,8 @@ describe("SAS verification", function() {
|
|||||||
type: "es.inquisition",
|
type: "es.inquisition",
|
||||||
content: {},
|
content: {},
|
||||||
}));
|
}));
|
||||||
const spy = expect.createSpy();
|
const spy = jest.fn();
|
||||||
await sas.verify()
|
await sas.verify().catch(spy);
|
||||||
.catch(spy);
|
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
|
|
||||||
// Cancel the SAS for cleanup (we started a verification, so abort)
|
// Cancel the SAS for cleanup (we started a verification, so abort)
|
||||||
@@ -346,11 +344,11 @@ describe("SAS verification", function() {
|
|||||||
verificationMethods: [verificationMethods.SAS],
|
verificationMethods: [verificationMethods.SAS],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
alice.client.setDeviceVerified = expect.createSpy();
|
alice.client.setDeviceVerified = jest.fn();
|
||||||
alice.client.downloadKeys = () => {
|
alice.client.downloadKeys = () => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
bob.client.setDeviceVerified = expect.createSpy();
|
bob.client.setDeviceVerified = jest.fn();
|
||||||
bob.client.downloadKeys = () => {
|
bob.client.downloadKeys = () => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
@@ -368,8 +366,8 @@ describe("SAS verification", function() {
|
|||||||
verificationMethods.SAS, bob.client.getUserId(), bob.client.deviceId,
|
verificationMethods.SAS, bob.client.getUserId(), bob.client.deviceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
const aliceSpy = expect.createSpy();
|
const aliceSpy = jest.fn();
|
||||||
const bobSpy = expect.createSpy();
|
const bobSpy = jest.fn();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
aliceVerifier.verify().catch(aliceSpy),
|
aliceVerifier.verify().catch(aliceSpy),
|
||||||
bobPromise.then((verifier) => verifier.verify()).catch(bobSpy),
|
bobPromise.then((verifier) => verifier.verify()).catch(bobSpy),
|
||||||
@@ -377,9 +375,9 @@ describe("SAS verification", function() {
|
|||||||
expect(aliceSpy).toHaveBeenCalled();
|
expect(aliceSpy).toHaveBeenCalled();
|
||||||
expect(bobSpy).toHaveBeenCalled();
|
expect(bobSpy).toHaveBeenCalled();
|
||||||
expect(alice.client.setDeviceVerified)
|
expect(alice.client.setDeviceVerified)
|
||||||
.toNotHaveBeenCalled();
|
.not.toHaveBeenCalled();
|
||||||
expect(bob.client.setDeviceVerified)
|
expect(bob.client.setDeviceVerified)
|
||||||
.toNotHaveBeenCalled();
|
.not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("verification in DM", function() {
|
describe("verification in DM", function() {
|
||||||
@@ -401,7 +399,7 @@ describe("SAS verification", function() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
alice.client.setDeviceVerified = expect.createSpy();
|
alice.client.setDeviceVerified = jest.fn();
|
||||||
alice.client.getDeviceEd25519Key = () => {
|
alice.client.getDeviceEd25519Key = () => {
|
||||||
return "alice+base64+ed25519+key";
|
return "alice+base64+ed25519+key";
|
||||||
};
|
};
|
||||||
@@ -419,7 +417,7 @@ describe("SAS verification", function() {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
bob.client.setDeviceVerified = expect.createSpy();
|
bob.client.setDeviceVerified = jest.fn();
|
||||||
bob.client.getStoredDevice = () => {
|
bob.client.getStoredDevice = () => {
|
||||||
return DeviceInfo.fromStorage(
|
return DeviceInfo.fromStorage(
|
||||||
{
|
{
|
||||||
@@ -445,7 +443,7 @@ describe("SAS verification", function() {
|
|||||||
const content = event.getContent();
|
const content = event.getContent();
|
||||||
if (event.getType() === "m.room.message"
|
if (event.getType() === "m.room.message"
|
||||||
&& content.msgtype === "m.key.verification.request") {
|
&& content.msgtype === "m.key.verification.request") {
|
||||||
expect(content.methods).toInclude(SAS.NAME);
|
expect(content.methods).toContain(SAS.NAME);
|
||||||
expect(content.to).toBe(bob.client.getUserId());
|
expect(content.to).toBe(bob.client.getUserId());
|
||||||
const verifier = bob.client.acceptVerificationDM(event, SAS.NAME);
|
const verifier = bob.client.acceptVerificationDM(event, SAS.NAME);
|
||||||
verifier.on("show_sas", (e) => {
|
verifier.on("show_sas", (e) => {
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ function mockRoomStates(timeline) {
|
|||||||
timeline._endState = utils.mock(sdk.RoomState, "endState");
|
timeline._endState = utils.mock(sdk.RoomState, "endState");
|
||||||
}
|
}
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("EventTimeline", function() {
|
describe("EventTimeline", function() {
|
||||||
const roomId = "!foo:bar";
|
const roomId = "!foo:bar";
|
||||||
const userA = "@alice:bar";
|
const userA = "@alice:bar";
|
||||||
@@ -18,8 +16,6 @@ describe("EventTimeline", function() {
|
|||||||
let timeline;
|
let timeline;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
|
|
||||||
// XXX: this is a horrid hack; should use sinon or something instead to mock
|
// XXX: this is a horrid hack; should use sinon or something instead to mock
|
||||||
const timelineSet = { room: { roomId: roomId }};
|
const timelineSet = { room: { roomId: roomId }};
|
||||||
timelineSet.room.getUnfilteredTimelineSet = function() {
|
timelineSet.room.getUnfilteredTimelineSet = function() {
|
||||||
@@ -78,7 +74,7 @@ describe("EventTimeline", function() {
|
|||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
timeline.initialiseState(state);
|
timeline.initialiseState(state);
|
||||||
}).toNotThrow();
|
}).not.toThrow();
|
||||||
timeline.addEvent(event, false);
|
timeline.addEvent(event, false);
|
||||||
expect(function() {
|
expect(function() {
|
||||||
timeline.initialiseState(state);
|
timeline.initialiseState(state);
|
||||||
@@ -121,7 +117,7 @@ describe("EventTimeline", function() {
|
|||||||
const next = {b: "b"};
|
const next = {b: "b"};
|
||||||
expect(function() {
|
expect(function() {
|
||||||
timeline.setNeighbouringTimeline(prev, EventTimeline.BACKWARDS);
|
timeline.setNeighbouringTimeline(prev, EventTimeline.BACKWARDS);
|
||||||
}).toNotThrow();
|
}).not.toThrow();
|
||||||
expect(timeline.getNeighbouringTimeline(EventTimeline.BACKWARDS))
|
expect(timeline.getNeighbouringTimeline(EventTimeline.BACKWARDS))
|
||||||
.toBe(prev);
|
.toBe(prev);
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -130,7 +126,7 @@ describe("EventTimeline", function() {
|
|||||||
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
timeline.setNeighbouringTimeline(next, EventTimeline.FORWARDS);
|
timeline.setNeighbouringTimeline(next, EventTimeline.FORWARDS);
|
||||||
}).toNotThrow();
|
}).not.toThrow();
|
||||||
expect(timeline.getNeighbouringTimeline(EventTimeline.FORWARDS))
|
expect(timeline.getNeighbouringTimeline(EventTimeline.FORWARDS))
|
||||||
.toBe(next);
|
.toBe(next);
|
||||||
expect(function() {
|
expect(function() {
|
||||||
@@ -187,14 +183,14 @@ describe("EventTimeline", function() {
|
|||||||
name: "Old Alice",
|
name: "Old Alice",
|
||||||
};
|
};
|
||||||
timeline.getState(EventTimeline.FORWARDS).getSentinelMember
|
timeline.getState(EventTimeline.FORWARDS).getSentinelMember
|
||||||
.andCall(function(uid) {
|
.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return sentinel;
|
return sentinel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
timeline.getState(EventTimeline.BACKWARDS).getSentinelMember
|
timeline.getState(EventTimeline.BACKWARDS).getSentinelMember
|
||||||
.andCall(function(uid) {
|
.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return oldSentinel;
|
return oldSentinel;
|
||||||
}
|
}
|
||||||
@@ -229,14 +225,14 @@ describe("EventTimeline", function() {
|
|||||||
name: "Old Alice",
|
name: "Old Alice",
|
||||||
};
|
};
|
||||||
timeline.getState(EventTimeline.FORWARDS).getSentinelMember
|
timeline.getState(EventTimeline.FORWARDS).getSentinelMember
|
||||||
.andCall(function(uid) {
|
.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return sentinel;
|
return sentinel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
timeline.getState(EventTimeline.BACKWARDS).getSentinelMember
|
timeline.getState(EventTimeline.BACKWARDS).getSentinelMember
|
||||||
.andCall(function(uid) {
|
.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return oldSentinel;
|
return oldSentinel;
|
||||||
}
|
}
|
||||||
@@ -281,7 +277,7 @@ describe("EventTimeline", function() {
|
|||||||
expect(events[1].forwardLooking).toBe(true);
|
expect(events[1].forwardLooking).toBe(true);
|
||||||
|
|
||||||
expect(timeline.getState(EventTimeline.BACKWARDS).setStateEvents).
|
expect(timeline.getState(EventTimeline.BACKWARDS).setStateEvents).
|
||||||
toNotHaveBeenCalled();
|
not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -311,7 +307,7 @@ describe("EventTimeline", function() {
|
|||||||
expect(events[1].forwardLooking).toBe(false);
|
expect(events[1].forwardLooking).toBe(false);
|
||||||
|
|
||||||
expect(timeline.getState(EventTimeline.FORWARDS).setStateEvents).
|
expect(timeline.getState(EventTimeline.FORWARDS).setStateEvents).
|
||||||
toNotHaveBeenCalled();
|
not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,17 +17,10 @@ limitations under the License.
|
|||||||
import sdk from '../..';
|
import sdk from '../..';
|
||||||
const MatrixEvent = sdk.MatrixEvent;
|
const MatrixEvent = sdk.MatrixEvent;
|
||||||
|
|
||||||
import testUtils from '../test-utils';
|
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
import logger from '../../src/logger';
|
import logger from '../../src/logger';
|
||||||
|
|
||||||
describe("MatrixEvent", () => {
|
describe("MatrixEvent", () => {
|
||||||
beforeEach(function() {
|
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
});
|
|
||||||
|
|
||||||
describe(".attemptDecryption", () => {
|
describe(".attemptDecryption", () => {
|
||||||
let encryptedEvent;
|
let encryptedEvent;
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
const sdk = require("../..");
|
const sdk = require("../..");
|
||||||
const Filter = sdk.Filter;
|
const Filter = sdk.Filter;
|
||||||
const utils = require("../test-utils");
|
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("Filter", function() {
|
describe("Filter", function() {
|
||||||
const filterId = "f1lt3ring15g00d4ursoul";
|
const filterId = "f1lt3ring15g00d4ursoul";
|
||||||
@@ -12,7 +9,6 @@ describe("Filter", function() {
|
|||||||
let filter;
|
let filter;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
filter = new Filter(userId);
|
filter = new Filter(userId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,10 @@ limitations under the License.
|
|||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
const sdk = require("../..");
|
const sdk = require("../..");
|
||||||
const utils = require("../test-utils");
|
|
||||||
|
|
||||||
const InteractiveAuth = sdk.InteractiveAuth;
|
const InteractiveAuth = sdk.InteractiveAuth;
|
||||||
const MatrixError = sdk.MatrixError;
|
const MatrixError = sdk.MatrixError;
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import logger from '../../src/logger';
|
import logger from '../../src/logger';
|
||||||
|
|
||||||
// Trivial client object to test interactive auth
|
// Trivial client object to test interactive auth
|
||||||
@@ -35,13 +33,9 @@ class FakeClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("InteractiveAuth", function() {
|
describe("InteractiveAuth", function() {
|
||||||
beforeEach(function() {
|
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should start an auth stage and complete it", function(done) {
|
it("should start an auth stage and complete it", function(done) {
|
||||||
const doRequest = expect.createSpy();
|
const doRequest = jest.fn();
|
||||||
const stateUpdated = expect.createSpy();
|
const stateUpdated = jest.fn();
|
||||||
|
|
||||||
const ia = new InteractiveAuth({
|
const ia = new InteractiveAuth({
|
||||||
matrixClient: new FakeClient(),
|
matrixClient: new FakeClient(),
|
||||||
@@ -64,7 +58,7 @@ describe("InteractiveAuth", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// first we expect a call here
|
// first we expect a call here
|
||||||
stateUpdated.andCall(function(stage) {
|
stateUpdated.mockImplementation(function(stage) {
|
||||||
logger.log('aaaa');
|
logger.log('aaaa');
|
||||||
expect(stage).toEqual("logintype");
|
expect(stage).toEqual("logintype");
|
||||||
ia.submitAuthDict({
|
ia.submitAuthDict({
|
||||||
@@ -75,7 +69,7 @@ describe("InteractiveAuth", function() {
|
|||||||
|
|
||||||
// .. which should trigger a call here
|
// .. which should trigger a call here
|
||||||
const requestRes = {"a": "b"};
|
const requestRes = {"a": "b"};
|
||||||
doRequest.andCall(function(authData) {
|
doRequest.mockImplementation(function(authData) {
|
||||||
logger.log('cccc');
|
logger.log('cccc');
|
||||||
expect(authData).toEqual({
|
expect(authData).toEqual({
|
||||||
session: "sessionId",
|
session: "sessionId",
|
||||||
@@ -87,14 +81,14 @@ describe("InteractiveAuth", function() {
|
|||||||
|
|
||||||
ia.attemptAuth().then(function(res) {
|
ia.attemptAuth().then(function(res) {
|
||||||
expect(res).toBe(requestRes);
|
expect(res).toBe(requestRes);
|
||||||
expect(doRequest.calls.length).toEqual(1);
|
expect(doRequest).toBeCalledTimes(1);
|
||||||
expect(stateUpdated.calls.length).toEqual(1);
|
expect(stateUpdated).toBeCalledTimes(1);
|
||||||
}).nodeify(done);
|
}).nodeify(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should make a request if no authdata is provided", function(done) {
|
it("should make a request if no authdata is provided", function(done) {
|
||||||
const doRequest = expect.createSpy();
|
const doRequest = jest.fn();
|
||||||
const stateUpdated = expect.createSpy();
|
const stateUpdated = jest.fn();
|
||||||
|
|
||||||
const ia = new InteractiveAuth({
|
const ia = new InteractiveAuth({
|
||||||
matrixClient: new FakeClient(),
|
matrixClient: new FakeClient(),
|
||||||
@@ -106,7 +100,7 @@ describe("InteractiveAuth", function() {
|
|||||||
expect(ia.getStageParams("logintype")).toBe(undefined);
|
expect(ia.getStageParams("logintype")).toBe(undefined);
|
||||||
|
|
||||||
// first we expect a call to doRequest
|
// first we expect a call to doRequest
|
||||||
doRequest.andCall(function(authData) {
|
doRequest.mockImplementation(function(authData) {
|
||||||
logger.log("request1", authData);
|
logger.log("request1", authData);
|
||||||
expect(authData).toEqual({});
|
expect(authData).toEqual({});
|
||||||
const err = new MatrixError({
|
const err = new MatrixError({
|
||||||
@@ -124,7 +118,7 @@ describe("InteractiveAuth", function() {
|
|||||||
|
|
||||||
// .. which should be followed by a call to stateUpdated
|
// .. which should be followed by a call to stateUpdated
|
||||||
const requestRes = {"a": "b"};
|
const requestRes = {"a": "b"};
|
||||||
stateUpdated.andCall(function(stage) {
|
stateUpdated.mockImplementation(function(stage) {
|
||||||
expect(stage).toEqual("logintype");
|
expect(stage).toEqual("logintype");
|
||||||
expect(ia.getSessionId()).toEqual("sessionId");
|
expect(ia.getSessionId()).toEqual("sessionId");
|
||||||
expect(ia.getStageParams("logintype")).toEqual({
|
expect(ia.getStageParams("logintype")).toEqual({
|
||||||
@@ -132,7 +126,7 @@ describe("InteractiveAuth", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// submitAuthDict should trigger another call to doRequest
|
// submitAuthDict should trigger another call to doRequest
|
||||||
doRequest.andCall(function(authData) {
|
doRequest.mockImplementation(function(authData) {
|
||||||
logger.log("request2", authData);
|
logger.log("request2", authData);
|
||||||
expect(authData).toEqual({
|
expect(authData).toEqual({
|
||||||
session: "sessionId",
|
session: "sessionId",
|
||||||
@@ -150,8 +144,8 @@ describe("InteractiveAuth", function() {
|
|||||||
|
|
||||||
ia.attemptAuth().then(function(res) {
|
ia.attemptAuth().then(function(res) {
|
||||||
expect(res).toBe(requestRes);
|
expect(res).toBe(requestRes);
|
||||||
expect(doRequest.calls.length).toEqual(2);
|
expect(doRequest).toBeCalledTimes(2);
|
||||||
expect(stateUpdated.calls.length).toEqual(1);
|
expect(stateUpdated).toBeCalledTimes(1);
|
||||||
}).nodeify(done);
|
}).nodeify(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import expect from 'expect';
|
|
||||||
import TestClient from '../TestClient';
|
import TestClient from '../TestClient';
|
||||||
|
|
||||||
describe('Login request', function() {
|
describe('Login request', function() {
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ import 'source-map-support/register';
|
|||||||
import Promise from 'bluebird';
|
import Promise from 'bluebird';
|
||||||
const sdk = require("../..");
|
const sdk = require("../..");
|
||||||
const MatrixClient = sdk.MatrixClient;
|
const MatrixClient = sdk.MatrixClient;
|
||||||
const utils = require("../test-utils");
|
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import lolex from 'lolex';
|
|
||||||
import logger from '../../src/logger';
|
import logger from '../../src/logger';
|
||||||
|
|
||||||
|
jest.useFakeTimers();
|
||||||
|
|
||||||
describe("MatrixClient", function() {
|
describe("MatrixClient", function() {
|
||||||
const userId = "@alice:bar";
|
const userId = "@alice:bar";
|
||||||
const identityServerUrl = "https://identity.server";
|
const identityServerUrl = "https://identity.server";
|
||||||
@@ -16,7 +15,6 @@ describe("MatrixClient", function() {
|
|||||||
let client;
|
let client;
|
||||||
let store;
|
let store;
|
||||||
let scheduler;
|
let scheduler;
|
||||||
let clock;
|
|
||||||
|
|
||||||
const KEEP_ALIVE_PATH = "/_matrix/client/versions";
|
const KEEP_ALIVE_PATH = "/_matrix/client/versions";
|
||||||
|
|
||||||
@@ -125,24 +123,22 @@ describe("MatrixClient", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
clock = lolex.install();
|
|
||||||
scheduler = [
|
scheduler = [
|
||||||
"getQueueForEvent", "queueEvent", "removeEventFromQueue",
|
"getQueueForEvent", "queueEvent", "removeEventFromQueue",
|
||||||
"setProcessFunction",
|
"setProcessFunction",
|
||||||
].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {});
|
].reduce((r, k) => { r[k] = jest.fn(); return r; }, {});
|
||||||
store = [
|
store = [
|
||||||
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
||||||
"save", "wantsSave", "setSyncToken", "storeEvents", "storeRoom", "storeUser",
|
"save", "wantsSave", "setSyncToken", "storeEvents", "storeRoom", "storeUser",
|
||||||
"getFilterIdByName", "setFilterIdByName", "getFilter", "storeFilter",
|
"getFilterIdByName", "setFilterIdByName", "getFilter", "storeFilter",
|
||||||
"getSyncAccumulator", "startup", "deleteAllData",
|
"getSyncAccumulator", "startup", "deleteAllData",
|
||||||
].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {});
|
].reduce((r, k) => { r[k] = jest.fn(); return r; }, {});
|
||||||
store.getSavedSync = expect.createSpy().andReturn(Promise.resolve(null));
|
store.getSavedSync = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.getSavedSyncToken = expect.createSpy().andReturn(Promise.resolve(null));
|
store.getSavedSyncToken = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.setSyncData = expect.createSpy().andReturn(Promise.resolve(null));
|
store.setSyncData = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.getClientOptions = expect.createSpy().andReturn(Promise.resolve(null));
|
store.getClientOptions = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.storeClientOptions = expect.createSpy().andReturn(Promise.resolve(null));
|
store.storeClientOptions = jest.fn().mockReturnValue(Promise.resolve(null));
|
||||||
store.isNewlyCreated = expect.createSpy().andReturn(Promise.resolve(true));
|
store.isNewlyCreated = jest.fn().mockReturnValue(Promise.resolve(true));
|
||||||
client = new MatrixClient({
|
client = new MatrixClient({
|
||||||
baseUrl: "https://my.home.server",
|
baseUrl: "https://my.home.server",
|
||||||
idBaseUrl: identityServerUrl,
|
idBaseUrl: identityServerUrl,
|
||||||
@@ -155,9 +151,9 @@ describe("MatrixClient", function() {
|
|||||||
// FIXME: We shouldn't be yanking _http like this.
|
// FIXME: We shouldn't be yanking _http like this.
|
||||||
client._http = [
|
client._http = [
|
||||||
"authedRequest", "getContentUri", "request", "uploadContent",
|
"authedRequest", "getContentUri", "request", "uploadContent",
|
||||||
].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {});
|
].reduce((r, k) => { r[k] = jest.fn(); return r; }, {});
|
||||||
client._http.authedRequest.andCall(httpReq);
|
client._http.authedRequest.mockImplementation(httpReq);
|
||||||
client._http.request.andCall(httpReq);
|
client._http.request.mockImplementation(httpReq);
|
||||||
|
|
||||||
// set reasonable working defaults
|
// set reasonable working defaults
|
||||||
acceptKeepalives = true;
|
acceptKeepalives = true;
|
||||||
@@ -169,13 +165,12 @@ describe("MatrixClient", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
clock.uninstall();
|
|
||||||
// need to re-stub the requests with NOPs because there are no guarantees
|
// need to re-stub the requests with NOPs because there are no guarantees
|
||||||
// clients from previous tests will be GC'd before the next test. This
|
// clients from previous tests will be GC'd before the next test. This
|
||||||
// means they may call /events and then fail an expect() which will fail
|
// means they may call /events and then fail an expect() which will fail
|
||||||
// a DIFFERENT test (pollution between tests!) - we return unresolved
|
// a DIFFERENT test (pollution between tests!) - we return unresolved
|
||||||
// promises to stop the client from continuing to run.
|
// promises to stop the client from continuing to run.
|
||||||
client._http.authedRequest.andCall(function() {
|
client._http.authedRequest.mockImplementation(function() {
|
||||||
return Promise.defer().promise;
|
return Promise.defer().promise;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -185,10 +180,10 @@ describe("MatrixClient", function() {
|
|||||||
httpLookups.push(PUSH_RULES_RESPONSE);
|
httpLookups.push(PUSH_RULES_RESPONSE);
|
||||||
httpLookups.push(SYNC_RESPONSE);
|
httpLookups.push(SYNC_RESPONSE);
|
||||||
const filterId = "ehfewf";
|
const filterId = "ehfewf";
|
||||||
store.getFilterIdByName.andReturn(filterId);
|
store.getFilterIdByName.mockReturnValue(filterId);
|
||||||
const filter = new sdk.Filter(0, filterId);
|
const filter = new sdk.Filter(0, filterId);
|
||||||
filter.setDefinition({"room": {"timeline": {"limit": 8}}});
|
filter.setDefinition({"room": {"timeline": {"limit": 8}}});
|
||||||
store.getFilter.andReturn(filter);
|
store.getFilter.mockReturnValue(filter);
|
||||||
const syncPromise = new Promise((resolve, reject) => {
|
const syncPromise = new Promise((resolve, reject) => {
|
||||||
client.on("sync", function syncListener(state) {
|
client.on("sync", function syncListener(state) {
|
||||||
if (state === "SYNCING") {
|
if (state === "SYNCING") {
|
||||||
@@ -249,7 +244,7 @@ describe("MatrixClient", function() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
httpLookups.push(FILTER_RESPONSE);
|
httpLookups.push(FILTER_RESPONSE);
|
||||||
store.getFilterIdByName.andReturn(invalidFilterId);
|
store.getFilterIdByName.mockReturnValue(invalidFilterId);
|
||||||
|
|
||||||
const filterName = getFilterName(client.credentials.userId);
|
const filterName = getFilterName(client.credentials.userId);
|
||||||
client.store.setFilterIdByName(filterName, invalidFilterId);
|
client.store.setFilterIdByName(filterName, invalidFilterId);
|
||||||
@@ -281,7 +276,7 @@ describe("MatrixClient", function() {
|
|||||||
if (state === "ERROR" && httpLookups.length > 0) {
|
if (state === "ERROR" && httpLookups.length > 0) {
|
||||||
expect(httpLookups.length).toEqual(2);
|
expect(httpLookups.length).toEqual(2);
|
||||||
expect(client.retryImmediately()).toBe(true);
|
expect(client.retryImmediately()).toBe(true);
|
||||||
clock.tick(1);
|
jest.advanceTimersByTime(1);
|
||||||
} else if (state === "PREPARED" && httpLookups.length === 0) {
|
} else if (state === "PREPARED" && httpLookups.length === 0) {
|
||||||
client.removeListener("sync", syncListener);
|
client.removeListener("sync", syncListener);
|
||||||
done();
|
done();
|
||||||
@@ -307,9 +302,9 @@ describe("MatrixClient", function() {
|
|||||||
expect(client.retryImmediately()).toBe(
|
expect(client.retryImmediately()).toBe(
|
||||||
true, "retryImmediately returned false",
|
true, "retryImmediately returned false",
|
||||||
);
|
);
|
||||||
clock.tick(1);
|
jest.advanceTimersByTime(1);
|
||||||
} else if (state === "RECONNECTING" && httpLookups.length > 0) {
|
} else if (state === "RECONNECTING" && httpLookups.length > 0) {
|
||||||
clock.tick(10000);
|
jest.advanceTimersByTime(10000);
|
||||||
} else if (state === "SYNCING" && httpLookups.length === 0) {
|
} else if (state === "SYNCING" && httpLookups.length === 0) {
|
||||||
client.removeListener("sync", syncListener);
|
client.removeListener("sync", syncListener);
|
||||||
done();
|
done();
|
||||||
@@ -331,7 +326,7 @@ describe("MatrixClient", function() {
|
|||||||
if (state === "ERROR" && httpLookups.length > 0) {
|
if (state === "ERROR" && httpLookups.length > 0) {
|
||||||
expect(httpLookups.length).toEqual(3);
|
expect(httpLookups.length).toEqual(3);
|
||||||
expect(client.retryImmediately()).toBe(true);
|
expect(client.retryImmediately()).toBe(true);
|
||||||
clock.tick(1);
|
jest.advanceTimersByTime(1);
|
||||||
} else if (state === "PREPARED" && httpLookups.length === 0) {
|
} else if (state === "PREPARED" && httpLookups.length === 0) {
|
||||||
client.removeListener("sync", syncListener);
|
client.removeListener("sync", syncListener);
|
||||||
done();
|
done();
|
||||||
@@ -362,7 +357,7 @@ describe("MatrixClient", function() {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
// standard retry time is 5 to 10 seconds
|
// standard retry time is 5 to 10 seconds
|
||||||
clock.tick(10000);
|
jest.advanceTimersByTime(10000);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import 'source-map-support/register';
|
|||||||
const PushProcessor = require("../../lib/pushprocessor");
|
const PushProcessor = require("../../lib/pushprocessor");
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe('NotificationService', function() {
|
describe('NotificationService', function() {
|
||||||
const testUserId = "@ali:matrix.org";
|
const testUserId = "@ali:matrix.org";
|
||||||
const testDisplayName = "Alice M";
|
const testDisplayName = "Alice M";
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
const callbacks = require("../../lib/realtime-callbacks");
|
const callbacks = require("../../src/realtime-callbacks");
|
||||||
const testUtils = require("../test-utils.js");
|
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
import lolex from 'lolex';
|
import lolex from 'lolex';
|
||||||
|
|
||||||
describe("realtime-callbacks", function() {
|
describe("realtime-callbacks", function() {
|
||||||
@@ -15,7 +13,6 @@ describe("realtime-callbacks", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
clock = lolex.install();
|
clock = lolex.install();
|
||||||
const fakeDate = clock.Date;
|
const fakeDate = clock.Date;
|
||||||
callbacks.setNow(fakeDate.now.bind(fakeDate));
|
callbacks.setNow(fakeDate.now.bind(fakeDate));
|
||||||
@@ -28,26 +25,26 @@ describe("realtime-callbacks", function() {
|
|||||||
|
|
||||||
describe("setTimeout", function() {
|
describe("setTimeout", function() {
|
||||||
it("should call the callback after the timeout", function() {
|
it("should call the callback after the timeout", function() {
|
||||||
const callback = expect.createSpy();
|
const callback = jest.fn();
|
||||||
callbacks.setTimeout(callback, 100);
|
callbacks.setTimeout(callback, 100);
|
||||||
|
|
||||||
expect(callback).toNotHaveBeenCalled();
|
expect(callback).not.toHaveBeenCalled();
|
||||||
tick(100);
|
tick(100);
|
||||||
expect(callback).toHaveBeenCalled();
|
expect(callback).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("should default to a zero timeout", function() {
|
it("should default to a zero timeout", function() {
|
||||||
const callback = expect.createSpy();
|
const callback = jest.fn();
|
||||||
callbacks.setTimeout(callback);
|
callbacks.setTimeout(callback);
|
||||||
|
|
||||||
expect(callback).toNotHaveBeenCalled();
|
expect(callback).not.toHaveBeenCalled();
|
||||||
tick(0);
|
tick(0);
|
||||||
expect(callback).toHaveBeenCalled();
|
expect(callback).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should pass any parameters to the callback", function() {
|
it("should pass any parameters to the callback", function() {
|
||||||
const callback = expect.createSpy();
|
const callback = jest.fn();
|
||||||
callbacks.setTimeout(callback, 0, "a", "b", "c");
|
callbacks.setTimeout(callback, 0, "a", "b", "c");
|
||||||
tick(0);
|
tick(0);
|
||||||
expect(callback).toHaveBeenCalledWith("a", "b", "c");
|
expect(callback).toHaveBeenCalledWith("a", "b", "c");
|
||||||
@@ -66,10 +63,10 @@ describe("realtime-callbacks", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should handle timeouts of several seconds", function() {
|
it("should handle timeouts of several seconds", function() {
|
||||||
const callback = expect.createSpy();
|
const callback = jest.fn();
|
||||||
callbacks.setTimeout(callback, 2000);
|
callbacks.setTimeout(callback, 2000);
|
||||||
|
|
||||||
expect(callback).toNotHaveBeenCalled();
|
expect(callback).not.toHaveBeenCalled();
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
tick(500);
|
tick(500);
|
||||||
}
|
}
|
||||||
@@ -77,24 +74,24 @@ describe("realtime-callbacks", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should call multiple callbacks in the right order", function() {
|
it("should call multiple callbacks in the right order", function() {
|
||||||
const callback1 = expect.createSpy();
|
const callback1 = jest.fn();
|
||||||
const callback2 = expect.createSpy();
|
const callback2 = jest.fn();
|
||||||
const callback3 = expect.createSpy();
|
const callback3 = jest.fn();
|
||||||
callbacks.setTimeout(callback2, 200);
|
callbacks.setTimeout(callback2, 200);
|
||||||
callbacks.setTimeout(callback1, 100);
|
callbacks.setTimeout(callback1, 100);
|
||||||
callbacks.setTimeout(callback3, 300);
|
callbacks.setTimeout(callback3, 300);
|
||||||
|
|
||||||
expect(callback1).toNotHaveBeenCalled();
|
expect(callback1).not.toHaveBeenCalled();
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
expect(callback3).toNotHaveBeenCalled();
|
expect(callback3).not.toHaveBeenCalled();
|
||||||
tick(100);
|
tick(100);
|
||||||
expect(callback1).toHaveBeenCalled();
|
expect(callback1).toHaveBeenCalled();
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
expect(callback3).toNotHaveBeenCalled();
|
expect(callback3).not.toHaveBeenCalled();
|
||||||
tick(100);
|
tick(100);
|
||||||
expect(callback1).toHaveBeenCalled();
|
expect(callback1).toHaveBeenCalled();
|
||||||
expect(callback2).toHaveBeenCalled();
|
expect(callback2).toHaveBeenCalled();
|
||||||
expect(callback3).toNotHaveBeenCalled();
|
expect(callback3).not.toHaveBeenCalled();
|
||||||
tick(100);
|
tick(100);
|
||||||
expect(callback1).toHaveBeenCalled();
|
expect(callback1).toHaveBeenCalled();
|
||||||
expect(callback2).toHaveBeenCalled();
|
expect(callback2).toHaveBeenCalled();
|
||||||
@@ -102,35 +99,35 @@ describe("realtime-callbacks", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should treat -ve timeouts the same as a zero timeout", function() {
|
it("should treat -ve timeouts the same as a zero timeout", function() {
|
||||||
const callback1 = expect.createSpy();
|
const callback1 = jest.fn();
|
||||||
const callback2 = expect.createSpy();
|
const callback2 = jest.fn();
|
||||||
|
|
||||||
// check that cb1 is called before cb2
|
// check that cb1 is called before cb2
|
||||||
callback1.andCall(function() {
|
callback1.mockImplementation(function() {
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
callbacks.setTimeout(callback1);
|
callbacks.setTimeout(callback1);
|
||||||
callbacks.setTimeout(callback2, -100);
|
callbacks.setTimeout(callback2, -100);
|
||||||
|
|
||||||
expect(callback1).toNotHaveBeenCalled();
|
expect(callback1).not.toHaveBeenCalled();
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
tick(0);
|
tick(0);
|
||||||
expect(callback1).toHaveBeenCalled();
|
expect(callback1).toHaveBeenCalled();
|
||||||
expect(callback2).toHaveBeenCalled();
|
expect(callback2).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not get confused by chained calls", function() {
|
it("should not get confused by chained calls", function() {
|
||||||
const callback2 = expect.createSpy();
|
const callback2 = jest.fn();
|
||||||
const callback1 = expect.createSpy();
|
const callback1 = jest.fn();
|
||||||
callback1.andCall(function() {
|
callback1.mockImplementation(function() {
|
||||||
callbacks.setTimeout(callback2, 0);
|
callbacks.setTimeout(callback2, 0);
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
callbacks.setTimeout(callback1);
|
callbacks.setTimeout(callback1);
|
||||||
expect(callback1).toNotHaveBeenCalled();
|
expect(callback1).not.toHaveBeenCalled();
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
tick(0);
|
tick(0);
|
||||||
expect(callback1).toHaveBeenCalled();
|
expect(callback1).toHaveBeenCalled();
|
||||||
// the fake timer won't actually run callbacks registered during
|
// the fake timer won't actually run callbacks registered during
|
||||||
@@ -140,16 +137,16 @@ describe("realtime-callbacks", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should be immune to exceptions", function() {
|
it("should be immune to exceptions", function() {
|
||||||
const callback1 = expect.createSpy();
|
const callback1 = jest.fn();
|
||||||
callback1.andCall(function() {
|
callback1.mockImplementation(function() {
|
||||||
throw new Error("prepare to die");
|
throw new Error("prepare to die");
|
||||||
});
|
});
|
||||||
const callback2 = expect.createSpy();
|
const callback2 = jest.fn();
|
||||||
callbacks.setTimeout(callback1, 0);
|
callbacks.setTimeout(callback1, 0);
|
||||||
callbacks.setTimeout(callback2, 0);
|
callbacks.setTimeout(callback2, 0);
|
||||||
|
|
||||||
expect(callback1).toNotHaveBeenCalled();
|
expect(callback1).not.toHaveBeenCalled();
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
tick(0);
|
tick(0);
|
||||||
expect(callback1).toHaveBeenCalled();
|
expect(callback1).toHaveBeenCalled();
|
||||||
expect(callback2).toHaveBeenCalled();
|
expect(callback2).toHaveBeenCalled();
|
||||||
@@ -158,16 +155,16 @@ describe("realtime-callbacks", function() {
|
|||||||
|
|
||||||
describe("cancelTimeout", function() {
|
describe("cancelTimeout", function() {
|
||||||
it("should cancel a pending timeout", function() {
|
it("should cancel a pending timeout", function() {
|
||||||
const callback = expect.createSpy();
|
const callback = jest.fn();
|
||||||
const k = callbacks.setTimeout(callback);
|
const k = callbacks.setTimeout(callback);
|
||||||
callbacks.clearTimeout(k);
|
callbacks.clearTimeout(k);
|
||||||
tick(0);
|
tick(0);
|
||||||
expect(callback).toNotHaveBeenCalled();
|
expect(callback).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not affect sooner timeouts", function() {
|
it("should not affect sooner timeouts", function() {
|
||||||
const callback1 = expect.createSpy();
|
const callback1 = jest.fn();
|
||||||
const callback2 = expect.createSpy();
|
const callback2 = jest.fn();
|
||||||
|
|
||||||
callbacks.setTimeout(callback1, 100);
|
callbacks.setTimeout(callback1, 100);
|
||||||
const k = callbacks.setTimeout(callback2, 200);
|
const k = callbacks.setTimeout(callback2, 200);
|
||||||
@@ -175,10 +172,10 @@ describe("realtime-callbacks", function() {
|
|||||||
|
|
||||||
tick(100);
|
tick(100);
|
||||||
expect(callback1).toHaveBeenCalled();
|
expect(callback1).toHaveBeenCalled();
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
|
|
||||||
tick(150);
|
tick(150);
|
||||||
expect(callback2).toNotHaveBeenCalled();
|
expect(callback2).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ const sdk = require("../..");
|
|||||||
const RoomMember = sdk.RoomMember;
|
const RoomMember = sdk.RoomMember;
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("RoomMember", function() {
|
describe("RoomMember", function() {
|
||||||
const roomId = "!foo:bar";
|
const roomId = "!foo:bar";
|
||||||
const userA = "@alice:bar";
|
const userA = "@alice:bar";
|
||||||
@@ -14,7 +12,6 @@ describe("RoomMember", function() {
|
|||||||
let member;
|
let member;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
member = new RoomMember(roomId, userA);
|
member = new RoomMember(roomId, userA);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -36,7 +33,7 @@ describe("RoomMember", function() {
|
|||||||
const url = member.getAvatarUrl(hsUrl);
|
const url = member.getAvatarUrl(hsUrl);
|
||||||
// we don't care about how the mxc->http conversion is done, other
|
// we don't care about how the mxc->http conversion is done, other
|
||||||
// than it contains the mxc body.
|
// than it contains the mxc body.
|
||||||
expect(url.indexOf("flibble/wibble")).toNotEqual(-1);
|
expect(url.indexOf("flibble/wibble")).not.toEqual(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return an identicon HTTP URL if allowDefault was set and there " +
|
it("should return an identicon HTTP URL if allowDefault was set and there " +
|
||||||
@@ -255,9 +252,9 @@ describe("RoomMember", function() {
|
|||||||
member.setMembershipEvent(joinEvent);
|
member.setMembershipEvent(joinEvent);
|
||||||
expect(member.name).toEqual("Alice"); // prefer displayname
|
expect(member.name).toEqual("Alice"); // prefer displayname
|
||||||
member.setMembershipEvent(joinEvent, roomState);
|
member.setMembershipEvent(joinEvent, roomState);
|
||||||
expect(member.name).toNotEqual("Alice"); // it should disambig.
|
expect(member.name).not.toEqual("Alice"); // it should disambig.
|
||||||
// user_id should be there somewhere
|
// user_id should be there somewhere
|
||||||
expect(member.name.indexOf(userA)).toNotEqual(-1);
|
expect(member.name.indexOf(userA)).not.toEqual(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should emit 'RoomMember.membership' if the membership changes", function() {
|
it("should emit 'RoomMember.membership' if the membership changes", function() {
|
||||||
@@ -328,9 +325,9 @@ describe("RoomMember", function() {
|
|||||||
};
|
};
|
||||||
expect(member.name).toEqual(userA); // default = user_id
|
expect(member.name).toEqual(userA); // default = user_id
|
||||||
member.setMembershipEvent(joinEvent, roomState);
|
member.setMembershipEvent(joinEvent, roomState);
|
||||||
expect(member.name).toNotEqual("Alíce"); // it should disambig.
|
expect(member.name).not.toEqual("Alíce"); // it should disambig.
|
||||||
// user_id should be there somewhere
|
// user_id should be there somewhere
|
||||||
expect(member.name.indexOf(userA)).toNotEqual(-1);
|
expect(member.name.indexOf(userA)).not.toEqual(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ const RoomState = sdk.RoomState;
|
|||||||
const RoomMember = sdk.RoomMember;
|
const RoomMember = sdk.RoomMember;
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("RoomState", function() {
|
describe("RoomState", function() {
|
||||||
const roomId = "!foo:bar";
|
const roomId = "!foo:bar";
|
||||||
const userA = "@alice:bar";
|
const userA = "@alice:bar";
|
||||||
@@ -17,7 +15,6 @@ describe("RoomState", function() {
|
|||||||
let state;
|
let state;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
state = new RoomState(roomId);
|
state = new RoomState(roomId);
|
||||||
state.setStateEvents([
|
state.setStateEvents([
|
||||||
utils.mkMembership({ // userA joined
|
utils.mkMembership({ // userA joined
|
||||||
@@ -49,8 +46,8 @@ describe("RoomState", function() {
|
|||||||
const members = state.getMembers();
|
const members = state.getMembers();
|
||||||
expect(members.length).toEqual(2);
|
expect(members.length).toEqual(2);
|
||||||
// ordering unimportant
|
// ordering unimportant
|
||||||
expect([userA, userB].indexOf(members[0].userId)).toNotEqual(-1);
|
expect([userA, userB].indexOf(members[0].userId)).not.toEqual(-1);
|
||||||
expect([userA, userB].indexOf(members[1].userId)).toNotEqual(-1);
|
expect([userA, userB].indexOf(members[1].userId)).not.toEqual(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -120,8 +117,8 @@ describe("RoomState", function() {
|
|||||||
const events = state.getStateEvents("m.room.member");
|
const events = state.getStateEvents("m.room.member");
|
||||||
expect(events.length).toEqual(2);
|
expect(events.length).toEqual(2);
|
||||||
// ordering unimportant
|
// ordering unimportant
|
||||||
expect([userA, userB].indexOf(events[0].getStateKey())).toNotEqual(-1);
|
expect([userA, userB].indexOf(events[0].getStateKey())).not.toEqual(-1);
|
||||||
expect([userA, userB].indexOf(events[1].getStateKey())).toNotEqual(-1);
|
expect([userA, userB].indexOf(events[1].getStateKey())).not.toEqual(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return a single MatrixEvent if a state_key was specified",
|
it("should return a single MatrixEvent if a state_key was specified",
|
||||||
@@ -258,7 +255,7 @@ describe("RoomState", function() {
|
|||||||
});
|
});
|
||||||
state.setStateEvents([memberEvent]);
|
state.setStateEvents([memberEvent]);
|
||||||
|
|
||||||
expect(state.members[userA].setMembershipEvent).toNotHaveBeenCalled();
|
expect(state.members[userA].setMembershipEvent).not.toHaveBeenCalled();
|
||||||
expect(state.members[userB].setMembershipEvent).toHaveBeenCalledWith(
|
expect(state.members[userB].setMembershipEvent).toHaveBeenCalledWith(
|
||||||
memberEvent, state,
|
memberEvent, state,
|
||||||
);
|
);
|
||||||
@@ -306,7 +303,7 @@ describe("RoomState", function() {
|
|||||||
state.markOutOfBandMembersStarted();
|
state.markOutOfBandMembersStarted();
|
||||||
state.setOutOfBandMembers([oobMemberEvent]);
|
state.setOutOfBandMembers([oobMemberEvent]);
|
||||||
const memberA = state.getMember(userA);
|
const memberA = state.getMember(userA);
|
||||||
expect(memberA.events.member.getId()).toNotEqual(oobMemberEvent.getId());
|
expect(memberA.events.member.getId()).not.toEqual(oobMemberEvent.getId());
|
||||||
expect(memberA.isOutOfBand()).toEqual(false);
|
expect(memberA.isOutOfBand()).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ const EventStatus = sdk.EventStatus;
|
|||||||
const EventTimeline = sdk.EventTimeline;
|
const EventTimeline = sdk.EventTimeline;
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("Room", function() {
|
describe("Room", function() {
|
||||||
const roomId = "!foo:bar";
|
const roomId = "!foo:bar";
|
||||||
const userA = "@alice:bar";
|
const userA = "@alice:bar";
|
||||||
@@ -19,7 +17,6 @@ describe("Room", function() {
|
|||||||
let room;
|
let room;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
room = new Room(roomId);
|
room = new Room(roomId);
|
||||||
// mock RoomStates
|
// mock RoomStates
|
||||||
room.oldState = room.getLiveTimeline()._startState =
|
room.oldState = room.getLiveTimeline()._startState =
|
||||||
@@ -32,7 +29,7 @@ describe("Room", function() {
|
|||||||
const hsUrl = "https://my.home.server";
|
const hsUrl = "https://my.home.server";
|
||||||
|
|
||||||
it("should return the URL from m.room.avatar preferentially", function() {
|
it("should return the URL from m.room.avatar preferentially", function() {
|
||||||
room.currentState.getStateEvents.andCall(function(type, key) {
|
room.currentState.getStateEvents.mockImplementation(function(type, key) {
|
||||||
if (type === "m.room.avatar" && key === "") {
|
if (type === "m.room.avatar" && key === "") {
|
||||||
return utils.mkEvent({
|
return utils.mkEvent({
|
||||||
event: true,
|
event: true,
|
||||||
@@ -49,7 +46,7 @@ describe("Room", function() {
|
|||||||
const url = room.getAvatarUrl(hsUrl);
|
const url = room.getAvatarUrl(hsUrl);
|
||||||
// we don't care about how the mxc->http conversion is done, other
|
// we don't care about how the mxc->http conversion is done, other
|
||||||
// than it contains the mxc body.
|
// than it contains the mxc body.
|
||||||
expect(url.indexOf("flibble/wibble")).toNotEqual(-1);
|
expect(url.indexOf("flibble/wibble")).not.toEqual(-1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return an identicon HTTP URL if allowDefault was set and there " +
|
it("should return an identicon HTTP URL if allowDefault was set and there " +
|
||||||
@@ -67,13 +64,13 @@ describe("Room", function() {
|
|||||||
|
|
||||||
describe("getMember", function() {
|
describe("getMember", function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
room.currentState.getMember.andCall(function(userId) {
|
room.currentState.getMember.mockImplementation(function(userId) {
|
||||||
return {
|
return {
|
||||||
"@alice:bar": {
|
"@alice:bar": {
|
||||||
userId: userA,
|
userId: userA,
|
||||||
roomId: roomId,
|
roomId: roomId,
|
||||||
},
|
},
|
||||||
}[userId];
|
}[userId] || null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -82,7 +79,7 @@ describe("Room", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return the member from current state", function() {
|
it("should return the member from current state", function() {
|
||||||
expect(room.getMember(userA)).toNotEqual(null);
|
expect(room.getMember(userA)).not.toEqual(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -174,7 +171,7 @@ describe("Room", function() {
|
|||||||
);
|
);
|
||||||
expect(events[0].forwardLooking).toBe(true);
|
expect(events[0].forwardLooking).toBe(true);
|
||||||
expect(events[1].forwardLooking).toBe(true);
|
expect(events[1].forwardLooking).toBe(true);
|
||||||
expect(room.oldState.setStateEvents).toNotHaveBeenCalled();
|
expect(room.oldState.setStateEvents).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should synthesize read receipts for the senders of events", function() {
|
it("should synthesize read receipts for the senders of events", function() {
|
||||||
@@ -183,7 +180,7 @@ describe("Room", function() {
|
|||||||
membership: "join",
|
membership: "join",
|
||||||
name: "Alice",
|
name: "Alice",
|
||||||
};
|
};
|
||||||
room.currentState.getSentinelMember.andCall(function(uid) {
|
room.currentState.getSentinelMember.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return sentinel;
|
return sentinel;
|
||||||
}
|
}
|
||||||
@@ -292,13 +289,13 @@ describe("Room", function() {
|
|||||||
membership: "join",
|
membership: "join",
|
||||||
name: "Old Alice",
|
name: "Old Alice",
|
||||||
};
|
};
|
||||||
room.currentState.getSentinelMember.andCall(function(uid) {
|
room.currentState.getSentinelMember.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return sentinel;
|
return sentinel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
room.oldState.getSentinelMember.andCall(function(uid) {
|
room.oldState.getSentinelMember.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return oldSentinel;
|
return oldSentinel;
|
||||||
}
|
}
|
||||||
@@ -331,13 +328,13 @@ describe("Room", function() {
|
|||||||
membership: "join",
|
membership: "join",
|
||||||
name: "Old Alice",
|
name: "Old Alice",
|
||||||
};
|
};
|
||||||
room.currentState.getSentinelMember.andCall(function(uid) {
|
room.currentState.getSentinelMember.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return sentinel;
|
return sentinel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
room.oldState.getSentinelMember.andCall(function(uid) {
|
room.oldState.getSentinelMember.mockImplementation(function(uid) {
|
||||||
if (uid === userA) {
|
if (uid === userA) {
|
||||||
return oldSentinel;
|
return oldSentinel;
|
||||||
}
|
}
|
||||||
@@ -379,7 +376,7 @@ describe("Room", function() {
|
|||||||
);
|
);
|
||||||
expect(events[0].forwardLooking).toBe(false);
|
expect(events[0].forwardLooking).toBe(false);
|
||||||
expect(events[1].forwardLooking).toBe(false);
|
expect(events[1].forwardLooking).toBe(false);
|
||||||
expect(room.currentState.setStateEvents).toNotHaveBeenCalled();
|
expect(room.currentState.setStateEvents).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -545,7 +542,7 @@ describe("Room", function() {
|
|||||||
|
|
||||||
describe("getJoinedMembers", function() {
|
describe("getJoinedMembers", function() {
|
||||||
it("should return members whose membership is 'join'", function() {
|
it("should return members whose membership is 'join'", function() {
|
||||||
room.currentState.getMembers.andCall(function() {
|
room.currentState.getMembers.mockImplementation(function() {
|
||||||
return [
|
return [
|
||||||
{ userId: "@alice:bar", membership: "join" },
|
{ userId: "@alice:bar", membership: "join" },
|
||||||
{ userId: "@bob:bar", membership: "invite" },
|
{ userId: "@bob:bar", membership: "invite" },
|
||||||
@@ -558,7 +555,7 @@ describe("Room", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return an empty list if no membership is 'join'", function() {
|
it("should return an empty list if no membership is 'join'", function() {
|
||||||
room.currentState.getMembers.andCall(function() {
|
room.currentState.getMembers.mockImplementation(function() {
|
||||||
return [
|
return [
|
||||||
{ userId: "@bob:bar", membership: "invite" },
|
{ userId: "@bob:bar", membership: "invite" },
|
||||||
];
|
];
|
||||||
@@ -571,7 +568,7 @@ describe("Room", function() {
|
|||||||
describe("hasMembershipState", function() {
|
describe("hasMembershipState", function() {
|
||||||
it("should return true for a matching userId and membership",
|
it("should return true for a matching userId and membership",
|
||||||
function() {
|
function() {
|
||||||
room.currentState.getMember.andCall(function(userId) {
|
room.currentState.getMember.mockImplementation(function(userId) {
|
||||||
return {
|
return {
|
||||||
"@alice:bar": { userId: "@alice:bar", membership: "join" },
|
"@alice:bar": { userId: "@alice:bar", membership: "join" },
|
||||||
"@bob:bar": { userId: "@bob:bar", membership: "invite" },
|
"@bob:bar": { userId: "@bob:bar", membership: "invite" },
|
||||||
@@ -582,7 +579,7 @@ describe("Room", function() {
|
|||||||
|
|
||||||
it("should return false if match membership but no match userId",
|
it("should return false if match membership but no match userId",
|
||||||
function() {
|
function() {
|
||||||
room.currentState.getMember.andCall(function(userId) {
|
room.currentState.getMember.mockImplementation(function(userId) {
|
||||||
return {
|
return {
|
||||||
"@alice:bar": { userId: "@alice:bar", membership: "join" },
|
"@alice:bar": { userId: "@alice:bar", membership: "join" },
|
||||||
}[userId];
|
}[userId];
|
||||||
@@ -592,7 +589,7 @@ describe("Room", function() {
|
|||||||
|
|
||||||
it("should return false if match userId but no match membership",
|
it("should return false if match userId but no match membership",
|
||||||
function() {
|
function() {
|
||||||
room.currentState.getMember.andCall(function(userId) {
|
room.currentState.getMember.mockImplementation(function(userId) {
|
||||||
return {
|
return {
|
||||||
"@alice:bar": { userId: "@alice:bar", membership: "join" },
|
"@alice:bar": { userId: "@alice:bar", membership: "join" },
|
||||||
}[userId];
|
}[userId];
|
||||||
@@ -602,7 +599,7 @@ describe("Room", function() {
|
|||||||
|
|
||||||
it("should return false if no match membership or userId",
|
it("should return false if no match membership or userId",
|
||||||
function() {
|
function() {
|
||||||
room.currentState.getMember.andCall(function(userId) {
|
room.currentState.getMember.mockImplementation(function(userId) {
|
||||||
return {
|
return {
|
||||||
"@alice:bar": { userId: "@alice:bar", membership: "join" },
|
"@alice:bar": { userId: "@alice:bar", membership: "join" },
|
||||||
}[userId];
|
}[userId];
|
||||||
@@ -814,8 +811,8 @@ describe("Room", function() {
|
|||||||
addMember(userC);
|
addMember(userC);
|
||||||
room.recalculate();
|
room.recalculate();
|
||||||
const name = room.name;
|
const name = room.name;
|
||||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||||
expect(name.indexOf(userC)).toNotEqual(-1, name);
|
expect(name.indexOf(userC)).not.toEqual(-1, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return the names of members in a public (public join_rules)" +
|
it("should return the names of members in a public (public join_rules)" +
|
||||||
@@ -827,8 +824,8 @@ describe("Room", function() {
|
|||||||
addMember(userC);
|
addMember(userC);
|
||||||
room.recalculate();
|
room.recalculate();
|
||||||
const name = room.name;
|
const name = room.name;
|
||||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||||
expect(name.indexOf(userC)).toNotEqual(-1, name);
|
expect(name.indexOf(userC)).not.toEqual(-1, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show the other user's name for public (public join_rules)" +
|
it("should show the other user's name for public (public join_rules)" +
|
||||||
@@ -839,7 +836,7 @@ describe("Room", function() {
|
|||||||
addMember(userB);
|
addMember(userB);
|
||||||
room.recalculate();
|
room.recalculate();
|
||||||
const name = room.name;
|
const name = room.name;
|
||||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show the other user's name for private " +
|
it("should show the other user's name for private " +
|
||||||
@@ -850,7 +847,7 @@ describe("Room", function() {
|
|||||||
addMember(userB);
|
addMember(userB);
|
||||||
room.recalculate();
|
room.recalculate();
|
||||||
const name = room.name;
|
const name = room.name;
|
||||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show the other user's name for private" +
|
it("should show the other user's name for private" +
|
||||||
@@ -860,7 +857,7 @@ describe("Room", function() {
|
|||||||
addMember(userB);
|
addMember(userB);
|
||||||
room.recalculate();
|
room.recalculate();
|
||||||
const name = room.name;
|
const name = room.name;
|
||||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show the room alias if one exists for private " +
|
it("should show the room alias if one exists for private " +
|
||||||
@@ -1004,7 +1001,7 @@ describe("Room", function() {
|
|||||||
|
|
||||||
it("should emit an event when a receipt is added",
|
it("should emit an event when a receipt is added",
|
||||||
function() {
|
function() {
|
||||||
const listener = expect.createSpy();
|
const listener = jest.fn();
|
||||||
room.on("Room.receipt", listener);
|
room.on("Room.receipt", listener);
|
||||||
|
|
||||||
const ts = 13787898424;
|
const ts = 13787898424;
|
||||||
@@ -1175,7 +1172,7 @@ describe("Room", function() {
|
|||||||
it("should emit Room.tags event when new tags are " +
|
it("should emit Room.tags event when new tags are " +
|
||||||
"received on the event stream",
|
"received on the event stream",
|
||||||
function() {
|
function() {
|
||||||
const listener = expect.createSpy();
|
const listener = jest.fn();
|
||||||
room.on("Room.tags", listener);
|
room.on("Room.tags", listener);
|
||||||
|
|
||||||
const tags = { "m.foo": { "order": 0.5 } };
|
const tags = { "m.foo": { "order": 0.5 } };
|
||||||
|
|||||||
@@ -8,11 +8,9 @@ const MatrixScheduler = sdk.MatrixScheduler;
|
|||||||
const MatrixError = sdk.MatrixError;
|
const MatrixError = sdk.MatrixError;
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import expect from 'expect';
|
jest.useFakeTimers();
|
||||||
import lolex from 'lolex';
|
|
||||||
|
|
||||||
describe("MatrixScheduler", function() {
|
describe("MatrixScheduler", function() {
|
||||||
let clock;
|
|
||||||
let scheduler;
|
let scheduler;
|
||||||
let retryFn;
|
let retryFn;
|
||||||
let queueFn;
|
let queueFn;
|
||||||
@@ -26,8 +24,6 @@ describe("MatrixScheduler", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
clock = lolex.install();
|
|
||||||
scheduler = new MatrixScheduler(function(ev, attempts, err) {
|
scheduler = new MatrixScheduler(function(ev, attempts, err) {
|
||||||
if (retryFn) {
|
if (retryFn) {
|
||||||
return retryFn(ev, attempts, err);
|
return retryFn(ev, attempts, err);
|
||||||
@@ -44,10 +40,6 @@ describe("MatrixScheduler", function() {
|
|||||||
defer = Promise.defer();
|
defer = Promise.defer();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
|
||||||
clock.uninstall();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should process events in a queue in a FIFO manner", async function() {
|
it("should process events in a queue in a FIFO manner", async function() {
|
||||||
retryFn = function() {
|
retryFn = function() {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -112,7 +104,7 @@ describe("MatrixScheduler", function() {
|
|||||||
defer.reject({});
|
defer.reject({});
|
||||||
await retryDefer.promise;
|
await retryDefer.promise;
|
||||||
expect(procCount).toEqual(1);
|
expect(procCount).toEqual(1);
|
||||||
clock.tick(waitTimeMs);
|
jest.advanceTimersByTime(waitTimeMs);
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
expect(procCount).toEqual(2);
|
expect(procCount).toEqual(2);
|
||||||
});
|
});
|
||||||
@@ -203,7 +195,7 @@ describe("MatrixScheduler", function() {
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
deferA.resolve({});
|
deferA.resolve({});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
clock.tick(1000);
|
jest.advanceTimersByTime(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("queueEvent", function() {
|
describe("queueEvent", function() {
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
import utils from "../test-utils";
|
|
||||||
import sdk from "../..";
|
import sdk from "../..";
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
const SyncAccumulator = sdk.SyncAccumulator;
|
const SyncAccumulator = sdk.SyncAccumulator;
|
||||||
|
|
||||||
@@ -26,7 +24,6 @@ describe("SyncAccumulator", function() {
|
|||||||
let sa;
|
let sa;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
sa = new SyncAccumulator({
|
sa = new SyncAccumulator({
|
||||||
maxTimelineEntries: 10,
|
maxTimelineEntries: 10,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const TimelineWindow = sdk.TimelineWindow;
|
|||||||
const TimelineIndex = require("../../lib/timeline-window").TimelineIndex;
|
const TimelineIndex = require("../../lib/timeline-window").TimelineIndex;
|
||||||
|
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
const ROOM_ID = "roomId";
|
const ROOM_ID = "roomId";
|
||||||
const USER_ID = "userId";
|
const USER_ID = "userId";
|
||||||
@@ -67,10 +66,6 @@ function createLinkedTimelines() {
|
|||||||
|
|
||||||
|
|
||||||
describe("TimelineIndex", function() {
|
describe("TimelineIndex", function() {
|
||||||
beforeEach(function() {
|
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("minIndex", function() {
|
describe("minIndex", function() {
|
||||||
it("should return the min index relative to BaseIndex", function() {
|
it("should return the min index relative to BaseIndex", function() {
|
||||||
const timelineIndex = new TimelineIndex(createTimeline(), 0);
|
const timelineIndex = new TimelineIndex(createTimeline(), 0);
|
||||||
@@ -163,10 +158,6 @@ describe("TimelineWindow", function() {
|
|||||||
return new TimelineWindow(client, timelineSet, opts);
|
return new TimelineWindow(client, timelineSet, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("load", function() {
|
describe("load", function() {
|
||||||
it("should initialise from the live timeline", function(done) {
|
it("should initialise from the live timeline", function(done) {
|
||||||
const liveTimeline = createTimeline();
|
const liveTimeline = createTimeline();
|
||||||
|
|||||||
@@ -4,14 +4,11 @@ const sdk = require("../..");
|
|||||||
const User = sdk.User;
|
const User = sdk.User;
|
||||||
const utils = require("../test-utils");
|
const utils = require("../test-utils");
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("User", function() {
|
describe("User", function() {
|
||||||
const userId = "@alice:bar";
|
const userId = "@alice:bar";
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
user = new User(userId);
|
user = new User(userId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import 'source-map-support/register';
|
import 'source-map-support/register';
|
||||||
const utils = require("../../lib/utils");
|
const utils = require("../../lib/utils");
|
||||||
const testUtils = require("../test-utils");
|
|
||||||
|
|
||||||
import expect from 'expect';
|
|
||||||
|
|
||||||
describe("utils", function() {
|
describe("utils", function() {
|
||||||
beforeEach(function() {
|
|
||||||
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("encodeParams", function() {
|
describe("encodeParams", function() {
|
||||||
it("should url encode and concat with &s", function() {
|
it("should url encode and concat with &s", function() {
|
||||||
const params = {
|
const params = {
|
||||||
@@ -135,7 +128,7 @@ describe("utils", function() {
|
|||||||
utils.checkObjectHasKeys({
|
utils.checkObjectHasKeys({
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
}, ["foo"]);
|
}, ["foo"]);
|
||||||
}).toNotThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -152,7 +145,7 @@ describe("utils", function() {
|
|||||||
utils.checkObjectHasNoAdditionalKeys({
|
utils.checkObjectHasNoAdditionalKeys({
|
||||||
foo: "bar",
|
foo: "bar",
|
||||||
}, ["foo"]);
|
}, ["foo"]);
|
||||||
}).toNotThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -895,7 +895,7 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline,
|
|||||||
* @return {RoomMember} The member or <code>null</code>.
|
* @return {RoomMember} The member or <code>null</code>.
|
||||||
*/
|
*/
|
||||||
Room.prototype.getMember = function(userId) {
|
Room.prototype.getMember = function(userId) {
|
||||||
return this.currentState.getMember(userId);
|
return this.currentState.getMember(userId);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -903,7 +903,7 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline,
|
|||||||
* @return {RoomMember[]} A list of currently joined members.
|
* @return {RoomMember[]} A list of currently joined members.
|
||||||
*/
|
*/
|
||||||
Room.prototype.getJoinedMembers = function() {
|
Room.prototype.getJoinedMembers = function() {
|
||||||
return this.getMembersWithMembership("join");
|
return this.getMembersWithMembership("join");
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user