You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Review comments
This commit is contained in:
@ -542,6 +542,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
|
|
||||||
describe("ExtensionE2EE", () => {
|
describe("ExtensionE2EE", () => {
|
||||||
let ext: Extension;
|
let ext: Extension;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await setupClient({
|
await setupClient({
|
||||||
withCrypto: true,
|
withCrypto: true,
|
||||||
@ -551,18 +552,21 @@ describe("SlidingSyncSdk", () => {
|
|||||||
await hasSynced;
|
await hasSynced;
|
||||||
ext = findExtension("e2ee");
|
ext = findExtension("e2ee");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
// needed else we do some async operations in the background which can cause Jest to whine:
|
// needed else we do some async operations in the background which can cause Jest to whine:
|
||||||
// "Cannot log after tests are done. Did you forget to wait for something async in your test?"
|
// "Cannot log after tests are done. Did you forget to wait for something async in your test?"
|
||||||
// Attempted to log "Saving device tracking data null"."
|
// Attempted to log "Saving device tracking data null"."
|
||||||
client!.crypto!.stop();
|
client!.crypto!.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("gets enabled on the initial request only", () => {
|
it("gets enabled on the initial request only", () => {
|
||||||
expect(ext.onRequest(true)).toEqual({
|
expect(ext.onRequest(true)).toEqual({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
});
|
});
|
||||||
expect(ext.onRequest(false)).toEqual(undefined);
|
expect(ext.onRequest(false)).toEqual(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can update device lists", () => {
|
it("can update device lists", () => {
|
||||||
ext.onResponse({
|
ext.onResponse({
|
||||||
device_lists: {
|
device_lists: {
|
||||||
@ -572,6 +576,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
});
|
});
|
||||||
// TODO: more assertions?
|
// TODO: more assertions?
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can update OTK counts", () => {
|
it("can update OTK counts", () => {
|
||||||
client!.crypto!.updateOneTimeKeyCount = jest.fn();
|
client!.crypto!.updateOneTimeKeyCount = jest.fn();
|
||||||
ext.onResponse({
|
ext.onResponse({
|
||||||
@ -588,6 +593,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
});
|
});
|
||||||
expect(client!.crypto!.updateOneTimeKeyCount).toHaveBeenCalledWith(0);
|
expect(client!.crypto!.updateOneTimeKeyCount).toHaveBeenCalledWith(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can update fallback keys", () => {
|
it("can update fallback keys", () => {
|
||||||
ext.onResponse({
|
ext.onResponse({
|
||||||
device_unused_fallback_key_types: ["signed_curve25519"],
|
device_unused_fallback_key_types: ["signed_curve25519"],
|
||||||
@ -599,8 +605,10 @@ describe("SlidingSyncSdk", () => {
|
|||||||
expect(client!.crypto!.getNeedsNewFallback()).toEqual(true);
|
expect(client!.crypto!.getNeedsNewFallback()).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("ExtensionAccountData", () => {
|
describe("ExtensionAccountData", () => {
|
||||||
let ext: Extension;
|
let ext: Extension;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await setupClient();
|
await setupClient();
|
||||||
const hasSynced = sdk!.sync();
|
const hasSynced = sdk!.sync();
|
||||||
@ -608,12 +616,14 @@ describe("SlidingSyncSdk", () => {
|
|||||||
await hasSynced;
|
await hasSynced;
|
||||||
ext = findExtension("account_data");
|
ext = findExtension("account_data");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("gets enabled on the initial request only", () => {
|
it("gets enabled on the initial request only", () => {
|
||||||
expect(ext.onRequest(true)).toEqual({
|
expect(ext.onRequest(true)).toEqual({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
});
|
});
|
||||||
expect(ext.onRequest(false)).toEqual(undefined);
|
expect(ext.onRequest(false)).toEqual(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("processes global account data", async () => {
|
it("processes global account data", async () => {
|
||||||
const globalType = "global_test";
|
const globalType = "global_test";
|
||||||
const globalContent = {
|
const globalContent = {
|
||||||
@ -633,6 +643,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
expect(globalData).toBeDefined();
|
expect(globalData).toBeDefined();
|
||||||
expect(globalData.getContent()).toEqual(globalContent);
|
expect(globalData.getContent()).toEqual(globalContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("processes rooms account data", async () => {
|
it("processes rooms account data", async () => {
|
||||||
const roomId = "!room:id";
|
const roomId = "!room:id";
|
||||||
mockSlidingSync!.emit(SlidingSyncEvent.RoomData, roomId, {
|
mockSlidingSync!.emit(SlidingSyncEvent.RoomData, roomId, {
|
||||||
@ -667,6 +678,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
expect(event).toBeDefined();
|
expect(event).toBeDefined();
|
||||||
expect(event.getContent()).toEqual(roomContent);
|
expect(event.getContent()).toEqual(roomContent);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("doesn't crash for unknown room account data", async () => {
|
it("doesn't crash for unknown room account data", async () => {
|
||||||
const unknownRoomId = "!unknown:id";
|
const unknownRoomId = "!unknown:id";
|
||||||
const roomType = "tester";
|
const roomType = "tester";
|
||||||
@ -686,6 +698,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
expect(room).toBeNull();
|
expect(room).toBeNull();
|
||||||
expect(client!.getAccountData(roomType)).toBeUndefined();
|
expect(client!.getAccountData(roomType)).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can update push rules via account data", async () => {
|
it("can update push rules via account data", async () => {
|
||||||
const roomId = "!foo:bar";
|
const roomId = "!foo:bar";
|
||||||
const pushRulesContent: IPushRules = {
|
const pushRulesContent: IPushRules = {
|
||||||
@ -718,8 +731,10 @@ describe("SlidingSyncSdk", () => {
|
|||||||
expect(pushRule).toEqual(pushRulesContent.global[PushRuleKind.RoomSpecific]![0]);
|
expect(pushRule).toEqual(pushRulesContent.global[PushRuleKind.RoomSpecific]![0]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("ExtensionToDevice", () => {
|
describe("ExtensionToDevice", () => {
|
||||||
let ext: Extension;
|
let ext: Extension;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await setupClient();
|
await setupClient();
|
||||||
const hasSynced = sdk!.sync();
|
const hasSynced = sdk!.sync();
|
||||||
@ -727,12 +742,14 @@ describe("SlidingSyncSdk", () => {
|
|||||||
await hasSynced;
|
await hasSynced;
|
||||||
ext = findExtension("to_device");
|
ext = findExtension("to_device");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("gets enabled with a limit on the initial request only", () => {
|
it("gets enabled with a limit on the initial request only", () => {
|
||||||
const reqJson: any = ext.onRequest(true);
|
const reqJson: any = ext.onRequest(true);
|
||||||
expect(reqJson.enabled).toEqual(true);
|
expect(reqJson.enabled).toEqual(true);
|
||||||
expect(reqJson.limit).toBeGreaterThan(0);
|
expect(reqJson.limit).toBeGreaterThan(0);
|
||||||
expect(reqJson.since).toBeUndefined();
|
expect(reqJson.since).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("updates the since value", async () => {
|
it("updates the since value", async () => {
|
||||||
ext.onResponse({
|
ext.onResponse({
|
||||||
next_batch: "12345",
|
next_batch: "12345",
|
||||||
@ -742,12 +759,14 @@ describe("SlidingSyncSdk", () => {
|
|||||||
since: "12345",
|
since: "12345",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can handle missing fields", async () => {
|
it("can handle missing fields", async () => {
|
||||||
ext.onResponse({
|
ext.onResponse({
|
||||||
next_batch: "23456",
|
next_batch: "23456",
|
||||||
// no events array
|
// no events array
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("emits to-device events on the client", async () => {
|
it("emits to-device events on the client", async () => {
|
||||||
const toDeviceType = "custom_test";
|
const toDeviceType = "custom_test";
|
||||||
const toDeviceContent = {
|
const toDeviceContent = {
|
||||||
@ -770,6 +789,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
});
|
});
|
||||||
expect(called).toBe(true);
|
expect(called).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can cancel key verification requests", async () => {
|
it("can cancel key verification requests", async () => {
|
||||||
const seen: Record<string, boolean> = {};
|
const seen: Record<string, boolean> = {};
|
||||||
client!.on(ClientEvent.ToDeviceEvent, (ev) => {
|
client!.on(ClientEvent.ToDeviceEvent, (ev) => {
|
||||||
@ -809,8 +829,10 @@ describe("SlidingSyncSdk", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("ExtensionTyping", () => {
|
describe("ExtensionTyping", () => {
|
||||||
let ext: Extension;
|
let ext: Extension;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await setupClient();
|
await setupClient();
|
||||||
const hasSynced = sdk!.sync();
|
const hasSynced = sdk!.sync();
|
||||||
@ -818,12 +840,14 @@ describe("SlidingSyncSdk", () => {
|
|||||||
await hasSynced;
|
await hasSynced;
|
||||||
ext = findExtension("typing");
|
ext = findExtension("typing");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("gets enabled on the initial request only", () => {
|
it("gets enabled on the initial request only", () => {
|
||||||
expect(ext.onRequest(true)).toEqual({
|
expect(ext.onRequest(true)).toEqual({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
});
|
});
|
||||||
expect(ext.onRequest(false)).toEqual(undefined);
|
expect(ext.onRequest(false)).toEqual(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("processes typing notifications", async () => {
|
it("processes typing notifications", async () => {
|
||||||
const roomId = "!room:id";
|
const roomId = "!room:id";
|
||||||
mockSlidingSync!.emit(SlidingSyncEvent.RoomData, roomId, {
|
mockSlidingSync!.emit(SlidingSyncEvent.RoomData, roomId, {
|
||||||
@ -867,6 +891,7 @@ describe("SlidingSyncSdk", () => {
|
|||||||
});
|
});
|
||||||
expect(room.getMember(selfUserId)?.typing).toEqual(false);
|
expect(room.getMember(selfUserId)?.typing).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("gracefully handles missing rooms and members when typing", async () => {
|
it("gracefully handles missing rooms and members when typing", async () => {
|
||||||
const roomId = "!room:id";
|
const roomId = "!room:id";
|
||||||
mockSlidingSync!.emit(SlidingSyncEvent.RoomData, roomId, {
|
mockSlidingSync!.emit(SlidingSyncEvent.RoomData, roomId, {
|
||||||
|
Reference in New Issue
Block a user