@@ -16,6 +16,7 @@ const mockedAppEligibilityInformation = {
16
16
persona : Persona . Student ,
17
17
eduType : EduType . HigherEducation ,
18
18
} ,
19
+ featureSet : { serverFeatures : [ 'feature1' , 'feature2' ] , uxFeatures : [ 'feature3' ] } ,
19
20
} ;
20
21
21
22
const mockedAppEligibilityInformationUserClassificationNull = {
@@ -188,6 +189,24 @@ describe('copilot', () => {
188
189
return expect ( promise ) . resolves . toEqual ( mockedAppEligibilityInformation ) ;
189
190
} ) ;
190
191
192
+ it ( `should not throw if featureSet in response is undefined - with context ${ frameContext } ` , async ( ) => {
193
+ await utils . initializeWithContext ( frameContext ) ;
194
+ utils . setRuntimeConfig ( copilotRuntimeConfig ) ;
195
+
196
+ const promise = copilot . eligibility . getEligibilityInfo ( ) ;
197
+ const message = utils . findMessageByFunc ( 'copilot.eligibility.getEligibilityInfo' ) ;
198
+ const mockedAppEligibilityInformationWithUndefinedFeatureSet = {
199
+ ...mockedAppEligibilityInformation ,
200
+ featureSet : undefined ,
201
+ } ;
202
+ expect ( message ) . not . toBeNull ( ) ;
203
+ if ( message ) {
204
+ utils . respondToMessage ( message , mockedAppEligibilityInformationWithUndefinedFeatureSet ) ;
205
+ }
206
+
207
+ return expect ( promise ) . resolves . toEqual ( mockedAppEligibilityInformationWithUndefinedFeatureSet ) ;
208
+ } ) ;
209
+
191
210
it ( `should throw error if host returns error - with context ${ frameContext } ` , async ( ) => {
192
211
await utils . initializeWithContext ( frameContext ) ;
193
212
utils . setRuntimeConfig ( copilotRuntimeConfig ) ;
@@ -319,6 +338,50 @@ describe('copilot', () => {
319
338
320
339
await expect ( promise ) . rejects . toThrowError ( 'Error deserializing eligibility information' ) ;
321
340
} ) ;
341
+
342
+ it ( 'getEligibilityInfo should throw if AppEligibilityInformation.featureSet.serverFeatures is undefined' , async ( ) => {
343
+ await utils . initializeWithContext ( FrameContexts . content ) ;
344
+ utils . setRuntimeConfig ( copilotRuntimeConfig ) ;
345
+
346
+ const mockedInvalidAppEligibilityInformationWithInvalidUxFeatures = {
347
+ ...mockedAppEligibilityInformation ,
348
+ featureSet : {
349
+ serverFeatures : undefined ,
350
+ uxFeatures : [ ] ,
351
+ } ,
352
+ } ;
353
+
354
+ const promise = copilot . eligibility . getEligibilityInfo ( ) ;
355
+ const message = utils . findMessageByFunc ( 'copilot.eligibility.getEligibilityInfo' ) ;
356
+ expect ( message ) . not . toBeNull ( ) ;
357
+ if ( message ) {
358
+ utils . respondToMessage ( message , mockedInvalidAppEligibilityInformationWithInvalidUxFeatures ) ;
359
+ }
360
+
361
+ await expect ( promise ) . rejects . toThrowError ( 'Error deserializing eligibility information' ) ;
362
+ } ) ;
363
+
364
+ it ( 'getEligibilityInfo should throw if AppEligibilityInformation.featureSet.uxFeatures is undefined' , async ( ) => {
365
+ await utils . initializeWithContext ( FrameContexts . content ) ;
366
+ utils . setRuntimeConfig ( copilotRuntimeConfig ) ;
367
+
368
+ const mockedInvalidAppEligibilityInformationWithInvalidUxFeatures = {
369
+ ...mockedAppEligibilityInformation ,
370
+ featureSet : {
371
+ serverFeatures : [ ] ,
372
+ uxFeatures : undefined ,
373
+ } ,
374
+ } ;
375
+
376
+ const promise = copilot . eligibility . getEligibilityInfo ( ) ;
377
+ const message = utils . findMessageByFunc ( 'copilot.eligibility.getEligibilityInfo' ) ;
378
+ expect ( message ) . not . toBeNull ( ) ;
379
+ if ( message ) {
380
+ utils . respondToMessage ( message , mockedInvalidAppEligibilityInformationWithInvalidUxFeatures ) ;
381
+ }
382
+
383
+ await expect ( promise ) . rejects . toThrowError ( 'Error deserializing eligibility information' ) ;
384
+ } ) ;
322
385
} ) ;
323
386
} ) ;
324
387
} ) ;
0 commit comments