aboutsummaryrefslogtreecommitdiff
path: root/t/tests/sietima/role/headers.t
blob: 6dcfff340d09d0f1b0f130ba4275a881e1a9b69c (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
93
94
95
96
#!perl 
use lib 't/lib';
use Test::Sietima;
 
package Sietima::Role::ForTesting {
    use Moo::Role;
    use Sietima::Policy;
    use Sietima::Types qw(AddressFromStr);
 
    around list_addresses => sub($orig,$self) {
        return {
            $self->$orig->%*,
            test1 => AddressFromStr->coerce('name <someone@example.com>'),
            'test+2' => 'http://test.example.com',
            test3 => ['name (comment) <other@example.com>','mailto:thing@example.com' ],
        };
    };
};
 
package Sietima::Role::ForTesting2 {
    use Moo::Role;
    use Sietima::Policy;
    use Sietima::Types qw(AddressFromStr);
 
    around list_addresses => sub($orig,$self) {
        return {
            $self->$orig->%*,
            post => 0,
        };
    };
};
 
subtest 'list headers should be added' => sub {
    my $s = make_sietima(
        with_traits => ['Headers','WithOwner','ForTesting'],
        name => 'test-list',
        owner => 'owner@example.com',
        subscribers => [
            'one@users.example.com',
            'two@users.example.com',
        ],
    );
 
    test_sending(
        sietima => $s,
        mails => [
            object {
                call sub { +{ shift->header_raw_pairs } } => hash {
                    field 'List-Id' => 'test-list <sietima-test.list.example.com>';
                    field 'List-Owner' => '<mailto:owner@example.com>';
                    field 'List-Post' => '<mailto:sietima-test@list.example.com>';
                    field 'List-Test1' => '<mailto:someone@example.com>';
                    field 'List-Test-2' => '<http://test.example.com>';
                    field 'List-Test3' => '<mailto:other@example.com> (comment), <mailto:thing@example.com>';
 
                    field 'Date' => D();
                    field 'MIME-Version' => D();
                    field 'Content-Type' => D();
                    field 'Content-Transfer-Encoding' => D();
                    field 'From' => 'someone@users.example.com';
                    field 'To' => 'sietima-test@list.example.com';
                    field 'Subject' => 'Test Message';
 
                    end;
                };
            },
        ],
    );
};
 
subtest 'no-post list' => sub {
    my $s = make_sietima(
        with_traits => ['Headers','WithOwner','ForTesting2'],
        name => 'test-list',
        owner => 'owner@example.com',
        subscribers => [
            'one@users.example.com',
            'two@users.example.com',
        ],
    );
 
    test_sending(
        sietima => $s,
        mails => [
            object {
                call sub { +{ shift->header_raw_pairs } } => hash {
                    field 'List-Post' => 'NO';
 
                    etc;
                };
            },
        ],
    );
};
 
done_testing;