2022-08-01 19:28:33 +02:00
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { Room, UNSTABLE_ELEMENT_FUNCTIONAL_USERS } from "matrix-js-sdk/src/matrix";
|
|
|
|
|
|
|
|
import { getFunctionalMembers } from "../../../src/utils/room/getFunctionalMembers";
|
|
|
|
import { createTestClient, mkEvent } from "../../test-utils";
|
|
|
|
|
|
|
|
describe("getRoomFunctionalMembers", () => {
|
|
|
|
const client = createTestClient();
|
2023-02-13 18:01:43 +01:00
|
|
|
const room = new Room("!room:example.com", client, client.getUserId()!);
|
2022-08-01 19:28:33 +02: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 12:24:14 +01: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 19:28:33 +02:00
|
|
|
expect(getFunctionalMembers(room)).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return service_members field of the functional users state event", () => {
|
2022-12-12 12:24:14 +01: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 19:28:33 +02:00
|
|
|
expect(getFunctionalMembers(room)).toEqual(["@user:example.com"]);
|
|
|
|
});
|
|
|
|
});
|