mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 20:24:05 -06:00
cdf1589a85
Currently, only user badge grants emit webhook events. This change extends the `user_badge` webhook to emit user badge revocation events. A new `user_badge_revoked` event has been introduced instead of relying on the existing `user_badge_removed` event. `user_badge_removed` emitted just the `badge_id` and `user_id` which aren't helpful for generating a meaningful webhook payload for revoked(deleted) user badges. The new event emits the user badge object.
32 lines
1.1 KiB
Ruby
32 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Webhook event handlers" do
|
|
fab!(:user_badge) { Fabricate(:user_badge) }
|
|
fab!(:web_hook) { Fabricate(:user_badge_web_hook) }
|
|
fab!(:user) { Fabricate(:user) }
|
|
fab!(:badge) { Fabricate(:badge) }
|
|
fab!(:post) { Fabricate(:post) }
|
|
|
|
describe "user_badge events" do
|
|
it "enqueues user_badge_granted webhook event" do
|
|
expect do
|
|
BadgeGranter.grant(badge, user, granted_by: Discourse.system_user, post_id: post.id)
|
|
end.to change { Jobs::EmitWebHookEvent.jobs.size }.by(1)
|
|
|
|
job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first
|
|
expect(job_args["id"]).to eq(user.user_badges.last.id)
|
|
expect(job_args["event_name"]).to eq("user_badge_granted")
|
|
end
|
|
|
|
it "enqueues user_badge_revoked webhook event" do
|
|
expect { BadgeGranter.revoke(user_badge) }.to change { Jobs::EmitWebHookEvent.jobs.size }.by(
|
|
1,
|
|
)
|
|
|
|
job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first
|
|
expect(job_args["id"]).to eq(user_badge.id)
|
|
expect(job_args["event_name"]).to eq("user_badge_revoked")
|
|
end
|
|
end
|
|
end
|