@@ -1024,6 +1024,98 @@ describe(`BotFrameworkAdapter`, function () {
10241024 assert ( false , `should have thrown an error message` ) ;
10251025 } ) ;
10261026
1027+ describe ( 'getSignInLink()' , ( ) => {
1028+ it ( `should throw if userName != from.id` , async ( ) => {
1029+ const adapter = new BotFrameworkAdapter ( ) ;
1030+ const context = new TurnContext ( adapter , incomingMessage ) ;
1031+ try {
1032+ const response = await adapter . getSignInLink ( context , 'aConnectionName' , new MicrosoftAppCredentials ( 'abc' , 'abc' ) , 'invalidId' ) ;
1033+ } catch ( err ) {
1034+ assert ( err . message === `cannot retrieve OAuth signin link for a user that's different from the conversation` ) ;
1035+ return ;
1036+ }
1037+ assert ( false , `should have thrown an error message` ) ;
1038+ } ) ;
1039+ it ( `should return return a sign-in URL with context and connectionName` , async ( ) => {
1040+ const argsPassedToMockClient = [ ] ;
1041+ class MockTokenApiClient {
1042+ constructor ( ) {
1043+ this . botSignIn = {
1044+ getSignInUrl : async ( ...args ) => {
1045+ argsPassedToMockClient . push ( { getSignInUrl : args } ) ;
1046+ return {
1047+ _response : { status : 200 , bodyAsText : 'http://mockedurl.com' }
1048+ }
1049+ }
1050+ } ;
1051+ this . credentials = new MicrosoftAppCredentials ( 'abc' , 'abc' ) ;
1052+ }
1053+
1054+ }
1055+ const { TokenApiClient} = connector ;
1056+ connector . TokenApiClient = MockTokenApiClient ;
1057+
1058+ const adapter = new BotFrameworkAdapter ( ) ;
1059+ const context = new TurnContext ( adapter , incomingMessage ) ;
1060+ const response = await adapter . getSignInLink ( context , 'aConnectionName' ) ;
1061+ assert ( response , 'http://mockedurl.com' ) ;
1062+
1063+ connector . TokenApiClient = TokenApiClient ; // restore
1064+ } ) ;
1065+ it ( `should return return a sign-in URL with context connectionName, oauthAppCredentials` , async ( ) => {
1066+ const argsPassedToMockClient = [ ] ;
1067+ class MockTokenApiClient {
1068+ constructor ( ) {
1069+ this . botSignIn = {
1070+ getSignInUrl : async ( ...args ) => {
1071+ argsPassedToMockClient . push ( { getSignInUrl : args } ) ;
1072+ return {
1073+ _response : { status : 200 , bodyAsText : 'http://mockedurl.com' }
1074+ }
1075+ }
1076+ } ;
1077+ this . credentials = new MicrosoftAppCredentials ( 'abc' , 'abc' ) ;
1078+ }
1079+
1080+ }
1081+ const { TokenApiClient} = connector ;
1082+ connector . TokenApiClient = MockTokenApiClient ;
1083+
1084+ const adapter = new BotFrameworkAdapter ( ) ;
1085+ const context = new TurnContext ( adapter , incomingMessage ) ;
1086+ const response = await adapter . getSignInLink ( context , 'aConnectionName' , new MicrosoftAppCredentials ( 'abc' , 'abc' ) ) ;
1087+ assert ( response , 'http://mockedurl.com' ) ;
1088+
1089+ connector . TokenApiClient = TokenApiClient ; // restore
1090+ } ) ;
1091+ it ( `should return return a sign-in URL with context connectionName, oauthAppCredentials, userId, finalRedirect` , async ( ) => {
1092+ const argsPassedToMockClient = [ ] ;
1093+ class MockTokenApiClient {
1094+ constructor ( ) {
1095+ this . botSignIn = {
1096+ getSignInUrl : async ( ...args ) => {
1097+ argsPassedToMockClient . push ( { getSignInUrl : args } ) ;
1098+ return {
1099+ _response : { status : 200 , bodyAsText : 'http://mockedurl.com' }
1100+ }
1101+ }
1102+ } ;
1103+ this . credentials = new MicrosoftAppCredentials ( 'abc' , 'abc' ) ;
1104+ }
1105+
1106+ }
1107+ const { TokenApiClient} = connector ;
1108+ connector . TokenApiClient = MockTokenApiClient ;
1109+
1110+ const adapter = new BotFrameworkAdapter ( ) ;
1111+ const context = new TurnContext ( adapter , incomingMessage ) ;
1112+ const response = await adapter . getSignInLink ( context , 'aConnectionName' , new MicrosoftAppCredentials ( 'abc' , 'abc' ) , incomingMessage . from . id , 'http://finalredirect.com' ) ;
1113+ assert ( response , 'http://mockedurl.com' ) ;
1114+
1115+ connector . TokenApiClient = TokenApiClient ; // restore
1116+ } ) ;
1117+ } ) ;
1118+
10271119 describe ( 'getTokenStatus()' , ( ) => {
10281120 xit ( `should return the status of every connection the user has` , async ( ) => {
10291121 const adapter = new AdapterUnderTest ( ) ;
0 commit comments