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
de-lint
This commit is contained in:
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {NamespacedValue, UnstableValue} from "../../src/NamespacedValue";
|
import { NamespacedValue, UnstableValue } from "../../src/NamespacedValue";
|
||||||
|
|
||||||
describe("NamespacedValue", () => {
|
describe("NamespacedValue", () => {
|
||||||
it("should prefer stable over unstable", () => {
|
it("should prefer stable over unstable", () => {
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
import { logger } from "../../src/logger";
|
import { logger } from "../../src/logger";
|
||||||
import { MatrixClient } from "../../src/client";
|
import { MatrixClient } from "../../src/client";
|
||||||
import { Filter } from "../../src/filter";
|
import { Filter } from "../../src/filter";
|
||||||
import {DEFAULT_TREE_POWER_LEVELS_TEMPLATE} from "../../src/models/MSC3089TreeSpace";
|
import { DEFAULT_TREE_POWER_LEVELS_TEMPLATE } from "../../src/models/MSC3089TreeSpace";
|
||||||
import {
|
import {
|
||||||
EventType,
|
EventType,
|
||||||
RoomCreateTypeField, RoomType,
|
RoomCreateTypeField,
|
||||||
|
RoomType,
|
||||||
UNSTABLE_MSC3088_ENABLED,
|
UNSTABLE_MSC3088_ENABLED,
|
||||||
UNSTABLE_MSC3088_PURPOSE,
|
UNSTABLE_MSC3088_PURPOSE,
|
||||||
UNSTABLE_MSC3089_TREE_SUBTYPE
|
UNSTABLE_MSC3089_TREE_SUBTYPE,
|
||||||
} from "../../src/@types/event";
|
} from "../../src/@types/event";
|
||||||
import {MEGOLM_ALGORITHM} from "../../src/crypto/olmlib";
|
import { MEGOLM_ALGORITHM } from "../../src/crypto/olmlib";
|
||||||
import {MatrixEvent} from "../../src/models/event";
|
import { MatrixEvent } from "../../src/models/event";
|
||||||
|
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
|
|
||||||
@ -217,7 +218,7 @@ describe("MatrixClient", function() {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
return {room_id: roomId};
|
return { room_id: roomId };
|
||||||
});
|
});
|
||||||
client.getUserId = () => userId;
|
client.getUserId = () => userId;
|
||||||
client.createRoom = fn;
|
client.createRoom = fn;
|
||||||
|
@ -70,15 +70,16 @@ describe("MSC3089Branch", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to delete the file', async () => {
|
it('should be able to delete the file', async () => {
|
||||||
const stateFn = jest.fn().mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
const stateFn = jest.fn()
|
||||||
expect(roomId).toEqual(branchRoomId);
|
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
||||||
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
|
expect(roomId).toEqual(branchRoomId);
|
||||||
expect(content).toMatchObject({});
|
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
|
||||||
expect(content['active']).toBeUndefined();
|
expect(content).toMatchObject({});
|
||||||
expect(stateKey).toEqual(fileEventId);
|
expect(content['active']).toBeUndefined();
|
||||||
|
expect(stateKey).toEqual(fileEventId);
|
||||||
|
|
||||||
return Promise.resolve(); // return value not used
|
return Promise.resolve(); // return value not used
|
||||||
});
|
});
|
||||||
client.sendStateEvent = stateFn;
|
client.sendStateEvent = stateFn;
|
||||||
|
|
||||||
const redactFn = jest.fn().mockImplementation((roomId: string, eventId: string) => {
|
const redactFn = jest.fn().mockImplementation((roomId: string, eventId: string) => {
|
||||||
@ -107,18 +108,19 @@ describe("MSC3089Branch", () => {
|
|||||||
it('should be able to change its name', async () => {
|
it('should be able to change its name', async () => {
|
||||||
const name = "My File.txt";
|
const name = "My File.txt";
|
||||||
indexEvent.getContent = () => ({ active: true, retained: true });
|
indexEvent.getContent = () => ({ active: true, retained: true });
|
||||||
const stateFn = jest.fn().mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
const stateFn = jest.fn()
|
||||||
expect(roomId).toEqual(branchRoomId);
|
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
||||||
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
|
expect(roomId).toEqual(branchRoomId);
|
||||||
expect(content).toMatchObject({
|
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test that we're definitely using the unstable value
|
||||||
retained: true, // canary for copying state
|
expect(content).toMatchObject({
|
||||||
active: true,
|
retained: true, // canary for copying state
|
||||||
name: name,
|
active: true,
|
||||||
});
|
name: name,
|
||||||
expect(stateKey).toEqual(fileEventId);
|
});
|
||||||
|
expect(stateKey).toEqual(fileEventId);
|
||||||
|
|
||||||
return Promise.resolve(); // return value not used
|
return Promise.resolve(); // return value not used
|
||||||
});
|
});
|
||||||
client.sendStateEvent = stateFn;
|
client.sendStateEvent = stateFn;
|
||||||
|
|
||||||
await branch.setName(name);
|
await branch.setName(name);
|
||||||
|
@ -83,13 +83,14 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
|
|
||||||
it('should support setting the name of the space', async () => {
|
it('should support setting the name of the space', async () => {
|
||||||
const newName = "NEW NAME";
|
const newName = "NEW NAME";
|
||||||
const fn = jest.fn().mockImplementation((stateRoomId: string, eventType: EventType, content: any, stateKey: string) => {
|
const fn = jest.fn()
|
||||||
expect(stateRoomId).toEqual(roomId);
|
.mockImplementation((stateRoomId: string, eventType: EventType, content: any, stateKey: string) => {
|
||||||
expect(eventType).toEqual(EventType.RoomName);
|
expect(stateRoomId).toEqual(roomId);
|
||||||
expect(stateKey).toEqual("");
|
expect(eventType).toEqual(EventType.RoomName);
|
||||||
expect(content).toMatchObject({ name: newName });
|
expect(stateKey).toEqual("");
|
||||||
return Promise.resolve();
|
expect(content).toMatchObject({ name: newName });
|
||||||
});
|
return Promise.resolve();
|
||||||
|
});
|
||||||
client.sendStateEvent = fn;
|
client.sendStateEvent = fn;
|
||||||
await tree.setName(newName);
|
await tree.setName(newName);
|
||||||
expect(fn.mock.calls.length).toBe(1);
|
expect(fn.mock.calls.length).toBe(1);
|
||||||
@ -109,18 +110,19 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
|
|
||||||
async function evaluatePowerLevels(pls: any, role: TreePermissions, expectedPl: number) {
|
async function evaluatePowerLevels(pls: any, role: TreePermissions, expectedPl: number) {
|
||||||
makePowerLevels(pls);
|
makePowerLevels(pls);
|
||||||
const fn = jest.fn().mockImplementation((stateRoomId: string, eventType: EventType, content: any, stateKey: string) => {
|
const fn = jest.fn()
|
||||||
expect(stateRoomId).toEqual(roomId);
|
.mockImplementation((stateRoomId: string, eventType: EventType, content: any, stateKey: string) => {
|
||||||
expect(eventType).toEqual(EventType.RoomPowerLevels);
|
expect(stateRoomId).toEqual(roomId);
|
||||||
expect(stateKey).toEqual("");
|
expect(eventType).toEqual(EventType.RoomPowerLevels);
|
||||||
expect(content).toMatchObject({
|
expect(stateKey).toEqual("");
|
||||||
...pls,
|
expect(content).toMatchObject({
|
||||||
users: {
|
...pls,
|
||||||
[targetUser]: expectedPl,
|
users: {
|
||||||
},
|
[targetUser]: expectedPl,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
return Promise.resolve();
|
|
||||||
});
|
|
||||||
client.sendStateEvent = fn;
|
client.sendStateEvent = fn;
|
||||||
await tree.setPermissions(targetUser, role);
|
await tree.setPermissions(targetUser, role);
|
||||||
expect(fn.mock.calls.length).toBe(1);
|
expect(fn.mock.calls.length).toBe(1);
|
||||||
@ -155,7 +157,7 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
users_default: 1024,
|
users_default: 1024,
|
||||||
users: {
|
users: {
|
||||||
[targetUser]: 2222,
|
[targetUser]: 2222,
|
||||||
}
|
},
|
||||||
}, TreePermissions.Viewer, 1024);
|
}, TreePermissions.Viewer, 1024);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
events_default: 1024,
|
events_default: 1024,
|
||||||
users: {
|
users: {
|
||||||
[targetUser]: 5,
|
[targetUser]: 5,
|
||||||
}
|
},
|
||||||
}, TreePermissions.Editor, 1024);
|
}, TreePermissions.Editor, 1024);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -199,19 +201,20 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
expect(name).toEqual(subspaceName);
|
expect(name).toEqual(subspaceName);
|
||||||
return new MSC3089TreeSpace(client, subspaceId);
|
return new MSC3089TreeSpace(client, subspaceId);
|
||||||
});
|
});
|
||||||
const sendStateFn = jest.fn().mockImplementation(async (roomId: string, eventType: EventType, content: any, stateKey: string) => {
|
const sendStateFn = jest.fn()
|
||||||
expect([tree.roomId, subspaceId]).toContain(roomId);
|
.mockImplementation(async (roomId: string, eventType: EventType, content: any, stateKey: string) => {
|
||||||
if (roomId === subspaceId) {
|
expect([tree.roomId, subspaceId]).toContain(roomId);
|
||||||
expect(eventType).toEqual(EventType.SpaceParent);
|
if (roomId === subspaceId) {
|
||||||
expect(stateKey).toEqual(tree.roomId);
|
expect(eventType).toEqual(EventType.SpaceParent);
|
||||||
} else {
|
expect(stateKey).toEqual(tree.roomId);
|
||||||
expect(eventType).toEqual(EventType.SpaceChild);
|
} else {
|
||||||
expect(stateKey).toEqual(subspaceId);
|
expect(eventType).toEqual(EventType.SpaceChild);
|
||||||
}
|
expect(stateKey).toEqual(subspaceId);
|
||||||
expect(content).toMatchObject({ via: [domain] });
|
}
|
||||||
|
expect(content).toMatchObject({ via: [domain] });
|
||||||
|
|
||||||
// return value not used
|
// return value not used
|
||||||
});
|
});
|
||||||
client.unstableCreateFileTree = createFn;
|
client.unstableCreateFileTree = createFn;
|
||||||
client.sendStateEvent = sendStateFn;
|
client.sendStateEvent = sendStateFn;
|
||||||
|
|
||||||
@ -311,7 +314,7 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
|
|
||||||
// ensure we don't kick ourselves
|
// ensure we don't kick ourselves
|
||||||
{ getContent: () => ({ membership: "join" }), getStateKey: () => selfUserId },
|
{ getContent: () => ({ membership: "join" }), getStateKey: () => selfUserId },
|
||||||
]
|
];
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -361,7 +364,7 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
getType: () => EventType.SpaceParent,
|
getType: () => EventType.SpaceParent,
|
||||||
getStateKey: () => tree.roomId,
|
getStateKey: () => tree.roomId,
|
||||||
getContent: () => ({
|
getContent: () => ({
|
||||||
via: [staticDomain]
|
via: [staticDomain],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -408,7 +411,12 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
roomId: tree.roomId,
|
roomId: tree.roomId,
|
||||||
currentState: {
|
currentState: {
|
||||||
getStateEvents: (eventType: EventType, stateKey?: string) => {
|
getStateEvents: (eventType: EventType, stateKey?: string) => {
|
||||||
expect([EventType.SpaceChild, EventType.RoomCreate, EventType.SpaceParent]).toContain(eventType);
|
expect([
|
||||||
|
EventType.SpaceChild,
|
||||||
|
EventType.RoomCreate,
|
||||||
|
EventType.SpaceParent,
|
||||||
|
]).toContain(eventType);
|
||||||
|
|
||||||
if (eventType === EventType.RoomCreate) {
|
if (eventType === EventType.RoomCreate) {
|
||||||
expect(stateKey).toEqual("");
|
expect(stateKey).toEqual("");
|
||||||
return parentState.filter(e => e.getType() === EventType.RoomCreate)[0];
|
return parentState.filter(e => e.getType() === EventType.RoomCreate)[0];
|
||||||
@ -429,22 +437,23 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
(<any>tree).room = parentRoom; // override readonly
|
(<any>tree).room = parentRoom; // override readonly
|
||||||
client.getRoom = (r) => rooms[r];
|
client.getRoom = (r) => rooms[r];
|
||||||
|
|
||||||
clientSendStateFn = jest.fn().mockImplementation((roomId: string, eventType: EventType, content: any, stateKey: string) => {
|
clientSendStateFn = jest.fn()
|
||||||
expect(roomId).toEqual(tree.roomId);
|
.mockImplementation((roomId: string, eventType: EventType, content: any, stateKey: string) => {
|
||||||
expect(eventType).toEqual(EventType.SpaceChild);
|
expect(roomId).toEqual(tree.roomId);
|
||||||
expect(content).toMatchObject(expect.objectContaining({
|
expect(eventType).toEqual(EventType.SpaceChild);
|
||||||
via: expect.any(Array),
|
expect(content).toMatchObject(expect.objectContaining({
|
||||||
order: expect.any(String),
|
via: expect.any(Array),
|
||||||
}));
|
order: expect.any(String),
|
||||||
expect(Object.keys(rooms)).toContain(stateKey);
|
}));
|
||||||
expect(stateKey).not.toEqual(tree.roomId);
|
expect(Object.keys(rooms)).toContain(stateKey);
|
||||||
|
expect(stateKey).not.toEqual(tree.roomId);
|
||||||
|
|
||||||
const stateEvent = parentState.find(e => e.getType() === eventType && e.getStateKey() === stateKey);
|
const stateEvent = parentState.find(e => e.getType() === eventType && e.getStateKey() === stateKey);
|
||||||
expect(stateEvent).toBeDefined();
|
expect(stateEvent).toBeDefined();
|
||||||
stateEvent.getContent = () => content;
|
stateEvent.getContent = () => content;
|
||||||
|
|
||||||
return Promise.resolve(); // return value not used
|
return Promise.resolve(); // return value not used
|
||||||
});
|
});
|
||||||
client.sendStateEvent = clientSendStateFn;
|
client.sendStateEvent = clientSendStateFn;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -652,7 +661,7 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
const d = "!d:example.org";
|
const d = "!d:example.org";
|
||||||
|
|
||||||
// Add in reverse order to make sure it gets ordered correctly
|
// Add in reverse order to make sure it gets ordered correctly
|
||||||
addSubspace(d, 4, "Z")
|
addSubspace(d, 4, "Z");
|
||||||
addSubspace(c, 3, "X");
|
addSubspace(c, 3, "X");
|
||||||
addSubspace(b, 2, "V");
|
addSubspace(b, 2, "V");
|
||||||
addSubspace(a, 1, "T");
|
addSubspace(a, 1, "T");
|
||||||
@ -681,7 +690,7 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
const d = "!d:example.org";
|
const d = "!d:example.org";
|
||||||
|
|
||||||
// Add in reverse order to make sure it gets ordered correctly
|
// Add in reverse order to make sure it gets ordered correctly
|
||||||
addSubspace(d, 4, "Z")
|
addSubspace(d, 4, "Z");
|
||||||
addSubspace(c, 3, "X");
|
addSubspace(c, 3, "X");
|
||||||
addSubspace(b, 2, "V");
|
addSubspace(b, 2, "V");
|
||||||
addSubspace(a, 1, "T");
|
addSubspace(a, 1, "T");
|
||||||
@ -710,7 +719,7 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
const d = "!d:example.org";
|
const d = "!d:example.org";
|
||||||
|
|
||||||
// Add in reverse order to make sure it gets ordered correctly
|
// Add in reverse order to make sure it gets ordered correctly
|
||||||
addSubspace(d, 4)
|
addSubspace(d, 4);
|
||||||
addSubspace(c, 3);
|
addSubspace(c, 3);
|
||||||
addSubspace(b, 2, "V");
|
addSubspace(b, 2, "V");
|
||||||
addSubspace(a, 1, "T");
|
addSubspace(a, 1, "T");
|
||||||
@ -775,17 +784,18 @@ describe("MSC3089TreeSpace", () => {
|
|||||||
});
|
});
|
||||||
client.sendMessage = sendMsgFn;
|
client.sendMessage = sendMsgFn;
|
||||||
|
|
||||||
const sendStateFn = jest.fn().mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
const sendStateFn = jest.fn()
|
||||||
expect(roomId).toEqual(tree.roomId);
|
.mockImplementation((roomId: string, eventType: string, content: any, stateKey: string) => {
|
||||||
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable
|
expect(roomId).toEqual(tree.roomId);
|
||||||
expect(stateKey).toEqual(fileEventId);
|
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable
|
||||||
expect(content).toMatchObject({
|
expect(stateKey).toEqual(fileEventId);
|
||||||
active: true,
|
expect(content).toMatchObject({
|
||||||
name: fileName,
|
active: true,
|
||||||
});
|
name: fileName,
|
||||||
|
});
|
||||||
|
|
||||||
return Promise.resolve(); // return value not used.
|
return Promise.resolve(); // return value not used.
|
||||||
});
|
});
|
||||||
client.sendStateEvent = sendStateFn;
|
client.sendStateEvent = sendStateFn;
|
||||||
|
|
||||||
const buf = Uint8Array.from(Array.from(fileContents).map((_, i) => fileContents.charCodeAt(i)));
|
const buf = Uint8Array.from(Array.from(fileContents).map((_, i) => fileContents.charCodeAt(i)));
|
||||||
|
@ -4,8 +4,9 @@ import {
|
|||||||
averageBetweenStrings,
|
averageBetweenStrings,
|
||||||
baseToString,
|
baseToString,
|
||||||
DEFAULT_ALPHABET,
|
DEFAULT_ALPHABET,
|
||||||
nextString, prevString,
|
nextString,
|
||||||
stringToBase
|
prevString,
|
||||||
|
stringToBase,
|
||||||
} from "../../src/utils";
|
} from "../../src/utils";
|
||||||
|
|
||||||
describe("utils", function() {
|
describe("utils", function() {
|
||||||
@ -270,7 +271,9 @@ describe("utils", function() {
|
|||||||
|
|
||||||
describe('DEFAULT_ALPHABET', () => {
|
describe('DEFAULT_ALPHABET', () => {
|
||||||
it('should be usefully printable ASCII in order', () => {
|
it('should be usefully printable ASCII in order', () => {
|
||||||
expect(DEFAULT_ALPHABET).toEqual(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
|
expect(DEFAULT_ALPHABET).toEqual(
|
||||||
|
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ export interface ICreateRoomOpts {
|
|||||||
name?: string;
|
name?: string;
|
||||||
topic?: string;
|
topic?: string;
|
||||||
preset?: string;
|
preset?: string;
|
||||||
power_level_content_override?: any;
|
power_level_content_override?: any;// eslint-disable-line camelcase
|
||||||
creation_content?: any;
|
creation_content?: any;// eslint-disable-line camelcase
|
||||||
initial_state?: {type: string, state_key: string, content: any}[];
|
initial_state?: {type: string, state_key: string, content: any}[]; // eslint-disable-line camelcase
|
||||||
// TODO: Types (next line)
|
// TODO: Types (next line)
|
||||||
invite_3pid?: any[]; // eslint-disable-line camelcase
|
invite_3pid?: any[]; // eslint-disable-line camelcase
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,8 @@ import {
|
|||||||
RoomCreateTypeField,
|
RoomCreateTypeField,
|
||||||
RoomType,
|
RoomType,
|
||||||
UNSTABLE_MSC3088_ENABLED,
|
UNSTABLE_MSC3088_ENABLED,
|
||||||
UNSTABLE_MSC3088_PURPOSE, UNSTABLE_MSC3089_TREE_SUBTYPE
|
UNSTABLE_MSC3088_PURPOSE,
|
||||||
|
UNSTABLE_MSC3089_TREE_SUBTYPE,
|
||||||
} from "./@types/event";
|
} from "./@types/event";
|
||||||
import { IImageInfo } from "./@types/partials";
|
import { IImageInfo } from "./@types/partials";
|
||||||
import { EventMapper, eventMapperFor, MapperOpts } from "./event-mapper";
|
import { EventMapper, eventMapperFor, MapperOpts } from "./event-mapper";
|
||||||
|
Reference in New Issue
Block a user