aboutsummaryrefslogtreecommitdiff
path: root/t/tests/sietima.t
blob: b0367b66eb2825497e117a1ae32b9b0f4272eb99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!perl 
use strict;
use warnings;
use 5.020;
use Test2::Bundle::Extended;
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->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;