2016-05-30 10:11:17 -05:00
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe WebhooksController do
|
2016-06-06 12:47:45 -05:00
|
|
|
before { $redis.flushall }
|
2016-05-30 10:11:17 -05:00
|
|
|
|
2016-06-01 14:48:06 -05:00
|
|
|
let(:email) { "em@il.com" }
|
2016-06-08 17:33:13 -05:00
|
|
|
let(:message_id) { "12345@il.com" }
|
2016-06-01 14:48:06 -05:00
|
|
|
|
|
|
|
context "mailgun" do
|
2016-05-30 10:11:17 -05:00
|
|
|
|
|
|
|
it "works" do
|
2016-06-06 18:55:24 -05:00
|
|
|
SiteSetting.mailgun_api_key = "key-8221462f0c915af3f6f2e2df7aa5a493"
|
2016-05-30 10:11:17 -05:00
|
|
|
|
2016-06-01 14:48:06 -05:00
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 12:06:35 -06:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-05-30 10:11:17 -05:00
|
|
|
|
|
|
|
WebhooksController.any_instance.expects(:mailgun_verify).returns(true)
|
|
|
|
|
2016-06-08 15:38:38 -05:00
|
|
|
post :mailgun, "token" => "705a8ccd2ce932be8e98c221fe701c1b4a0afcb8bbd57726de",
|
2016-05-30 10:11:17 -05:00
|
|
|
"timestamp" => Time.now.to_i,
|
|
|
|
"event" => "dropped",
|
2017-02-05 12:06:35 -06:00
|
|
|
"recipient" => email,
|
2016-06-08 17:33:13 -05:00
|
|
|
"Message-Id" => "<12345@il.com>"
|
2016-05-30 10:11:17 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-06-01 14:48:06 -05:00
|
|
|
context "sendgrid" do
|
|
|
|
|
|
|
|
it "works" do
|
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 12:06:35 -06:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-06-01 14:48:06 -05:00
|
|
|
|
|
|
|
post :sendgrid, "_json" => [
|
|
|
|
{
|
2016-06-06 12:47:45 -05:00
|
|
|
"email" => email,
|
|
|
|
"smtp-id" => "<12345@il.com>",
|
|
|
|
"event" => "bounce",
|
|
|
|
"status" => "5.0.0"
|
2016-06-01 14:48:06 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-06-06 12:47:45 -05:00
|
|
|
context "mailjet" do
|
|
|
|
|
|
|
|
it "works" do
|
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 12:06:35 -06:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-06-06 12:47:45 -05:00
|
|
|
|
|
|
|
post :mailjet, {
|
|
|
|
"event" => "bounce",
|
2017-02-05 12:06:35 -06:00
|
|
|
"email" => email,
|
2016-06-06 12:47:45 -05:00
|
|
|
"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
|
|
|
|
|
2016-06-13 05:31:01 -05:00
|
|
|
context "mandrill" do
|
|
|
|
|
|
|
|
it "works" do
|
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 12:06:35 -06:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-06-13 05:31:01 -05:00
|
|
|
|
|
|
|
post :mandrill, mandrill_events: [{
|
|
|
|
"event" => "hard_bounce",
|
|
|
|
"msg" => {
|
2017-02-05 12:06:35 -06:00
|
|
|
"email" => email,
|
2016-06-13 05:31:01 -05:00
|
|
|
"metadata" => {
|
|
|
|
"message_id" => 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
|
|
|
|
|
2016-09-27 00:13:34 -05:00
|
|
|
context "sparkpost" do
|
|
|
|
|
|
|
|
it "works" do
|
|
|
|
user = Fabricate(:user, email: email)
|
2017-02-05 12:06:35 -06:00
|
|
|
email_log = Fabricate(:email_log, user: user, message_id: message_id, to_address: email)
|
2016-09-27 00:13:34 -05:00
|
|
|
|
|
|
|
post :sparkpost, "_json" => [{
|
|
|
|
"msys" => {
|
|
|
|
"message_event" => {
|
|
|
|
"bounce_class" => 10,
|
2017-02-05 12:06:35 -06:00
|
|
|
"rcpt_to" => email,
|
2016-10-27 12:35:50 -05:00
|
|
|
"rcpt_meta" => {
|
|
|
|
"message_id" => message_id
|
|
|
|
}
|
2016-09-27 00:13:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-05-30 10:11:17 -05:00
|
|
|
end
|