Skip to content
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
22 changes: 10 additions & 12 deletions cmd/app/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ func TestAppAddCommandPreRun(t *testing.T) {
testutil.TableTestCommand(t, testutil.CommandTests{
"errors if not run in a project directory": {
ExpectedError: slackerror.New(slackerror.ErrInvalidAppDirectory),
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Copy link
Member Author

Choose a reason for hiding this comment

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

note: This change is made about 200 times 😆 Scroll down to the very bottom to see the updates to testutil.TableTestCommand that implement this feature. ⬇️

Copy link
Member

Choose a reason for hiding this comment

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

Praises @mwbrooks! This is a tedious but meaningful change 🎁

},
},
"proceeds if run in a project directory": {
ExpectedError: nil,
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cf.SDKConfig.WorkingDirectory = "."
},
},
Expand All @@ -100,8 +100,7 @@ func TestAppAddCommandPreRun(t *testing.T) {
Message: "Cannot install apps with manifests sourced from app settings",
},
}),
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
ctx := context.Background()
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cf.SDKConfig.WorkingDirectory = "."
cm.AddDefaultMocks()
cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, experiment.BoltFrameworks)
Expand All @@ -113,8 +112,7 @@ func TestAppAddCommandPreRun(t *testing.T) {
},
"proceeds if manifest.source is local with the bolt experiment": {
ExpectedError: nil,
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
ctx := context.Background()
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cf.SDKConfig.WorkingDirectory = "."
cm.AddDefaultMocks()
cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, experiment.BoltFrameworks)
Expand All @@ -137,7 +135,7 @@ func TestAppAddCommand(t *testing.T) {
"adds a new deployed app": {
CmdArgs: []string{},
ExpectedOutputs: []string{"Creating app manifest", "Installing"},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareAddMocks(t, cf, cm)

// Mock TeamSelector prompt to return "team1"
Expand Down Expand Up @@ -209,7 +207,7 @@ func TestAppAddCommand(t *testing.T) {
"updates an existing deployed app": {
CmdArgs: []string{},
ExpectedOutputs: []string{"Updated app manifest"},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareAddMocks(t, cf, cm)

// Mock TeamSelector prompt to return "team1"
Expand Down Expand Up @@ -291,7 +289,7 @@ func TestAppAddCommand(t *testing.T) {
"errors if authentication for the team is missing": {
CmdArgs: []string{},
ExpectedError: slackerror.New(slackerror.ErrCredentialsNotFound),
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareAddMocks(t, cf, cm)
appSelectMock := prompts.NewAppSelectMock()
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
Expand All @@ -301,7 +299,7 @@ func TestAppAddCommand(t *testing.T) {
"adds a new deployed app to an org with a workspace grant": {
CmdArgs: []string{"--" + cmdutil.OrgGrantWorkspaceFlag, "T123"},
ExpectedOutputs: []string{"Creating app manifest", "Installing"},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareAddMocks(t, cf, cm)
// Select workspace
appSelectMock := prompts.NewAppSelectMock()
Expand Down Expand Up @@ -361,7 +359,7 @@ func TestAppAddCommand(t *testing.T) {
"When admin approval request is pending, outputs instructions": {
CmdArgs: []string{"--" + cmdutil.OrgGrantWorkspaceFlag, "T123"},
ExpectedOutputs: []string{"Creating app manifest", "Installing", "Your request to install the app is pending", "complete installation by re-running"},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareAddMocks(t, cf, cm)
// Select workspace
appSelectMock := prompts.NewAppSelectMock()
Expand Down Expand Up @@ -417,7 +415,7 @@ func TestAppAddCommand(t *testing.T) {
"When admin approval request is cancelled, outputs instructions": {
CmdArgs: []string{"--" + cmdutil.OrgGrantWorkspaceFlag, "T123"},
ExpectedOutputs: []string{"Creating app manifest", "Installing", "Your request to install the app has been cancelled"},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareAddMocks(t, cf, cm)
// Select workspace
appSelectMock := prompts.NewAppSelectMock()
Expand Down
9 changes: 5 additions & 4 deletions cmd/app/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package app

import (
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -49,7 +50,7 @@ func TestAppsDeleteCommand(t *testing.T) {
testutil.TableTestCommand(t, testutil.CommandTests{
"happy path; delete the deployed app": {
CmdArgs: []string{},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareCommonDeleteMocks(t, cf, cm)
// Mock App Selection
appSelectMock := prompts.NewAppSelectMock()
Expand Down Expand Up @@ -83,7 +84,7 @@ func TestAppsDeleteCommand(t *testing.T) {
},
"happy path; delete the local app": {
CmdArgs: []string{},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareCommonDeleteMocks(t, cf, cm)
// Mock App Selection
appSelectMock := prompts.NewAppSelectMock()
Expand Down Expand Up @@ -116,7 +117,7 @@ func TestAppsDeleteCommand(t *testing.T) {
},
"sad path; deleting the deployed app fails": {
CmdArgs: []string{},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareCommonDeleteMocks(t, cf, cm)
// Mock App Selection
appSelectMock := prompts.NewAppSelectMock()
Expand All @@ -143,7 +144,7 @@ func TestAppsDeleteCommand(t *testing.T) {
"errors if authentication for the team is missing": {
CmdArgs: []string{},
ExpectedError: slackerror.New(slackerror.ErrCredentialsNotFound),
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareCommonDeleteMocks(t, cf, cm)
cm.ApiInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{}, nil)
appSelectMock := prompts.NewAppSelectMock()
Expand Down
19 changes: 8 additions & 11 deletions cmd/app/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var mockLinkSlackAuth2 = types.SlackAuth{
func Test_Apps_Link(t *testing.T) {
testutil.TableTestCommand(t, testutil.CommandTests{
"saves information about the provided deployed app": {
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
mockLinkSlackAuth2,
mockLinkSlackAuth1,
Expand Down Expand Up @@ -111,7 +111,7 @@ func Test_Apps_Link(t *testing.T) {
},
},
"saves information about the provided local app": {
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
mockLinkSlackAuth2,
mockLinkSlackAuth1,
Expand Down Expand Up @@ -170,8 +170,7 @@ func Test_Apps_Link(t *testing.T) {
},
},
"avoids overwriting an app saved in json without confirmation": {
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
ctx := context.Background()
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
mockLinkSlackAuth1,
mockLinkSlackAuth2,
Expand Down Expand Up @@ -240,8 +239,7 @@ func Test_Apps_Link(t *testing.T) {
WithRemediation("Remove the app from this project or try again with --force"),
},
"avoids overwriting a matching app id for the team without confirmation": {
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
ctx := context.Background()
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
mockLinkSlackAuth1,
mockLinkSlackAuth2,
Expand Down Expand Up @@ -316,8 +314,7 @@ func Test_Apps_Link(t *testing.T) {
WithRemediation("Remove the app from this project or try again with --force"),
},
"completes overwriting an app saved in json with confirmation": {
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
ctx := context.Background()
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
mockLinkSlackAuth1,
mockLinkSlackAuth2,
Expand Down Expand Up @@ -385,7 +382,7 @@ func Test_Apps_Link(t *testing.T) {
},
},
"refuses to write an app with app id not existing upstream": {
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
mockLinkSlackAuth1,
mockLinkSlackAuth2,
Expand Down Expand Up @@ -433,7 +430,7 @@ func Test_Apps_Link(t *testing.T) {
ExpectedError: slackerror.New(slackerror.ErrAppNotFound),
},
"accept manifest source prompt and saves information about the provided deployed app": {
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.AuthInterface.On("Auths", mock.Anything).Return([]types.SlackAuth{
mockLinkSlackAuth2,
mockLinkSlackAuth1,
Expand Down Expand Up @@ -506,7 +503,7 @@ func Test_Apps_Link(t *testing.T) {
},
},
"decline manifest source prompt should not link app": {
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.AddDefaultMocks()
setupAppLinkCommandMocks(t, cm, cf)
// Set manifest source to project to trigger confirmation prompt
Expand Down
8 changes: 4 additions & 4 deletions cmd/app/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestAppsUninstall(t *testing.T) {

testutil.TableTestCommand(t, testutil.CommandTests{
"Successfully uninstall": {
Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
prepareCommonUninstallMocks(clients, clientsMock)
clientsMock.ApiInterface.On("UninstallApp", mock.Anything, mock.Anything, fakeAppID, fakeAppTeamID).
Return(nil).Once()
Expand All @@ -57,7 +57,7 @@ func TestAppsUninstall(t *testing.T) {
},
},
"Successfully uninstall with a get-manifest hook error": {
Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
prepareCommonUninstallMocks(clients, clientsMock)
clientsMock.ApiInterface.On("UninstallApp", mock.Anything, mock.Anything, fakeAppID, fakeAppTeamID).
Return(nil).Once()
Expand All @@ -72,7 +72,7 @@ func TestAppsUninstall(t *testing.T) {
},
"Fail to uninstall due to API error": {
ExpectedError: slackerror.New("something went wrong"),
Setup: func(t *testing.T, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, clientsMock *shared.ClientsMock, clients *shared.ClientFactory) {
prepareCommonUninstallMocks(clients, clientsMock)
clientsMock.ApiInterface.On("UninstallApp", mock.Anything, mock.Anything, fakeAppID, fakeAppTeamID).
Return(slackerror.New("something went wrong")).Once()
Expand All @@ -81,7 +81,7 @@ func TestAppsUninstall(t *testing.T) {
"errors if authentication for the team is missing": {
CmdArgs: []string{},
ExpectedError: slackerror.New(slackerror.ErrCredentialsNotFound),
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
prepareCommonUninstallMocks(cf, cm)
appSelectMock := prompts.NewAppSelectMock()
uninstallAppSelectPromptFunc = appSelectMock.AppSelectPrompt
Expand Down
11 changes: 6 additions & 5 deletions cmd/auth/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package auth

import (
"context"
"testing"

"github.com/slackapi/slack-cli/internal/api"
Expand Down Expand Up @@ -52,7 +53,7 @@ func TestLoginCommmand(t *testing.T) {
"deprecated auth flag is noted in outputs": {
CmdArgs: []string{"--auth", "xoxp-example"},
ExpectedOutputs: []string{deprecatedUserTokenMessage},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.ApiInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
UserID: &mockOrgAuth.UserID,
TeamID: &mockOrgAuth.TeamID,
Expand All @@ -79,7 +80,7 @@ func TestLoginCommmand(t *testing.T) {
"suggests creating a new app if not in a project": {
CmdArgs: []string{"--ticket=example", "--challenge=tictactoe"},
ExpectedStdoutOutputs: []string{"Get started by creating a new app"},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.ApiInterface.On(
"ExchangeAuthTicket",
mock.Anything,
Expand Down Expand Up @@ -109,7 +110,7 @@ func TestLoginCommmand(t *testing.T) {
"suggests listing existing apps from the project": {
CmdArgs: []string{"--ticket", "example", "--challenge", "tictactoe"},
ExpectedStdoutOutputs: []string{"Review existing installations of the app"},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.ApiInterface.On(
"ExchangeAuthTicket",
mock.Anything,
Expand Down Expand Up @@ -139,7 +140,7 @@ func TestLoginCommmand(t *testing.T) {
},
"happy path login with prompt flow should pass challenge code to ExchangeAuthTicket API": {
CmdArgs: []string{},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.ApiInterface.On("GenerateAuthTicket", mock.Anything, mock.Anything, mock.Anything).Return(api.GenerateAuthTicketResult{}, nil)
cm.IO.On("InputPrompt", mock.Anything, "Enter challenge code", iostreams.InputPromptConfig{
Required: true,
Expand All @@ -162,7 +163,7 @@ func TestLoginCommmand(t *testing.T) {
},
"should explode if ExchangeAuthTicket API fails": {
CmdArgs: []string{},
Setup: func(t *testing.T, cm *shared.ClientsMock, cf *shared.ClientFactory) {
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
cm.ApiInterface.On("GenerateAuthTicket", mock.Anything, mock.Anything, mock.Anything).Return(api.GenerateAuthTicketResult{}, nil)
cm.IO.On("InputPrompt", mock.Anything, "Enter challenge code", iostreams.InputPromptConfig{
Required: true,
Expand Down
Loading
Loading