-
Notifications
You must be signed in to change notification settings - Fork 24
test: assert output for collaborator list command #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,33 +29,45 @@ import ( | |
|
|
||
| func TestCollaboratorsCommand(t *testing.T) { | ||
| tests := map[string]struct { | ||
| App types.App | ||
| Collaborators []types.SlackUser | ||
| app types.App | ||
| collaborators []types.SlackUser | ||
| expectedOutputs []string | ||
| }{ | ||
| "lists no collaborators if none exist": { | ||
| App: types.App{ | ||
| app: types.App{ | ||
| AppID: "A001", | ||
| }, | ||
| Collaborators: []types.SlackUser{}, | ||
| collaborators: []types.SlackUser{}, | ||
| expectedOutputs: []string{ | ||
| " 0 collaborators", // Include space to not match "10 collaborators" | ||
| }, | ||
| }, | ||
| "lists the collaborator if one exists": { | ||
| App: types.App{ | ||
| app: types.App{ | ||
| AppID: "A002", | ||
| }, | ||
| Collaborators: []types.SlackUser{ | ||
| collaborators: []types.SlackUser{ | ||
| { | ||
| ID: "USLACKBOT", | ||
| UserName: "slackbot", | ||
| Email: "[email protected]", | ||
| PermissionType: types.OWNER, | ||
| }, | ||
| }, | ||
| expectedOutputs: []string{ | ||
| "1 collaborator", | ||
| // User info: slackbot | ||
| "USLACKBOT", | ||
| "slackbot", | ||
| "[email protected]", | ||
| string(types.OWNER), | ||
| }, | ||
|
Comment on lines
+57
to
+64
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Assert 1 user is listed |
||
| }, | ||
| "lists all collaborators if many exist": { | ||
| App: types.App{ | ||
| app: types.App{ | ||
| AppID: "A002", | ||
| }, | ||
| Collaborators: []types.SlackUser{ | ||
| collaborators: []types.SlackUser{ | ||
| { | ||
| ID: "USLACKBOT", | ||
| UserName: "slackbot", | ||
|
|
@@ -69,37 +81,54 @@ func TestCollaboratorsCommand(t *testing.T) { | |
| PermissionType: types.READER, | ||
| }, | ||
| }, | ||
| expectedOutputs: []string{ | ||
| "2 collaborators", | ||
| // User info: slackbot | ||
| "USLACKBOT", | ||
| "slackbot", | ||
| "[email protected]", | ||
| string(types.OWNER), | ||
| // User info: bookworm | ||
| "U00READER", | ||
| "bookworm", | ||
| "[email protected]", | ||
| string(types.READER), | ||
| }, | ||
|
Comment on lines
+84
to
+96
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Assert 2 users are listed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📚 🪱 🤖 ✨ What an interesting app! |
||
| }, | ||
| } | ||
|
|
||
| for name, tt := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| appSelectMock := prompts.NewAppSelectMock() | ||
| teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt | ||
| appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: tt.App, Auth: types.SlackAuth{}}, nil) | ||
| appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: tt.app, Auth: types.SlackAuth{}}, nil) | ||
| clientsMock := shared.NewClientsMock() | ||
| clientsMock.AddDefaultMocks() | ||
| clientsMock.ApiInterface.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything). | ||
| Return(tt.Collaborators, nil) | ||
| Return(tt.collaborators, nil) | ||
| clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(clients *shared.ClientFactory) { | ||
| clients.SDKConfig = hooks.NewSDKConfigMock() | ||
| }) | ||
|
|
||
| err := NewCommand(clients).Execute() | ||
| require.NoError(t, err) | ||
| clientsMock.ApiInterface.AssertCalled(t, "ListCollaborators", mock.Anything, mock.Anything, tt.App.AppID) | ||
| clientsMock.ApiInterface.AssertCalled(t, "ListCollaborators", mock.Anything, mock.Anything, tt.app.AppID) | ||
| clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListSuccess, mock.Anything) | ||
| clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListCount, []string{ | ||
| fmt.Sprintf("%d", len(tt.Collaborators)), | ||
| fmt.Sprintf("%d", len(tt.collaborators)), | ||
| }) | ||
| for _, collaborator := range tt.Collaborators { | ||
| for _, collaborator := range tt.collaborators { | ||
| clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListCollaborator, []string{ | ||
| collaborator.ID, | ||
| collaborator.UserName, | ||
| collaborator.Email, | ||
| string(collaborator.PermissionType), | ||
| }) | ||
| } | ||
| output := clientsMock.GetCombinedOutput() | ||
| for _, expectedOutput := range tt.expectedOutputs { | ||
| require.Contains(t, output, expectedOutput) | ||
| } | ||
|
Comment on lines
+128
to
+131
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: This is the meat and potatoes that implements the assertions |
||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,33 +29,45 @@ import ( | |
|
|
||
| func TestListCommand(t *testing.T) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: This files changes are identical to |
||
| tests := map[string]struct { | ||
| App types.App | ||
| Collaborators []types.SlackUser | ||
| app types.App | ||
| collaborators []types.SlackUser | ||
| expectedOutputs []string | ||
| }{ | ||
| "lists no collaborators if none exist": { | ||
| App: types.App{ | ||
| app: types.App{ | ||
| AppID: "A001", | ||
| }, | ||
| Collaborators: []types.SlackUser{}, | ||
| collaborators: []types.SlackUser{}, | ||
| expectedOutputs: []string{ | ||
| "0 collaborators", | ||
| }, | ||
| }, | ||
| "lists the collaborator if one exists": { | ||
| App: types.App{ | ||
| app: types.App{ | ||
| AppID: "A002", | ||
| }, | ||
| Collaborators: []types.SlackUser{ | ||
| collaborators: []types.SlackUser{ | ||
| { | ||
| ID: "USLACKBOT", | ||
| UserName: "slackbot", | ||
| Email: "[email protected]", | ||
| PermissionType: types.OWNER, | ||
| }, | ||
| }, | ||
| expectedOutputs: []string{ | ||
| "1 collaborator", | ||
| // User info: slackbot | ||
| "USLACKBOT", | ||
| "slackbot", | ||
| "[email protected]", | ||
| string(types.OWNER), | ||
| }, | ||
| }, | ||
| "lists all collaborators if many exist": { | ||
| App: types.App{ | ||
| app: types.App{ | ||
| AppID: "A002", | ||
| }, | ||
| Collaborators: []types.SlackUser{ | ||
| collaborators: []types.SlackUser{ | ||
| { | ||
| ID: "USLACKBOT", | ||
| UserName: "slackbot", | ||
|
|
@@ -69,37 +81,54 @@ func TestListCommand(t *testing.T) { | |
| PermissionType: types.READER, | ||
| }, | ||
| }, | ||
| expectedOutputs: []string{ | ||
| "2 collaborators", | ||
| // User info: slackbot | ||
| "USLACKBOT", | ||
| "slackbot", | ||
| "[email protected]", | ||
| string(types.OWNER), | ||
| // User info: bookworm | ||
| "U00READER", | ||
| "bookworm", | ||
| "[email protected]", | ||
| string(types.READER), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for name, tt := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| appSelectMock := prompts.NewAppSelectMock() | ||
| teamAppSelectPromptFunc = appSelectMock.TeamAppSelectPrompt | ||
| appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: tt.App, Auth: types.SlackAuth{}}, nil) | ||
| appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{App: tt.app, Auth: types.SlackAuth{}}, nil) | ||
| clientsMock := shared.NewClientsMock() | ||
| clientsMock.AddDefaultMocks() | ||
| clientsMock.ApiInterface.On("ListCollaborators", mock.Anything, mock.Anything, mock.Anything). | ||
| Return(tt.Collaborators, nil) | ||
| Return(tt.collaborators, nil) | ||
| clients := shared.NewClientFactory(clientsMock.MockClientFactory(), func(clients *shared.ClientFactory) { | ||
| clients.SDKConfig = hooks.NewSDKConfigMock() | ||
| }) | ||
|
|
||
| err := NewListCommand(clients).Execute() | ||
| require.NoError(t, err) | ||
| clientsMock.ApiInterface.AssertCalled(t, "ListCollaborators", mock.Anything, mock.Anything, tt.App.AppID) | ||
| clientsMock.ApiInterface.AssertCalled(t, "ListCollaborators", mock.Anything, mock.Anything, tt.app.AppID) | ||
| clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListSuccess, mock.Anything) | ||
| clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListCount, []string{ | ||
| fmt.Sprintf("%d", len(tt.Collaborators)), | ||
| fmt.Sprintf("%d", len(tt.collaborators)), | ||
| }) | ||
| for _, collaborator := range tt.Collaborators { | ||
| for _, collaborator := range tt.collaborators { | ||
| clientsMock.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.CollaboratorListCollaborator, []string{ | ||
| collaborator.ID, | ||
| collaborator.UserName, | ||
| collaborator.Email, | ||
| string(collaborator.PermissionType), | ||
| }) | ||
| } | ||
| output := clientsMock.GetCombinedOutput() | ||
| for _, expectedOutput := range tt.expectedOutputs { | ||
| require.Contains(t, output, expectedOutput) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: We don't need to export these variables and the default is typically to not export unless it's intentional. Happy to hear your thoughts @zimeg so we can start to make this a standard across the tests. 🧠
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a super appreciated change - thank you for considering it! 🙏 ✨
I agree that we should aim to match test setups to this format also.