@@ -15,7 +15,7 @@ limitations under the License.
15
15
*/
16
16
17
17
import { MatrixEvent } from "../../../src" ;
18
- import { CallMembership , CallMembershipDataLegacy , SessionMembershipData } from "../../../src/matrixrtc/CallMembership" ;
18
+ import { CallMembership , SessionMembershipData } from "../../../src/matrixrtc/CallMembership" ;
19
19
20
20
function makeMockEvent ( originTs = 0 ) : MatrixEvent {
21
21
return {
@@ -25,91 +25,15 @@ function makeMockEvent(originTs = 0): MatrixEvent {
25
25
}
26
26
27
27
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 ) ;
28
+ describe ( "SessionMembershipData" , ( ) => {
29
+ beforeEach ( ( ) => {
30
+ jest . useFakeTimers ( ) ;
99
31
} ) ;
100
32
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 ] ) ;
33
+ afterEach ( ( ) => {
34
+ jest . useRealTimers ( ) ;
109
35
} ) ;
110
- } ) ;
111
36
112
- describe ( "SessionMembershipData" , ( ) => {
113
37
const membershipTemplate : SessionMembershipData = {
114
38
call_id : "" ,
115
39
scope : "m.room" ,
@@ -150,13 +74,6 @@ describe("CallMembership", () => {
150
74
expect ( membership . createdTs ( ) ) . toEqual ( 67890 ) ;
151
75
} ) ;
152
76
153
- it ( "considers memberships unexpired if local age low enough" , ( ) => {
154
- const fakeEvent = makeMockEvent ( 1000 ) ;
155
- fakeEvent . getLocalAge = jest . fn ( ) . mockReturnValue ( 3000 ) ;
156
- const membership = new CallMembership ( fakeEvent , membershipTemplate ) ;
157
- expect ( membership . isExpired ( ) ) . toEqual ( false ) ;
158
- } ) ;
159
-
160
77
it ( "returns preferred foci" , ( ) => {
161
78
const fakeEvent = makeMockEvent ( ) ;
162
79
const mockFocus = { type : "this_is_a_mock_focus" } ;
@@ -168,49 +85,29 @@ describe("CallMembership", () => {
168
85
} ) ;
169
86
} ) ;
170
87
171
- describe ( "expiry calculation" , ( ) => {
172
- let fakeEvent : MatrixEvent ;
173
- 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
- } ;
183
-
184
- beforeEach ( ( ) => {
185
- // server origin timestamp for this event is 1000
186
- fakeEvent = makeMockEvent ( 1000 ) ;
187
- membership = new CallMembership ( fakeEvent ! , membershipTemplate ) ;
188
-
189
- jest . useFakeTimers ( ) ;
190
- } ) ;
191
-
192
- afterEach ( ( ) => {
193
- jest . useRealTimers ( ) ;
194
- } ) ;
195
-
196
- it ( "converts expiry time into local clock" , ( ) => {
197
- // our clock would have been at 2000 at the creation time (our clock at event receive time - age)
198
- // (ie. the local clock is 1 second ahead of the servers' clocks)
199
- fakeEvent . localTimestamp = 2000 ;
200
-
201
- // for simplicity's sake, we say that the event's age is zero
202
- fakeEvent . getLocalAge = jest . fn ( ) . mockReturnValue ( 0 ) ;
203
-
204
- // for sanity's sake, make sure the server-relative expiry time is what we expect
205
- expect ( membership . getAbsoluteExpiry ( ) ) . toEqual ( 6000 ) ;
206
- // therefore the expiry time converted to our clock should be 1 second later
207
- expect ( membership . getLocalExpiry ( ) ) . toEqual ( 7000 ) ;
208
- } ) ;
209
-
210
- it ( "calculates time until expiry" , ( ) => {
211
- jest . setSystemTime ( 2000 ) ;
212
- // should be using absolute expiry time
213
- expect ( membership . getMsUntilExpiry ( ) ) . toEqual ( 4000 ) ;
214
- } ) ;
215
- } ) ;
88
+ // TODO: re-enable this test when expiry is implemented
89
+ // eslint-disable-next-line jest/no-commented-out-tests
90
+ // describe("expiry calculation", () => {
91
+ // let fakeEvent: MatrixEvent;
92
+ // let membership: CallMembership;
93
+
94
+ // beforeEach(() => {
95
+ // // server origin timestamp for this event is 1000
96
+ // fakeEvent = makeMockEvent(1000);
97
+ // membership = new CallMembership(fakeEvent!, membershipTemplate);
98
+
99
+ // jest.useFakeTimers();
100
+ // });
101
+
102
+ // afterEach(() => {
103
+ // jest.useRealTimers();
104
+ // });
105
+
106
+ // eslint-disable-next-line jest/no-commented-out-tests
107
+ // it("calculates time until expiry", () => {
108
+ // jest.setSystemTime(2000);
109
+ // // should be using absolute expiry time
110
+ // expect(membership.getMsUntilExpiry()).toEqual(DEFAULT_EXPIRE_DURATION - 1000);
111
+ // });
112
+ // });
216
113
} ) ;
0 commit comments