aboutsummaryrefslogtreecommitdiff
path: root/t/tests/sietima/role/subscriberonly/moderate.t
blob: b76a01abdc0c77c1962afeffa47889ef6d7ad11e (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
80
#!perl 
use strict;
use warnings;
use 5.024;
use lib 't/lib';
use Test::Sietima;
use Test::Sietima::MailStore;
 
my @subscriber_addresses = (
    'one@users.example.com',
    'two@users.example.com',
);
my $admin = 'admin@lists.example.com';
my $ms = Test::Sietima::MailStore->new();
my $s = make_sietima(
    with_traits => ['SubscriberOnly::Moderate'],
    subscribers => \@subscriber_addresses,
    admin => $admin,
    mail_store => $ms,
);
 
subtest 'from subscriber' => sub {
    $ms->clear;
    test_sending(
        sietima => $s,
        mail => { from=>'one@users.example.com' },
    );
    is(
        $ms->retrieve_by_tags('moderation'),
        [],
        'no mails held for moderation',
    );
};
 
subtest 'from non-subscriber' => sub {
    $ms->clear;
    test_sending(
        sietima => $s,
        mail => { from=>'someone@users.example.com' },
        mails => [{
            => object {
                call [header_str => 'subject'] => match qr{\bheld for moderation\b};
                call_list parts => [
                    object {
                        call body => match qr{Use id \S+ to refer to it};
                    },
                    object {
                        call sub {Email::MIME->new(shift->body)} => object {
                            call [header_str => 'subject'] => 'Test Message';
                        };
                    },
                ];
            },
            to => [$admin],
        }],
    );
 
    is(
        my $to_moderate = $ms->retrieve_by_tags('moderation'),
        [
            {
                id => T(),
                mail => object {
                    call [header_str => 'from'] => 'someone@users.example.com';
                    call [header_str => 'to'] => $s->return_path->address,
                },
            },
        ],
        'mails was held for moderation',
    );
 
    transport->clear_deliveries;
    my $msg_id = $to_moderate->[0]->{id};
    $s->resume($msg_id);
    deliveries_are(
        to => \@subscriber_addresses,
    );
};
 
done_testing;