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
62 changes: 31 additions & 31 deletions cmd/app/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,32 +144,32 @@ func TestAppAddCommand(t *testing.T) {
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{Auth: mockAuthTeam1}, nil)

// Mock valid session for team1
cm.APIInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
UserID: &mockAuthTeam1.UserID,
TeamID: &mockAuthTeam1.TeamID,
TeamName: &mockAuthTeam1.TeamDomain,
}, nil)

// Mock a clean ValidateAppManifest result
cm.APIInterface.On("ValidateAppManifest", mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything).Return(
cm.API.On("ValidateAppManifest", mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything).Return(
api.ValidateAppManifestResult{
Warnings: slackerror.Warnings{},
}, nil,
)

// Mock Host
cm.APIInterface.On("Host").Return("")
cm.API.On("Host").Return("")

// Mock a successful CreateApp call and return our mocked AppID
cm.APIInterface.On("CreateApp", mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything).Return(
cm.API.On("CreateApp", mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything).Return(
api.CreateAppResult{
AppID: mockAppTeam1.AppID,
},
nil,
)

// Mock a successful DeveloperAppInstall
cm.APIInterface.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
cm.API.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
api.DeveloperAppInstallResult{
AppID: mockAppTeam1.AppID,
APIAccessTokens: struct {
Expand All @@ -183,7 +183,7 @@ func TestAppAddCommand(t *testing.T) {
)

// Mock existing and updated cache
cm.APIInterface.On(
cm.API.On(
"ExportAppManifest",
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -216,21 +216,21 @@ func TestAppAddCommand(t *testing.T) {
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: mockAppTeam1, Auth: mockAuthTeam1}, nil)

// Mock valid session for team1
cm.APIInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
UserID: &mockAuthTeam1.UserID,
TeamID: &mockAuthTeam1.TeamID,
TeamName: &mockAuthTeam1.TeamDomain,
}, nil)

// Mock a clean ValidateAppManifest result
cm.APIInterface.On("ValidateAppManifest", mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything).Return(
cm.API.On("ValidateAppManifest", mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything).Return(
api.ValidateAppManifestResult{
Warnings: slackerror.Warnings{},
}, nil,
)

// Mock Host
cm.APIInterface.On("Host").Return("")
cm.API.On("Host").Return("")

// Mock to ensure that an existing deployed app is found
appClientMock := &app.AppClientMock{}
Expand All @@ -241,7 +241,7 @@ func TestAppAddCommand(t *testing.T) {
cf.AppClient().AppClientInterface = appClientMock

// Mock to ensure that the existing deployed app is updated successfully
cm.APIInterface.On("UpdateApp", mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
cm.API.On("UpdateApp", mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
api.UpdateAppResult{
AppID: mockAppTeam1.AppID,
Credentials: api.Credentials{},
Expand All @@ -251,7 +251,7 @@ func TestAppAddCommand(t *testing.T) {
)

// Mock a successful DeveloperAppInstall
cm.APIInterface.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
cm.API.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockAuthTeam1.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
api.DeveloperAppInstallResult{
AppID: mockAppTeam1.AppID,
APIAccessTokens: struct {
Expand All @@ -265,7 +265,7 @@ func TestAppAddCommand(t *testing.T) {
)

// Mock existing and updated cache
cm.APIInterface.On(
cm.API.On(
"ExportAppManifest",
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -306,24 +306,24 @@ func TestAppAddCommand(t *testing.T) {
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
// Mock calls
cm.APIInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
UserID: &mockOrgAuth.UserID,
TeamID: &mockOrgAuth.TeamID,
TeamName: &mockOrgAuth.TeamDomain,
}, nil)
cm.APIInterface.On("ValidateAppManifest", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
cm.API.On("ValidateAppManifest", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
api.ValidateAppManifestResult{}, nil,
)
cm.APIInterface.On("Host").Return("")
cm.API.On("Host").Return("")
// Return mocked AppID
cm.APIInterface.On("CreateApp", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
cm.API.On("CreateApp", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
api.CreateAppResult{
AppID: mockOrgApp.AppID,
},
nil,
)
// Mock call to apps.developerInstall
cm.APIInterface.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
cm.API.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
api.DeveloperAppInstallResult{
AppID: mockOrgApp.AppID,
},
Expand All @@ -332,7 +332,7 @@ func TestAppAddCommand(t *testing.T) {
)

// Mock existing and updated cache
cm.APIInterface.On(
cm.API.On(
"ExportAppManifest",
mock.Anything,
mock.Anything,
Expand All @@ -353,7 +353,7 @@ func TestAppAddCommand(t *testing.T) {
cm.Config.ProjectConfig = mockProjectConfig
},
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
cm.APIInterface.AssertCalled(t, "DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, "T123", mock.Anything)
cm.API.AssertCalled(t, "DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, "T123", mock.Anything)
},
},
"When admin approval request is pending, outputs instructions": {
Expand All @@ -366,32 +366,32 @@ func TestAppAddCommand(t *testing.T) {
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
// Mock calls
cm.APIInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
UserID: &mockOrgAuth.UserID,
TeamID: &mockOrgAuth.TeamID,
TeamName: &mockOrgAuth.TeamDomain,
}, nil)
cm.APIInterface.On("ValidateAppManifest", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
cm.API.On("ValidateAppManifest", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
api.ValidateAppManifestResult{}, nil,
)
cm.APIInterface.On("Host").Return("")
cm.API.On("Host").Return("")
// Return mocked AppID
cm.APIInterface.On("CreateApp", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
cm.API.On("CreateApp", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
api.CreateAppResult{
AppID: mockOrgApp.AppID,
},
nil,
)
// Mock call to apps.developerInstall
cm.APIInterface.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
cm.API.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
api.DeveloperAppInstallResult{
AppID: mockOrgApp.AppID,
},
types.InstallRequestPending,
nil,
)
// Mock existing and updated cache
cm.APIInterface.On(
cm.API.On(
"ExportAppManifest",
mock.Anything,
mock.Anything,
Expand Down Expand Up @@ -422,32 +422,32 @@ func TestAppAddCommand(t *testing.T) {
teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt
appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: types.NewApp(), Auth: mockOrgAuth}, nil)
// Mock calls
cm.APIInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
UserID: &mockOrgAuth.UserID,
TeamID: &mockOrgAuth.TeamID,
TeamName: &mockOrgAuth.TeamDomain,
}, nil)
cm.APIInterface.On("ValidateAppManifest", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
cm.API.On("ValidateAppManifest", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
api.ValidateAppManifestResult{}, nil,
)
cm.APIInterface.On("Host").Return("")
cm.API.On("Host").Return("")
// Return mocked AppID
cm.APIInterface.On("CreateApp", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
cm.API.On("CreateApp", mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything).Return(
api.CreateAppResult{
AppID: mockOrgApp.AppID,
},
nil,
)
// Mock call to apps.developerInstall
cm.APIInterface.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
cm.API.On("DeveloperAppInstall", mock.Anything, mock.Anything, mockOrgAuth.Token, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(
api.DeveloperAppInstallResult{
AppID: mockOrgApp.AppID,
},
types.InstallRequestCancelled,
nil,
)
// Mock existing and updated cache
cm.APIInterface.On(
cm.API.On(
"ExportAppManifest",
mock.Anything,
mock.Anything,
Expand Down
18 changes: 9 additions & 9 deletions cmd/app/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func TestAppsDeleteCommand(t *testing.T) {
}, nil)
// Mock delete confirmation prompt
cm.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to delete the app?", mock.Anything).Return(true, nil)
cm.APIInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
TeamName: &fakeDeployedApp.TeamDomain,
TeamID: &fakeDeployedApp.TeamID,
}, nil)
// Mock delete API call
cm.APIInterface.On("DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID).Return(nil)
cm.API.On("DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID).Return(nil)
// Mock AppClient calls
appClientMock := &app.AppClientMock{}
appClientMock.On("GetDeployed", mock.Anything, mock.Anything).Return(fakeDeployedApp, nil)
Expand All @@ -75,7 +75,7 @@ func TestAppsDeleteCommand(t *testing.T) {
cf.AppClient().AppClientInterface = appClientMock
},
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
cm.APIInterface.AssertCalled(t, "DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID)
cm.API.AssertCalled(t, "DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID)
},
ExpectedStdoutOutputs: []string{
fmt.Sprintf(`Uninstalled the app "%s" from "%s"`, fakeDeployedApp.AppID, fakeDeployedApp.TeamDomain),
Expand All @@ -95,20 +95,20 @@ func TestAppsDeleteCommand(t *testing.T) {
}, nil)
// Mock delete confirmation prompt
cm.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to delete the app?", mock.Anything).Return(true, nil)
cm.APIInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
TeamName: &fakeLocalApp.TeamDomain,
TeamID: &fakeLocalApp.TeamID,
}, nil)
// Mock delete API call
cm.APIInterface.On("DeleteApp", mock.Anything, mock.Anything, fakeLocalApp.AppID).Return(nil)
cm.API.On("DeleteApp", mock.Anything, mock.Anything, fakeLocalApp.AppID).Return(nil)
// Mock AppClient calls
appClientMock := &app.AppClientMock{}
appClientMock.On("GetLocal", mock.Anything, mock.Anything).Return(fakeLocalApp, nil)
appClientMock.On("Remove", mock.Anything, mock.Anything).Return(fakeLocalApp, nil)
cf.AppClient().AppClientInterface = appClientMock
},
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
cm.APIInterface.AssertCalled(t, "DeleteApp", mock.Anything, mock.Anything, fakeLocalApp.AppID)
cm.API.AssertCalled(t, "DeleteApp", mock.Anything, mock.Anything, fakeLocalApp.AppID)
},
ExpectedStdoutOutputs: []string{
fmt.Sprintf(`Uninstalled the app "%s" from "%s"`, fakeLocalApp.AppID, fakeLocalApp.TeamDomain),
Expand All @@ -128,12 +128,12 @@ func TestAppsDeleteCommand(t *testing.T) {
}, nil)
// Mock delete confirmation prompt
cm.IO.On("ConfirmPrompt", mock.Anything, "Are you sure you want to delete the app?", mock.Anything).Return(true, nil)
cm.APIInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{
TeamName: &fakeDeployedApp.TeamDomain,
TeamID: &fakeDeployedApp.TeamID,
}, nil)
// Mock delete API call
cm.APIInterface.On("DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID).Return(fmt.Errorf("something went terribly wrong"))
cm.API.On("DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID).Return(fmt.Errorf("something went terribly wrong"))
// Mock AppClient calls
appClientMock := &app.AppClientMock{}
appClientMock.On("GetDeployed", mock.Anything, mock.Anything).Return(fakeDeployedApp, nil)
Expand All @@ -146,7 +146,7 @@ func TestAppsDeleteCommand(t *testing.T) {
ExpectedError: slackerror.New(slackerror.ErrCredentialsNotFound),
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)
cm.API.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{}, nil)
appSelectMock := prompts.NewAppSelectMock()
deleteAppSelectPromptFunc = appSelectMock.AppSelectPrompt
appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{App: fakeDeployedApp}, nil)
Expand Down
2 changes: 1 addition & 1 deletion cmd/app/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func LinkExistingApp(ctx context.Context, clients *shared.ClientFactory, app *ty
}

appIDs := []string{app.AppID}
_, err = clients.APIInterface().GetAppStatus(ctx, auth.Token, appIDs, app.TeamID)
_, err = clients.API().GetAppStatus(ctx, auth.Token, appIDs, app.TeamID)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions cmd/app/link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Test_Apps_Link(t *testing.T) {
Flag: true,
Option: "deployed",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth1.Token,
Expand Down Expand Up @@ -146,7 +146,7 @@ func Test_Apps_Link(t *testing.T) {
Prompt: true,
Option: "local",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth2.Token,
Expand Down Expand Up @@ -213,7 +213,7 @@ func Test_Apps_Link(t *testing.T) {
Prompt: true,
Option: "deployed",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth1.Token,
Expand Down Expand Up @@ -282,7 +282,7 @@ func Test_Apps_Link(t *testing.T) {
Prompt: true,
Option: "local",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth1.Token,
Expand Down Expand Up @@ -358,7 +358,7 @@ func Test_Apps_Link(t *testing.T) {
Prompt: true,
Option: "local",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth2.Token,
Expand Down Expand Up @@ -417,7 +417,7 @@ func Test_Apps_Link(t *testing.T) {
Prompt: true,
Option: "Deployed",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth1.Token,
Expand Down Expand Up @@ -474,7 +474,7 @@ func Test_Apps_Link(t *testing.T) {
Flag: true,
Option: "deployed",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth1.Token,
Expand Down Expand Up @@ -585,7 +585,7 @@ func Test_Apps_Link(t *testing.T) {
Flag: true,
Option: "deployed",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth1.Token,
Expand Down Expand Up @@ -661,7 +661,7 @@ func Test_Apps_Link(t *testing.T) {
Flag: true,
Option: "deployed",
}, nil)
cm.APIInterface.On(
cm.API.On(
"GetAppStatus",
mock.Anything,
mockLinkSlackAuth1.Token,
Expand Down
Loading
Loading