require 'spec_helper'
require 'jam_ruby/recurly_client'
describe ApiRecurlyWebHookController, :type=>:request do
let(:success_xml) {
'
56d5b2c6-2a4b-46e4-a984-ec1fbe83a50dseth@jamkazam.comSethCall2de4448533db12d6d92b4c4b4e90a4f12de44484fa4528b504555f43ac8bf42f10372de44484b460d95863799a431383b165purchase2015-04-01T14:53:44Z216successSuccessful test transaction6249355subscriptionStreet address and postal code match.truetruetrue'
}
let(:no_user_xml) {
'
HUHUHUHUHUHUHUHUseth@jamkazam.comSethCall2de4448533db12d6d92b4c4b4e90a4f12de44484fa4528b504555f43ac8bf42f10372de44484b460d95863799a431383b165purchase2015-04-01T14:53:44Z216successSuccessful test transaction6249355subscriptionStreet address and postal code match.truetruetrue'
}
before(:all) do
User.delete_all
@user = FactoryGirl.create(:user, id: '56d5b2c6-2a4b-46e4-a984-ec1fbe83a50d')
end
let (:authorization) { "Basic " + Base64::encode64(Rails.application.config.recurly_webhook_user + ":" + Rails.application.config.recurly_webhook_pass ) }
it "no auth" do
post '/api/recurly/webhook', success_xml, { 'CONTENT_TYPE' => 'application/xml', 'ACCEPT' => 'application/xml' }
response.status.should eq(401)
end
it "succeeds" do
post '/api/recurly/webhook', success_xml, { 'Content-Type' => 'application/xml', 'HTTP_AUTHORIZATION' => authorization }
response.status.should eq(200)
end
it "returns 422 on error" do
post '/api/recurly/webhook', no_user_xml, { 'Content-Type' => 'application/xml', 'HTTP_AUTHORIZATION' => authorization }
response.status.should eq(422)
end
it "returns 200 for unknown hook event" do
post '/api/recurly/webhook', '', { 'Content-Type' => 'application/xml', 'HTTP_AUTHORIZATION' => authorization }
response.status.should eq(200)
end
end