Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 167f04a

Browse files
authored
DEV: Adds method to update an invite (#229)
* DEV: Adds method to update an invite * DEV: Adds rspec test for update_invite & invite_user method
1 parent 3227bbd commit 167f04a

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

examples/invite_users.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
client.api_username = config['api_username'] || "YOUR_USERNAME"
1010

1111
# invite user
12-
client.invite_user(email: "[email protected]", group_ids: "41,42")
12+
invite = client.invite_user(email: "[email protected]", group_ids: "41,42")
13+
14+
#update invite
15+
client.update_invite(invite["id"], email: "[email protected]")
1316

1417
# invite to a topic
1518
client.invite_user_to_topic(email: "[email protected]", topic_id: 1)

lib/discourse_api/api/invite.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ def invite_to_topic(topic_id, params = {})
3939
def disposable_tokens(params = {})
4040
post("/invite-token/generate", params)
4141
end
42+
43+
def update_invite(invite_id, params = {})
44+
args = API.params(params)
45+
.optional(
46+
:topic_id,
47+
:group_ids,
48+
:group_names,
49+
:email,
50+
:send_email,
51+
:custom_message,
52+
:max_redemptions_allowed,
53+
:expires_at
54+
).to_h
55+
56+
put("invites/#{invite_id}", args)
57+
end
4258
end
4359
end
4460
end

spec/discourse_api/api/invite_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
require 'spec_helper'
3+
4+
describe DiscourseApi::API::Invite do
5+
subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user") }
6+
7+
describe "#invite_user" do
8+
before do
9+
stub_post("#{host}/invites").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
10+
end
11+
12+
it "requests the correct resource" do
13+
subject.invite_user(email: "[email protected]", group_ids: "41,42")
14+
expect(a_post("#{host}/invites")).to have_been_made
15+
end
16+
17+
it "returns success" do
18+
response = subject.invite_user(email: "[email protected]", group_ids: "41,42")
19+
expect(response).to be_a Hash
20+
expect(response['success']).to be_truthy
21+
end
22+
end
23+
24+
describe "#update_invite" do
25+
before do
26+
stub_put("#{host}/invites/27").to_return(body: fixture("topic_invite_user.json"), headers: { content_type: "application/json" })
27+
end
28+
29+
it "updates invite" do
30+
subject.update_invite(27, email: "[email protected]")
31+
expect(a_put("#{host}/invites/27")).to have_been_made
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)