mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 19:13:48 +08:00
6e161d3e75
The most common thing that we do with fab! is: fab!(:thing) { Fabricate(:thing) } This commit adds a shorthand for this which is just simply: fab!(:thing) i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
32 lines
1023 B
Ruby
32 lines
1023 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Webhook event handlers" do
|
|
fab!(:user_badge)
|
|
fab!(:web_hook) { Fabricate(:user_badge_web_hook) }
|
|
fab!(:user)
|
|
fab!(:badge)
|
|
fab!(: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
|