Sha256: e34a9749e4c03b2fc5faf40e3352564c89c738f93dd5ef31230315c1a0fb55db
Contents?: true
Size: 1.47 KB
Versions: 22
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true require 'test_plugin_helper' module ForemanWebhooks class WebhookServiceTest < ActiveSupport::TestCase let(:event_name) { 'subnet_created' } let(:payload) { { id: 2 } } let(:payload_json) { payload.to_json } let(:webhook) do FactoryBot.build(:webhook, :with_template, template: '<%= payload({id: @payload[:id]}, with_defaults: false) %>') end let(:webhook_service) do WebhookService.new( webhook: webhook, event_name: event_name, payload: payload_json, headers: {}, url: webhook.target_url ) end it 'executes a request to the configured webhook' do expected = { status: :success, message: '', http_status: 200 } stub_request(:post, 'https://hook.example.com/api/callback') .with( body: payload_json, headers: { 'Content-Type' => 'application/json' } ) .to_return(status: 200, body: '', headers: {}) assert_equal expected, webhook_service.execute end it 'handles a failed request' do expected = { status: :error, message: '', http_status: 404 } stub_request(:post, 'https://hook.example.com/api/callback') .with( body: payload_json, headers: { 'Content-Type' => 'application/json' } ) .to_return(status: 404, body: '', headers: {}) assert_equal expected, webhook_service.execute end end end
Version data entries
22 entries across 22 versions & 1 rubygems