From efcbe4f6fa498faf43962d6ff5af63dbeeb5a93c Mon Sep 17 00:00:00 2001 From: HarHarLinks <2803622+HarHarLinks@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:26:46 +0100 Subject: [PATCH] add tests for functional members --- spec/unit/room-state.spec.ts | 112 ++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/spec/unit/room-state.spec.ts b/spec/unit/room-state.spec.ts index 6c60d08f908..93466e63cbd 100644 --- a/spec/unit/room-state.spec.ts +++ b/spec/unit/room-state.spec.ts @@ -21,7 +21,12 @@ import { makeBeaconEvent, makeBeaconInfoEvent } from "../test-utils/beacon"; import { filterEmitCallsByEventType } from "../test-utils/emitter"; import { RoomState, RoomStateEvent } from "../../src/models/room-state"; import { Beacon, BeaconEvent, getBeaconInfoIdentifier } from "../../src/models/beacon"; -import { EventType, RelationType, UNSTABLE_MSC2716_MARKER } from "../../src/@types/event"; +import { + EventType, + RelationType, + UNSTABLE_ELEMENT_FUNCTIONAL_USERS, + UNSTABLE_MSC2716_MARKER, +} from "../../src/@types/event"; import { MatrixEvent, MatrixEventEvent } from "../../src/models/event"; import { M_BEACON } from "../../src/@types/beacon"; import { MatrixClient } from "../../src/client"; @@ -704,6 +709,59 @@ describe("RoomState", function () { }); }); + describe("getJoinedFunctionalMemberCount", function () { + beforeEach(() => { + state = new RoomState(roomId); + }); + + it("should update after adding joined functional member", function () { + state.setStateEvents([ + utils.mkMembership({ event: true, mship: "join", user: userA, room: roomId }), + utils.mkEvent({ + event: true, + type: UNSTABLE_ELEMENT_FUNCTIONAL_USERS.unstable!, + skey: "", + sender: userB, + room: roomId, + content: { service_members: [userA] }, + }), + ]); + expect(state.getJoinedMemberCount()).toEqual(1); + expect(state.getJoinedFunctionalMemberCount()).toEqual(1); + state.setStateEvents([ + utils.mkMembership({ event: true, mship: "join", user: userC, room: roomId }), + utils.mkEvent({ + event: true, + type: UNSTABLE_ELEMENT_FUNCTIONAL_USERS.unstable!, + skey: "", + sender: userB, + room: roomId, + content: { service_members: [userA, userC] }, + }), + ]); + expect(state.getJoinedMemberCount()).toEqual(2); + expect(state.getJoinedFunctionalMemberCount()).toEqual(2); + }); + + it("should not update after adding joined non-functional member", function () { + state.setStateEvents([utils.mkMembership({ event: true, mship: "join", user: userA, room: roomId })]); + expect(state.getJoinedMemberCount()).toEqual(1); + expect(state.getJoinedFunctionalMemberCount()).toEqual(0); + state.setStateEvents([ + utils.mkEvent({ + event: true, + type: UNSTABLE_ELEMENT_FUNCTIONAL_USERS.unstable!, + skey: "", + sender: userB, + room: roomId, + content: { service_members: [userA] }, + }), + ]); + expect(state.getJoinedMemberCount()).toEqual(1); + expect(state.getJoinedFunctionalMemberCount()).toEqual(1); + }); + }); + describe("getInvitedMemberCount", function () { beforeEach(() => { state = new RoomState(roomId); @@ -717,6 +775,58 @@ describe("RoomState", function () { }); }); + describe("getInvitedFunctionalMemberCount", function () { + beforeEach(() => { + state = new RoomState(roomId); + }); + it("should update after adding invited functional member", function () { + state.setStateEvents([ + utils.mkMembership({ event: true, mship: "invite", user: userA, room: roomId }), + utils.mkEvent({ + event: true, + type: UNSTABLE_ELEMENT_FUNCTIONAL_USERS.unstable!, + skey: "", + sender: userB, + room: roomId, + content: { service_members: [userA] }, + }), + ]); + expect(state.getInvitedMemberCount()).toEqual(1); + expect(state.getInvitedFunctionalMemberCount()).toEqual(1); + state.setStateEvents([ + utils.mkMembership({ event: true, mship: "invite", user: userC, room: roomId }), + utils.mkEvent({ + event: true, + type: UNSTABLE_ELEMENT_FUNCTIONAL_USERS.unstable!, + skey: "", + sender: userB, + room: roomId, + content: { service_members: [userA, userC] }, + }), + ]); + expect(state.getInvitedMemberCount()).toEqual(2); + expect(state.getInvitedFunctionalMemberCount()).toEqual(2); + }); + + it("should not update after adding invited non-functional member", function () { + state.setStateEvents([utils.mkMembership({ event: true, mship: "invite", user: userA, room: roomId })]); + expect(state.getInvitedMemberCount()).toEqual(1); + expect(state.getInvitedFunctionalMemberCount()).toEqual(0); + state.setStateEvents([ + utils.mkEvent({ + event: true, + type: UNSTABLE_ELEMENT_FUNCTIONAL_USERS.unstable!, + skey: "", + sender: userB, + room: roomId, + content: { service_members: [userA] }, + }), + ]); + expect(state.getInvitedMemberCount()).toEqual(1); + expect(state.getInvitedFunctionalMemberCount()).toEqual(1); + }); + }); + describe("setJoinedMemberCount", function () { beforeEach(() => { state = new RoomState(roomId);