From 5ddccddf4a5627935c32fa0d24cd87f552f4fa7e 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 | 106 ++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/spec/unit/room-state.spec.ts b/spec/unit/room-state.spec.ts index 6c60d08f908..08e7dffc4f5 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,56 @@ 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!, + 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!, + sender: userB, + room: roomId, + content: { service_members: 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!, + 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 +772,55 @@ 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!, + 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!, + sender: userB, + room: roomId, + content: { service_members: 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!, + 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);