Skip to content

Commit

Permalink
add tests for functional members
Browse files Browse the repository at this point in the history
  • Loading branch information
HarHarLinks committed Feb 6, 2024
1 parent 547e0be commit efcbe4f
Showing 1 changed file with 111 additions and 1 deletion.
112 changes: 111 additions & 1 deletion spec/unit/room-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit efcbe4f

Please sign in to comment.