Skip to content

Commit deb9915

Browse files
authored
test: add unit tests for printAuthTicketSubmissionInstructions in internal/pkg/auth (#781)
1 parent af80565 commit deb9915

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎internal/pkg/auth/login_test.go‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/slackapi/slack-cli/internal/shared/types"
2424
"github.com/slackapi/slack-cli/internal/slackcontext"
2525
"github.com/slackapi/slack-cli/internal/slackerror"
26+
"github.com/slackapi/slack-cli/internal/slacktrace"
2627
"github.com/stretchr/testify/assert"
2728
"github.com/stretchr/testify/mock"
2829
)
@@ -87,3 +88,37 @@ func Test_Login(t *testing.T) {
8788
})
8889
}
8990
}
91+
92+
func Test_printAuthTicketSubmissionInstructions(t *testing.T) {
93+
tests := map[string]struct {
94+
authTicket string
95+
expectedOutputs []string
96+
}{
97+
"prints the slash command with the ticket on its own line without indentation": {
98+
authTicket: "ABC123",
99+
expectedOutputs: []string{"\n/slackauthticket ABC123\n"},
100+
},
101+
"prints the steps to approve permissions and get a challenge code": {
102+
authTicket: "XYZ789",
103+
expectedOutputs: []string{
104+
"Run the following slash command in any Slack channel or DM",
105+
"This will open a modal with user permissions for you to approve",
106+
"Once approved, a challenge code will be generated in Slack",
107+
},
108+
},
109+
}
110+
for name, tc := range tests {
111+
t.Run(name, func(t *testing.T) {
112+
ctx := slackcontext.MockContext(t.Context())
113+
cm := shared.NewClientsMock()
114+
cm.AddDefaultMocks()
115+
116+
printAuthTicketSubmissionInstructions(ctx, cm.IO, tc.authTicket)
117+
118+
for _, expected := range tc.expectedOutputs {
119+
assert.Contains(t, cm.GetStdoutOutput(), expected)
120+
}
121+
cm.IO.AssertCalled(t, "PrintTrace", mock.Anything, slacktrace.AuthLoginStart, mock.Anything)
122+
})
123+
}
124+
}

0 commit comments

Comments
 (0)