spec/mandrill/web_hook/processor_spec.rb in mandrill-rails-1.2.0 vs spec/mandrill/web_hook/processor_spec.rb in mandrill-rails-1.3.0
- old
+ new
@@ -7,23 +7,34 @@
let(:processor) { processor_class.new(params) }
describe "#run!" do
context "when handler methods are present" do
+ let(:event1) { { "event" => "inbound" } }
+ let(:event2) { { "event" => "click" } }
+ let(:event3) { { "type" => "blacklist" } }
+ let(:params) { { "mandrill_events" => [event1, event2, event3].to_json } }
+
before do
allow(processor_class).to receive(:handle_inbound)
allow(processor_class).to receive(:handle_click)
+ allow(processor_class).to receive(:handle_sync)
end
- let(:event1) { { "event" => "inbound" } }
- let(:event2) { { "event" => "click" } }
- let(:params) { { "mandrill_events" => [event1,event2].to_json } }
- it "should pass all event payloads to the handler" do
+
+ it "passes all event payloads to the handler" do
expect(processor).to receive(:handle_inbound)
expect(processor).to receive(:handle_click)
+ expect(processor).to receive(:handle_sync)
processor.run!
end
end
+ context "but no valid handler methods are present" do
+ let(:params) { nil }
+ it "keeps calm and carries on" do
+ processor.run!
+ end
+ end
context "with callback host" do
let(:callback_host) { callback_host_class.new }
let(:processor) { processor_class.new(params,callback_host) }
let(:event1) { { "event" => "inbound" } }
@@ -37,11 +48,11 @@
def handle_inbound; end
end
end
- it "should pass event payload to the handler" do
+ it "passes event payload to the handler" do
expect(callback_host).to receive(:handle_inbound).twice
processor.run!
end
end
context "with handler method as protected" do
@@ -51,11 +62,11 @@
def handle_inbound; end
end
end
- it "should pass event payload to the handler" do
+ it "passes event payload to the handler" do
expect(callback_host).to receive(:handle_inbound).twice
processor.run!
end
end
context "with handler method as private" do
@@ -65,11 +76,11 @@
def handle_inbound; end
end
end
- it "should pass event payload to the handler" do
+ it "passes event payload to the handler" do
expect(callback_host).to receive(:handle_inbound).twice
processor.run!
end
end
@@ -94,11 +105,11 @@
expect { processor.run! }.to_not raise_error
end
end
context "and ignore missing handler behaviour" do
- it "logs an error" do
+ it "keeps calm and carries on" do
processor.on_unhandled_mandrill_events = :ignore
expect { processor.run! }.to_not raise_error
end
end
@@ -107,47 +118,43 @@
processor.on_unhandled_mandrill_events = :raise_exception
expect { processor.run! }
.to raise_error(Mandrill::Rails::Errors::MissingEventHandler)
end
end
-
end
-
end
-
-
end
- describe "#wrap_payload" do
- let(:raw_payload) { {} }
- subject { processor.wrap_payload(raw_payload) }
- it "returns a decorated hash" do
- expect(subject.class).to eql(Mandrill::WebHook::EventDecorator)
- end
- end
-
describe "##authentic?" do
let(:example_payload) { webhook_example_event('click_with_signature') }
let(:expected_signature) { example_payload['headers']['X-Mandrill-Signature'] }
let(:original_url) { example_payload['original_url'] }
let(:webhook_key) { example_payload['private_key'] }
let(:mandrill_webhook_keys) { [webhook_key] }
let(:params) { example_payload['raw_params'] }
subject { processor_class.authentic?(expected_signature, mandrill_webhook_keys, original_url, params) }
context "when valid" do
- it { should eql(true) }
+ it "passes" do
+ expect(subject).to eql(true)
+ end
end
context "when no keys" do
let(:mandrill_webhook_keys) { [] }
- it { should eql(true) }
+ it "passes" do
+ expect(subject).to eql(true)
+ end
end
context "when keys don't match" do
let(:mandrill_webhook_keys) { ['bogative'] }
- it { should eql(false) }
+ it "fails" do
+ expect(subject).to eql(false)
+ end
end
context "when signature don't match" do
let(:expected_signature) { 'bogative' }
- it { should eql(false) }
+ it "fails" do
+ expect(subject).to eql(false)
+ end
end
end