Skip to content

Commit deff9d3

Browse files
authored
DEV: Adds methods from invite controller (#235)
1 parent ca5a29d commit deff9d3

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

examples/invite_users.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#update invite
1515
client.update_invite(invite["id"], email: "namee@example.com")
1616

17+
# resend invite
18+
client.resend_invite("namee@example.com")
19+
1720
# invite to a topic
1821
client.invite_user_to_topic(email: "foo@bar.com", topic_id: 1)
1922

@@ -23,5 +26,11 @@
2326
# retrieve invite
2427
puts client.retrieve_invite(email: "foo@bar.com")
2528

29+
# resend all invites
30+
client.resend_all_invites
31+
32+
# destroy invite
33+
client.destroy_invite(invite["id"])
34+
2635
# destroy all expired invites
2736
client.destroy_all_expired_invites

lib/discourse_api/api/invite.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ def update_invite(invite_id, params = {})
6767
def destroy_all_expired_invites
6868
post("invites/destroy-all-expired")
6969
end
70+
71+
def resend_all_invites
72+
post("invites/reinvite-all")
73+
end
74+
75+
def resend_invite(email)
76+
post("invites/reinvite", { "email": email })
77+
end
78+
79+
def destroy_invite(invite_id)
80+
delete("/invites", { id: invite_id })
81+
end
7082
end
7183
end
7284
end

spec/discourse_api/api/invite_spec.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,54 @@
7070
expect(a_post(url)).to have_been_made
7171
end
7272
end
73+
74+
describe "#resend_all_invites" do
75+
let(:url) { "#{host}/invites/reinvite-all" }
76+
77+
before do
78+
stub_post(url)
79+
.to_return(
80+
body: '{"success": "OK"}',
81+
headers: { content_type: "application/json" }
82+
)
83+
end
84+
85+
it "resends all invites" do
86+
subject.resend_all_invites
87+
expect(a_post(url)).to have_been_made
88+
end
89+
end
90+
91+
describe "#resend_invite" do
92+
let(:url) { "#{host}/invites/reinvite" }
93+
94+
before do
95+
stub_post(url)
96+
.to_return(
97+
body: '{"success": "OK"}',
98+
headers: { content_type: "application/json" }
99+
)
100+
end
101+
102+
it "resends invite" do
103+
subject.resend_invite("foo@bar.com")
104+
expect(a_post(url)).to have_been_made
105+
end
106+
end
107+
108+
describe "#destroy_invite" do
109+
let(:url) { "#{host}/invites?id=27" }
110+
111+
before do
112+
stub_delete(url).to_return(
113+
body: '{"success": "OK"}',
114+
headers: { content_type: "application/json" }
115+
)
116+
end
117+
118+
it "destroys the invite" do
119+
subject.destroy_invite(27)
120+
expect(a_delete(url)).to have_been_made
121+
end
122+
end
73123
end

0 commit comments

Comments
 (0)