discourse_api 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +6 -6
- data/.rubocop.yml +3 -0
- data/.streerc +1 -1
- data/CHANGELOG.md +10 -0
- data/config_example.yml +1 -1
- data/discourse_api.gemspec +36 -31
- data/lib/discourse_api/api/categories.rb +45 -54
- data/lib/discourse_api/api/topics.rb +13 -1
- data/lib/discourse_api/single_sign_on.rb +3 -3
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/api_key_spec.rb +11 -11
- data/spec/discourse_api/api/backups_spec.rb +3 -3
- data/spec/discourse_api/api/badges_spec.rb +5 -5
- data/spec/discourse_api/api/categories_spec.rb +37 -15
- data/spec/discourse_api/api/email_spec.rb +5 -5
- data/spec/discourse_api/api/groups_spec.rb +17 -17
- data/spec/discourse_api/api/invite_spec.rb +11 -11
- data/spec/discourse_api/api/notifications_spec.rb +3 -3
- data/spec/discourse_api/api/polls_spec.rb +7 -7
- data/spec/discourse_api/api/posts_spec.rb +1 -3
- data/spec/discourse_api/api/private_messages_spec.rb +6 -6
- data/spec/discourse_api/api/search_spec.rb +5 -5
- data/spec/discourse_api/api/site_settings_spec.rb +2 -2
- data/spec/discourse_api/api/sso_spec.rb +3 -3
- data/spec/discourse_api/api/topics_spec.rb +32 -32
- data/spec/discourse_api/api/uploads_spec.rb +3 -3
- data/spec/discourse_api/api/user_actions_spec.rb +5 -5
- data/spec/discourse_api/api/users_spec.rb +51 -51
- data/spec/discourse_api/client_spec.rb +33 -33
- data/spec/discourse_api/single_sign_on_spec.rb +23 -6
- data/spec/spec_helper.rb +1 -0
- metadata +9 -26
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::API::Topics do
|
|
5
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
6
6
|
|
|
7
7
|
describe "#change_topic_status" do
|
|
8
8
|
before do
|
|
@@ -15,7 +15,7 @@ describe DiscourseApi::API::Topics do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "changes the topic status" do
|
|
18
|
-
|
|
18
|
+
client.update_topic_status(57, { status: "visible", enabled: false })
|
|
19
19
|
expect(a_put("#{host}/t/57/status")).to have_been_made
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -31,12 +31,12 @@ describe DiscourseApi::API::Topics do
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
it "requests the correct resource" do
|
|
34
|
-
|
|
34
|
+
client.invite_to_topic(12, email: "fake_user@example.com")
|
|
35
35
|
expect(a_post("#{host}/t/12/invite")).to have_been_made
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "returns success" do
|
|
39
|
-
response =
|
|
39
|
+
response = client.invite_to_topic(12, email: "fake_user@example.com")
|
|
40
40
|
expect(response).to be_a Hash
|
|
41
41
|
expect(response["success"]).to be_truthy
|
|
42
42
|
end
|
|
@@ -53,18 +53,18 @@ describe DiscourseApi::API::Topics do
|
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
it "requests the correct resource" do
|
|
56
|
-
|
|
56
|
+
client.latest_topics
|
|
57
57
|
expect(a_get("#{host}/latest.json")).to have_been_made
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
it "returns the requested topics" do
|
|
61
|
-
topics =
|
|
61
|
+
topics = client.latest_topics
|
|
62
62
|
expect(topics).to be_an Array
|
|
63
63
|
expect(topics.first).to be_a Hash
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
it "can take a hash param" do
|
|
67
|
-
topics =
|
|
67
|
+
topics = client.latest_topics({})
|
|
68
68
|
expect(topics).to be_an Array
|
|
69
69
|
expect(topics.first).to be_a Hash
|
|
70
70
|
end
|
|
@@ -81,18 +81,18 @@ describe DiscourseApi::API::Topics do
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
it "requests the correct resource" do
|
|
84
|
-
|
|
84
|
+
client.top_topics
|
|
85
85
|
expect(a_get("#{host}/top.json")).to have_been_made
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "returns the requested topics" do
|
|
89
|
-
topics =
|
|
89
|
+
topics = client.top_topics
|
|
90
90
|
expect(topics).to be_an Array
|
|
91
91
|
expect(topics.first).to be_a Hash
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
it "can take a hash param" do
|
|
95
|
-
topics =
|
|
95
|
+
topics = client.top_topics({})
|
|
96
96
|
expect(topics).to be_an Array
|
|
97
97
|
expect(topics.first).to be_a Hash
|
|
98
98
|
end
|
|
@@ -109,13 +109,13 @@ describe DiscourseApi::API::Topics do
|
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
it "requests the correct resource" do
|
|
112
|
-
|
|
112
|
+
client.new_topics
|
|
113
113
|
expect(a_get("#{host}/new.json")).to have_been_made
|
|
114
114
|
end
|
|
115
115
|
|
|
116
116
|
it "returns the requested topics" do
|
|
117
|
-
|
|
118
|
-
topics =
|
|
117
|
+
client.api_username = "test_user"
|
|
118
|
+
topics = client.new_topics
|
|
119
119
|
expect(topics).to be_an Array
|
|
120
120
|
expect(topics.first).to be_a Hash
|
|
121
121
|
end
|
|
@@ -132,12 +132,12 @@ describe DiscourseApi::API::Topics do
|
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
it "requests the correct resource" do
|
|
135
|
-
|
|
135
|
+
client.topic(57)
|
|
136
136
|
expect(a_get("#{host}/t/57.json")).to have_been_made
|
|
137
137
|
end
|
|
138
138
|
|
|
139
139
|
it "returns the requested topic" do
|
|
140
|
-
topic =
|
|
140
|
+
topic = client.topic(57)
|
|
141
141
|
expect(topic).to be_a Hash
|
|
142
142
|
expect(topic["id"]).to eq(57)
|
|
143
143
|
end
|
|
@@ -154,12 +154,12 @@ describe DiscourseApi::API::Topics do
|
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
it "renames the topic" do
|
|
157
|
-
|
|
157
|
+
client.rename_topic(57, "A new title!")
|
|
158
158
|
expect(a_put("#{host}/t/57.json")).to have_been_made
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
it "assigns the topic a new category" do
|
|
162
|
-
|
|
162
|
+
client.recategorize_topic(57, 3)
|
|
163
163
|
expect(a_put("#{host}/t/57.json")).to have_been_made
|
|
164
164
|
end
|
|
165
165
|
end
|
|
@@ -175,12 +175,12 @@ describe DiscourseApi::API::Topics do
|
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
it "requests the correct resource" do
|
|
178
|
-
|
|
178
|
+
client.topics_by("test")
|
|
179
179
|
expect(a_get("#{host}/topics/created-by/test.json")).to have_been_made
|
|
180
180
|
end
|
|
181
181
|
|
|
182
182
|
it "returns the requested topics" do
|
|
183
|
-
topics =
|
|
183
|
+
topics = client.topics_by("test")
|
|
184
184
|
expect(topics).to be_an Array
|
|
185
185
|
expect(topics.first).to be_a Hash
|
|
186
186
|
end
|
|
@@ -197,24 +197,24 @@ describe DiscourseApi::API::Topics do
|
|
|
197
197
|
end
|
|
198
198
|
|
|
199
199
|
it "requests the correct resource" do
|
|
200
|
-
|
|
200
|
+
client.topic_posts(57)
|
|
201
201
|
expect(a_get("#{host}/t/57/posts.json")).to have_been_made
|
|
202
202
|
end
|
|
203
203
|
|
|
204
204
|
it "allows scoping to specific post ids" do
|
|
205
|
-
|
|
205
|
+
client.topic_posts(57, [123, 456])
|
|
206
206
|
expect(a_get("#{host}/t/57/posts.json?post_ids[]=123&post_ids[]=456")).to have_been_made
|
|
207
207
|
end
|
|
208
208
|
|
|
209
209
|
it "returns the requested topic posts" do
|
|
210
|
-
body =
|
|
210
|
+
body = client.topic_posts(57, [123])
|
|
211
211
|
expect(body).to be_a Hash
|
|
212
212
|
expect(body["post_stream"]["posts"]).to be_an Array
|
|
213
213
|
expect(body["post_stream"]["posts"].first).to be_a Hash
|
|
214
214
|
end
|
|
215
215
|
|
|
216
216
|
it "can retrieve a topic posts' raw attribute" do
|
|
217
|
-
body =
|
|
217
|
+
body = client.topic_posts(57, [123], { include_raw: true })
|
|
218
218
|
expect(body).to be_a Hash
|
|
219
219
|
expect(body["post_stream"]["posts"]).to be_an Array
|
|
220
220
|
expect(body["post_stream"]["posts"].first).to be_a Hash
|
|
@@ -233,17 +233,17 @@ describe DiscourseApi::API::Topics do
|
|
|
233
233
|
end
|
|
234
234
|
|
|
235
235
|
it "makes the post request" do
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
client.create_topic title: "Sample Topic Title",
|
|
237
|
+
raw: "Sample topic content body",
|
|
238
|
+
tags: %w[asdf fdsa]
|
|
239
239
|
expect(a_post("#{host}/posts")).to have_been_made
|
|
240
240
|
end
|
|
241
241
|
|
|
242
242
|
it "returns success" do
|
|
243
243
|
response =
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
client.create_topic title: "Sample Topic Title",
|
|
245
|
+
raw: "Sample topic content body",
|
|
246
|
+
tags: %w[asdf fdsa]
|
|
247
247
|
expect(response).to be_a Hash
|
|
248
248
|
expect(response["topic_id"]).to eq 21
|
|
249
249
|
end
|
|
@@ -260,7 +260,7 @@ describe DiscourseApi::API::Topics do
|
|
|
260
260
|
end
|
|
261
261
|
|
|
262
262
|
it "makes the post request" do
|
|
263
|
-
response =
|
|
263
|
+
response = client.topic_set_user_notification_level(1, notification_level: 3)
|
|
264
264
|
expect(
|
|
265
265
|
a_post("#{host}/t/1/notifications").with(body: "notification_level=3"),
|
|
266
266
|
).to have_been_made
|
|
@@ -279,7 +279,7 @@ describe DiscourseApi::API::Topics do
|
|
|
279
279
|
end
|
|
280
280
|
|
|
281
281
|
it "makes the put request" do
|
|
282
|
-
response =
|
|
282
|
+
response = client.bookmark_topic(1)
|
|
283
283
|
expect(a_put("#{host}/t/1/bookmark.json")).to have_been_made
|
|
284
284
|
expect(response.body).to eq(nil)
|
|
285
285
|
end
|
|
@@ -296,7 +296,7 @@ describe DiscourseApi::API::Topics do
|
|
|
296
296
|
end
|
|
297
297
|
|
|
298
298
|
it "makes the put request" do
|
|
299
|
-
response =
|
|
299
|
+
response = client.remove_topic_bookmark(1)
|
|
300
300
|
expect(a_put("#{host}/t/1/remove_bookmarks.json")).to have_been_made
|
|
301
301
|
expect(response.body).to eq(nil)
|
|
302
302
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::API::Uploads do
|
|
5
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
6
6
|
|
|
7
7
|
describe "#upload_file" do
|
|
8
8
|
before do
|
|
@@ -18,7 +18,7 @@ describe DiscourseApi::API::Uploads do
|
|
|
18
18
|
image =
|
|
19
19
|
"https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
|
|
20
20
|
args = { url: image }
|
|
21
|
-
response =
|
|
21
|
+
response = client.upload_file(args)
|
|
22
22
|
expect(response["url"]).to eq(
|
|
23
23
|
"/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg",
|
|
24
24
|
)
|
|
@@ -27,7 +27,7 @@ describe DiscourseApi::API::Uploads do
|
|
|
27
27
|
it "uploads a file" do
|
|
28
28
|
file = Faraday::UploadIO.new("spec/fixtures/upload_file.json", "application/json")
|
|
29
29
|
args = { file: file }
|
|
30
|
-
response =
|
|
30
|
+
response = client.upload_file(args)
|
|
31
31
|
expect(response["url"]).to eq(
|
|
32
32
|
"/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg",
|
|
33
33
|
)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::API::UserActions do
|
|
5
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
6
6
|
|
|
7
7
|
describe "#user_replies" do
|
|
8
8
|
before do
|
|
@@ -15,12 +15,12 @@ describe DiscourseApi::API::UserActions do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "requests the correct resource" do
|
|
18
|
-
|
|
18
|
+
client.user_replies("testuser")
|
|
19
19
|
expect(a_get("#{host}/user_actions.json?username=testuser&filter=5")).to have_been_made
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "returns the requested user" do
|
|
23
|
-
replies =
|
|
23
|
+
replies = client.user_replies("testuser")
|
|
24
24
|
expect(replies).to be_an Array
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -36,12 +36,12 @@ describe DiscourseApi::API::UserActions do
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "requests the correct resource" do
|
|
39
|
-
|
|
39
|
+
client.user_topics_and_replies("testuser")
|
|
40
40
|
expect(a_get("#{host}/user_actions.json?username=testuser&filter=4,5")).to have_been_made
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "returns the requested user" do
|
|
44
|
-
replies =
|
|
44
|
+
replies = client.user_topics_and_replies("testuser")
|
|
45
45
|
expect(replies).to be_an Array
|
|
46
46
|
end
|
|
47
47
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
require "spec_helper"
|
|
3
3
|
|
|
4
4
|
describe DiscourseApi::API::Users do
|
|
5
|
-
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
5
|
+
subject(:client) { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
|
6
6
|
|
|
7
7
|
describe "#user" do
|
|
8
8
|
before do
|
|
@@ -15,17 +15,17 @@ describe DiscourseApi::API::Users do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "requests the correct resource" do
|
|
18
|
-
|
|
18
|
+
client.user("test")
|
|
19
19
|
expect(a_get("#{host}/users/test.json")).to have_been_made
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "returns the requested user" do
|
|
23
|
-
user =
|
|
23
|
+
user = client.user("test")
|
|
24
24
|
expect(user).to be_a Hash
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "works with optional params" do
|
|
28
|
-
user =
|
|
28
|
+
user = client.user("test", {})
|
|
29
29
|
expect(user).to be_a Hash
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -41,12 +41,12 @@ describe DiscourseApi::API::Users do
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
it "requests the correct resource" do
|
|
44
|
-
|
|
44
|
+
client.user_sso(15)
|
|
45
45
|
expect(a_get("#{host}/admin/users/15.json")).to have_been_made
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
it "has single_sign_on_record" do
|
|
49
|
-
user_sso =
|
|
49
|
+
user_sso = client.user_sso(15)
|
|
50
50
|
expect(user_sso).to be_a Hash
|
|
51
51
|
expect(user_sso).to have_key("external_id")
|
|
52
52
|
end
|
|
@@ -72,7 +72,7 @@ describe DiscourseApi::API::Users do
|
|
|
72
72
|
sam =
|
|
73
73
|
"https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
|
|
74
74
|
args = { url: sam }
|
|
75
|
-
response =
|
|
75
|
+
response = client.update_avatar("test_user", args)
|
|
76
76
|
expect(response[:body]["success"]).to eq("OK")
|
|
77
77
|
end
|
|
78
78
|
end
|
|
@@ -88,12 +88,12 @@ describe DiscourseApi::API::Users do
|
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
it "makes the put request" do
|
|
91
|
-
|
|
91
|
+
client.update_email("fake_user", "fake_user_2@example.com")
|
|
92
92
|
expect(a_put("#{host}/u/fake_user/preferences/email")).to have_been_made
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
it "returns success" do
|
|
96
|
-
response =
|
|
96
|
+
response = client.update_email("fake_user", "fake_user_2@example.com")
|
|
97
97
|
expect(response[:body]["success"]).to be_truthy
|
|
98
98
|
end
|
|
99
99
|
end
|
|
@@ -109,16 +109,16 @@ describe DiscourseApi::API::Users do
|
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
it "makes the put request" do
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
client.api_key = "test_d7fd0429940"
|
|
113
|
+
client.api_username = "test_user"
|
|
114
|
+
client.update_user("fake_user", name: "Fake User 2")
|
|
115
115
|
expect(a_put("#{host}/u/fake_user")).to have_been_made
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it "returns success" do
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
response =
|
|
119
|
+
client.api_key = "test_d7fd0429940"
|
|
120
|
+
client.api_username = "test_user"
|
|
121
|
+
response = client.update_user("fake_user", name: "Fake User 2")
|
|
122
122
|
expect(response[:body]["success"]).to be_truthy
|
|
123
123
|
end
|
|
124
124
|
end
|
|
@@ -134,12 +134,12 @@ describe DiscourseApi::API::Users do
|
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
it "makes the put request" do
|
|
137
|
-
|
|
137
|
+
client.update_username("fake_user", "fake_user_2")
|
|
138
138
|
expect(a_put("#{host}/u/fake_user/preferences/username")).to have_been_made
|
|
139
139
|
end
|
|
140
140
|
|
|
141
141
|
it "returns the updated username" do
|
|
142
|
-
response =
|
|
142
|
+
response = client.update_username("fake_user", "fake_user_2")
|
|
143
143
|
expect(response[:body]["username"]).to eq("fake_user_2")
|
|
144
144
|
end
|
|
145
145
|
end
|
|
@@ -155,19 +155,19 @@ describe DiscourseApi::API::Users do
|
|
|
155
155
|
end
|
|
156
156
|
|
|
157
157
|
it "makes the post request" do
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
client.create_user name: "Test User",
|
|
159
|
+
email: "test2@example.com",
|
|
160
|
+
password: "P@ssword",
|
|
161
|
+
username: "test2"
|
|
162
162
|
expect(a_post("#{host}/users")).to have_been_made
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
it "returns success" do
|
|
166
166
|
response =
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
client.create_user name: "Test User",
|
|
168
|
+
email: "test2@example.com",
|
|
169
|
+
password: "P@ssword",
|
|
170
|
+
username: "test2"
|
|
171
171
|
expect(response).to be_a Hash
|
|
172
172
|
expect(response["success"]).to be_truthy
|
|
173
173
|
end
|
|
@@ -184,12 +184,12 @@ describe DiscourseApi::API::Users do
|
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
it "makes the put request" do
|
|
187
|
-
|
|
187
|
+
client.activate(15)
|
|
188
188
|
expect(a_put("#{host}/admin/users/15/activate")).to have_been_made
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
it "returns success" do
|
|
192
|
-
response =
|
|
192
|
+
response = client.activate(15)
|
|
193
193
|
expect(response[:body]["success"]).to eq("OK")
|
|
194
194
|
end
|
|
195
195
|
end
|
|
@@ -205,12 +205,12 @@ describe DiscourseApi::API::Users do
|
|
|
205
205
|
end
|
|
206
206
|
|
|
207
207
|
it "makes a post request" do
|
|
208
|
-
|
|
208
|
+
client.log_out(4)
|
|
209
209
|
expect(a_post("#{host}/admin/users/4/log_out")).to have_been_made
|
|
210
210
|
end
|
|
211
211
|
|
|
212
212
|
it "returns success" do
|
|
213
|
-
response =
|
|
213
|
+
response = client.log_out(4)
|
|
214
214
|
expect(response).to be_a Hash
|
|
215
215
|
expect(response["success"]).to eq("OK")
|
|
216
216
|
end
|
|
@@ -227,7 +227,7 @@ describe DiscourseApi::API::Users do
|
|
|
227
227
|
end
|
|
228
228
|
|
|
229
229
|
it "Raises API Error" do
|
|
230
|
-
expect {
|
|
230
|
+
expect { client.log_out(90) }.to raise_error DiscourseApi::NotFoundError
|
|
231
231
|
end
|
|
232
232
|
end
|
|
233
233
|
|
|
@@ -242,12 +242,12 @@ describe DiscourseApi::API::Users do
|
|
|
242
242
|
end
|
|
243
243
|
|
|
244
244
|
it "requests the correct resource" do
|
|
245
|
-
|
|
245
|
+
client.list_users("active")
|
|
246
246
|
expect(a_get("#{host}/admin/users/list/active.json")).to have_been_made
|
|
247
247
|
end
|
|
248
248
|
|
|
249
249
|
it "returns the requested users" do
|
|
250
|
-
users =
|
|
250
|
+
users = client.list_users("active")
|
|
251
251
|
expect(users).to be_an Array
|
|
252
252
|
expect(users.first).to be_a Hash
|
|
253
253
|
end
|
|
@@ -266,14 +266,14 @@ describe DiscourseApi::API::Users do
|
|
|
266
266
|
|
|
267
267
|
it "makes the correct put request" do
|
|
268
268
|
params = { level: 2 }
|
|
269
|
-
|
|
269
|
+
client.update_trust_level(2, params)
|
|
270
270
|
url = "#{host}/admin/users/2/trust_level"
|
|
271
271
|
expect(a_put(url)).to have_been_made
|
|
272
272
|
end
|
|
273
273
|
|
|
274
274
|
it "updates the trust_level" do
|
|
275
275
|
params = { level: 2 }
|
|
276
|
-
admin_user =
|
|
276
|
+
admin_user = client.update_trust_level(2, params)
|
|
277
277
|
expect(admin_user).to be_a Hash
|
|
278
278
|
expect(admin_user["admin_user"]).to have_key("trust_level")
|
|
279
279
|
end
|
|
@@ -291,13 +291,13 @@ describe DiscourseApi::API::Users do
|
|
|
291
291
|
end
|
|
292
292
|
|
|
293
293
|
it "makes the correct put request" do
|
|
294
|
-
|
|
294
|
+
client.grant_admin(11)
|
|
295
295
|
url = "#{host}/admin/users/11/grant_admin"
|
|
296
296
|
expect(a_put(url)).to have_been_made
|
|
297
297
|
end
|
|
298
298
|
|
|
299
299
|
it "makes the user an admin" do
|
|
300
|
-
result =
|
|
300
|
+
result = client.grant_admin(11)
|
|
301
301
|
expect(result).to be_a Hash
|
|
302
302
|
expect(result["admin_user"]["admin"]).to eq(true)
|
|
303
303
|
end
|
|
@@ -315,13 +315,13 @@ describe DiscourseApi::API::Users do
|
|
|
315
315
|
end
|
|
316
316
|
|
|
317
317
|
it "makes the correct put request" do
|
|
318
|
-
|
|
318
|
+
client.grant_moderation(11)
|
|
319
319
|
url = "#{host}/admin/users/11/grant_moderation"
|
|
320
320
|
expect(a_put(url)).to have_been_made
|
|
321
321
|
end
|
|
322
322
|
|
|
323
323
|
it "makes the user a moderator" do
|
|
324
|
-
result =
|
|
324
|
+
result = client.grant_moderation(11)
|
|
325
325
|
expect(result).to be_a Hash
|
|
326
326
|
expect(result["admin_user"]["moderator"]).to eq(true)
|
|
327
327
|
end
|
|
@@ -334,7 +334,7 @@ describe DiscourseApi::API::Users do
|
|
|
334
334
|
end
|
|
335
335
|
|
|
336
336
|
it "makes the correct put request" do
|
|
337
|
-
result =
|
|
337
|
+
result = client.revoke_moderation(11)
|
|
338
338
|
url = "#{host}/admin/users/11/revoke_moderation"
|
|
339
339
|
expect(a_put(url)).to have_been_made
|
|
340
340
|
expect(result.status).to eq(200)
|
|
@@ -352,12 +352,12 @@ describe DiscourseApi::API::Users do
|
|
|
352
352
|
end
|
|
353
353
|
|
|
354
354
|
it "requests the correct resource" do
|
|
355
|
-
|
|
355
|
+
client.by_external_id(1)
|
|
356
356
|
expect(a_get("#{host}/users/by-external/1")).to have_been_made
|
|
357
357
|
end
|
|
358
358
|
|
|
359
359
|
it "returns the requested user" do
|
|
360
|
-
user =
|
|
360
|
+
user = client.by_external_id(1)
|
|
361
361
|
expect(user["id"]).to eq 1
|
|
362
362
|
end
|
|
363
363
|
end
|
|
@@ -369,7 +369,7 @@ describe DiscourseApi::API::Users do
|
|
|
369
369
|
end
|
|
370
370
|
|
|
371
371
|
it "makes the correct put request" do
|
|
372
|
-
result =
|
|
372
|
+
result = client.suspend(11, "2030-01-01", "no reason")
|
|
373
373
|
url = "#{host}/admin/users/11/suspend"
|
|
374
374
|
expect(a_put(url)).to have_been_made
|
|
375
375
|
expect(result.status).to eq(200)
|
|
@@ -383,7 +383,7 @@ describe DiscourseApi::API::Users do
|
|
|
383
383
|
end
|
|
384
384
|
|
|
385
385
|
it "makes the correct put request" do
|
|
386
|
-
result =
|
|
386
|
+
result = client.unsuspend(11)
|
|
387
387
|
url = "#{host}/admin/users/11/unsuspend"
|
|
388
388
|
expect(a_put(url)).to have_been_made
|
|
389
389
|
expect(result.status).to eq(200)
|
|
@@ -397,7 +397,7 @@ describe DiscourseApi::API::Users do
|
|
|
397
397
|
end
|
|
398
398
|
|
|
399
399
|
it "makes the correct put request" do
|
|
400
|
-
result =
|
|
400
|
+
result = client.anonymize(11)
|
|
401
401
|
url = "#{host}/admin/users/11/anonymize"
|
|
402
402
|
expect(a_put(url)).to have_been_made
|
|
403
403
|
expect(result.status).to eq(200)
|
|
@@ -411,7 +411,7 @@ describe DiscourseApi::API::Users do
|
|
|
411
411
|
end
|
|
412
412
|
|
|
413
413
|
it "makes the correct delete request" do
|
|
414
|
-
result =
|
|
414
|
+
result = client.delete_user(11, true)
|
|
415
415
|
url = "#{host}/admin/users/11.json?delete_posts=true"
|
|
416
416
|
expect(a_delete(url)).to have_been_made
|
|
417
417
|
expect(result.body).to eq('{"deleted": true}')
|
|
@@ -426,12 +426,12 @@ describe DiscourseApi::API::Users do
|
|
|
426
426
|
before { stub_get(url).to_return(body: body, headers: { content_type: "application/json" }) }
|
|
427
427
|
|
|
428
428
|
it "requests the correct resource" do
|
|
429
|
-
|
|
429
|
+
client.check_username("sparrow")
|
|
430
430
|
expect(a_get(url)).to have_been_made
|
|
431
431
|
end
|
|
432
432
|
|
|
433
433
|
it "returns the result" do
|
|
434
|
-
result =
|
|
434
|
+
result = client.check_username("sparrow")
|
|
435
435
|
expect(result["available"]).to eq false
|
|
436
436
|
end
|
|
437
437
|
|
|
@@ -440,12 +440,12 @@ describe DiscourseApi::API::Users do
|
|
|
440
440
|
let(:body) { '{"errors":["must only include numbers, letters, dashes, and underscores"]}' }
|
|
441
441
|
|
|
442
442
|
it "escapes them" do
|
|
443
|
-
|
|
443
|
+
client.check_username("1_[4]! @the$#?")
|
|
444
444
|
expect(a_get(url)).to have_been_made
|
|
445
445
|
end
|
|
446
446
|
|
|
447
447
|
it "returns the result" do
|
|
448
|
-
result =
|
|
448
|
+
result = client.check_username("1_[4]! @the$#?")
|
|
449
449
|
expect(
|
|
450
450
|
result["errors"].first,
|
|
451
451
|
).to eq "must only include numbers, letters, dashes, and underscores"
|
|
@@ -457,12 +457,12 @@ describe DiscourseApi::API::Users do
|
|
|
457
457
|
before { stub_put("#{host}/admin/users/15/deactivate").to_return(body: nil) }
|
|
458
458
|
|
|
459
459
|
it "makes the put request" do
|
|
460
|
-
|
|
460
|
+
client.deactivate(15)
|
|
461
461
|
expect(a_put("#{host}/admin/users/15/deactivate")).to have_been_made
|
|
462
462
|
end
|
|
463
463
|
|
|
464
464
|
it "returns success" do
|
|
465
|
-
response =
|
|
465
|
+
response = client.deactivate(15)
|
|
466
466
|
expect(response.status).to eq(200)
|
|
467
467
|
end
|
|
468
468
|
end
|