aboutsummaryrefslogtreecommitdiff
path: root/t/tests/sietima/role/subscriberonly/moderate.t
blob: 6564b13d6938792e078089dd1615e35204869f08 (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
81
82
83
84
85
86
87
88
89
90
91
92
#!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' },
        to => [$admin],
    );
 
 
    my @deliveries = transport->deliveries;
    is(
        \@deliveries,
        [
            hash {
                field email => object {
                    call [cast=>'Email::MIME'] => 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';
                                };
                            },
                        ];
                    };
                };
            },
        ],
        'the original mail should be attached',
        np @deliveries,
    );
 
    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;