aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-06-16 17:29:48 +0100
committerdakkar <dakkar@thenautilus.net>2016-06-16 18:03:06 +0100
commit437d3a4eba02ef4dcafe062510cf2f428bbaa1db (patch)
tree15806b5298a81574e0e4caed6d589aa0b99b2008 /t
parenttest Subscriber (diff)
downloadSietima-437d3a4eba02ef4dcafe062510cf2f428bbaa1db.tar.gz
Sietima-437d3a4eba02ef4dcafe062510cf2f428bbaa1db.tar.bz2
Sietima-437d3a4eba02ef4dcafe062510cf2f428bbaa1db.zip
role: drop mail from non-subscribers
Diffstat (limited to 't')
-rw-r--r--t/tests/sietima/role/subscriberonly/drop.t94
1 files changed, 94 insertions, 0 deletions
diff --git a/t/tests/sietima/role/subscriberonly/drop.t b/t/tests/sietima/role/subscriberonly/drop.t
new file mode 100644
index 0000000..886acce
--- /dev/null
+++ b/t/tests/sietima/role/subscriberonly/drop.t
@@ -0,0 +1,94 @@
+#!perl
+use strict;
+use warnings;
+use 5.020;
+use lib 't/lib';
+use Test2::Bundle::Extended;
+use Test2::Tools::MoreCompare qw(bag);
+use Test2::Plugin::DieOnFail;
+use Email::Stuffer;
+use Email::Sender::Transport::Test;
+use Data::Printer;
+use Sietima;
+
+my $return_path = 'sietima-test@list.example.com';
+my $transport = Email::Sender::Transport::Test->new;
+sub make_sietima {
+ $transport->clear_deliveries;
+ Sietima
+ ->with_traits('SubscriberOnly::Drop')
+ ->new({
+ return_path => $return_path,
+ transport => $transport,
+ @_,
+ });
+}
+
+sub make_mail {
+ my (%args) = @_;
+ Email::Stuffer
+ ->from($args{from}||'someone@users.example.com')
+ ->to($args{no}||$return_path)
+ ->text_body($args{body}||'some simple message')
+ ->email;
+}
+
+my @subscriber_addresses = (
+ 'one@users.example.com',
+ 'two@users.example.com',
+);
+my $s = make_sietima(
+ subscribers => [@subscriber_addresses],
+);
+
+subtest 'from subscriber' => sub {
+ $transport->clear_deliveries;
+ my $m = make_mail(from=>'one@users.example.com');
+
+ ok(
+ lives { $s->handle_mail($m) },
+ 'should handle the mail',
+ $@,
+ );
+
+ my @deliveries = $transport->deliveries;
+ is(
+ \@deliveries,
+ array {
+ item hash {
+ field envelope => hash {
+ field from => $return_path;
+ field to => bag {
+ for (@subscriber_addresses) {
+ item object { call address => $_ };
+ }
+ };
+ };
+ };
+ end();
+ },
+ 'there should be two deliveries',
+ np @deliveries,
+ );
+};
+
+subtest 'from non-subscriber' => sub {
+ $transport->clear_deliveries;
+ my $m = make_mail(from=>'someone@users.example.com');
+
+ ok(
+ lives { $s->handle_mail($m) },
+ 'should handle the mail',
+ $@,
+ );
+
+ my @deliveries = $transport->deliveries;
+ is(
+ \@deliveries,
+ [],
+ 'there should be no deliveries',
+ np @deliveries,
+ );
+};
+
+done_testing;