You probably are using a controller to handle POST
requests, let's call it WebhookController
You can simply test that a post with the params of what you need is doing what you want. E.g.,I ntegration tests (in test unit but rspec does the same thing).
Rspec may have a different version of fixture_file_upload
for uploading/adding an xml file, but according to this stack question it looks like you can use it too. Stick the file in say spec/files
.
Regardless, for the web and noobs, you would be testing that your Delayed::Job
call actually works in another test.
Something like:
class GetWebhookTest < ActionController::IntegrationTest
fixtures :all
def recieve_webhook
post '/webhook/338782', fixture_file_upload('webhook.xml', 'application/xml')
end
#Test you do what the outcome of your POST would be.
#this is refactored but you can shove the post line where receive_webhook is
test "recieve a webhook via xml" do
assert_difference('RawData.count') do
receive_webhook
end
end
test "make sure the status is 200" do
recieve_webhook
assert_response :success
end
#Test 1 will fail before this, but i was more/too thorough back in the day
test "Delayed Job increases" do
assert_difference "Delayed::Job.count", 1 do
recieve_webhook
end
end
end
Again, Rspec has things like response.should be_success
and their Object.count difference method too. Adjust for your situation. The key is fixture_file_upload