mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Start making better-written tests for the email job
This commit is contained in:
parent
d87edce6c3
commit
d7df4e5979
5 changed files with 99 additions and 4 deletions
5
spec/fixtures/emails/valid_incoming.cooked
vendored
Normal file
5
spec/fixtures/emails/valid_incoming.cooked
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
<p>Hey folks,</p>
|
||||
|
||||
<p>I was thinking. Wouldn't it be great if we could post topics via email? Yes it would!</p>
|
||||
|
||||
<p>Jakie</p>
|
4
spec/fixtures/emails/valid_incoming.eml
vendored
4
spec/fixtures/emails/valid_incoming.eml
vendored
|
@ -4,8 +4,8 @@ Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b
|
|||
Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <TO>; Thu, 13 Jun 2013 14:03:48 -0700
|
||||
Received: by 10.0.0.1 with HTTP; Thu, 13 Jun 2013 14:03:48 -0700
|
||||
Date: Thu, 13 Jun 2013 17:03:48 -0400
|
||||
From: Jake the Dog <FROM>
|
||||
To: <TO>
|
||||
From: Jake the Dog <jake@email.example.com>
|
||||
To: Foo Discourse <incoming+amazing@discourse.example.com>
|
||||
Message-ID: <CADkmRc+rNGAGGbV2iE5p918UVy4UyJqVcXRO2=otppgzduJSg@mail.gmail.com>
|
||||
Subject: We should have a post-by-email-feature.
|
||||
Mime-Version: 1.0
|
||||
|
|
3
spec/fixtures/emails/valid_reply.cooked
vendored
Normal file
3
spec/fixtures/emails/valid_reply.cooked
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<p>I could not disagree more. I am obviously biased but adventure time is the greatest show ever created. Everyone should watch it.</p>
|
||||
|
||||
<p>- Jake out</p>
|
4
spec/fixtures/emails/valid_reply.eml
vendored
4
spec/fixtures/emails/valid_reply.eml
vendored
|
@ -4,8 +4,8 @@ Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b
|
|||
Received: by mail-ie0-f180.google.com with SMTP id f4so21977375iea.25 for <reply+59d8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo>; Thu, 13 Jun 2013 14:03:48 -0700
|
||||
Received: by 10.0.0.1 with HTTP; Thu, 13 Jun 2013 14:03:48 -0700
|
||||
Date: Thu, 13 Jun 2013 17:03:48 -0400
|
||||
From: Jake the Dog <jake@adventuretime.ooo>
|
||||
To: reply+59d8df8370b7e95c5a49fbf86aeb2c93@appmail.adventuretime.ooo
|
||||
From: Jake the Dog <jake@email.example.com>
|
||||
To: reply+59d8df8370b7e95c5a49fbf86aeb2c93@discourse.example.com
|
||||
Message-ID: <CADkmRc+rNGAGGbV2iE5p918UVy4UyJqVcXRO2=otppgzduJSg@mail.gmail.com>
|
||||
Subject: re: [Discourse Meta] eviltrout posted in 'Adventure Time Sux'
|
||||
Mime-Version: 1.0
|
||||
|
|
|
@ -41,6 +41,93 @@ describe Jobs::PollMailbox do
|
|||
|
||||
end
|
||||
|
||||
# Testing mock for the email objects that you get
|
||||
# from Net::POP3.start { |pop| pop.mails }
|
||||
class MockPop3EmailObject
|
||||
def initialize(mail_string)
|
||||
@message = mail_string
|
||||
@delete_called = 0
|
||||
end
|
||||
|
||||
def pop
|
||||
@message
|
||||
end
|
||||
|
||||
def delete
|
||||
@delete_called += 1
|
||||
end
|
||||
|
||||
# call 'assert email.deleted?' at the end of the test
|
||||
def deleted?
|
||||
@delete_called == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "processing email B" do
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
SiteSetting.email_in = true
|
||||
SiteSetting.reply_by_email_address = 'reply+%{reply_key}@discourse.example.com'
|
||||
category.email_in = 'incoming+amazing@discourse.example.com'
|
||||
category.save
|
||||
user.change_trust_level! :regular
|
||||
user.username = 'Jake'
|
||||
user.email = 'jake@email.example.com'
|
||||
user.save
|
||||
end
|
||||
|
||||
describe "valid incoming email" do
|
||||
let(:email) { MockPop3EmailObject.new fixture_file('emails/valid_incoming.eml')}
|
||||
let(:expected_post) { fixture_file('emails/valid_incoming.cooked') }
|
||||
|
||||
it "posts a new topic with the correct content" do
|
||||
|
||||
poller.handle_mail(email)
|
||||
|
||||
topic = Topic.where(category: category).where.not(id: category.topic_id).first
|
||||
assert topic.present?
|
||||
post = topic.posts.first
|
||||
assert_equal expected_post.strip, post.cooked.strip
|
||||
|
||||
assert email.deleted?
|
||||
end
|
||||
end
|
||||
|
||||
describe "valid reply" do
|
||||
let(:email) { MockPop3EmailObject.new fixture_file('emails/valid_reply.eml')}
|
||||
let(:expected_post) { fixture_file('emails/valid_reply.cooked')}
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:first_post) { Fabricate(:post, topic: topic, post_number: 1)}
|
||||
|
||||
before do
|
||||
first_post.save
|
||||
EmailLog.create(to_address: 'jake@email.example.com',
|
||||
email_type: 'user_posted',
|
||||
reply_key: '59d8df8370b7e95c5a49fbf86aeb2c93',
|
||||
post: first_post,
|
||||
topic: topic)
|
||||
end
|
||||
|
||||
pending "creates a new post with the correct content" do
|
||||
RejectionMailer.expects(:send_rejection).never
|
||||
Discourse.expects(:handle_exception).never
|
||||
|
||||
poller.handle_mail(email)
|
||||
|
||||
new_post = Post.where(topic: topic, post_number: 2)
|
||||
assert new_post.present?
|
||||
|
||||
assert_equal expected_post.strip, new_post.cooked.strip
|
||||
|
||||
assert email.deleted?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe "processing email" do
|
||||
|
||||
let!(:receiver) { mock }
|
||||
|
|
Loading…
Reference in a new issue