Commit e9467011 authored by Michał "rysiek" Woźniak's avatar Michał "rysiek" Woźniak 🔒

added two tests for deliver_selfsent

parent a5dbb04c
Pipeline #31520 failed with stages
in 10 minutes and 9 seconds
......@@ -742,5 +742,57 @@ describe Schleuder::List do
teardown_list_and_mailer(list)
end
it "sends the message to all subscribers including the sender, if deliver_selfsent is true" do
list = create(:list, send_encrypted_only: false, deliver_selfsent: true)
sub, msgs = list.subscribe("admin@example.org", nil, true)
sub, msgs = list.subscribe("user1@example.org")
sub, msgs = list.subscribe("user2@example.org")
mail = Mail.new
mail.to = list.email
mail.from = 'user1@example.org'
mail.subject = 'Something'
mail.body = "Some content"
Schleuder::Runner.new().run(mail, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(messages.size).to be(3)
expect(recipients).to eql(['admin@example.org', 'user1@example.org', 'user2@example.org'])
expect(messages[0].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[0].subject).to eql("Something")
expect(messages[1].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[1].subject).to eql("Something")
expect(messages[2].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[2].subject).to eql("Something")
teardown_list_and_mailer(list)
end
it "sends the message to all subscribers but not the sender, if deliver_selfsent is false" do
list = create(:list, send_encrypted_only: false, deliver_selfsent: false)
sub, msgs = list.subscribe("admin@example.org", nil, true)
sub, msgs = list.subscribe("user1@example.org")
sub, msgs = list.subscribe("user2@example.org")
mail = Mail.new
mail.to = list.email
mail.from = 'user1@example.org'
mail.subject = 'Something'
mail.body = "Some content"
Schleuder::Runner.new().run(mail, list.email)
messages = Mail::TestMailer.deliveries
recipients = messages.map { |m| m.to.first }.sort
expect(messages.size).to be(2)
expect(recipients).to eql(['admin@example.org', 'user2@example.org'])
expect(messages[0].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[0].subject).to eql("Something")
expect(messages[1].parts.first.parts.last.body.to_s).to eql("Some content")
expect(messages[1].subject).to eql("Something")
teardown_list_and_mailer(list)
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment