@@ -543,7 +543,8 @@ func TestPrompt_AppSelectPrompt_GetApps(t *testing.T) {
543543 },
544544 },
545545 },
546- "returns unknown installation statuses for apps without auths" : {
546+ "returns unknown installation statuses for apps when status check fails" : {
547+ mockAuths : fakeAuthsByTeamDomainSlice ,
547548 mockAppsSavedDeployed : []types.App {
548549 deployedTeam1InstalledApp ,
549550 },
@@ -559,6 +560,7 @@ func TestPrompt_AppSelectPrompt_GetApps(t *testing.T) {
559560 TeamID : team1TeamID ,
560561 InstallStatus : types .AppInstallationStatusUnknown ,
561562 },
563+ Auth : fakeAuthsByTeamDomain [team1TeamDomain ],
562564 },
563565 },
564566 },
@@ -1093,6 +1095,7 @@ func TestPrompt_AppSelectPrompt(t *testing.T) {
10931095 expectedError : slackerror .New (slackerror .ErrLocalAppNotSupported ),
10941096 },
10951097 "errors if team id flag does not have authorization" : {
1098+ mockAuths : []types.SlackAuth {fakeAuthsByTeamDomain [team2TeamDomain ]},
10961099 mockFlagTeam : team1TeamID ,
10971100 appPromptConfigEnvironment : ShowHostedOnly ,
10981101 appPromptConfigStatus : ShowInstalledAndNewApps ,
@@ -1807,3 +1810,99 @@ func Test_ValidateAuth(t *testing.T) {
18071810 })
18081811 }
18091812}
1813+
1814+ // Test_getAuths_NoWorkspacesConnected tests the login prompt behavior when no
1815+ // workspaces are connected
1816+ func Test_getAuths_NoWorkspacesConnected (t * testing.T ) {
1817+ tests := map [string ]struct {
1818+ isTTY bool
1819+ expectedErr error
1820+ apiExchangeAuthTicketResultResponse api.ExchangeAuthTicketResult
1821+ apiExchangeAuthTicketResultError error
1822+ apiGenerateAuthTicketResultResponse api.GenerateAuthTicketResult
1823+ apiGenerateAuthTicketResultError error
1824+ }{
1825+ "returns error when not interactive and no workspaces connected" : {
1826+ isTTY : false ,
1827+ expectedErr : slackerror .New (slackerror .ErrNotAuthed ),
1828+ },
1829+ "prompts for login when interactive and no workspaces connected" : {
1830+ isTTY : true ,
1831+ apiExchangeAuthTicketResultResponse : api.ExchangeAuthTicketResult {
1832+ TeamDomain : team1TeamDomain ,
1833+ TeamID : team1TeamID ,
1834+ Token : team1Token ,
1835+ UserID : team1UserID ,
1836+ },
1837+ apiGenerateAuthTicketResultResponse : api.GenerateAuthTicketResult {
1838+ Ticket : "ticket123" ,
1839+ },
1840+ expectedErr : nil ,
1841+ },
1842+ }
1843+ for name , tc := range tests {
1844+ t .Run (name , func (t * testing.T ) {
1845+ ctx := slackcontext .MockContext (t .Context ())
1846+ clientsMock := shared .NewClientsMock ()
1847+ clientsMock .Auth .On (Auths , mock .Anything ).Return ([]types.SlackAuth {}, nil )
1848+ clientsMock .IO .On ("IsTTY" ).Return (tc .isTTY )
1849+ clientsMock .API .On (
1850+ "GenerateAuthTicket" ,
1851+ mock .Anything ,
1852+ mock .Anything ,
1853+ mock .Anything ,
1854+ ).Return (
1855+ tc .apiGenerateAuthTicketResultResponse ,
1856+ tc .apiGenerateAuthTicketResultError ,
1857+ )
1858+ clientsMock .API .On (
1859+ "ExchangeAuthTicket" ,
1860+ mock .Anything ,
1861+ mock .Anything ,
1862+ mock .Anything ,
1863+ mock .Anything ,
1864+ ).Return (
1865+ tc .apiExchangeAuthTicketResultResponse ,
1866+ tc .apiExchangeAuthTicketResultError ,
1867+ )
1868+ clientsMock .Auth .On (
1869+ "IsAPIHostSlackProd" ,
1870+ mock .Anything ,
1871+ ).Return (true )
1872+ clientsMock .Auth .On (
1873+ "SetAuth" ,
1874+ mock .Anything ,
1875+ mock .Anything ,
1876+ ).Return (
1877+ types.SlackAuth {},
1878+ "" ,
1879+ nil ,
1880+ )
1881+ clientsMock .IO .On (
1882+ "InputPrompt" ,
1883+ mock .Anything ,
1884+ "Enter challenge code" ,
1885+ iostreams.InputPromptConfig {Required : true },
1886+ ).Return (
1887+ "challengeCode" ,
1888+ nil ,
1889+ )
1890+ clientsMock .AddDefaultMocks ()
1891+ clients := shared .NewClientFactory (clientsMock .MockClientFactory ())
1892+
1893+ auths , err := getAuths (ctx , clients )
1894+
1895+ if tc .expectedErr != nil {
1896+ require .Error (t , err )
1897+ assert .Equal (t , tc .expectedErr .(* slackerror.Error ).Code , slackerror .ToSlackError (err ).Code )
1898+ assert .Contains (t , slackerror .ToSlackError (err ).Message , "No workspaces connected" )
1899+ } else {
1900+ require .NoError (t , err )
1901+ require .Len (t , auths , 1 )
1902+ assert .Equal (t , team1TeamID , auths [0 ].TeamID )
1903+ // Verify the welcome message was printed
1904+ assert .Contains (t , clientsMock .GetStdoutOutput (), "No workspaces connected" )
1905+ }
1906+ })
1907+ }
1908+ }
0 commit comments