DEV: Specs for redeliver_web_hook_events job (#27779)
It is a PR to add a spec for checking redeliver_web_hook_events job not to delete webhook event in process.
This commit is contained in:
parent
d7d3555378
commit
a01be4150a
|
@ -1,3 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
Fabricator(:redelivering_webhook_event) { web_hook_event_id { Fabricate(:web_hook_event).id } }
|
Fabricator(:redelivering_webhook_event) do
|
||||||
|
web_hook_event_id { Fabricate(:web_hook_event).id }
|
||||||
|
processing false
|
||||||
|
end
|
||||||
|
|
|
@ -6,7 +6,16 @@ RSpec.describe Jobs::RedeliverWebHookEvents do
|
||||||
subject(:job) { described_class.new }
|
subject(:job) { described_class.new }
|
||||||
|
|
||||||
fab!(:web_hook)
|
fab!(:web_hook)
|
||||||
fab!(:web_hook_event) do
|
fab!(:web_hook_event1) do
|
||||||
|
Fabricate(
|
||||||
|
:web_hook_event,
|
||||||
|
web_hook: web_hook,
|
||||||
|
payload: "abc",
|
||||||
|
headers: JSON.dump(aa: "1", bb: "2"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
fab!(:web_hook_event2) do
|
||||||
Fabricate(
|
Fabricate(
|
||||||
:web_hook_event,
|
:web_hook_event,
|
||||||
web_hook: web_hook,
|
web_hook: web_hook,
|
||||||
|
@ -16,7 +25,7 @@ RSpec.describe Jobs::RedeliverWebHookEvents do
|
||||||
end
|
end
|
||||||
|
|
||||||
fab!(:redelivering_webhook_event) do
|
fab!(:redelivering_webhook_event) do
|
||||||
Fabricate(:redelivering_webhook_event, web_hook_event_id: web_hook_event.id)
|
Fabricate(:redelivering_webhook_event, web_hook_event_id: web_hook_event1.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redelivers webhook events" do
|
it "redelivers webhook events" do
|
||||||
|
@ -29,10 +38,37 @@ RSpec.describe Jobs::RedeliverWebHookEvents do
|
||||||
).to_return(status: 400, body: "", headers: {})
|
).to_return(status: 400, body: "", headers: {})
|
||||||
|
|
||||||
messages =
|
messages =
|
||||||
MessageBus.track_publish { job.execute(web_hook: web_hook, web_hook_event: web_hook_event) }
|
MessageBus.track_publish { job.execute(web_hook: web_hook, web_hook_event: web_hook_event1) }
|
||||||
|
|
||||||
expect(RedeliveringWebhookEvent.count).to eq(0)
|
expect(RedeliveringWebhookEvent.count).to eq(0)
|
||||||
expect(messages.count).to eq(1)
|
expect(messages.count).to eq(1)
|
||||||
expect(messages.first.data).to include(type: "redelivered")
|
expect(messages.first.data).to include(type: "redelivered")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when there is a redelivering_webhook_event in process" do
|
||||||
|
fab!(:redelivering_webhook_event_in_process) do
|
||||||
|
Fabricate(
|
||||||
|
:redelivering_webhook_event,
|
||||||
|
web_hook_event_id: web_hook_event2.id,
|
||||||
|
processing: true,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not delete the webhook event in process" do
|
||||||
|
stub_request(:post, web_hook.payload_url).with(
|
||||||
|
body: "abc",
|
||||||
|
headers: {
|
||||||
|
"aa" => 1,
|
||||||
|
"bb" => 2,
|
||||||
|
},
|
||||||
|
).to_return(status: 400, body: "", headers: {})
|
||||||
|
|
||||||
|
job.execute({})
|
||||||
|
|
||||||
|
expect(RedeliveringWebhookEvent.count).to eq(1)
|
||||||
|
expect(
|
||||||
|
RedeliveringWebhookEvent.find_by(id: redelivering_webhook_event_in_process.id),
|
||||||
|
).to be_present
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue