discourse_api 1.1.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +23 -10
- data/.rubocop.yml +1 -1
- data/.streerc +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -1
- data/README.md +0 -4
- data/discourse_api.gemspec +7 -4
- data/examples/backups.rb +5 -5
- data/examples/badges.rb +5 -5
- data/examples/bookmark_topic.rb +5 -5
- data/examples/category.rb +10 -6
- data/examples/change_topic_status.rb +12 -11
- data/examples/create_private_message.rb +6 -6
- data/examples/create_topic.rb +9 -9
- data/examples/create_update_category.rb +13 -16
- data/examples/create_user.rb +12 -11
- data/examples/dashboard.rb +5 -5
- data/examples/disposable_invite_tokens.rb +9 -10
- data/examples/example.rb +5 -5
- data/examples/group_set_user_notification_level.rb +18 -19
- data/examples/groups.rb +7 -7
- data/examples/invite_users.rb +5 -5
- data/examples/manage_api_keys.rb +6 -11
- data/examples/notifications.rb +6 -6
- data/examples/polls.rb +12 -12
- data/examples/post_action.rb +5 -5
- data/examples/search.rb +5 -5
- data/examples/sent_private_messages.rb +6 -6
- data/examples/sso.rb +6 -6
- data/examples/topic_lists.rb +5 -5
- data/examples/update_user.rb +15 -7
- data/examples/upload_file.rb +7 -7
- data/lib/discourse_api/api/api_key.rb +1 -3
- data/lib/discourse_api/api/backups.rb +1 -1
- data/lib/discourse_api/api/badges.rb +21 -6
- data/lib/discourse_api/api/categories.rb +69 -37
- data/lib/discourse_api/api/dashboard.rb +2 -6
- data/lib/discourse_api/api/groups.rb +68 -73
- data/lib/discourse_api/api/invite.rb +30 -30
- data/lib/discourse_api/api/notifications.rb +2 -3
- data/lib/discourse_api/api/params.rb +4 -14
- data/lib/discourse_api/api/polls.rb +9 -12
- data/lib/discourse_api/api/posts.rb +5 -8
- data/lib/discourse_api/api/private_messages.rb +9 -8
- data/lib/discourse_api/api/search.rb +2 -2
- data/lib/discourse_api/api/topics.rb +20 -22
- data/lib/discourse_api/api/uploads.rb +7 -5
- data/lib/discourse_api/api/user_actions.rb +2 -2
- data/lib/discourse_api/api/users.rb +31 -23
- data/lib/discourse_api/client.rb +58 -56
- data/lib/discourse_api/example_helper.rb +2 -4
- data/lib/discourse_api/single_sign_on.rb +53 -57
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +39 -25
- data/spec/discourse_api/api/backups_spec.rb +8 -3
- data/spec/discourse_api/api/badges_spec.rb +17 -7
- data/spec/discourse_api/api/categories_spec.rb +95 -53
- data/spec/discourse_api/api/email_spec.rb +17 -7
- data/spec/discourse_api/api/groups_spec.rb +71 -52
- data/spec/discourse_api/api/invite_spec.rb +41 -21
- data/spec/discourse_api/api/notifications_spec.rb +8 -4
- data/spec/discourse_api/api/params_spec.rb +5 -3
- data/spec/discourse_api/api/polls_spec.rb +53 -44
- data/spec/discourse_api/api/posts_spec.rb +33 -16
- data/spec/discourse_api/api/private_messages_spec.rb +25 -12
- data/spec/discourse_api/api/search_spec.rb +8 -3
- data/spec/discourse_api/api/site_settings_spec.rb +2 -3
- data/spec/discourse_api/api/sso_spec.rb +29 -25
- data/spec/discourse_api/api/topics_spec.rb +100 -31
- data/spec/discourse_api/api/uploads_spec.rb +16 -7
- data/spec/discourse_api/api/user_actions_spec.rb +13 -3
- data/spec/discourse_api/api/users_spec.rb +137 -55
- data/spec/discourse_api/client_spec.rb +32 -32
- data/spec/discourse_api/single_sign_on_spec.rb +15 -15
- data/spec/fixtures/categories.json +1 -1
- data/spec/spec_helper.rb +10 -15
- metadata +55 -12
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe DiscourseApi::API::Badges do
|
5
5
|
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
6
6
|
|
7
7
|
describe "#badges" do
|
8
8
|
before do
|
9
|
-
stub_get("#{host}/admin/badges.json").to_return(
|
9
|
+
stub_get("#{host}/admin/badges.json").to_return(
|
10
|
+
body: fixture("badges.json"),
|
11
|
+
headers: {
|
12
|
+
content_type: "application/json",
|
13
|
+
},
|
14
|
+
)
|
10
15
|
end
|
11
16
|
|
12
17
|
it "requests the correct resource" do
|
@@ -17,25 +22,30 @@ describe DiscourseApi::API::Badges do
|
|
17
22
|
it "returns the requested badges" do
|
18
23
|
badges = subject.badges
|
19
24
|
expect(badges).to be_a Hash
|
20
|
-
expect(badges[
|
25
|
+
expect(badges["badges"]).to be_an Array
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
24
29
|
describe "#user-badges" do
|
25
30
|
before do
|
26
|
-
stub_get("#{host}/user-badges/test_user.json").to_return(
|
31
|
+
stub_get("#{host}/user-badges/test_user.json").to_return(
|
32
|
+
body: fixture("user_badges.json"),
|
33
|
+
headers: {
|
34
|
+
content_type: "application/json",
|
35
|
+
},
|
36
|
+
)
|
27
37
|
end
|
28
38
|
|
29
39
|
it "requests the correct resource" do
|
30
|
-
subject.user_badges(
|
40
|
+
subject.user_badges("test_user")
|
31
41
|
expect(a_get("#{host}/user-badges/test_user.json")).to have_been_made
|
32
42
|
end
|
33
43
|
|
34
44
|
it "returns the requested user badges" do
|
35
|
-
badges = subject.user_badges(
|
45
|
+
badges = subject.user_badges("test_user")
|
36
46
|
expect(badges).to be_an Array
|
37
47
|
expect(badges.first).to be_a Hash
|
38
|
-
expect(badges.first).to have_key(
|
48
|
+
expect(badges.first).to have_key("badge_type_id")
|
39
49
|
end
|
40
50
|
end
|
41
51
|
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe DiscourseApi::API::Categories do
|
5
5
|
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
6
6
|
|
7
7
|
describe "#categories" do
|
8
8
|
before do
|
9
|
-
stub_get("#{host}/categories.json")
|
10
|
-
|
9
|
+
stub_get("#{host}/categories.json").to_return(
|
10
|
+
body: fixture("categories.json"),
|
11
|
+
headers: {
|
12
|
+
content_type: "application/json",
|
13
|
+
},
|
14
|
+
)
|
11
15
|
end
|
12
16
|
|
13
17
|
it "requests the correct resource" do
|
@@ -30,8 +34,12 @@ describe DiscourseApi::API::Categories do
|
|
30
34
|
|
31
35
|
describe "#categories_full" do
|
32
36
|
before do
|
33
|
-
stub_get("#{host}/categories.json")
|
34
|
-
|
37
|
+
stub_get("#{host}/categories.json").to_return(
|
38
|
+
body: fixture("categories.json"),
|
39
|
+
headers: {
|
40
|
+
content_type: "application/json",
|
41
|
+
},
|
42
|
+
)
|
35
43
|
end
|
36
44
|
|
37
45
|
it "requests the correct resource" do
|
@@ -42,137 +50,171 @@ describe DiscourseApi::API::Categories do
|
|
42
50
|
it "returns the entire categories response" do
|
43
51
|
categories = subject.categories_full
|
44
52
|
expect(categories).to be_a Hash
|
45
|
-
expect(categories).to have_key
|
46
|
-
expect(categories).to have_key
|
53
|
+
expect(categories).to have_key "category_list"
|
54
|
+
expect(categories).to have_key "featured_users"
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
50
|
-
describe
|
58
|
+
describe "#category_latest_topics" do
|
51
59
|
before do
|
52
|
-
stub_get("#{host}/c/category-slug/l/latest.json")
|
53
|
-
|
60
|
+
stub_get("#{host}/c/category-slug/l/latest.json").to_return(
|
61
|
+
body: fixture("category_latest_topics.json"),
|
62
|
+
headers: {
|
63
|
+
content_type: "application/json",
|
64
|
+
},
|
65
|
+
)
|
54
66
|
end
|
55
67
|
|
56
68
|
it "returns the latest topics in a category" do
|
57
|
-
latest_topics = subject.category_latest_topics(category_slug:
|
69
|
+
latest_topics = subject.category_latest_topics(category_slug: "category-slug")
|
58
70
|
expect(latest_topics).to be_an Array
|
59
71
|
end
|
60
72
|
end
|
61
73
|
|
62
|
-
describe
|
74
|
+
describe "#category_latest_topics_full" do
|
63
75
|
before do
|
64
|
-
stub_get("#{host}/c/category-slug/l/latest.json")
|
65
|
-
|
76
|
+
stub_get("#{host}/c/category-slug/l/latest.json").to_return(
|
77
|
+
body: fixture("category_latest_topics.json"),
|
78
|
+
headers: {
|
79
|
+
content_type: "application/json",
|
80
|
+
},
|
81
|
+
)
|
66
82
|
end
|
67
83
|
|
68
84
|
it "returns the entire latest topics in a category response" do
|
69
|
-
latest_topics = subject.category_latest_topics_full(category_slug:
|
85
|
+
latest_topics = subject.category_latest_topics_full(category_slug: "category-slug")
|
70
86
|
expect(latest_topics).to be_a Hash
|
71
|
-
expect(latest_topics).to have_key
|
72
|
-
expect(latest_topics).to have_key
|
87
|
+
expect(latest_topics).to have_key "topic_list"
|
88
|
+
expect(latest_topics).to have_key "users"
|
73
89
|
end
|
74
90
|
end
|
75
91
|
|
76
|
-
describe
|
92
|
+
describe "#category_top_topics" do
|
77
93
|
before do
|
78
|
-
stub_get("#{host}/c/category-slug/l/top.json")
|
79
|
-
.to_return(
|
94
|
+
stub_get("#{host}/c/category-slug/l/top.json").to_return(
|
80
95
|
body: fixture("category_topics.json"),
|
81
|
-
headers: {
|
96
|
+
headers: {
|
97
|
+
content_type: "application/json",
|
98
|
+
},
|
82
99
|
)
|
83
100
|
end
|
84
101
|
|
85
102
|
it "returns the top topics in a category" do
|
86
|
-
topics = subject.category_top_topics(
|
103
|
+
topics = subject.category_top_topics("category-slug")
|
87
104
|
expect(topics).to be_an Array
|
88
105
|
end
|
89
106
|
end
|
90
107
|
|
91
|
-
describe
|
108
|
+
describe "#category_top_topics_full" do
|
92
109
|
before do
|
93
|
-
stub_get("#{host}/c/category-slug/l/top.json")
|
94
|
-
.to_return(
|
110
|
+
stub_get("#{host}/c/category-slug/l/top.json").to_return(
|
95
111
|
body: fixture("category_topics.json"),
|
96
|
-
headers: {
|
112
|
+
headers: {
|
113
|
+
content_type: "application/json",
|
114
|
+
},
|
97
115
|
)
|
98
116
|
end
|
99
117
|
|
100
118
|
it "returns the entire top topics in a category response" do
|
101
|
-
topics = subject.category_top_topics_full(
|
119
|
+
topics = subject.category_top_topics_full("category-slug")
|
102
120
|
expect(topics).to be_a Hash
|
103
|
-
expect(topics).to have_key
|
104
|
-
expect(topics).to have_key
|
121
|
+
expect(topics).to have_key "topic_list"
|
122
|
+
expect(topics).to have_key "users"
|
105
123
|
end
|
106
124
|
end
|
107
125
|
|
108
|
-
describe
|
126
|
+
describe "#category_new_topics" do
|
109
127
|
before do
|
110
|
-
stub_get("#{host}/c/category-slug/l/new.json")
|
111
|
-
.to_return(
|
128
|
+
stub_get("#{host}/c/category-slug/l/new.json").to_return(
|
112
129
|
body: fixture("category_topics.json"),
|
113
|
-
headers: {
|
130
|
+
headers: {
|
131
|
+
content_type: "application/json",
|
132
|
+
},
|
114
133
|
)
|
115
134
|
end
|
116
135
|
|
117
136
|
it "returns the new topics in a category" do
|
118
|
-
topics = subject.category_new_topics(
|
137
|
+
topics = subject.category_new_topics("category-slug")
|
119
138
|
expect(topics).to be_an Array
|
120
139
|
end
|
121
140
|
end
|
122
141
|
|
123
|
-
describe
|
142
|
+
describe "#category_new_topics_full" do
|
124
143
|
before do
|
125
|
-
stub_get("#{host}/c/category-slug/l/new.json")
|
126
|
-
.to_return(
|
144
|
+
stub_get("#{host}/c/category-slug/l/new.json").to_return(
|
127
145
|
body: fixture("category_topics.json"),
|
128
|
-
headers: {
|
146
|
+
headers: {
|
147
|
+
content_type: "application/json",
|
148
|
+
},
|
129
149
|
)
|
130
150
|
end
|
131
151
|
|
132
152
|
it "returns the new topics in a category" do
|
133
|
-
topics = subject.category_new_topics_full(
|
153
|
+
topics = subject.category_new_topics_full("category-slug")
|
134
154
|
expect(topics).to be_a Hash
|
135
|
-
expect(topics).to have_key
|
136
|
-
expect(topics).to have_key
|
155
|
+
expect(topics).to have_key "topic_list"
|
156
|
+
expect(topics).to have_key "users"
|
137
157
|
end
|
138
158
|
end
|
139
159
|
|
140
|
-
describe
|
160
|
+
describe "#category_new_category" do
|
141
161
|
before do
|
142
162
|
stub_post("#{host}/categories")
|
143
|
-
subject.create_category(
|
144
|
-
|
145
|
-
|
163
|
+
subject.create_category(
|
164
|
+
name: "test_category",
|
165
|
+
color: "283890",
|
166
|
+
text_color: "FFFFFF",
|
167
|
+
description: "This is a description",
|
168
|
+
permissions: {
|
169
|
+
"group_1" => 1,
|
170
|
+
"admins" => 1,
|
171
|
+
},
|
172
|
+
)
|
146
173
|
end
|
147
174
|
|
148
175
|
it "makes a create category request" do
|
149
|
-
expect(
|
150
|
-
|
151
|
-
|
176
|
+
expect(
|
177
|
+
a_post("#{host}/categories").with(
|
178
|
+
body:
|
179
|
+
"color=283890&description=This+is+a+description&name=test_category&parent_category_id&permissions%5Badmins%5D=1&permissions%5Bgroup_1%5D=1&text_color=FFFFFF",
|
180
|
+
),
|
181
|
+
).to have_been_made
|
152
182
|
end
|
153
183
|
end
|
154
184
|
|
155
185
|
describe "#category_set_user_notification" do
|
156
186
|
before do
|
157
|
-
stub_post("#{host}/category/1/notifications").to_return(
|
187
|
+
stub_post("#{host}/category/1/notifications").to_return(
|
188
|
+
body: fixture("notification_success.json"),
|
189
|
+
headers: {
|
190
|
+
content_type: "application/json",
|
191
|
+
},
|
192
|
+
)
|
158
193
|
end
|
159
194
|
|
160
195
|
it "makes the post request" do
|
161
196
|
response = subject.category_set_user_notification(id: 1, notification_level: 3)
|
162
197
|
expect(a_post("#{host}/category/1/notifications")).to have_been_made
|
163
|
-
expect(response[
|
198
|
+
expect(response["success"]).to eq("OK")
|
164
199
|
end
|
165
200
|
end
|
166
201
|
|
167
202
|
describe "#category_set_user_notification_level" do
|
168
203
|
before do
|
169
|
-
stub_post("#{host}/category/1/notifications").to_return(
|
204
|
+
stub_post("#{host}/category/1/notifications").to_return(
|
205
|
+
body: fixture("notification_success.json"),
|
206
|
+
headers: {
|
207
|
+
content_type: "application/json",
|
208
|
+
},
|
209
|
+
)
|
170
210
|
end
|
171
211
|
|
172
212
|
it "makes the post request" do
|
173
213
|
response = subject.category_set_user_notification_level(1, notification_level: 3)
|
174
|
-
expect(
|
175
|
-
|
214
|
+
expect(
|
215
|
+
a_post("#{host}/category/1/notifications").with(body: "notification_level=3"),
|
216
|
+
).to have_been_made
|
217
|
+
expect(response["success"]).to eq("OK")
|
176
218
|
end
|
177
219
|
end
|
178
220
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe DiscourseApi::API::Email do
|
5
5
|
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
6
6
|
|
7
7
|
describe "#email_settings" do
|
8
8
|
before do
|
9
|
-
stub_get("#{host}/admin/email.json").to_return(
|
9
|
+
stub_get("#{host}/admin/email.json").to_return(
|
10
|
+
body: fixture("email_settings.json"),
|
11
|
+
headers: {
|
12
|
+
content_type: "application/json",
|
13
|
+
},
|
14
|
+
)
|
10
15
|
end
|
11
16
|
|
12
17
|
it "requests the correct resource" do
|
@@ -17,23 +22,28 @@ describe DiscourseApi::API::Email do
|
|
17
22
|
it "returns the requested settings" do
|
18
23
|
settings = subject.email_settings
|
19
24
|
expect(settings).to be_a Hash
|
20
|
-
expect(settings).to have_key(
|
21
|
-
expect(settings).to have_key(
|
25
|
+
expect(settings).to have_key("delivery_method")
|
26
|
+
expect(settings).to have_key("settings")
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
25
30
|
describe "#list_email_all" do
|
26
31
|
before do
|
27
|
-
stub_get("#{host}/admin/email/all.json").to_return(
|
32
|
+
stub_get("#{host}/admin/email/all.json").to_return(
|
33
|
+
body: fixture("email_list_all.json"),
|
34
|
+
headers: {
|
35
|
+
content_type: "application/json",
|
36
|
+
},
|
37
|
+
)
|
28
38
|
end
|
29
39
|
|
30
40
|
it "requests the correct resource" do
|
31
|
-
subject.list_email(
|
41
|
+
subject.list_email("all")
|
32
42
|
expect(a_get("#{host}/admin/email/all.json")).to have_been_made
|
33
43
|
end
|
34
44
|
|
35
45
|
it "returns all email" do
|
36
|
-
all_email = subject.list_email(
|
46
|
+
all_email = subject.list_email("all")
|
37
47
|
expect(all_email).to be_an Array
|
38
48
|
end
|
39
49
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe DiscourseApi::API::Groups do
|
5
5
|
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
6
6
|
|
7
7
|
describe "#groups" do
|
8
8
|
before do
|
9
|
-
stub_get("#{host}/groups.json").to_return(
|
9
|
+
stub_get("#{host}/groups.json").to_return(
|
10
|
+
body: fixture("groups.json"),
|
11
|
+
headers: {
|
12
|
+
content_type: "application/json",
|
13
|
+
},
|
14
|
+
)
|
10
15
|
end
|
11
16
|
|
12
17
|
it "requests the correct resource" do
|
@@ -21,69 +26,74 @@ describe DiscourseApi::API::Groups do
|
|
21
26
|
end
|
22
27
|
|
23
28
|
it "returns a single group" do
|
24
|
-
stub_get("#{host}/groups/some-group.json").to_return(
|
25
|
-
|
26
|
-
|
29
|
+
stub_get("#{host}/groups/some-group.json").to_return(
|
30
|
+
body: fixture("group.json"),
|
31
|
+
headers: {
|
32
|
+
content_type: "application/json",
|
33
|
+
},
|
34
|
+
)
|
35
|
+
group = subject.group("some-group")
|
36
|
+
expect(group["basic_group"]).to be_a Hash
|
27
37
|
end
|
28
38
|
|
29
39
|
it "create new groups" do
|
30
40
|
stub_post("#{host}/admin/groups")
|
31
41
|
subject.create_group(name: "test_group")
|
32
42
|
params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
|
33
|
-
expect(a_post("#{host}/admin/groups").
|
34
|
-
with(body: params)
|
35
|
-
).to have_been_made
|
43
|
+
expect(a_post("#{host}/admin/groups").with(body: params)).to have_been_made
|
36
44
|
end
|
37
45
|
|
38
46
|
it "update an existing group" do
|
39
47
|
stub_put("#{host}/groups/42")
|
40
48
|
subject.update_group(42, name: "test_group")
|
41
49
|
params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
|
42
|
-
expect(a_put("#{host}/groups/42").
|
43
|
-
with(body: params)
|
44
|
-
).to have_been_made
|
50
|
+
expect(a_put("#{host}/groups/42").with(body: params)).to have_been_made
|
45
51
|
end
|
46
52
|
|
47
53
|
describe "add members" do
|
48
|
-
before
|
49
|
-
stub_request(:put, "#{host}/admin/groups/123/members.json")
|
50
|
-
end
|
54
|
+
before { stub_request(:put, "#{host}/admin/groups/123/members.json") }
|
51
55
|
|
52
56
|
it "adds a single member by username" do
|
53
57
|
subject.group_add(123, username: "sam")
|
54
|
-
expect(
|
55
|
-
|
56
|
-
|
58
|
+
expect(
|
59
|
+
a_request(:put, "#{host}/admin/groups/123/members.json").with(body: { usernames: "sam" }),
|
60
|
+
).to have_been_made
|
57
61
|
end
|
58
62
|
|
59
63
|
it "adds an array of members by username" do
|
60
|
-
subject.group_add(123, usernames: [
|
61
|
-
expect(
|
62
|
-
|
63
|
-
|
64
|
+
subject.group_add(123, usernames: %w[sam jeff])
|
65
|
+
expect(
|
66
|
+
a_request(:put, "#{host}/admin/groups/123/members.json").with(
|
67
|
+
body: {
|
68
|
+
usernames: "sam,jeff",
|
69
|
+
},
|
70
|
+
),
|
71
|
+
).to have_been_made
|
64
72
|
end
|
65
73
|
|
66
74
|
it "adds a single member by user_id" do
|
67
75
|
subject.group_add(123, user_id: 456)
|
68
|
-
expect(
|
69
|
-
|
70
|
-
|
76
|
+
expect(
|
77
|
+
a_request(:put, "#{host}/admin/groups/123/members.json").with(body: { user_ids: "456" }),
|
78
|
+
).to have_been_made
|
71
79
|
end
|
72
80
|
|
73
81
|
it "adds an array of members by user_id" do
|
74
82
|
subject.group_add(123, user_id: [123, 456])
|
75
|
-
expect(
|
76
|
-
|
77
|
-
|
83
|
+
expect(
|
84
|
+
a_request(:put, "#{host}/admin/groups/123/members.json").with(
|
85
|
+
body: {
|
86
|
+
user_ids: "123,456",
|
87
|
+
},
|
88
|
+
),
|
89
|
+
).to have_been_made
|
78
90
|
end
|
79
91
|
end
|
80
92
|
|
81
93
|
describe "remove members" do
|
82
94
|
let(:url) { "#{host}/admin/groups/123/members.json?usernames=sam" }
|
83
95
|
|
84
|
-
before
|
85
|
-
stub_delete(url)
|
86
|
-
end
|
96
|
+
before { stub_delete(url) }
|
87
97
|
|
88
98
|
it "removes member" do
|
89
99
|
subject.group_remove(123, username: "sam")
|
@@ -94,25 +104,21 @@ describe DiscourseApi::API::Groups do
|
|
94
104
|
describe "add owners" do
|
95
105
|
let(:url) { "#{host}/admin/groups/123/owners.json" }
|
96
106
|
|
97
|
-
before
|
98
|
-
stub_put(url)
|
99
|
-
end
|
107
|
+
before { stub_put(url) }
|
100
108
|
|
101
109
|
it "makes the member an owner" do
|
102
110
|
subject.group_add_owners(123, usernames: "sam")
|
103
111
|
params = escape_params("group[usernames]" => "sam")
|
104
|
-
expect(
|
105
|
-
|
106
|
-
|
112
|
+
expect(
|
113
|
+
a_request(:put, "#{host}/admin/groups/123/owners.json").with(body: params),
|
114
|
+
).to have_been_made
|
107
115
|
end
|
108
116
|
end
|
109
117
|
|
110
118
|
describe "remove owners" do
|
111
119
|
let(:url) { "#{host}/admin/groups/123/owners.json?group%5Busernames%5D=sam" }
|
112
120
|
|
113
|
-
before
|
114
|
-
stub_delete(url)
|
115
|
-
end
|
121
|
+
before { stub_delete(url) }
|
116
122
|
|
117
123
|
it "removes the owner role from the group member" do
|
118
124
|
subject.group_remove_owners(123, usernames: "sam")
|
@@ -122,39 +128,52 @@ describe DiscourseApi::API::Groups do
|
|
122
128
|
|
123
129
|
describe "group members" do
|
124
130
|
it "list members" do
|
125
|
-
stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(
|
126
|
-
|
127
|
-
|
131
|
+
stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(
|
132
|
+
body: fixture("members_0.json"),
|
133
|
+
headers: {
|
134
|
+
content_type: "application/json",
|
135
|
+
},
|
136
|
+
)
|
137
|
+
stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=100").to_return(
|
138
|
+
body: fixture("members_1.json"),
|
139
|
+
headers: {
|
140
|
+
content_type: "application/json",
|
141
|
+
},
|
142
|
+
)
|
143
|
+
members = subject.group_members("mygroup")
|
128
144
|
expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
|
129
145
|
expect(members.length).to eq(100)
|
130
|
-
members = subject.group_members(
|
146
|
+
members = subject.group_members("mygroup", offset: 100)
|
131
147
|
expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=100")).to have_been_made
|
132
148
|
expect(members.length).to eq(90)
|
133
149
|
end
|
134
150
|
|
135
151
|
context "with :all params" do
|
136
152
|
it "lists members and owners" do
|
137
|
-
stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(
|
138
|
-
|
153
|
+
stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(
|
154
|
+
body: fixture("members_2.json"),
|
155
|
+
headers: {
|
156
|
+
content_type: "application/json",
|
157
|
+
},
|
158
|
+
)
|
159
|
+
member_data = subject.group_members("mygroup", all: true)
|
139
160
|
expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
|
140
161
|
expect(member_data["members"].length).to eq(100)
|
141
162
|
expect(member_data["owners"].length).to eq(7)
|
142
|
-
expect(member_data.keys.sort).to eq([
|
163
|
+
expect(member_data.keys.sort).to eq(%w[members meta owners])
|
143
164
|
end
|
144
165
|
end
|
145
166
|
end
|
146
167
|
|
147
168
|
describe "group user notification level" do
|
148
|
-
before
|
149
|
-
stub_post("#{host}/groups/mygroup/notifications?user_id=77¬ification_level=3")
|
150
|
-
end
|
169
|
+
before { stub_post("#{host}/groups/mygroup/notifications?user_id=77¬ification_level=3") }
|
151
170
|
|
152
171
|
it "updates user's notification level for group" do
|
153
172
|
subject.group_set_user_notification_level("mygroup", 77, 3)
|
154
|
-
expect(
|
155
|
-
|
173
|
+
expect(
|
174
|
+
a_post("#{host}/groups/mygroup/notifications?user_id=77¬ification_level=3"),
|
175
|
+
).to have_been_made
|
156
176
|
end
|
157
177
|
end
|
158
|
-
|
159
178
|
end
|
160
179
|
end
|