Skip to content

Commit 05915fb

Browse files
committed
remove all legacy call related code and adjust tests.
We actually had a bit of tests just for legacy and not for session events. All those tests got ported over so we do not remove any tests.
1 parent a0502c5 commit 05915fb

8 files changed

Lines changed: 219 additions & 613 deletions

File tree

spec/unit/matrixrtc/CallMembership.spec.ts

Lines changed: 18 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ limitations under the License.
1515
*/
1616

1717
import { MatrixEvent } from "../../../src";
18-
import { CallMembership, CallMembershipDataLegacy, SessionMembershipData } from "../../../src/matrixrtc/CallMembership";
18+
import { CallMembership, DEFAULT_EXPIRE_DURATION, SessionMembershipData } from "../../../src/matrixrtc/CallMembership";
19+
import { membershipTemplate } from "./mocks";
1920

2021
function makeMockEvent(originTs = 0): MatrixEvent {
2122
return {
@@ -25,91 +26,15 @@ function makeMockEvent(originTs = 0): MatrixEvent {
2526
}
2627

2728
describe("CallMembership", () => {
28-
describe("CallMembershipDataLegacy", () => {
29-
const membershipTemplate: CallMembershipDataLegacy = {
30-
call_id: "",
31-
scope: "m.room",
32-
application: "m.call",
33-
device_id: "AAAAAAA",
34-
expires: 5000,
35-
membershipID: "bloop",
36-
foci_active: [{ type: "livekit" }],
37-
};
38-
it("rejects membership with no expiry and no expires_ts", () => {
39-
expect(() => {
40-
new CallMembership(
41-
makeMockEvent(),
42-
Object.assign({}, membershipTemplate, { expires: undefined, expires_ts: undefined }),
43-
);
44-
}).toThrow();
45-
});
46-
47-
it("rejects membership with no device_id", () => {
48-
expect(() => {
49-
new CallMembership(makeMockEvent(), Object.assign({}, membershipTemplate, { device_id: undefined }));
50-
}).toThrow();
51-
});
52-
53-
it("rejects membership with no call_id", () => {
54-
expect(() => {
55-
new CallMembership(makeMockEvent(), Object.assign({}, membershipTemplate, { call_id: undefined }));
56-
}).toThrow();
57-
});
58-
59-
it("allow membership with no scope", () => {
60-
expect(() => {
61-
new CallMembership(makeMockEvent(), Object.assign({}, membershipTemplate, { scope: undefined }));
62-
}).not.toThrow();
63-
});
64-
it("rejects with malformatted expires_ts", () => {
65-
expect(() => {
66-
new CallMembership(makeMockEvent(), Object.assign({}, membershipTemplate, { expires_ts: "string" }));
67-
}).toThrow();
68-
});
69-
it("rejects with malformatted expires", () => {
70-
expect(() => {
71-
new CallMembership(makeMockEvent(), Object.assign({}, membershipTemplate, { expires: "string" }));
72-
}).toThrow();
73-
});
74-
75-
it("uses event timestamp if no created_ts", () => {
76-
const membership = new CallMembership(makeMockEvent(12345), membershipTemplate);
77-
expect(membership.createdTs()).toEqual(12345);
78-
});
79-
80-
it("uses created_ts if present", () => {
81-
const membership = new CallMembership(
82-
makeMockEvent(12345),
83-
Object.assign({}, membershipTemplate, { created_ts: 67890 }),
84-
);
85-
expect(membership.createdTs()).toEqual(67890);
86-
});
87-
88-
it("computes absolute expiry time based on expires", () => {
89-
const membership = new CallMembership(makeMockEvent(1000), membershipTemplate);
90-
expect(membership.getAbsoluteExpiry()).toEqual(5000 + 1000);
91-
});
92-
93-
it("computes absolute expiry time based on expires_ts", () => {
94-
const membership = new CallMembership(
95-
makeMockEvent(1000),
96-
Object.assign({}, membershipTemplate, { expires_ts: 6000 }),
97-
);
98-
expect(membership.getAbsoluteExpiry()).toEqual(5000 + 1000);
29+
describe("SessionMembershipData", () => {
30+
beforeEach(() => {
31+
jest.useFakeTimers();
9932
});
10033

101-
it("returns preferred foci", () => {
102-
const fakeEvent = makeMockEvent();
103-
const mockFocus = { type: "this_is_a_mock_focus" };
104-
const membership = new CallMembership(
105-
fakeEvent,
106-
Object.assign({}, membershipTemplate, { foci_active: [mockFocus] }),
107-
);
108-
expect(membership.getPreferredFoci()).toEqual([mockFocus]);
34+
afterEach(() => {
35+
jest.useRealTimers();
10936
});
110-
});
11137

112-
describe("SessionMembershipData", () => {
11338
const membershipTemplate: SessionMembershipData = {
11439
call_id: "",
11540
scope: "m.room",
@@ -152,9 +77,14 @@ describe("CallMembership", () => {
15277

15378
it("considers memberships unexpired if local age low enough", () => {
15479
const fakeEvent = makeMockEvent(1000);
155-
fakeEvent.getLocalAge = jest.fn().mockReturnValue(3000);
156-
const membership = new CallMembership(fakeEvent, membershipTemplate);
157-
expect(membership.isExpired()).toEqual(false);
80+
fakeEvent.getTs = jest.fn().mockReturnValue(Date.now() - (DEFAULT_EXPIRE_DURATION - 1));
81+
expect(new CallMembership(fakeEvent, membershipTemplate).isExpired()).toEqual(false);
82+
});
83+
84+
it("considers memberships expired if local age large enough", () => {
85+
const fakeEvent = makeMockEvent(1000);
86+
fakeEvent.getTs = jest.fn().mockReturnValue(Date.now() - (DEFAULT_EXPIRE_DURATION + 1));
87+
expect(new CallMembership(fakeEvent, membershipTemplate).isExpired()).toEqual(true);
15888
});
15989

16090
it("returns preferred foci", () => {
@@ -171,15 +101,6 @@ describe("CallMembership", () => {
171101
describe("expiry calculation", () => {
172102
let fakeEvent: MatrixEvent;
173103
let membership: CallMembership;
174-
const membershipTemplate: CallMembershipDataLegacy = {
175-
call_id: "",
176-
scope: "m.room",
177-
application: "m.call",
178-
device_id: "AAAAAAA",
179-
expires: 5000,
180-
membershipID: "bloop",
181-
foci_active: [{ type: "livekit" }],
182-
};
183104

184105
beforeEach(() => {
185106
// server origin timestamp for this event is 1000
@@ -202,15 +123,15 @@ describe("CallMembership", () => {
202123
fakeEvent.getLocalAge = jest.fn().mockReturnValue(0);
203124

204125
// for sanity's sake, make sure the server-relative expiry time is what we expect
205-
expect(membership.getAbsoluteExpiry()).toEqual(6000);
126+
expect(membership.getAbsoluteExpiry()).toEqual(DEFAULT_EXPIRE_DURATION + 1000);
206127
// therefore the expiry time converted to our clock should be 1 second later
207-
expect(membership.getLocalExpiry()).toEqual(7000);
128+
expect(membership.getLocalExpiry()).toEqual(DEFAULT_EXPIRE_DURATION + 2000);
208129
});
209130

210131
it("calculates time until expiry", () => {
211132
jest.setSystemTime(2000);
212133
// should be using absolute expiry time
213-
expect(membership.getMsUntilExpiry()).toEqual(4000);
134+
expect(membership.getMsUntilExpiry()).toEqual(DEFAULT_EXPIRE_DURATION - 1000);
214135
});
215136
});
216137
});

0 commit comments

Comments
 (0)