discourse_api 1.1.0 → 2.0.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 +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 -19
- 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::Users do
|
5
5
|
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
|
6
6
|
|
7
7
|
describe "#user" do
|
8
8
|
before do
|
9
|
-
stub_get("#{host}/users/test.json").to_return(
|
9
|
+
stub_get("#{host}/users/test.json").to_return(
|
10
|
+
body: fixture("user.json"),
|
11
|
+
headers: {
|
12
|
+
content_type: "application/json",
|
13
|
+
},
|
14
|
+
)
|
10
15
|
end
|
11
16
|
|
12
17
|
it "requests the correct resource" do
|
@@ -27,7 +32,12 @@ describe DiscourseApi::API::Users do
|
|
27
32
|
|
28
33
|
describe "#user_sso" do
|
29
34
|
before do
|
30
|
-
stub_get("#{host}/admin/users/15.json").to_return(
|
35
|
+
stub_get("#{host}/admin/users/15.json").to_return(
|
36
|
+
body: fixture("admin_user.json"),
|
37
|
+
headers: {
|
38
|
+
content_type: "application/json",
|
39
|
+
},
|
40
|
+
)
|
31
41
|
end
|
32
42
|
|
33
43
|
it "requests the correct resource" do
|
@@ -44,21 +54,37 @@ describe DiscourseApi::API::Users do
|
|
44
54
|
|
45
55
|
describe "#update_avatar" do
|
46
56
|
before do
|
47
|
-
stub_post("#{host}/uploads").to_return(
|
48
|
-
|
57
|
+
stub_post("#{host}/uploads").to_return(
|
58
|
+
body: fixture("upload_avatar.json"),
|
59
|
+
headers: {
|
60
|
+
content_type: "application/json",
|
61
|
+
},
|
62
|
+
)
|
63
|
+
stub_put("#{host}/u/test_user/preferences/avatar/pick").to_return(
|
64
|
+
body: fixture("user_update_avatar_success.json"),
|
65
|
+
headers: {
|
66
|
+
content_type: "application/json",
|
67
|
+
},
|
68
|
+
)
|
49
69
|
end
|
50
70
|
|
51
71
|
it "uploads an image" do
|
52
|
-
sam =
|
72
|
+
sam =
|
73
|
+
"https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
|
53
74
|
args = { url: sam }
|
54
|
-
response = subject.update_avatar(
|
55
|
-
expect(response[:body][
|
75
|
+
response = subject.update_avatar("test_user", args)
|
76
|
+
expect(response[:body]["success"]).to eq("OK")
|
56
77
|
end
|
57
78
|
end
|
58
79
|
|
59
80
|
describe "#update_email" do
|
60
81
|
before do
|
61
|
-
stub_put("#{host}/u/fake_user/preferences/email").to_return(
|
82
|
+
stub_put("#{host}/u/fake_user/preferences/email").to_return(
|
83
|
+
body: fixture("user_update_user.json"),
|
84
|
+
headers: {
|
85
|
+
content_type: "application/json",
|
86
|
+
},
|
87
|
+
)
|
62
88
|
end
|
63
89
|
|
64
90
|
it "makes the put request" do
|
@@ -68,33 +94,43 @@ describe DiscourseApi::API::Users do
|
|
68
94
|
|
69
95
|
it "returns success" do
|
70
96
|
response = subject.update_email("fake_user", "fake_user_2@example.com")
|
71
|
-
expect(response[:body][
|
97
|
+
expect(response[:body]["success"]).to be_truthy
|
72
98
|
end
|
73
99
|
end
|
74
100
|
|
75
101
|
describe "#update_user" do
|
76
102
|
before do
|
77
|
-
stub_put("#{host}/u/fake_user").to_return(
|
103
|
+
stub_put("#{host}/u/fake_user").to_return(
|
104
|
+
body: fixture("user_update_user.json"),
|
105
|
+
headers: {
|
106
|
+
content_type: "application/json",
|
107
|
+
},
|
108
|
+
)
|
78
109
|
end
|
79
110
|
|
80
111
|
it "makes the put request" do
|
81
|
-
subject.api_key =
|
82
|
-
subject.api_username =
|
112
|
+
subject.api_key = "test_d7fd0429940"
|
113
|
+
subject.api_username = "test_user"
|
83
114
|
subject.update_user("fake_user", name: "Fake User 2")
|
84
115
|
expect(a_put("#{host}/u/fake_user")).to have_been_made
|
85
116
|
end
|
86
117
|
|
87
118
|
it "returns success" do
|
88
|
-
subject.api_key =
|
89
|
-
subject.api_username =
|
119
|
+
subject.api_key = "test_d7fd0429940"
|
120
|
+
subject.api_username = "test_user"
|
90
121
|
response = subject.update_user("fake_user", name: "Fake User 2")
|
91
|
-
expect(response[:body][
|
122
|
+
expect(response[:body]["success"]).to be_truthy
|
92
123
|
end
|
93
124
|
end
|
94
125
|
|
95
126
|
describe "#update_username" do
|
96
127
|
before do
|
97
|
-
stub_put("#{host}/u/fake_user/preferences/username").to_return(
|
128
|
+
stub_put("#{host}/u/fake_user/preferences/username").to_return(
|
129
|
+
body: fixture("user_update_username.json"),
|
130
|
+
headers: {
|
131
|
+
content_type: "application/json",
|
132
|
+
},
|
133
|
+
)
|
98
134
|
end
|
99
135
|
|
100
136
|
it "makes the put request" do
|
@@ -104,30 +140,47 @@ describe DiscourseApi::API::Users do
|
|
104
140
|
|
105
141
|
it "returns the updated username" do
|
106
142
|
response = subject.update_username("fake_user", "fake_user_2")
|
107
|
-
expect(response[:body][
|
143
|
+
expect(response[:body]["username"]).to eq("fake_user_2")
|
108
144
|
end
|
109
145
|
end
|
110
146
|
|
111
147
|
describe "#create_user" do
|
112
148
|
before do
|
113
|
-
stub_post("#{host}/users").to_return(
|
149
|
+
stub_post("#{host}/users").to_return(
|
150
|
+
body: fixture("user_create_success.json"),
|
151
|
+
headers: {
|
152
|
+
content_type: "application/json",
|
153
|
+
},
|
154
|
+
)
|
114
155
|
end
|
115
156
|
|
116
157
|
it "makes the post request" do
|
117
|
-
subject.create_user name: "Test User",
|
158
|
+
subject.create_user name: "Test User",
|
159
|
+
email: "test2@example.com",
|
160
|
+
password: "P@ssword",
|
161
|
+
username: "test2"
|
118
162
|
expect(a_post("#{host}/users")).to have_been_made
|
119
163
|
end
|
120
164
|
|
121
165
|
it "returns success" do
|
122
|
-
response =
|
166
|
+
response =
|
167
|
+
subject.create_user name: "Test User",
|
168
|
+
email: "test2@example.com",
|
169
|
+
password: "P@ssword",
|
170
|
+
username: "test2"
|
123
171
|
expect(response).to be_a Hash
|
124
|
-
expect(response[
|
172
|
+
expect(response["success"]).to be_truthy
|
125
173
|
end
|
126
174
|
end
|
127
175
|
|
128
176
|
describe "#activate_user" do
|
129
177
|
before do
|
130
|
-
stub_put("#{host}/admin/users/15/activate").to_return(
|
178
|
+
stub_put("#{host}/admin/users/15/activate").to_return(
|
179
|
+
body: fixture("user_activate_success.json"),
|
180
|
+
headers: {
|
181
|
+
content_type: "application/json",
|
182
|
+
},
|
183
|
+
)
|
131
184
|
end
|
132
185
|
|
133
186
|
it "makes the put request" do
|
@@ -137,13 +190,18 @@ describe DiscourseApi::API::Users do
|
|
137
190
|
|
138
191
|
it "returns success" do
|
139
192
|
response = subject.activate(15)
|
140
|
-
expect(response[:body][
|
193
|
+
expect(response[:body]["success"]).to eq("OK")
|
141
194
|
end
|
142
195
|
end
|
143
196
|
|
144
197
|
describe "#log_out_success" do
|
145
198
|
before do
|
146
|
-
stub_post("#{host}/admin/users/4/log_out").to_return(
|
199
|
+
stub_post("#{host}/admin/users/4/log_out").to_return(
|
200
|
+
body: fixture("user_log_out_success.json"),
|
201
|
+
headers: {
|
202
|
+
content_type: "application/json",
|
203
|
+
},
|
204
|
+
)
|
147
205
|
end
|
148
206
|
|
149
207
|
it "makes a post request" do
|
@@ -154,13 +212,18 @@ describe DiscourseApi::API::Users do
|
|
154
212
|
it "returns success" do
|
155
213
|
response = subject.log_out(4)
|
156
214
|
expect(response).to be_a Hash
|
157
|
-
expect(response[
|
215
|
+
expect(response["success"]).to eq("OK")
|
158
216
|
end
|
159
217
|
end
|
160
218
|
|
161
219
|
describe "#log_out_unsuccessful" do
|
162
220
|
before do
|
163
|
-
stub_post("#{host}/admin/users/90/log_out").to_return(
|
221
|
+
stub_post("#{host}/admin/users/90/log_out").to_return(
|
222
|
+
status: 404,
|
223
|
+
headers: {
|
224
|
+
content_type: "application/json",
|
225
|
+
},
|
226
|
+
)
|
164
227
|
end
|
165
228
|
|
166
229
|
it "Raises API Error" do
|
@@ -170,16 +233,21 @@ describe DiscourseApi::API::Users do
|
|
170
233
|
|
171
234
|
describe "#list_users" do
|
172
235
|
before do
|
173
|
-
stub_get("#{host}/admin/users/list/active.json").to_return(
|
236
|
+
stub_get("#{host}/admin/users/list/active.json").to_return(
|
237
|
+
body: fixture("user_list.json"),
|
238
|
+
headers: {
|
239
|
+
content_type: "application/json",
|
240
|
+
},
|
241
|
+
)
|
174
242
|
end
|
175
243
|
|
176
244
|
it "requests the correct resource" do
|
177
|
-
subject.list_users(
|
245
|
+
subject.list_users("active")
|
178
246
|
expect(a_get("#{host}/admin/users/list/active.json")).to have_been_made
|
179
247
|
end
|
180
248
|
|
181
249
|
it "returns the requested users" do
|
182
|
-
users = subject.list_users(
|
250
|
+
users = subject.list_users("active")
|
183
251
|
expect(users).to be_an Array
|
184
252
|
expect(users.first).to be_a Hash
|
185
253
|
end
|
@@ -188,8 +256,12 @@ describe DiscourseApi::API::Users do
|
|
188
256
|
describe "#update_trust_level" do
|
189
257
|
before do
|
190
258
|
url = "#{host}/admin/users/2/trust_level"
|
191
|
-
stub_put(url).to_return(
|
192
|
-
|
259
|
+
stub_put(url).to_return(
|
260
|
+
body: fixture("update_trust_level.json"),
|
261
|
+
headers: {
|
262
|
+
content_type: "application/json",
|
263
|
+
},
|
264
|
+
)
|
193
265
|
end
|
194
266
|
|
195
267
|
it "makes the correct put request" do
|
@@ -203,15 +275,19 @@ describe DiscourseApi::API::Users do
|
|
203
275
|
params = { level: 2 }
|
204
276
|
admin_user = subject.update_trust_level(2, params)
|
205
277
|
expect(admin_user).to be_a Hash
|
206
|
-
expect(admin_user[
|
278
|
+
expect(admin_user["admin_user"]).to have_key("trust_level")
|
207
279
|
end
|
208
280
|
end
|
209
281
|
|
210
282
|
describe "#grant admin" do
|
211
283
|
before do
|
212
284
|
url = "#{host}/admin/users/11/grant_admin"
|
213
|
-
stub_put(url).to_return(
|
214
|
-
|
285
|
+
stub_put(url).to_return(
|
286
|
+
body: fixture("user_grant_admin.json"),
|
287
|
+
headers: {
|
288
|
+
content_type: "application/json",
|
289
|
+
},
|
290
|
+
)
|
215
291
|
end
|
216
292
|
|
217
293
|
it "makes the correct put request" do
|
@@ -223,15 +299,19 @@ describe DiscourseApi::API::Users do
|
|
223
299
|
it "makes the user an admin" do
|
224
300
|
result = subject.grant_admin(11)
|
225
301
|
expect(result).to be_a Hash
|
226
|
-
expect(result[
|
302
|
+
expect(result["admin_user"]["admin"]).to eq(true)
|
227
303
|
end
|
228
304
|
end
|
229
305
|
|
230
306
|
describe "#grant moderation" do
|
231
307
|
before do
|
232
308
|
url = "#{host}/admin/users/11/grant_moderation"
|
233
|
-
stub_put(url).to_return(
|
234
|
-
|
309
|
+
stub_put(url).to_return(
|
310
|
+
body: fixture("user_grant_moderator.json"),
|
311
|
+
headers: {
|
312
|
+
content_type: "application/json",
|
313
|
+
},
|
314
|
+
)
|
235
315
|
end
|
236
316
|
|
237
317
|
it "makes the correct put request" do
|
@@ -243,14 +323,14 @@ describe DiscourseApi::API::Users do
|
|
243
323
|
it "makes the user a moderator" do
|
244
324
|
result = subject.grant_moderation(11)
|
245
325
|
expect(result).to be_a Hash
|
246
|
-
expect(result[
|
326
|
+
expect(result["admin_user"]["moderator"]).to eq(true)
|
247
327
|
end
|
248
328
|
end
|
249
329
|
|
250
330
|
describe "#revoke moderation" do
|
251
331
|
before do
|
252
332
|
url = "#{host}/admin/users/11/revoke_moderation"
|
253
|
-
stub_put(url).to_return(body:
|
333
|
+
stub_put(url).to_return(body: "", status: 200)
|
254
334
|
end
|
255
335
|
|
256
336
|
it "makes the correct put request" do
|
@@ -259,12 +339,16 @@ describe DiscourseApi::API::Users do
|
|
259
339
|
expect(a_put(url)).to have_been_made
|
260
340
|
expect(result.status).to eq(200)
|
261
341
|
end
|
262
|
-
|
263
342
|
end
|
264
343
|
|
265
344
|
describe "#by_external_id" do
|
266
345
|
before do
|
267
|
-
stub_get("#{host}/users/by-external/1").to_return(
|
346
|
+
stub_get("#{host}/users/by-external/1").to_return(
|
347
|
+
body: fixture("user.json"),
|
348
|
+
headers: {
|
349
|
+
content_type: "application/json",
|
350
|
+
},
|
351
|
+
)
|
268
352
|
end
|
269
353
|
|
270
354
|
it "requests the correct resource" do
|
@@ -274,18 +358,18 @@ describe DiscourseApi::API::Users do
|
|
274
358
|
|
275
359
|
it "returns the requested user" do
|
276
360
|
user = subject.by_external_id(1)
|
277
|
-
expect(user[
|
361
|
+
expect(user["id"]).to eq 1
|
278
362
|
end
|
279
363
|
end
|
280
364
|
|
281
365
|
describe "#suspend" do
|
282
366
|
before do
|
283
367
|
url = "#{host}/admin/users/11/suspend"
|
284
|
-
stub_put(url).to_return(body:
|
368
|
+
stub_put(url).to_return(body: "", status: 200)
|
285
369
|
end
|
286
370
|
|
287
371
|
it "makes the correct put request" do
|
288
|
-
result = subject.suspend(11,
|
372
|
+
result = subject.suspend(11, "2030-01-01", "no reason")
|
289
373
|
url = "#{host}/admin/users/11/suspend"
|
290
374
|
expect(a_put(url)).to have_been_made
|
291
375
|
expect(result.status).to eq(200)
|
@@ -295,7 +379,7 @@ describe DiscourseApi::API::Users do
|
|
295
379
|
describe "#unsuspend" do
|
296
380
|
before do
|
297
381
|
url = "#{host}/admin/users/11/unsuspend"
|
298
|
-
stub_put(url).to_return(body:
|
382
|
+
stub_put(url).to_return(body: "", status: 200)
|
299
383
|
end
|
300
384
|
|
301
385
|
it "makes the correct put request" do
|
@@ -309,7 +393,7 @@ describe DiscourseApi::API::Users do
|
|
309
393
|
describe "#anonymize" do
|
310
394
|
before do
|
311
395
|
url = "#{host}/admin/users/11/anonymize"
|
312
|
-
stub_put(url).to_return(body:
|
396
|
+
stub_put(url).to_return(body: "", status: 200)
|
313
397
|
end
|
314
398
|
|
315
399
|
it "makes the correct put request" do
|
@@ -339,9 +423,7 @@ describe DiscourseApi::API::Users do
|
|
339
423
|
let(:url) { "#{host}/users/check_username.json?username=sparrow" }
|
340
424
|
let(:body) { '{"available":false,"suggestion":"sparrow1"}' }
|
341
425
|
|
342
|
-
before
|
343
|
-
stub_get(url).to_return(body: body, headers: { content_type: "application/json" })
|
344
|
-
end
|
426
|
+
before { stub_get(url).to_return(body: body, headers: { content_type: "application/json" }) }
|
345
427
|
|
346
428
|
it "requests the correct resource" do
|
347
429
|
subject.check_username("sparrow")
|
@@ -350,7 +432,7 @@ describe DiscourseApi::API::Users do
|
|
350
432
|
|
351
433
|
it "returns the result" do
|
352
434
|
result = subject.check_username("sparrow")
|
353
|
-
expect(result[
|
435
|
+
expect(result["available"]).to eq false
|
354
436
|
end
|
355
437
|
|
356
438
|
context "when non-URI characters are used" do
|
@@ -364,15 +446,15 @@ describe DiscourseApi::API::Users do
|
|
364
446
|
|
365
447
|
it "returns the result" do
|
366
448
|
result = subject.check_username("1_[4]! @the$#?")
|
367
|
-
expect(
|
449
|
+
expect(
|
450
|
+
result["errors"].first,
|
451
|
+
).to eq "must only include numbers, letters, dashes, and underscores"
|
368
452
|
end
|
369
453
|
end
|
370
454
|
end
|
371
455
|
|
372
456
|
describe "#deactivate" do
|
373
|
-
before
|
374
|
-
stub_put("#{host}/admin/users/15/deactivate").to_return(body: nil)
|
375
|
-
end
|
457
|
+
before { stub_put("#{host}/admin/users/15/deactivate").to_return(body: nil) }
|
376
458
|
|
377
459
|
it "makes the put request" do
|
378
460
|
subject.deactivate(15)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe DiscourseApi::Client do
|
5
5
|
subject { DiscourseApi::Client.new(host) }
|
@@ -18,24 +18,24 @@ describe DiscourseApi::Client do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "accepts an api key argument" do
|
21
|
-
client = DiscourseApi::Client.new(host,
|
22
|
-
expect(client.api_key).to eq(
|
21
|
+
client = DiscourseApi::Client.new(host, "test")
|
22
|
+
expect(client.api_key).to eq("test")
|
23
23
|
end
|
24
24
|
|
25
25
|
it "accepts an api username argument" do
|
26
|
-
client = DiscourseApi::Client.new(host,
|
27
|
-
expect(client.api_username).to eq(
|
26
|
+
client = DiscourseApi::Client.new(host, "test", "test_user")
|
27
|
+
expect(client.api_username).to eq("test_user")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "#timeout" do
|
32
|
-
context
|
32
|
+
context "with a custom timeout" do
|
33
33
|
it "is set to Faraday connection" do
|
34
34
|
expect(subject.send(:connection).options.timeout).to eq(30)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
context
|
38
|
+
context "with the default timeout" do
|
39
39
|
it "is set to Faraday connection" do
|
40
40
|
subject.timeout = 25
|
41
41
|
expect(subject.send(:connection).options.timeout).to eq(25)
|
@@ -50,25 +50,25 @@ describe DiscourseApi::Client do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "#api_key" do
|
53
|
-
it "is
|
53
|
+
it "is publicly accessible" do
|
54
54
|
subject.api_key = "test_d7fd0429940"
|
55
55
|
expect(subject.api_key).to eq("test_d7fd0429940")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe "#api_username" do
|
60
|
-
it "is
|
60
|
+
it "is publicly accessible" do
|
61
61
|
subject.api_username = "test_user"
|
62
62
|
expect(subject.api_username).to eq("test_user")
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
describe "#host" do
|
67
|
-
it "is
|
67
|
+
it "is publicly readable" do
|
68
68
|
expect(subject.host).to eq("#{host}")
|
69
69
|
end
|
70
70
|
|
71
|
-
it "is not
|
71
|
+
it "is not publicly writeable" do
|
72
72
|
expect(subject).not_to respond_to(:host=)
|
73
73
|
end
|
74
74
|
end
|
@@ -87,8 +87,8 @@ describe DiscourseApi::Client do
|
|
87
87
|
describe "#delete" do
|
88
88
|
before do
|
89
89
|
stub_delete("#{host}/test/delete").with(query: { deleted: "object" })
|
90
|
-
subject.api_key =
|
91
|
-
subject.api_username =
|
90
|
+
subject.api_key = "test_d7fd0429940"
|
91
|
+
subject.api_username = "test_user"
|
92
92
|
end
|
93
93
|
|
94
94
|
it "allows custom delete requests" do
|
@@ -96,16 +96,16 @@ describe DiscourseApi::Client do
|
|
96
96
|
expect(a_delete("#{host}/test/delete").with(query: { deleted: "object" })).to have_been_made
|
97
97
|
end
|
98
98
|
|
99
|
-
context
|
99
|
+
context "when using a host with a subdirectory" do
|
100
100
|
subject { DiscourseApi::Client.new("#{host}/forum") }
|
101
101
|
|
102
|
-
before
|
103
|
-
stub_delete("#{host}/forum/test/delete").with(query: { deleted: "object" })
|
104
|
-
end
|
102
|
+
before { stub_delete("#{host}/forum/test/delete").with(query: { deleted: "object" }) }
|
105
103
|
|
106
104
|
it "allows custom delete requests" do
|
107
105
|
subject.delete("/test/delete", { deleted: "object" })
|
108
|
-
expect(
|
106
|
+
expect(
|
107
|
+
a_delete("#{host}/forum/test/delete").with(query: { deleted: "object" }),
|
108
|
+
).to have_been_made
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
@@ -113,8 +113,8 @@ describe DiscourseApi::Client do
|
|
113
113
|
describe "#post" do
|
114
114
|
before do
|
115
115
|
stub_post("#{host}/test/post").with(body: { created: "object" })
|
116
|
-
subject.api_key =
|
117
|
-
subject.api_username =
|
116
|
+
subject.api_key = "test_d7fd0429940"
|
117
|
+
subject.api_username = "test_user"
|
118
118
|
end
|
119
119
|
|
120
120
|
it "allows custom post requests" do
|
@@ -122,16 +122,16 @@ describe DiscourseApi::Client do
|
|
122
122
|
expect(a_post("#{host}/test/post").with(body: { created: "object" })).to have_been_made
|
123
123
|
end
|
124
124
|
|
125
|
-
context
|
125
|
+
context "when using a host with a subdirectory" do
|
126
126
|
subject { DiscourseApi::Client.new("#{host}/forum") }
|
127
127
|
|
128
|
-
before
|
129
|
-
stub_post("#{host}/forum/test/post").with(body: { created: "object" })
|
130
|
-
end
|
128
|
+
before { stub_post("#{host}/forum/test/post").with(body: { created: "object" }) }
|
131
129
|
|
132
130
|
it "allows custom post requests" do
|
133
131
|
subject.post("/test/post", { created: "object" })
|
134
|
-
expect(
|
132
|
+
expect(
|
133
|
+
a_post("#{host}/forum/test/post").with(body: { created: "object" }),
|
134
|
+
).to have_been_made
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
@@ -139,8 +139,8 @@ describe DiscourseApi::Client do
|
|
139
139
|
describe "#put" do
|
140
140
|
before do
|
141
141
|
stub_put("#{host}/test/put").with(body: { updated: "object" })
|
142
|
-
subject.api_key =
|
143
|
-
subject.api_username =
|
142
|
+
subject.api_key = "test_d7fd0429940"
|
143
|
+
subject.api_username = "test_user"
|
144
144
|
end
|
145
145
|
|
146
146
|
it "allows custom put requests" do
|
@@ -148,12 +148,10 @@ describe DiscourseApi::Client do
|
|
148
148
|
expect(a_put("#{host}/test/put").with(body: { updated: "object" })).to have_been_made
|
149
149
|
end
|
150
150
|
|
151
|
-
context
|
151
|
+
context "when using a host with a subdirectory" do
|
152
152
|
subject { DiscourseApi::Client.new("#{host}/forum") }
|
153
153
|
|
154
|
-
before
|
155
|
-
stub_put("#{host}/forum/test/put").with(body: { updated: "object" })
|
156
|
-
end
|
154
|
+
before { stub_put("#{host}/forum/test/put").with(body: { updated: "object" }) }
|
157
155
|
|
158
156
|
it "allows custom post requests" do
|
159
157
|
subject.put("/test/put", { updated: "object" })
|
@@ -165,7 +163,9 @@ describe DiscourseApi::Client do
|
|
165
163
|
describe "#request" do
|
166
164
|
it "catches 500 errors" do
|
167
165
|
connection = instance_double(Faraday::Connection)
|
168
|
-
allow(connection).to receive(:get).and_return(
|
166
|
+
allow(connection).to receive(:get).and_return(
|
167
|
+
OpenStruct.new(env: { body: "error page html" }, status: 500),
|
168
|
+
)
|
169
169
|
allow(Faraday).to receive(:new).and_return(connection)
|
170
170
|
expect { subject.send(:request, :get, "/test") }.to raise_error DiscourseApi::Error
|
171
171
|
end
|
@@ -1,43 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe DiscourseApi::SingleSignOn do
|
6
|
-
|
6
|
+
describe DiscourseApi::SingleSignOn::MissingConfigError do
|
7
7
|
it "inherits from RuntimeError for backward compatibility" do
|
8
8
|
expect(DiscourseApi::SingleSignOn::MissingConfigError).to be < RuntimeError
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
describe DiscourseApi::SingleSignOn::ParseError do
|
13
13
|
it "inherits from RuntimeError for backward compatibility" do
|
14
14
|
expect(DiscourseApi::SingleSignOn::ParseError).to be < RuntimeError
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
describe ".sso_secret" do
|
19
19
|
it "raises MissingConfigError when sso_secret is not present" do
|
20
|
-
expect {
|
21
|
-
|
22
|
-
|
20
|
+
expect { described_class.sso_secret }.to raise_error(
|
21
|
+
DiscourseApi::SingleSignOn::MissingConfigError,
|
22
|
+
)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
describe ".sso_url" do
|
27
27
|
it "raises MissingConfigError when sso_url is not present" do
|
28
|
-
expect {
|
29
|
-
|
30
|
-
|
28
|
+
expect { described_class.sso_url }.to raise_error(
|
29
|
+
DiscourseApi::SingleSignOn::MissingConfigError,
|
30
|
+
)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
describe ".parse" do
|
35
35
|
it "raises ParseError when there's a signature mismatch" do
|
36
36
|
sso = described_class.new
|
37
37
|
sso.sso_secret = "abcd"
|
38
|
-
expect {
|
39
|
-
|
40
|
-
|
38
|
+
expect { described_class.parse(sso.payload, "dcba") }.to raise_error(
|
39
|
+
DiscourseApi::SingleSignOn::ParseError,
|
40
|
+
)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|