Skip to content

Commit 451b470

Browse files
Added force refresh parameter to get eligbility info API. (#2784)
* Added force refresh parameter to get eligbility info API. * Add unit testing with new argument. * Add input to get eligibility info test app. --------- Co-authored-by: Jeff Klouda <[email protected]>
1 parent 287d211 commit 451b470

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Added `forceRefresh` optional argument in `getEligibilityInfo` API.",
4+
"packageName": "@microsoft/teams-js",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/teams-js/src/private/copilot/eligibility.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,24 @@ export function isSupported(): boolean {
3434
}
3535

3636
/**
37+
*
38+
* @param forceRefresh - boolean to represent whether to force refresh the eligibility information
39+
* @returns the copilot eligibility information about the user
40+
* @throws Error if {@linkcode app.initialize} has not successfully completed
41+
*
3742
* @hidden
3843
* @internal
3944
* Limited to Microsoft-internal use
4045
* @beta
41-
* @returns the copilot eligibility information about the user
42-
*
43-
* @throws Error if {@linkcode app.initialize} has not successfully completed
4446
*/
45-
export async function getEligibilityInfo(): Promise<AppEligibilityInformation> {
47+
export async function getEligibilityInfo(forceRefresh?: boolean): Promise<AppEligibilityInformation> {
4648
ensureInitialized(runtime);
4749
if (!isSupported()) {
4850
throw new Error(`Error code: ${errorNotSupportedOnPlatform.errorCode}, message: Not supported on platform`);
4951
}
5052

5153
// Return the eligibility information if it is already available
52-
if (runtime.hostVersionsInfo?.appEligibilityInformation) {
54+
if (runtime.hostVersionsInfo?.appEligibilityInformation && !forceRefresh) {
5355
copilotLogger('Eligibility information is already available on runtime.');
5456
return runtime.hostVersionsInfo!.appEligibilityInformation;
5557
}
@@ -59,6 +61,7 @@ export async function getEligibilityInfo(): Promise<AppEligibilityInformation> {
5961
const response = await sendAndUnwrap<AppEligibilityInformation | SdkError>(
6062
getApiVersionTag(copilotTelemetryVersionNumber, ApiName.Copilot_Eligibility_GetEligibilityInfo),
6163
ApiName.Copilot_Eligibility_GetEligibilityInfo,
64+
forceRefresh,
6265
);
6366

6467
if (isSdkError(response)) {

packages/teams-js/test/private/copilot.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,33 @@ describe('copilot', () => {
192192
return expect(promise).resolves.toEqual(mockedAppEligibilityInformation);
193193
});
194194

195+
it(`should pass forceRefresh parameter if it exists - with context ${frameContext}`, async () => {
196+
expect.assertions(1);
197+
await utils.initializeWithContext(frameContext);
198+
utils.setRuntimeConfig(copilotRuntimeConfig);
199+
copilot.eligibility.getEligibilityInfo(true);
200+
const message = utils.findMessageByActionName('copilot.eligibility.getEligibilityInfo');
201+
expect(message.args?.[0]).toBe(true);
202+
});
203+
204+
it(`should pass forceRefresh parameter if it exists - with context ${frameContext}`, async () => {
205+
expect.assertions(1);
206+
await utils.initializeWithContext(frameContext);
207+
utils.setRuntimeConfig(copilotRuntimeConfig);
208+
copilot.eligibility.getEligibilityInfo(false);
209+
const message = utils.findMessageByActionName('copilot.eligibility.getEligibilityInfo');
210+
expect(message.args?.[0]).toBe(false);
211+
});
212+
213+
it(`should default forceRefresh parameter to false if not passed - with context ${frameContext}`, async () => {
214+
expect.assertions(1);
215+
await utils.initializeWithContext(frameContext);
216+
utils.setRuntimeConfig(copilotRuntimeConfig);
217+
copilot.eligibility.getEligibilityInfo();
218+
const message = utils.findMessageByActionName('copilot.eligibility.getEligibilityInfo');
219+
expect(message.args?.[0]).toBe(undefined);
220+
});
221+
195222
it(`should not throw if featureSet in response is undefined - with context ${frameContext}`, async () => {
196223
await utils.initializeWithContext(frameContext);
197224
utils.setRuntimeConfig(copilotRuntimeConfig);

0 commit comments

Comments
 (0)