Skip to content

Commit

Permalink
Supporting isNAAChannelRecommended flag for Legacy Teams Mobile Scena…
Browse files Browse the repository at this point in the history
…rio (#2604)

* updated isNAAChannelRecommended condition and added nestedAppAuth capability with version check in `runtime.ts`

* updated the conditions for isNAAChannelRecommended

pull from main and resolve conflicts

* updated teams client version and added unit tests

* addressed review comment

---------

Co-authored-by: Trevor Harris <trharris@microsoft.com>
  • Loading branch information
singhmanp0707 and TrevorJoelHarris authored Nov 20, 2024
1 parent ed5a63a commit 3a07cf5
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Added `nestedAppAuth` capability against a new client version `2.1.1` to support isNAAChannelRecommended for Teams Mobile",
"packageName": "@microsoft/teams-js",
"email": "singhmanp@microsoft.com",
"dependentChangeType": "patch"
}
25 changes: 24 additions & 1 deletion packages/teams-js/src/public/nestedAppAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* @module
*/

import { GlobalVars } from '../internal/globalVars';
import { ensureInitialized } from '../internal/internalAPIs';
import { HostClientType } from './constants';
import { runtime } from './runtime';

/**
Expand All @@ -16,5 +18,26 @@ import { runtime } from './runtime';
* @beta
*/
export function isNAAChannelRecommended(): boolean {
return (ensureInitialized(runtime) && runtime.isNAAChannelRecommended) ?? false;
return (
(ensureInitialized(runtime) &&
(runtime.isNAAChannelRecommended || isNAAChannelRecommendedForLegacyTeamsMobile())) ??
false
);
}

function isNAAChannelRecommendedForLegacyTeamsMobile(): boolean {
return ensureInitialized(runtime) &&
isHostAndroidOrIOSOrIPadOS() &&
runtime.isLegacyTeams &&
runtime.supports.nestedAppAuth
? true
: false;
}

function isHostAndroidOrIOSOrIPadOS(): boolean {
return (
GlobalVars.hostClientType === HostClientType.android ||
GlobalVars.hostClientType === HostClientType.ios ||
GlobalVars.hostClientType === HostClientType.ipados
);
}
6 changes: 6 additions & 0 deletions packages/teams-js/src/public/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@ export const mapTeamsVersionToSupportedCapabilities: Record<string, Array<ICapab
hostClientTypes: [HostClientType.android, HostClientType.ios],
},
],
'2.1.1': [
{
capability: { nestedAppAuth: {} },
hostClientTypes: [HostClientType.android, HostClientType.ios, HostClientType.ipados],
},
],
};

const generateBackCompatRuntimeConfigLogger = runtimeLogger.extend('generateBackCompatRuntimeConfig');
Expand Down
97 changes: 95 additions & 2 deletions packages/teams-js/test/public/nestedAppAuth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { errorLibraryNotInitialized } from '../../src/internal/constants';
import { app, FrameContexts, nestedAppAuth } from '../../src/public';
import { app, FrameContexts, HostClientType, nestedAppAuth } from '../../src/public';
import { _minRuntimeConfigToUninitialize, Runtime } from '../../src/public/runtime';
import { Utils } from '../utils';

Expand All @@ -10,7 +10,7 @@ import { Utils } from '../utils';
/**
* Test cases for nested app auth APIs
*/
describe('nestedAppAuth', () => {
describe('nestedAppAuth.isNAAChannelRecommended', () => {
const utils = new Utils();

beforeEach(() => {
Expand Down Expand Up @@ -63,4 +63,97 @@ describe('nestedAppAuth', () => {
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy();
});

it('should return false if isNAAChannelRecommended is false in runtimeConfig for macos client', async () => {
await utils.initializeWithContext(FrameContexts.content, HostClientType.macos);
const runtimeConfig: Runtime = {
apiVersion: 4,
supports: {},
isNAAChannelRecommended: false,
};
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy();
});

it('should return false if isNAAChannelRecommended is false in runtimeConfig for desktop client', async () => {
await utils.initializeWithContext(FrameContexts.content, HostClientType.desktop);
const runtimeConfig: Runtime = {
apiVersion: 4,
supports: {},
isNAAChannelRecommended: false,
};
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy();
});

it('should return false if isNAAChannelRecommended is false in runtimeConfig for web client', async () => {
await utils.initializeWithContext(FrameContexts.content, HostClientType.web);
const runtimeConfig: Runtime = {
apiVersion: 4,
supports: {},
isNAAChannelRecommended: false,
};
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy();
});

it('should return false if isNAAChannelRecommended is false and isLegacyTeams is false in runtimeConfig', async () => {
await utils.initializeWithContext(FrameContexts.content, HostClientType.android);
const runtimeConfig: Runtime = {
apiVersion: 4,
supports: {},
isNAAChannelRecommended: false,
isLegacyTeams: false,
};
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy();
});

it('should return false if isNAAChannelRecommended is false and isLegacyTeams is true in runtimeConfig for android client that does not supports nestedAppAuth', async () => {
await utils.initializeWithContext(FrameContexts.content, HostClientType.android);
const runtimeConfig: Runtime = {
apiVersion: 4,
supports: {},
isNAAChannelRecommended: false,
isLegacyTeams: true,
};
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeFalsy();
});

it('should return true if isNAAChannelRecommended is false and isLegacyTeams is true in runtimeConfig for android client that supports nestedAppAuth', async () => {
await utils.initializeWithContext(FrameContexts.content, HostClientType.android);
const runtimeConfig: Runtime = {
apiVersion: 4,
supports: { nestedAppAuth },
isNAAChannelRecommended: false,
isLegacyTeams: true,
};
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeTruthy();
});

it('should return true if isNAAChannelRecommended is false and isLegacyTeams is true in runtimeConfig for ios client that supports nestedAppAuth', async () => {
await utils.initializeWithContext(FrameContexts.content, HostClientType.ios);
const runtimeConfig: Runtime = {
apiVersion: 4,
supports: { nestedAppAuth },
isNAAChannelRecommended: false,
isLegacyTeams: true,
};
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeTruthy();
});

it('should return true if isNAAChannelRecommended is false and isLegacyTeams is true in runtimeConfig for ipados client that supports nestedAppAuth', async () => {
await utils.initializeWithContext(FrameContexts.content, HostClientType.ipados);
const runtimeConfig: Runtime = {
apiVersion: 4,
supports: { nestedAppAuth },
isNAAChannelRecommended: false,
isLegacyTeams: true,
};
utils.setRuntimeConfig(runtimeConfig);
expect(nestedAppAuth.isNAAChannelRecommended()).toBeTruthy();
});
});
2 changes: 2 additions & 0 deletions packages/teams-js/test/public/runtime.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/ban-types */

import { errorRuntimeNotInitialized } from '../../src/internal/constants';
import { GlobalVars } from '../../src/internal/globalVars';
import { compareSDKVersions } from '../../src/internal/utils';
import { app, HostClientType } from '../../src/public';
import {
Expand Down Expand Up @@ -243,6 +244,7 @@ describe('runtime', () => {

for (const clientType of capabilityAdditionsInASpecificVersion.hostClientTypes) {
await utils.initializeWithContext('content', clientType);
GlobalVars.hostClientType = clientType;
const generatedCapabilityObjectForThisVersion = generateVersionBasedTeamsRuntimeConfig(
version,
versionAndPlatformAgnosticTeamsRuntimeConfig,
Expand Down

0 comments on commit 3a07cf5

Please sign in to comment.