-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathcollaborators_test.go
More file actions
115 lines (104 loc) · 3.89 KB
/
collaborators_test.go
File metadata and controls
115 lines (104 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package api
import (
"testing"
"github.com/slackapi/slack-cli/internal/shared/types"
"github.com/slackapi/slack-cli/internal/slackcontext"
"github.com/stretchr/testify/require"
)
func TestClient_AddCollaborator_Ok(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsAddMethod,
Response: `{"ok":true}`,
})
defer teardown()
err := c.AddCollaborator(ctx, "token", "A123", types.SlackUser{Email: "user@example.com", PermissionType: "owner"})
require.NoError(t, err)
}
func TestClient_AddCollaborator_WithUserID(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsAddMethod,
Response: `{"ok":true}`,
})
defer teardown()
err := c.AddCollaborator(ctx, "token", "A123", types.SlackUser{ID: "U123", PermissionType: "owner"})
require.NoError(t, err)
}
func TestClient_AddCollaborator_Error(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsAddMethod,
Response: `{"ok":false,"error":"user_not_found"}`,
})
defer teardown()
err := c.AddCollaborator(ctx, "token", "A123", types.SlackUser{Email: "bad@example.com"})
require.Error(t, err)
require.Contains(t, err.Error(), "user_not_found")
}
func TestClient_ListCollaborators_Ok(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsListMethod,
Response: `{"ok":true,"owners":[{"user_id":"U123","username":"Test User"}]}`,
})
defer teardown()
users, err := c.ListCollaborators(ctx, "token", "A123")
require.NoError(t, err)
require.Len(t, users, 1)
require.Equal(t, "U123", users[0].ID)
}
func TestClient_ListCollaborators_Error(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsListMethod,
Response: `{"ok":false,"error":"app_not_found"}`,
})
defer teardown()
_, err := c.ListCollaborators(ctx, "token", "A123")
require.Error(t, err)
require.Contains(t, err.Error(), "app_not_found")
}
func TestClient_RemoveCollaborator_Ok(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsRemoveMethod,
Response: `{"ok":true}`,
})
defer teardown()
warnings, err := c.RemoveCollaborator(ctx, "token", "A123", types.SlackUser{ID: "U123"})
require.NoError(t, err)
require.Empty(t, warnings)
}
func TestClient_RemoveCollaborator_Error(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsRemoveMethod,
Response: `{"ok":false,"error":"cannot_remove_owner"}`,
})
defer teardown()
_, err := c.RemoveCollaborator(ctx, "token", "A123", types.SlackUser{Email: "owner@example.com"})
require.Error(t, err)
require.Contains(t, err.Error(), "cannot_remove_owner")
}
func TestClient_UpdateCollaborator_Ok(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsUpdateMethod,
Response: `{"ok":true}`,
})
defer teardown()
err := c.UpdateCollaborator(ctx, "token", "A123", types.SlackUser{ID: "U123", PermissionType: "collaborator"})
require.NoError(t, err)
}
func TestClient_UpdateCollaborator_Error(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
c, teardown := NewFakeClient(t, FakeClientParams{
ExpectedMethod: collaboratorsUpdateMethod,
Response: `{"ok":false,"error":"invalid_permission"}`,
})
defer teardown()
err := c.UpdateCollaborator(ctx, "token", "A123", types.SlackUser{ID: "U123", PermissionType: "invalid"})
require.Error(t, err)
require.Contains(t, err.Error(), "invalid_permission")
}