Skip to content

Commit 3632f26

Browse files
committed
test: update tests for local and remote manifest source
1 parent f5ab1ef commit 3632f26

1 file changed

Lines changed: 12 additions & 87 deletions

File tree

cmd/app/link_test.go

Lines changed: 12 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func Test_Apps_Link(t *testing.T) {
466466
mock.Anything,
467467
).Return(iostreams.SelectPromptResponse{
468468
Flag: true,
469-
Option: "deployed",
469+
Option: "local",
470470
}, nil)
471471
cm.API.On(
472472
"GetAppStatus",
@@ -483,8 +483,10 @@ func Test_Apps_Link(t *testing.T) {
483483
TeamDomain: mockLinkSlackAuth1.TeamDomain,
484484
TeamID: mockLinkSlackAuth1.TeamID,
485485
EnterpriseID: mockLinkSlackAuth1.EnterpriseID,
486+
UserID: mockLinkSlackAuth1.UserID,
487+
IsDev: true,
486488
}
487-
actualApp, err := cm.AppClient.GetDeployed(
489+
actualApp, err := cm.AppClient.GetLocal(
488490
ctx,
489491
mockLinkSlackAuth1.TeamID,
490492
)
@@ -496,97 +498,18 @@ func Test_Apps_Link(t *testing.T) {
496498
assert.Contains(t, output, `"project" (local)`)
497499
},
498500
},
499-
"displays manifest info for Run-on-Slack apps with local manifest source": {
501+
"links app when manifest source is remote": {
500502
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
501503
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
502-
mockLinkSlackAuth1,
503504
mockLinkSlackAuth2,
504-
}, nil)
505-
cm.AddDefaultMocks()
506-
setupAppLinkCommandMocks(t, ctx, cm, cf)
507-
// Set manifest source to local
508-
if err := config.SetManifestSource(ctx, cm.Fs, cm.Os, config.ManifestSourceLocal); err != nil {
509-
require.FailNow(t, fmt.Sprintf("Failed to set the manifest source in the memory-based file system: %s", err))
510-
}
511-
// Mock manifest for Run-on-Slack app
512-
manifestMock := &app.ManifestMockObject{}
513-
manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{
514-
AppManifest: types.AppManifest{
515-
Settings: &types.AppSettings{
516-
FunctionRuntime: types.SlackHosted,
517-
},
518-
},
519-
}, nil)
520-
cf.AppClient().Manifest = manifestMock
521-
cm.IO.On("SelectPrompt",
522-
mock.Anything,
523-
"Select the existing app team",
524-
mock.Anything,
525-
mock.Anything,
526-
mock.Anything,
527-
).Return(iostreams.SelectPromptResponse{
528-
Flag: true,
529-
Option: mockLinkSlackAuth1.TeamDomain,
530-
}, nil)
531-
cm.IO.On("InputPrompt",
532-
mock.Anything,
533-
"Enter the existing app ID",
534-
mock.Anything,
535-
).Return(mockLinkAppID1, nil)
536-
cm.IO.On("SelectPrompt",
537-
mock.Anything,
538-
"Choose the app environment",
539-
mock.Anything,
540-
mock.Anything,
541-
mock.Anything,
542-
).Return(iostreams.SelectPromptResponse{
543-
Flag: true,
544-
Option: "deployed",
545-
}, nil)
546-
cm.API.On(
547-
"GetAppStatus",
548-
mock.Anything,
549-
mockLinkSlackAuth1.Token,
550-
[]string{mockLinkAppID1},
551-
mockLinkSlackAuth1.TeamID,
552-
).Return(api.GetAppStatusResult{}, nil)
553-
},
554-
CmdArgs: []string{},
555-
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
556-
expectedApp := types.App{
557-
AppID: mockLinkAppID1,
558-
TeamDomain: mockLinkSlackAuth1.TeamDomain,
559-
TeamID: mockLinkSlackAuth1.TeamID,
560-
EnterpriseID: mockLinkSlackAuth1.EnterpriseID,
561-
}
562-
actualApp, err := cm.AppClient.GetDeployed(
563-
ctx,
564-
mockLinkSlackAuth1.TeamID,
565-
)
566-
require.NoError(t, err)
567-
assert.Equal(t, expectedApp, actualApp)
568-
// Assert manifest source info is displayed
569-
output := cm.GetCombinedOutput()
570-
assert.Contains(t, output, "App Manifest")
571-
assert.Contains(t, output, `"project" (local)`)
572-
},
573-
},
574-
"displays manifest info for GBP apps with local manifest source": {
575-
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
576-
cm.Auth.On("Auths", mock.Anything).Return([]types.SlackAuth{
577505
mockLinkSlackAuth1,
578-
mockLinkSlackAuth2,
579506
}, nil)
580507
cm.AddDefaultMocks()
581508
setupAppLinkCommandMocks(t, ctx, cm, cf)
582-
// Set manifest source to local
583-
if err := config.SetManifestSource(ctx, cm.Fs, cm.Os, config.ManifestSourceLocal); err != nil {
509+
// Set manifest source to remote
510+
if err := config.SetManifestSource(ctx, cm.Fs, cm.Os, config.ManifestSourceRemote); err != nil {
584511
require.FailNow(t, fmt.Sprintf("Failed to set the manifest source in the memory-based file system: %s", err))
585512
}
586-
// Mock manifest for GBP app
587-
manifestMock := &app.ManifestMockObject{}
588-
manifestMock.On("GetManifestLocal", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{}, nil)
589-
cf.AppClient().Manifest = manifestMock
590513
cm.IO.On("SelectPrompt",
591514
mock.Anything,
592515
"Select the existing app team",
@@ -610,7 +533,7 @@ func Test_Apps_Link(t *testing.T) {
610533
mock.Anything,
611534
).Return(iostreams.SelectPromptResponse{
612535
Flag: true,
613-
Option: "deployed",
536+
Option: "local",
614537
}, nil)
615538
cm.API.On(
616539
"GetAppStatus",
@@ -627,8 +550,10 @@ func Test_Apps_Link(t *testing.T) {
627550
TeamDomain: mockLinkSlackAuth1.TeamDomain,
628551
TeamID: mockLinkSlackAuth1.TeamID,
629552
EnterpriseID: mockLinkSlackAuth1.EnterpriseID,
553+
UserID: mockLinkSlackAuth1.UserID,
554+
IsDev: true,
630555
}
631-
actualApp, err := cm.AppClient.GetDeployed(
556+
actualApp, err := cm.AppClient.GetLocal(
632557
ctx,
633558
mockLinkSlackAuth1.TeamID,
634559
)
@@ -637,7 +562,7 @@ func Test_Apps_Link(t *testing.T) {
637562
// Assert manifest source info is displayed
638563
output := cm.GetCombinedOutput()
639564
assert.Contains(t, output, "App Manifest")
640-
assert.Contains(t, output, `"project" (local)`)
565+
assert.Contains(t, output, `"app settings" (remote)`)
641566
},
642567
},
643568
}, func(clients *shared.ClientFactory) *cobra.Command {

0 commit comments

Comments
 (0)