aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/author-no-tabs.t2
-rw-r--r--t/tests/sietima/headeruri.t80
-rw-r--r--t/tests/sietima/role/headers.t60
-rw-r--r--t/tests/sietima/role/manualsubscription.t2
4 files changed, 133 insertions, 11 deletions
diff --git a/t/author-no-tabs.t b/t/author-no-tabs.t
index 3bac52a..169b4c9 100644
--- a/t/author-no-tabs.t
+++ b/t/author-no-tabs.t
@@ -17,6 +17,7 @@ use Test::NoTabs;
my @files = (
'lib/Sietima.pm',
'lib/Sietima/CmdLine.pm',
+ 'lib/Sietima/HeaderURI.pm',
'lib/Sietima/MailStore.pm',
'lib/Sietima/MailStore/FS.pm',
'lib/Sietima/Message.pm',
@@ -41,6 +42,7 @@ my @files = (
't/lib/Test/Sietima/MailStore.pm',
't/tests/sietima.t',
't/tests/sietima/cmdline.t',
+ 't/tests/sietima/headeruri.t',
't/tests/sietima/mailstore.t',
't/tests/sietima/message.t',
't/tests/sietima/multi-role/debounce-moderate.t',
diff --git a/t/tests/sietima/headeruri.t b/t/tests/sietima/headeruri.t
new file mode 100644
index 0000000..c158f3d
--- /dev/null
+++ b/t/tests/sietima/headeruri.t
@@ -0,0 +1,80 @@
+#!perl
+use lib 't/lib';
+use Test::Sietima;
+use Email::Address;
+use URI;
+use Sietima::HeaderURI;
+
+subtest 'new' => sub {
+ is(
+ Sietima::HeaderURI->new({
+ uri => 'http://foo/',
+ comment => 'a thing',
+ })->as_header_raw,
+ '<http://foo/> (a thing)',
+ 'normal constructor call',
+ );
+
+ is(
+ Sietima::HeaderURI->new(
+ '(comment) address@example.com',
+ )->as_header_raw,
+ '<mailto:address@example.com> (comment)',
+ 'string, address+comment',
+ );
+
+ is(
+ Sietima::HeaderURI->new(
+ 'http://some/url'
+ )->as_header_raw,
+ '<http://some/url>',
+ 'string, URI',
+ );
+
+ is(
+ Sietima::HeaderURI->new(
+ { scheme => 'https', host => 'foo', path => [1,2,3] }
+ )->as_header_raw,
+ '<https://foo/1/2/3>',
+ 'hashref, URI::FromHash',
+ );
+
+ is(
+ Sietima::HeaderURI->new(
+ URI->new('http://bar')
+ )->as_header_raw,
+ '<http://bar>',
+ 'URI object',
+ );
+
+ is(
+ Sietima::HeaderURI->new(
+ Email::Address->parse('(comment) address@example.com'),
+ )->as_header_raw,
+ '<mailto:address@example.com> (comment)',
+ 'Email::Address object',
+ );
+};
+
+
+subtest 'new_from_address' => sub {
+
+ is(
+ Sietima::HeaderURI->new_from_address(
+ '(comment) address@example.com',
+ )->as_header_raw,
+ '<mailto:address@example.com> (comment)',
+ 'string',
+ );
+
+ is(
+ Sietima::HeaderURI->new_from_address(
+ '(comment) address@example.com',
+ { subject => 'test me' },
+ )->as_header_raw,
+ '<mailto:address@example.com?subject=test+me> (comment)',
+ 'string and hashref',
+ );
+};
+
+done_testing;
diff --git a/t/tests/sietima/role/headers.t b/t/tests/sietima/role/headers.t
index 9f3e664..6dcfff3 100644
--- a/t/tests/sietima/role/headers.t
+++ b/t/tests/sietima/role/headers.t
@@ -12,31 +12,46 @@ package Sietima::Role::ForTesting {
$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' ],
};
};
};
-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',
- ],
-);
+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_str_pairs } } => hash {
+ 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();
@@ -53,4 +68,29 @@ subtest 'list headers should be added' => sub {
);
};
+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;
diff --git a/t/tests/sietima/role/manualsubscription.t b/t/tests/sietima/role/manualsubscription.t
index f99805d..ade2062 100644
--- a/t/tests/sietima/role/manualsubscription.t
+++ b/t/tests/sietima/role/manualsubscription.t
@@ -17,7 +17,7 @@ subtest '(un)sub headers should be added' => sub {
sietima => $s,
mails => [
object {
- call sub { +{ shift->header_str_pairs } } => hash {
+ call sub { +{ shift->header_raw_pairs } } => hash {
field 'List-Subscribe' => '<mailto:owner@example.com?subject=Please+add+me+to+test-list>';
field 'List-Unsubscribe' => '<mailto:owner@example.com?subject=Please+remove+me+from+test-list>';