aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-06-10 13:13:24 +0100
committerdakkar <dakkar@thenautilus.net>2016-06-10 13:13:24 +0100
commitbbc8e2aaab621464c0530d613b18cb5ee8c13290 (patch)
treefa2e3a58292d198c22865d1fdf6b396b6ac47acb /t
parentsome skeleton (diff)
downloadSietima-bbc8e2aaab621464c0530d613b18cb5ee8c13290.tar.gz
Sietima-bbc8e2aaab621464c0530d613b18cb5ee8c13290.tar.bz2
Sietima-bbc8e2aaab621464c0530d613b18cb5ee8c13290.zip
passes its first test!
Diffstat (limited to 't')
-rw-r--r--t/tests/sietima.t76
1 files changed, 71 insertions, 5 deletions
diff --git a/t/tests/sietima.t b/t/tests/sietima.t
index 217c06d..b0367b6 100644
--- a/t/tests/sietima.t
+++ b/t/tests/sietima.t
@@ -2,12 +2,78 @@
use strict;
use warnings;
use 5.020;
-use Test::Most;
+use Test2::Bundle::Extended;
+use Test2::Plugin::DieOnFail;
+use Email::Stuffer;
+use Email::Sender::Transport::Test;
+use Data::Printer;
use Sietima;
-ok(
- my $s=Sietima->new,
- 'should instantiate',
-);
+my $return_path = 'sietima-test@list.example.com',
+my $transport = Email::Sender::Transport::Test->new;
+sub make_sietima {
+ $transport->clear_deliveries;
+ Sietima->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;
+}
+
+ok(make_sietima(),'should instantiate') or bail_out;
+
+subtest 'no subscribers' => sub {
+ my $s = make_sietima();
+ my $m = make_mail();
+
+ ok(
+ lives { $s->handle_mail($m) },
+ 'should handle the mail',
+ $@,
+ );
+
+ my @deliveries = $transport->deliveries;
+ is(
+ \@deliveries,
+ [],
+ 'nothing should be delivered',
+ np @deliveries,
+ );
+};
+
+subtest 'with subscribers' => sub {
+ my $s = make_sietima(
+ subscribers => [
+ 'one@users.example.com',
+ 'two@users.example.com',
+ ],
+ );
+ my $m = make_mail();
+
+ ok(
+ lives { $s->handle_mail($m) },
+ 'should handle the mail',
+ $@,
+ );
+
+ my @deliveries = $transport->deliveries;
+ is(
+ \@deliveries,
+ array {
+ # we'd need a 'bag' comparison check here!
+ },
+ 'there should be two deliveries',
+ np @deliveries,
+ );
+};
done_testing;