2023-04-25 04:36:40 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe "Webhook event handlers" do
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:user_badge)
|
2023-04-25 04:36:40 +08:00
|
|
|
fab!(:web_hook) { Fabricate(:user_badge_web_hook) }
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:user)
|
|
|
|
fab!(:badge)
|
|
|
|
fab!(:post)
|
2023-04-25 04:36:40 +08:00
|
|
|
|
|
|
|
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
|