@@ -117,7 +117,7 @@ describe.each([['channelData' as const], ['entities' as const]])('using %s', whe
117117 } ) ;
118118 } ) ;
119119
120- test ( 'activity with "streamType" of "streaming" without critical fields should return undefined' , ( ) => {
120+ test ( 'activity with "streamType" of "streaming" without critical fields should return undefined' , ( ) =>
121121 expect (
122122 getActivityLivestreamingMetadata (
123123 inject (
@@ -129,8 +129,7 @@ describe.each([['channelData' as const], ['entities' as const]])('using %s', whe
129129 }
130130 )
131131 )
132- ) . toBeUndefined ( ) ;
133- } ) ;
132+ ) . toBeUndefined ( ) ) ;
134133
135134 test . each ( [
136135 [ 'integer' , 1 , true ] ,
@@ -158,7 +157,7 @@ describe.each([['channelData' as const], ['entities' as const]])('using %s', whe
158157 } ) ;
159158
160159 describe ( '"typing" activity with "streamType" of "final"' , ( ) => {
161- test ( 'should return undefined if "text" field is defined' , ( ) => {
160+ test ( 'should return undefined if "text" field is defined' , ( ) =>
162161 expect (
163162 getActivityLivestreamingMetadata (
164163 inject (
@@ -173,10 +172,9 @@ describe.each([['channelData' as const], ['entities' as const]])('using %s', whe
173172 }
174173 )
175174 )
176- ) . toBeUndefined ( ) ;
177- } ) ;
175+ ) . toBeUndefined ( ) ) ;
178176
179- test ( 'should return truthy if "text" field is not defined' , ( ) => {
177+ test ( 'should return truthy if "text" field is not defined' , ( ) =>
180178 expect (
181179 getActivityLivestreamingMetadata (
182180 inject (
@@ -191,11 +189,10 @@ describe.each([['channelData' as const], ['entities' as const]])('using %s', whe
191189 }
192190 )
193191 )
194- ) . toHaveProperty ( 'type' , 'final activity' ) ;
195- } ) ;
192+ ) . toHaveProperty ( 'type' , 'final activity' ) ) ;
196193 } ) ;
197194
198- test ( 'activity with "streamType" of "streaming" without "content" should return type of "contentless"' , ( ) => {
195+ test ( 'activity with "streamType" of "streaming" without "content" should return type of "contentless"' , ( ) =>
199196 expect (
200197 getActivityLivestreamingMetadata (
201198 inject (
@@ -209,9 +206,92 @@ describe.each([['channelData' as const], ['entities' as const]])('using %s', whe
209206 }
210207 )
211208 )
212- ) . toHaveProperty ( 'type' , 'contentless' ) ;
213- } ) ;
209+ ) . toHaveProperty ( 'type' , 'contentless' ) ) ;
214210} ) ;
215211
216212test ( 'invalid activity should return undefined' , ( ) =>
217213 expect ( getActivityLivestreamingMetadata ( 'invalid' as any ) ) . toBeUndefined ( ) ) ;
214+
215+ test ( 'should prefer channelData over entities' , ( ) =>
216+ expect (
217+ getActivityLivestreamingMetadata ( {
218+ channelData : {
219+ streamId : 'a-channelData' ,
220+ streamSequence : 2 ,
221+ streamType : 'streaming'
222+ } ,
223+ entities : [
224+ {
225+ streamId : 'a-entities' ,
226+ streamSequence : 2 ,
227+ streamType : 'streaming' ,
228+ type : 'streaminfo'
229+ }
230+ ] ,
231+ id : 'a-00002' ,
232+ type : 'typing'
233+ } as any )
234+ ) . toHaveProperty ( 'sessionId' , 'a-channelData' ) ) ;
235+
236+ test ( 'should prefer first entity' , ( ) =>
237+ expect (
238+ getActivityLivestreamingMetadata ( {
239+ entities : [
240+ {
241+ streamId : 'a-first' ,
242+ streamSequence : 2 ,
243+ streamType : 'streaming' ,
244+ type : 'streaminfo'
245+ } ,
246+ {
247+ streamId : 'a-second' ,
248+ streamSequence : 2 ,
249+ streamType : 'streaming' ,
250+ type : 'streaminfo'
251+ }
252+ ] ,
253+ id : 'a-00002' ,
254+ type : 'typing'
255+ } as any )
256+ ) . toHaveProperty ( 'sessionId' , 'a-first' ) ) ;
257+
258+ test ( 'channelData-based livestreaming metadata should be harmony with other entities' , ( ) =>
259+ expect (
260+ getActivityLivestreamingMetadata ( {
261+ channelData : {
262+ streamSequence : 1 ,
263+ streamType : 'streaming'
264+ } ,
265+ entities : [
266+ {
267+ '@context' : 'https://schema.org' ,
268+ '@id' : '' ,
269+ '@type' : 'Message' ,
270+ type : 'https://schema.org/Message'
271+ }
272+ ] ,
273+ id : 'a-00001' ,
274+ type : 'typing'
275+ } as any )
276+ ) . toHaveProperty ( 'sequenceNumber' , 1 ) ) ;
277+
278+ test ( 'entity-based livestreaming metadata should be harmony with other entities' , ( ) =>
279+ expect (
280+ getActivityLivestreamingMetadata ( {
281+ entities : [
282+ {
283+ '@context' : 'https://schema.org' ,
284+ '@id' : '' ,
285+ '@type' : 'Message' ,
286+ type : 'https://schema.org/Message'
287+ } ,
288+ {
289+ streamSequence : 1 ,
290+ streamType : 'streaming' ,
291+ type : 'streaminfo'
292+ }
293+ ] ,
294+ id : 'a-00001' ,
295+ type : 'typing'
296+ } as any )
297+ ) . toHaveProperty ( 'sequenceNumber' , 1 ) ) ;
0 commit comments