@@ -27,6 +27,7 @@ function makeMockEvent(originTs = 0): MatrixEvent {
2727 return {
2828 getTs : jest . fn ( ) . mockReturnValue ( originTs ) ,
2929 getSender : jest . fn ( ) . mockReturnValue ( "@alice:example.org" ) ,
30+ getId : jest . fn ( ) . mockReturnValue ( "$eventid" ) ,
3031 } as unknown as MatrixEvent ;
3132}
3233
@@ -41,12 +42,13 @@ describe("CallMembership", () => {
4142 } ) ;
4243
4344 const membershipTemplate : SessionMembershipData = {
44- call_id : "" ,
45- scope : "m.room" ,
46- application : "m.call" ,
47- device_id : "AAAAAAA" ,
48- focus_active : { type : "livekit" , focus_selection : "oldest_membership" } ,
49- foci_preferred : [ { type : "livekit" } ] ,
45+ "call_id" : "" ,
46+ "scope" : "m.room" ,
47+ "application" : "m.call" ,
48+ "device_id" : "AAAAAAA" ,
49+ "focus_active" : { type : "livekit" , focus_selection : "oldest_membership" } ,
50+ "foci_preferred" : [ { type : "livekit" } ] ,
51+ "m.call.intent" : "voice" ,
5052 } ;
5153
5254 it ( "rejects membership with no device_id" , ( ) => {
@@ -98,6 +100,7 @@ describe("CallMembership", () => {
98100 const membership = new CallMembership ( fakeEvent , { ...membershipTemplate , foci_preferred : [ mockFocus ] } ) ;
99101 expect ( membership . transports ) . toEqual ( [ mockFocus ] ) ;
100102 } ) ;
103+
101104 describe ( "getTransport" , ( ) => {
102105 const mockFocus = { type : "this_is_a_mock_focus" } ;
103106 const oldestMembership = new CallMembership ( makeMockEvent ( ) , membershipTemplate ) ;
@@ -129,6 +132,42 @@ describe("CallMembership", () => {
129132 expect ( membership . getTransport ( oldestMembership ) ) . toBe ( mockFocus ) ;
130133 } ) ;
131134 } ) ;
135+ describe ( "correct values from computed fields" , ( ) => {
136+ const membership = new CallMembership ( makeMockEvent ( ) , membershipTemplate ) ;
137+ it ( "returns correct sender" , ( ) => {
138+ expect ( membership . sender ) . toBe ( "@alice:example.org" ) ;
139+ } ) ;
140+ it ( "returns correct eventId" , ( ) => {
141+ expect ( membership . eventId ) . toBe ( "$eventid" ) ;
142+ } ) ;
143+ it ( "returns correct slot_id" , ( ) => {
144+ expect ( membership . slotId ) . toBe ( "m.call#" ) ;
145+ expect ( membership . slotDescription ) . toStrictEqual ( { id : "" , application : "m.call" } ) ;
146+ } ) ;
147+ it ( "returns correct deviceId" , ( ) => {
148+ expect ( membership . deviceId ) . toBe ( "AAAAAAA" ) ;
149+ } ) ;
150+ it ( "returns correct call intent" , ( ) => {
151+ expect ( membership . callIntent ) . toBe ( "voice" ) ;
152+ } ) ;
153+ it ( "returns correct application" , ( ) => {
154+ expect ( membership . application ) . toStrictEqual ( "m.call" ) ;
155+ } ) ;
156+ it ( "returns correct applicationData" , ( ) => {
157+ expect ( membership . applicationData ) . toStrictEqual ( { "type" : "m.call" , "m.call.intent" : "voice" } ) ;
158+ } ) ;
159+ it ( "returns correct scope" , ( ) => {
160+ expect ( membership . scope ) . toBe ( "m.room" ) ;
161+ } ) ;
162+ it ( "returns correct membershipID" , ( ) => {
163+ expect ( membership . membershipID ) . toBe ( "0" ) ;
164+ } ) ;
165+ it ( "returns correct unused fields" , ( ) => {
166+ expect ( membership . getAbsoluteExpiry ( ) ) . toBe ( 14400000 ) ;
167+ expect ( membership . getMsUntilExpiry ( ) ) . toBe ( 14400000 - Date . now ( ) ) ;
168+ expect ( membership . isExpired ( ) ) . toBe ( true ) ;
169+ } ) ;
170+ } ) ;
132171 } ) ;
133172
134173 describe ( "RtcMembershipData" , ( ) => {
@@ -141,11 +180,12 @@ describe("CallMembership", () => {
141180 } ) ;
142181
143182 const membershipTemplate : RtcMembershipData = {
144- slot_id : "m.call#1" ,
145- application : { type : "m.call" } ,
146- member : { user_id : "@alice:example.org" , device_id : "AAAAAAA" , id : "xyzHASHxyz" } ,
147- rtc_transports : [ { type : "livekit" } ] ,
148- versions : [ ] ,
183+ "slot_id" : "m.call#" ,
184+ "application" : { "type" : "m.call" , "m.call.id" : "" , "m.call.intent" : "voice" } ,
185+ "member" : { user_id : "@alice:example.org" , device_id : "AAAAAAA" , id : "xyzHASHxyz" } ,
186+ "rtc_transports" : [ { type : "livekit" } ] ,
187+ "m.call.intent" : "voice" ,
188+ "versions" : [ ] ,
149189 } ;
150190
151191 it ( "rejects membership with no slot_id" , ( ) => {
@@ -228,6 +268,46 @@ describe("CallMembership", () => {
228268 expect ( membership . getTransport ( oldestMembership ) ) . toStrictEqual ( { type : "livekit" } ) ;
229269 } ) ;
230270 } ) ;
271+ describe ( "correct values from computed fields" , ( ) => {
272+ const membership = new CallMembership ( makeMockEvent ( ) , membershipTemplate ) ;
273+ it ( "returns correct sender" , ( ) => {
274+ expect ( membership . sender ) . toBe ( "@alice:example.org" ) ;
275+ } ) ;
276+ it ( "returns correct eventId" , ( ) => {
277+ expect ( membership . eventId ) . toBe ( "$eventid" ) ;
278+ } ) ;
279+ it ( "returns correct slot_id" , ( ) => {
280+ expect ( membership . slotId ) . toBe ( "m.call#" ) ;
281+ expect ( membership . slotDescription ) . toStrictEqual ( { id : "" , application : "m.call" } ) ;
282+ } ) ;
283+ it ( "returns correct deviceId" , ( ) => {
284+ expect ( membership . deviceId ) . toBe ( "AAAAAAA" ) ;
285+ } ) ;
286+ it ( "returns correct call intent" , ( ) => {
287+ expect ( membership . callIntent ) . toBe ( "voice" ) ;
288+ } ) ;
289+ it ( "returns correct application" , ( ) => {
290+ expect ( membership . application ) . toStrictEqual ( "m.call" ) ;
291+ } ) ;
292+ it ( "returns correct applicationData" , ( ) => {
293+ expect ( membership . applicationData ) . toStrictEqual ( {
294+ "type" : "m.call" ,
295+ "m.call.id" : "" ,
296+ "m.call.intent" : "voice" ,
297+ } ) ;
298+ } ) ;
299+ it ( "returns correct scope" , ( ) => {
300+ expect ( membership . scope ) . toBe ( undefined ) ;
301+ } ) ;
302+ it ( "returns correct membershipID" , ( ) => {
303+ expect ( membership . membershipID ) . toBe ( "xyzHASHxyz" ) ;
304+ } ) ;
305+ it ( "returns correct unused fields" , ( ) => {
306+ expect ( membership . getAbsoluteExpiry ( ) ) . toBe ( undefined ) ;
307+ expect ( membership . getMsUntilExpiry ( ) ) . toBe ( undefined ) ;
308+ expect ( membership . isExpired ( ) ) . toBe ( false ) ;
309+ } ) ;
310+ } ) ;
231311 } ) ;
232312
233313 describe ( "expiry calculation" , ( ) => {
0 commit comments