mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
SMQ-3061 - Separate CLI command for Domain and User Invitations (#3117)
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
This commit is contained in:
@@ -45,6 +45,8 @@ const sendCmd = "send"
|
||||
const (
|
||||
acceptCmd = "accept"
|
||||
rejectCmd = "reject"
|
||||
userCmd = "user"
|
||||
domainCmd = "domain"
|
||||
)
|
||||
|
||||
// Role commands
|
||||
|
||||
+105
-57
@@ -8,41 +8,16 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cmdInvitations = []cobra.Command{
|
||||
var cmdUserInvitations = []cobra.Command{
|
||||
{
|
||||
Use: "send <user_id> <domain_id> <role_id> <user_auth_token>",
|
||||
Short: "Send invitation",
|
||||
Long: "Send invitation to user\n" +
|
||||
"For example:\n" +
|
||||
"\tsupermq-cli invitations send 39f97daf-d6b6-40f4-b229-2697be8006ef 4ef09eff-d500-4d56-b04f-d23a512d6f2a ba4c904c-e6d4-4978-9417-1694aac6793e $USER_AUTH_TOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 4 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
return
|
||||
}
|
||||
inv := smqsdk.Invitation{
|
||||
InviteeUserID: args[0],
|
||||
DomainID: args[1],
|
||||
RoleID: args[2],
|
||||
}
|
||||
if err := sdk.SendInvitation(cmd.Context(), inv, args[3]); err != nil {
|
||||
logErrorCmd(*cmd, err)
|
||||
return
|
||||
}
|
||||
|
||||
logOKCmd(*cmd)
|
||||
},
|
||||
},
|
||||
{
|
||||
Use: "get [all | <domain_id> ] <user_auth_token>",
|
||||
Short: "Get invitations",
|
||||
Long: "Get invitations\n" +
|
||||
Use: "get <user_auth_token>",
|
||||
Short: "Get user invitations",
|
||||
Long: "Get all invitations for the authenticated user\n" +
|
||||
"Usage:\n" +
|
||||
"\tsupermq-cli invitations get all <user_auth_token> - lists all invitations\n" +
|
||||
"\tsupermq-cli invitations get all <user_auth_token> --offset <offset> --limit <limit> - lists all invitations with provided offset and limit\n" +
|
||||
"\tsupermq-cli invitations get <domain_id> <user_auth_token> - shows invitation by domain id\n",
|
||||
"\tsupermq-cli invitations user get <user_auth_token> - lists all invitations for the user\n" +
|
||||
"\tsupermq-cli invitations user get <user_auth_token> --offset <offset> --limit <limit> - lists all invitations with provided offset and limit\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
if len(args) != 1 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
return
|
||||
}
|
||||
@@ -51,23 +26,13 @@ var cmdInvitations = []cobra.Command{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
if args[0] == all {
|
||||
l, err := sdk.Invitations(cmd.Context(), pageMetadata, args[1])
|
||||
if err != nil {
|
||||
logErrorCmd(*cmd, err)
|
||||
return
|
||||
}
|
||||
logJSONCmd(*cmd, l)
|
||||
return
|
||||
}
|
||||
pageMetadata.DomainID = args[0]
|
||||
u, err := sdk.Invitations(cmd.Context(), pageMetadata, args[1])
|
||||
|
||||
l, err := sdk.Invitations(cmd.Context(), pageMetadata, args[0])
|
||||
if err != nil {
|
||||
logErrorCmd(*cmd, err)
|
||||
return
|
||||
}
|
||||
|
||||
logJSONCmd(*cmd, u)
|
||||
logJSONCmd(*cmd, l)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -75,7 +40,7 @@ var cmdInvitations = []cobra.Command{
|
||||
Short: "Accept invitation",
|
||||
Long: "Accept invitation to domain\n" +
|
||||
"Usage:\n" +
|
||||
"\tsupermq-cli invitations accept 39f97daf-d6b6-40f4-b229-2697be8006ef $USERTOKEN\n",
|
||||
"\tsupermq-cli invitations user accept 39f97daf-d6b6-40f4-b229-2697be8006ef $USER_TOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
@@ -95,7 +60,7 @@ var cmdInvitations = []cobra.Command{
|
||||
Short: "Reject invitation",
|
||||
Long: "Reject invitation to domain\n" +
|
||||
"Usage:\n" +
|
||||
"\tsupermq-cli invitations reject 39f97daf-d6b6-40f4-b229-2697be8006ef $USER_AUTH_TOKEN\n",
|
||||
"\tsupermq-cli invitations user reject 39f97daf-d6b6-40f4-b229-2697be8006ef $USER_AUTH_TOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
@@ -110,12 +75,66 @@ var cmdInvitations = []cobra.Command{
|
||||
logOKCmd(*cmd)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var cmdDomainInvitations = []cobra.Command{
|
||||
{
|
||||
Use: "send <user_id> <domain_id> <role_id> <user_auth_token>",
|
||||
Short: "Send domain invitation",
|
||||
Long: "Send invitation to user for a domain\n" +
|
||||
"For example:\n" +
|
||||
"\tsupermq-cli invitations domain send 39f97daf-d6b6-40f4-b229-2697be8006ef 4ef09eff-d500-4d56-b04f-d23a512d6f2a ba4c904c-e6d4-4978-9417-1694aac6793e $USER_AUTH_TOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 4 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
return
|
||||
}
|
||||
inv := smqsdk.Invitation{
|
||||
InviteeUserID: args[0],
|
||||
DomainID: args[1],
|
||||
RoleID: args[2],
|
||||
}
|
||||
if err := sdk.SendInvitation(cmd.Context(), inv, args[3]); err != nil {
|
||||
logErrorCmd(*cmd, err)
|
||||
return
|
||||
}
|
||||
|
||||
logOKCmd(*cmd)
|
||||
},
|
||||
},
|
||||
{
|
||||
Use: "get <domain_id> <user_auth_token>",
|
||||
Short: "Get domain invitations",
|
||||
Long: "Get all invitations for a specific domain\n" +
|
||||
"Usage:\n" +
|
||||
"\tsupermq-cli invitations domain get <domain_id> <user_auth_token> - shows invitations for domain\n" +
|
||||
"\tsupermq-cli invitations domain get <domain_id> <user_auth_token> --offset <offset> --limit <limit> - shows invitations with provided offset and limit\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
pageMetadata := smqsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
|
||||
u, err := sdk.DomainInvitations(cmd.Context(), pageMetadata, args[1], args[0])
|
||||
if err != nil {
|
||||
logErrorCmd(*cmd, err)
|
||||
return
|
||||
}
|
||||
|
||||
logJSONCmd(*cmd, u)
|
||||
},
|
||||
},
|
||||
{
|
||||
Use: "delete <user_id> <domain_id> <user_auth_token>",
|
||||
Short: "Delete invitation",
|
||||
Long: "Delete invitation\n" +
|
||||
Short: "Delete domain invitation",
|
||||
Long: "Delete invitation for a specific user and domain\n" +
|
||||
"Usage:\n" +
|
||||
"\tsupermq-cli invitations delete 39f97daf-d6b6-40f4-b229-2697be8006ef 4ef09eff-d500-4d56-b04f-d23a512d6f2a $USERTOKEN\n",
|
||||
"\tsupermq-cli invitations domain delete 39f97daf-d6b6-40f4-b229-2697be8006ef 4ef09eff-d500-4d56-b04f-d23a512d6f2a $USER_TOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsageCmd(*cmd, cmd.Use)
|
||||
@@ -132,17 +151,46 @@ var cmdInvitations = []cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
// NewInvitationsCmd returns invitations command.
|
||||
func NewInvitationsCmd() *cobra.Command {
|
||||
// NewUserInvitationsCmd returns user invitations command.
|
||||
func NewUserInvitationsCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "invitations [send | get | accept | delete]",
|
||||
Short: "Invitations management",
|
||||
Long: `Invitations management to send, get, accept and delete invitations`,
|
||||
Use: "user [get | accept | reject]",
|
||||
Short: "User invitations management",
|
||||
Long: `User invitations management to get, accept and reject invitations received by the user`,
|
||||
}
|
||||
|
||||
for i := range cmdInvitations {
|
||||
cmd.AddCommand(&cmdInvitations[i])
|
||||
for i := range cmdUserInvitations {
|
||||
cmd.AddCommand(&cmdUserInvitations[i])
|
||||
}
|
||||
|
||||
return &cmd
|
||||
}
|
||||
|
||||
// NewDomainInvitationsCmd returns domain invitations command.
|
||||
func NewDomainInvitationsCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "domain [send | get | delete]",
|
||||
Short: "Domain invitations management",
|
||||
Long: `Domain invitations management to send, get and delete invitations for domains`,
|
||||
}
|
||||
|
||||
for i := range cmdDomainInvitations {
|
||||
cmd.AddCommand(&cmdDomainInvitations[i])
|
||||
}
|
||||
|
||||
return &cmd
|
||||
}
|
||||
|
||||
// NewInvitationsCmd returns invitations command.
|
||||
func NewInvitationsCmd() *cobra.Command {
|
||||
cmd := cobra.Command{
|
||||
Use: "invitations [user | domain]",
|
||||
Short: "Invitations management",
|
||||
Long: `Invitations management with separate commands for user and domain invitations`,
|
||||
}
|
||||
|
||||
cmd.AddCommand(NewUserInvitationsCmd())
|
||||
cmd.AddCommand(NewDomainInvitationsCmd())
|
||||
|
||||
return &cmd
|
||||
}
|
||||
|
||||
+92
-55
@@ -26,7 +26,7 @@ var invitation = mgsdk.Invitation{
|
||||
DomainID: domain.ID,
|
||||
}
|
||||
|
||||
func TestSendUserInvitationCmd(t *testing.T) {
|
||||
func TestSendDomainInvitationCmd(t *testing.T) {
|
||||
sdkMock := new(sdkmocks.SDK)
|
||||
cli.SetSDK(sdkMock)
|
||||
invCmd := cli.NewInvitationsCmd()
|
||||
@@ -40,7 +40,7 @@ func TestSendUserInvitationCmd(t *testing.T) {
|
||||
sdkErr errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "send invitation successfully",
|
||||
desc: "send domain invitation successfully",
|
||||
args: []string{
|
||||
user.ID,
|
||||
domain.ID,
|
||||
@@ -50,7 +50,7 @@ func TestSendUserInvitationCmd(t *testing.T) {
|
||||
logType: okLog,
|
||||
},
|
||||
{
|
||||
desc: "send invitation with invalid args",
|
||||
desc: "send domain invitation with invalid args",
|
||||
args: []string{
|
||||
user.ID,
|
||||
domain.ID,
|
||||
@@ -61,7 +61,7 @@ func TestSendUserInvitationCmd(t *testing.T) {
|
||||
logType: usageLog,
|
||||
},
|
||||
{
|
||||
desc: "send invitation with invalid token",
|
||||
desc: "send domain invitation with invalid token",
|
||||
args: []string{
|
||||
user.ID,
|
||||
domain.ID,
|
||||
@@ -77,7 +77,7 @@ func TestSendUserInvitationCmd(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
sdkCall := sdkMock.On("SendInvitation", mock.Anything, mock.Anything, mock.Anything).Return(tc.sdkErr)
|
||||
out := executeCommand(t, rootCmd, append([]string{sendCmd}, tc.args...)...)
|
||||
out := executeCommand(t, rootCmd, append([]string{domainCmd, sendCmd}, tc.args...)...)
|
||||
switch tc.logType {
|
||||
case okLog:
|
||||
assert.True(t, strings.Contains(out, "ok"), fmt.Sprintf("%s unexpected response: expected success message, got: %v", tc.desc, out))
|
||||
@@ -91,13 +91,12 @@ func TestSendUserInvitationCmd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetInvitationCmd(t *testing.T) {
|
||||
func TestGetUserInvitationsCmd(t *testing.T) {
|
||||
sdkMock := new(sdkmocks.SDK)
|
||||
cli.SetSDK(sdkMock)
|
||||
invCmd := cli.NewInvitationsCmd()
|
||||
rootCmd := setFlags(invCmd)
|
||||
|
||||
var inv mgsdk.Invitation
|
||||
var page mgsdk.InvitationPage
|
||||
|
||||
cases := []struct {
|
||||
@@ -105,14 +104,12 @@ func TestGetInvitationCmd(t *testing.T) {
|
||||
args []string
|
||||
sdkErr errors.SDKError
|
||||
page mgsdk.InvitationPage
|
||||
inv mgsdk.Invitation
|
||||
logType outputLog
|
||||
errLogMessage string
|
||||
}{
|
||||
{
|
||||
desc: "get all invitations successfully",
|
||||
desc: "get user invitations successfully",
|
||||
args: []string{
|
||||
all,
|
||||
token,
|
||||
},
|
||||
page: mgsdk.InvitationPage{
|
||||
@@ -124,40 +121,86 @@ func TestGetInvitationCmd(t *testing.T) {
|
||||
logType: entityLog,
|
||||
},
|
||||
{
|
||||
desc: "get invitation with domain id",
|
||||
desc: "get user invitations with invalid args",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
token,
|
||||
},
|
||||
logType: entityLog,
|
||||
page: mgsdk.InvitationPage{
|
||||
Total: 1,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Invitations: []mgsdk.Invitation{invitation},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "get invitation with invalid args",
|
||||
args: []string{
|
||||
all,
|
||||
token,
|
||||
extraArg,
|
||||
},
|
||||
logType: usageLog,
|
||||
},
|
||||
{
|
||||
desc: "get all invitations with invalid token",
|
||||
desc: "get user invitations with invalid token",
|
||||
args: []string{
|
||||
all,
|
||||
invalidToken,
|
||||
},
|
||||
logType: errLog,
|
||||
sdkErr: errors.NewSDKErrorWithStatus(svcerr.ErrAuthorization, http.StatusForbidden),
|
||||
errLogMessage: fmt.Sprintf("\nerror: %s\n\n", errors.NewSDKErrorWithStatus(svcerr.ErrAuthorization, http.StatusForbidden)),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
sdkCall := sdkMock.On("Invitations", mock.Anything, mock.Anything, tc.args[0]).Return(tc.page, tc.sdkErr)
|
||||
|
||||
out := executeCommand(t, rootCmd, append([]string{userCmd, getCmd}, tc.args...)...)
|
||||
|
||||
switch tc.logType {
|
||||
case entityLog:
|
||||
err := json.Unmarshal([]byte(out), &page)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, tc.page, page, fmt.Sprintf("%v unexpected response, expected: %v, got: %v", tc.desc, tc.page, page))
|
||||
case errLog:
|
||||
assert.Equal(t, tc.errLogMessage, out, fmt.Sprintf("%s unexpected error response: expected %s got errLogMessage:%s", tc.desc, tc.errLogMessage, out))
|
||||
case usageLog:
|
||||
assert.False(t, strings.Contains(out, rootCmd.Use), fmt.Sprintf("%s invalid usage: %s", tc.desc, out))
|
||||
}
|
||||
sdkCall.Unset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDomainInvitationsCmd(t *testing.T) {
|
||||
sdkMock := new(sdkmocks.SDK)
|
||||
cli.SetSDK(sdkMock)
|
||||
invCmd := cli.NewInvitationsCmd()
|
||||
rootCmd := setFlags(invCmd)
|
||||
|
||||
var page mgsdk.InvitationPage
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
args []string
|
||||
sdkErr errors.SDKError
|
||||
page mgsdk.InvitationPage
|
||||
logType outputLog
|
||||
errLogMessage string
|
||||
}{
|
||||
{
|
||||
desc: "get invitation with invalid token",
|
||||
desc: "get domain invitations successfully",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
token,
|
||||
},
|
||||
page: mgsdk.InvitationPage{
|
||||
Total: 1,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Invitations: []mgsdk.Invitation{invitation},
|
||||
},
|
||||
logType: entityLog,
|
||||
},
|
||||
{
|
||||
desc: "get domain invitations with invalid args",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
token,
|
||||
extraArg,
|
||||
},
|
||||
logType: usageLog,
|
||||
},
|
||||
{
|
||||
desc: "get domain invitations with invalid token",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
invalidToken,
|
||||
@@ -170,21 +213,15 @@ func TestGetInvitationCmd(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
sdkCall := sdkMock.On("Invitations", mock.Anything, mock.Anything, tc.args[1]).Return(tc.page, tc.sdkErr)
|
||||
sdkCall := sdkMock.On("DomainInvitations", mock.Anything, mock.Anything, tc.args[1], tc.args[0]).Return(tc.page, tc.sdkErr)
|
||||
|
||||
out := executeCommand(t, rootCmd, append([]string{getCmd}, tc.args...)...)
|
||||
out := executeCommand(t, rootCmd, append([]string{domainCmd, getCmd}, tc.args...)...)
|
||||
|
||||
switch tc.logType {
|
||||
case entityLog:
|
||||
if tc.args[0] == all {
|
||||
err := json.Unmarshal([]byte(out), &page)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, tc.page, page, fmt.Sprintf("%v unexpected response, expected: %v, got: %v", tc.desc, tc.page, page))
|
||||
} else {
|
||||
err := json.Unmarshal([]byte(out), &inv)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, tc.inv, inv, fmt.Sprintf("%v unexpected response, expected: %v, got: %v", tc.desc, tc.inv, inv))
|
||||
}
|
||||
err := json.Unmarshal([]byte(out), &page)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, tc.page, page, fmt.Sprintf("%v unexpected response, expected: %v, got: %v", tc.desc, tc.page, page))
|
||||
case errLog:
|
||||
assert.Equal(t, tc.errLogMessage, out, fmt.Sprintf("%s unexpected error response: expected %s got errLogMessage:%s", tc.desc, tc.errLogMessage, out))
|
||||
case usageLog:
|
||||
@@ -195,7 +232,7 @@ func TestGetInvitationCmd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAcceptInvitationCmd(t *testing.T) {
|
||||
func TestAcceptUserInvitationCmd(t *testing.T) {
|
||||
sdkMock := new(sdkmocks.SDK)
|
||||
cli.SetSDK(sdkMock)
|
||||
invCmd := cli.NewInvitationsCmd()
|
||||
@@ -209,7 +246,7 @@ func TestAcceptInvitationCmd(t *testing.T) {
|
||||
sdkErr errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "accept invitation successfully",
|
||||
desc: "accept user invitation successfully",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
validToken,
|
||||
@@ -217,7 +254,7 @@ func TestAcceptInvitationCmd(t *testing.T) {
|
||||
logType: okLog,
|
||||
},
|
||||
{
|
||||
desc: "accept invitation with invalid args",
|
||||
desc: "accept user invitation with invalid args",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
validToken,
|
||||
@@ -226,7 +263,7 @@ func TestAcceptInvitationCmd(t *testing.T) {
|
||||
logType: usageLog,
|
||||
},
|
||||
{
|
||||
desc: "accept invitation with invalid token",
|
||||
desc: "accept user invitation with invalid token",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
invalidToken,
|
||||
@@ -240,7 +277,7 @@ func TestAcceptInvitationCmd(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
sdkCall := sdkMock.On("AcceptInvitation", mock.Anything, mock.Anything, mock.Anything).Return(tc.sdkErr)
|
||||
out := executeCommand(t, rootCmd, append([]string{acceptCmd}, tc.args...)...)
|
||||
out := executeCommand(t, rootCmd, append([]string{userCmd, acceptCmd}, tc.args...)...)
|
||||
switch tc.logType {
|
||||
case okLog:
|
||||
assert.True(t, strings.Contains(out, "ok"), fmt.Sprintf("%s unexpected response: expected success message, got: %v", tc.desc, out))
|
||||
@@ -254,7 +291,7 @@ func TestAcceptInvitationCmd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRejectInvitationCmd(t *testing.T) {
|
||||
func TestRejectUserInvitationCmd(t *testing.T) {
|
||||
sdkMock := new(sdkmocks.SDK)
|
||||
cli.SetSDK(sdkMock)
|
||||
invCmd := cli.NewInvitationsCmd()
|
||||
@@ -268,7 +305,7 @@ func TestRejectInvitationCmd(t *testing.T) {
|
||||
sdkErr errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "reject invitation successfully",
|
||||
desc: "reject user invitation successfully",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
validToken,
|
||||
@@ -276,7 +313,7 @@ func TestRejectInvitationCmd(t *testing.T) {
|
||||
logType: okLog,
|
||||
},
|
||||
{
|
||||
desc: "reject invitation with invalid args",
|
||||
desc: "reject user invitation with invalid args",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
validToken,
|
||||
@@ -285,7 +322,7 @@ func TestRejectInvitationCmd(t *testing.T) {
|
||||
logType: usageLog,
|
||||
},
|
||||
{
|
||||
desc: "reject invitation with invalid token",
|
||||
desc: "reject user invitation with invalid token",
|
||||
args: []string{
|
||||
domain.ID,
|
||||
invalidToken,
|
||||
@@ -299,7 +336,7 @@ func TestRejectInvitationCmd(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
sdkCall := sdkMock.On("RejectInvitation", mock.Anything, mock.Anything, mock.Anything).Return(tc.sdkErr)
|
||||
out := executeCommand(t, rootCmd, append([]string{rejectCmd}, tc.args...)...)
|
||||
out := executeCommand(t, rootCmd, append([]string{userCmd, rejectCmd}, tc.args...)...)
|
||||
switch tc.logType {
|
||||
case okLog:
|
||||
assert.True(t, strings.Contains(out, "ok"), fmt.Sprintf("%s unexpected response: expected success message, got: %v", tc.desc, out))
|
||||
@@ -313,7 +350,7 @@ func TestRejectInvitationCmd(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteInvitationCmd(t *testing.T) {
|
||||
func TestDeleteDomainInvitationCmd(t *testing.T) {
|
||||
sdkMock := new(sdkmocks.SDK)
|
||||
cli.SetSDK(sdkMock)
|
||||
invCmd := cli.NewInvitationsCmd()
|
||||
@@ -327,7 +364,7 @@ func TestDeleteInvitationCmd(t *testing.T) {
|
||||
sdkErr errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "delete invitation successfully",
|
||||
desc: "delete domain invitation successfully",
|
||||
args: []string{
|
||||
user.ID,
|
||||
domain.ID,
|
||||
@@ -336,7 +373,7 @@ func TestDeleteInvitationCmd(t *testing.T) {
|
||||
logType: okLog,
|
||||
},
|
||||
{
|
||||
desc: "delete invitation with invalid args",
|
||||
desc: "delete domain invitation with invalid args",
|
||||
args: []string{
|
||||
user.ID,
|
||||
domain.ID,
|
||||
@@ -346,7 +383,7 @@ func TestDeleteInvitationCmd(t *testing.T) {
|
||||
logType: usageLog,
|
||||
},
|
||||
{
|
||||
desc: "delete invitation with invalid token",
|
||||
desc: "delete domain invitation with invalid token",
|
||||
args: []string{
|
||||
user.ID,
|
||||
domain.ID,
|
||||
@@ -361,7 +398,7 @@ func TestDeleteInvitationCmd(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
sdkCall := sdkMock.On("DeleteInvitation", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.sdkErr)
|
||||
out := executeCommand(t, rootCmd, append([]string{delCmd}, tc.args...)...)
|
||||
out := executeCommand(t, rootCmd, append([]string{domainCmd, delCmd}, tc.args...)...)
|
||||
switch tc.logType {
|
||||
case okLog:
|
||||
assert.True(t, strings.Contains(out, "ok"), fmt.Sprintf("%s unexpected response: expected success message, got: %v", tc.desc, out))
|
||||
|
||||
Reference in New Issue
Block a user