2022-08-01 17:28:33 +00:00
|
|
|
/*
|
2024-09-09 13:57:16 +00:00
|
|
|
Copyright 2024 New Vector Ltd.
|
2022-08-01 17:28:33 +00:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
2024-09-09 13:57:16 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2022-08-01 17:28:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import { Room, UNSTABLE_ELEMENT_FUNCTIONAL_USERS } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
2024-10-15 13:57:26 +00:00
|
|
|
import { getFunctionalMembers } from "../../../../src/utils/room/getFunctionalMembers";
|
|
|
|
import { createTestClient, mkEvent } from "../../../test-utils";
|
2022-08-01 17:28:33 +00:00
|
|
|
|
|
|
|
describe("getRoomFunctionalMembers", () => {
|
|
|
|
const client = createTestClient();
|
2023-02-13 17:01:43 +00:00
|
|
|
const room = new Room("!room:example.com", client, client.getUserId()!);
|
2022-08-01 17:28:33 +00:00
|
|
|
|
|
|
|
it("should return an empty array if no functional members state event exists", () => {
|
|
|
|
expect(getFunctionalMembers(room)).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return an empty array if functional members state event does not have a service_members field", () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
room.currentState.setStateEvents([
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: UNSTABLE_ELEMENT_FUNCTIONAL_USERS.name,
|
|
|
|
user: "@user:example.com)",
|
|
|
|
room: room.roomId,
|
|
|
|
skey: "",
|
|
|
|
content: {},
|
|
|
|
}),
|
|
|
|
]);
|
2022-08-01 17:28:33 +00:00
|
|
|
expect(getFunctionalMembers(room)).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return service_members field of the functional users state event", () => {
|
2022-12-12 11:24:14 +00:00
|
|
|
room.currentState.setStateEvents([
|
|
|
|
mkEvent({
|
|
|
|
event: true,
|
|
|
|
type: UNSTABLE_ELEMENT_FUNCTIONAL_USERS.name,
|
|
|
|
user: "@user:example.com)",
|
|
|
|
room: room.roomId,
|
|
|
|
skey: "",
|
|
|
|
content: { service_members: ["@user:example.com"] },
|
|
|
|
}),
|
|
|
|
]);
|
2022-08-01 17:28:33 +00:00
|
|
|
expect(getFunctionalMembers(room)).toEqual(["@user:example.com"]);
|
|
|
|
});
|
|
|
|
});
|