diff options
Diffstat (limited to 't/tests/sietima.t')
-rw-r--r-- | t/tests/sietima.t | 76 |
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; |