discourse/spec/controllers/webhooks_controller_spec.rb

141 lines
3.4 KiB
Ruby
Raw Normal View History

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