Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional FeatureSet parameter to eligibility interface #2623

Merged
merged 16 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Added optional `FeatureSet` field to `AppEligibilityInformation` interface",
"packageName": "@microsoft/teams-js",
"email": "email not defined",
"dependentChangeType": "patch"
}
4 changes: 3 additions & 1 deletion packages/teams-js/src/private/copilot/eligibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ function isEligibilityInfoValid(eligibilityInfo: AppEligibilityInformation): boo
eligibilityInfo.userClassification === undefined ||
eligibilityInfo.isCopilotEligible === undefined ||
eligibilityInfo.isCopilotEnabledRegion === undefined ||
eligibilityInfo.isOptedOutByAdmin === undefined
eligibilityInfo.isOptedOutByAdmin === undefined ||
(eligibilityInfo.featureSet &&
(eligibilityInfo.featureSet.serverFeatures === undefined || eligibilityInfo.featureSet.uxFeatures === undefined))
) {
return false;
}
Expand Down
21 changes: 21 additions & 0 deletions packages/teams-js/src/public/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,11 @@ export interface AppEligibilityInformation {
* A user will be in at most one cohort.
*/
cohort: Cohort | null;
/**
* Feature Sets
* If this property is undefined, it indicates that the host is an older version that doesn't support this property.
*/
featureSet?: FeatureSet;
Copy link
Contributor

@AE-MS AE-MS Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

What would be the semantic difference between having this property be undefined vs defined but with two empty array properties?

I'm guessing the answer is something like "this has to have the ? because older version of the host won't know to send this property so it will show up as undefined then." If that's true, then consider adding documentation for the property that says:
"If this property is undefined, it indicates that the host is an older version that doesn't support this property." #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is it's the latter, so I think adding a comment is the way to go here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep it is for back compatibility. Added the comment!

/**
* Indicates that the user is eligible for Microsoft Entra ID Authenticated Copilot experience.
*/
Expand All @@ -1150,6 +1155,22 @@ export interface AppEligibilityInformation {
userClassification: UserClassification | null;
}

/**
* @hidden
* @beta
* Represents the feature set available to the user.
*/
export interface FeatureSet {
/**
* Server Feature set
*/
serverFeatures: ReadonlyArray<string>;
/**
* UX Feature set
*/
uxFeatures: ReadonlyArray<string>;
}

/**
* @hidden
*
Expand Down
63 changes: 63 additions & 0 deletions packages/teams-js/test/private/copilot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const mockedAppEligibilityInformation = {
persona: Persona.Student,
eduType: EduType.HigherEducation,
},
featureSet: { serverFeatures: ['feature1', 'feature2'], uxFeatures: ['feature3'] },
};

const mockedAppEligibilityInformationUserClassificationNull = {
Expand Down Expand Up @@ -188,6 +189,24 @@ describe('copilot', () => {
return expect(promise).resolves.toEqual(mockedAppEligibilityInformation);
});

it(`should not throw if featureSet in response is undefined - with context ${frameContext}`, async () => {
await utils.initializeWithContext(frameContext);
utils.setRuntimeConfig(copilotRuntimeConfig);

const promise = copilot.eligibility.getEligibilityInfo();
const message = utils.findMessageByFunc('copilot.eligibility.getEligibilityInfo');
const mockedAppEligibilityInformationWithUndefinedFeatureSet = {
...mockedAppEligibilityInformation,
featureSet: undefined,
};
expect(message).not.toBeNull();
if (message) {
utils.respondToMessage(message, mockedAppEligibilityInformationWithUndefinedFeatureSet);
}

return expect(promise).resolves.toEqual(mockedAppEligibilityInformationWithUndefinedFeatureSet);
});

it(`should throw error if host returns error - with context ${frameContext}`, async () => {
await utils.initializeWithContext(frameContext);
utils.setRuntimeConfig(copilotRuntimeConfig);
Expand Down Expand Up @@ -319,6 +338,50 @@ describe('copilot', () => {

await expect(promise).rejects.toThrowError('Error deserializing eligibility information');
});

it('getEligibilityInfo should throw if AppEligibilityInformation.featureSet.serverFeatures is undefined', async () => {
await utils.initializeWithContext(FrameContexts.content);
utils.setRuntimeConfig(copilotRuntimeConfig);

const mockedInvalidAppEligibilityInformationWithInvalidUxFeatures = {
...mockedAppEligibilityInformation,
featureSet: {
serverFeatures: undefined,
uxFeatures: [],
},
};

const promise = copilot.eligibility.getEligibilityInfo();
const message = utils.findMessageByFunc('copilot.eligibility.getEligibilityInfo');
expect(message).not.toBeNull();
if (message) {
utils.respondToMessage(message, mockedInvalidAppEligibilityInformationWithInvalidUxFeatures);
}

await expect(promise).rejects.toThrowError('Error deserializing eligibility information');
});

it('getEligibilityInfo should throw if AppEligibilityInformation.featureSet.uxFeatures is undefined', async () => {
await utils.initializeWithContext(FrameContexts.content);
utils.setRuntimeConfig(copilotRuntimeConfig);

const mockedInvalidAppEligibilityInformationWithInvalidUxFeatures = {
...mockedAppEligibilityInformation,
featureSet: {
serverFeatures: [],
uxFeatures: undefined,
},
};

const promise = copilot.eligibility.getEligibilityInfo();
const message = utils.findMessageByFunc('copilot.eligibility.getEligibilityInfo');
expect(message).not.toBeNull();
if (message) {
utils.respondToMessage(message, mockedInvalidAppEligibilityInformationWithInvalidUxFeatures);
}

await expect(promise).rejects.toThrowError('Error deserializing eligibility information');
});
});
});
});
Loading