2024-04-03 23:20:43 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe "ZapierWebhook" do
|
|
|
|
fab!(:topic)
|
|
|
|
|
|
|
|
fab!(:automation) { Fabricate(:automation, script: DiscourseAutomation::Scripts::ZAPIER_WEBHOOK) }
|
|
|
|
|
|
|
|
context "with valid webhook url" do
|
|
|
|
before do
|
|
|
|
automation.upsert_field!(
|
|
|
|
"webhook_url",
|
|
|
|
"text",
|
|
|
|
{ value: "https://hooks.zapier.com/hooks/catch/foo/bar" },
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "enqueues the zapier call" do
|
|
|
|
expect { automation.trigger! }.to change {
|
2024-05-07 04:12:55 +08:00
|
|
|
Jobs::DiscourseAutomation::CallZapierWebhook.jobs.length
|
2024-04-03 23:20:43 +08:00
|
|
|
}.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with invalid webhook url" do
|
2024-11-13 08:47:39 +08:00
|
|
|
let(:fake_logger) { FakeLogger.new }
|
|
|
|
|
|
|
|
before { Rails.logger.broadcast_to(fake_logger) }
|
2024-04-03 23:20:43 +08:00
|
|
|
|
2024-11-13 08:47:39 +08:00
|
|
|
after { Rails.logger.stop_broadcasting_to(fake_logger) }
|
2024-04-03 23:20:43 +08:00
|
|
|
|
|
|
|
it "logs an error and do nothing" do
|
|
|
|
expect { automation.trigger! }.not_to change {
|
2024-05-07 04:12:55 +08:00
|
|
|
Jobs::DiscourseAutomation::CallZapierWebhook.jobs.length
|
2024-04-03 23:20:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
expect(Rails.logger.warnings.first).to match(/is not a valid Zapier/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|