require 'spec_helper' require 'jam_ruby/recurly_client' describe ApiRecurlyWebHookController, :type=>:request do let(:success_xml) { ' 56d5b2c6-2a4b-46e4-a984-ec1fbe83a50d seth@jamkazam.com Seth Call 2de4448533db12d6d92b4c4b4e90a4f1 2de44484fa4528b504555f43ac8bf42f 1037 2de44484b460d95863799a431383b165 purchase 2015-04-01T14:53:44Z 216 success Successful test transaction 6249355 subscription Street address and postal code match. true true true ' } let(:no_user_xml) { ' HUHUHUHUHUHUHUHU seth@jamkazam.com Seth Call 2de4448533db12d6d92b4c4b4e90a4f1 2de44484fa4528b504555f43ac8bf42f 1037 2de44484b460d95863799a431383b165 purchase 2015-04-01T14:53:44Z 216 success Successful test transaction 6249355 subscription Street address and postal code match. true true true ' } 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