FEATURE: mailjet webhook

This commit is contained in:
Régis Hanol
2016-06-06 19:47:45 +02:00
parent 1e2bad135f
commit fe595f1653
4 changed files with 62 additions and 10 deletions

View File

@ -1,11 +1,10 @@
require "rails_helper"
describe WebhooksController do
before { $redis.flushall }
let(:email) { "em@il.com" }
before { $redis.del("bounce_score:#{email}:#{Date.today}") }
context "mailgun" do
it "works" do
@ -16,7 +15,6 @@ describe WebhooksController do
email_log = Fabricate(:email_log, user: user, bounce_key: SecureRandom.hex)
return_path = "foo+verp-#{email_log.bounce_key}@bar.com"
$redis.del("mailgun_token_#{token}")
WebhooksController.any_instance.expects(:mailgun_verify).returns(true)
post :mailgun, "token" => token,
@ -41,11 +39,10 @@ describe WebhooksController do
post :sendgrid, "_json" => [
{
"email" => email,
"timestamp" => 1249948800,
"smtp-id" => "<12345@il.com>",
"event" => "bounce",
"status" => "5.0.0"
"email" => email,
"smtp-id" => "<12345@il.com>",
"event" => "bounce",
"status" => "5.0.0"
}
]
@ -58,4 +55,26 @@ describe WebhooksController do
end
context "mailjet" do
it "works" do
message_id = "12345@il.com"
user = Fabricate(:user, email: email)
email_log = Fabricate(:email_log, user: user, message_id: message_id)
post :mailjet, {
"event" => "bounce",
"hard_bounce" => true,
"CustomID" => message_id
}
expect(response).to be_success
email_log.reload
expect(email_log.bounced).to eq(true)
expect(email_log.user.user_stat.bounce_score).to eq(2)
end
end
end