Skip to content

Commit

Permalink
Fix a bug where null values in RuntimeConfig cause initialize to fail (
Browse files Browse the repository at this point in the history
…#2490)

* Handle the case where `null` values in the `RuntimeConfig` from the host SDK will cause an error, ultimately causing `app.initialize` to fail.

* Update the `AppEligibilityInformation` interface to match the definition in the host SDK library and add a unit test to validate handling `null` values.

* Change file

* Update change file

---------

Co-authored-by: Erin <[email protected]>
  • Loading branch information
erinha and erinha committed Aug 30, 2024
1 parent d007a31 commit 8377643
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fixed a bug with `AppEligibilityInformation` that could cause `app.initialize` to fail.",
"packageName": "@microsoft/teams-js",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 3 additions & 0 deletions packages/teams-js/src/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export function generateGUID(): string {
*/
export function deepFreeze<T extends object>(obj: T): T {
Object.keys(obj).forEach((prop) => {
if (obj[prop] === null || obj[prop] === undefined) {
return;
}
if (typeof obj[prop] === 'object') {
deepFreeze(obj[prop]);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/teams-js/src/public/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ export interface AppEligibilityInformation {
/**
* Education Eligibility Information for the app user
*/
userClassification: UserClassification;
userClassification: UserClassification | null;
}

/**
Expand Down
34 changes: 34 additions & 0 deletions packages/teams-js/test/private/copilot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ const mockedAppEligibilityInformation = {
},
};

const mockedAppEligibilityInformationUserClassificationNull = {
cohort: Cohort.BCAIS,
ageGroup: LegalAgeGroupClassification.Adult,
isCopilotEnabledRegion: true,
isCopilotEligible: true,
isOptedOutByAdmin: false,
userClassification: null,
};

const copilotRuntimeConfig: Runtime = {
apiVersion: 4,
hostVersionsInfo: {
Expand All @@ -35,6 +44,25 @@ const copilotRuntimeConfig: Runtime = {
logs: {},
},
};

const copilotRuntimeConfigWithUserClassificationNull: Runtime = {
apiVersion: 4,
hostVersionsInfo: {
appEligibilityInformation: mockedAppEligibilityInformationUserClassificationNull,
},
supports: {
pages: {
appButton: {},
tabs: {},
config: {},
backStack: {},
fullTrust: {},
},
teamsCore: {},
logs: {},
},
};

describe('copilot', () => {
let utils: Utils;
beforeEach(() => {
Expand Down Expand Up @@ -73,5 +101,11 @@ describe('copilot', () => {
expect.objectContaining(errorNotSupportedOnPlatform),
);
});
it('should return null userClassification if the host provided eligibility information with userClassification as null', async () => {
await utils.initializeWithContext(FrameContexts.content);
utils.setRuntimeConfig(copilotRuntimeConfigWithUserClassificationNull);
expect(copilot.eligibility.isSupported()).toBeTruthy();
expect(copilot.eligibility.getEligibilityInfo()).toBe(mockedAppEligibilityInformationUserClassificationNull);
});
});
});

0 comments on commit 8377643

Please sign in to comment.