#!/usr/bin/env perl
use
lib
"$Bin/../../../../lib"
;
use_ok(
'Mail::Alias::LocalFile'
);
subtest
'Empty processed_aliases HashRef'
=>
sub
{
my
$aliases
= {
'test1'
=>
'test1@example.com'
,
'test2'
=>
'test2@example.com'
,
};
my
$resolver
= Mail::Alias::LocalFile->new(
aliases
=>
$aliases
);
is_deeply(
$resolver
->processed_aliases, {},
'processed_aliases starts empty'
);
my
$result
=
$resolver
->resolve_recipients([
'direct1@example.com'
,
'direct2@example.com'
]);
is_deeply(
$result
->{processed_aliases}, {},
'processed_aliases remains empty when only direct emails are given'
);
$resolver
= Mail::Alias::LocalFile->new(
aliases
=>
$aliases
);
$result
=
$resolver
->resolve_recipients([]);
is_deeply(
$result
->{processed_aliases}, {},
'processed_aliases remains empty when no recipients are provided'
);
$resolver
= Mail::Alias::LocalFile->new(
aliases
=>
$aliases
);
$result
=
$resolver
->resolve_recipients([
'nonexistent1'
,
'nonexistent2'
]);
is_deeply(
$result
->{processed_aliases}, {},
'processed_aliases remains empty when only non-existent aliases are given'
);
$resolver
= Mail::Alias::LocalFile->new(
aliases
=>
$aliases
);
$result
=
$resolver
->resolve_recipients([
'mta_alias1'
,
'mta_alias2'
]);
is_deeply(
$result
->{processed_aliases}, {},
'processed_aliases remains empty when only MTA aliases are given'
);
$resolver
= Mail::Alias::LocalFile->new(
aliases
=>
$aliases
);
$resolver
->extract_addresses_from_list(
'direct@example.com'
);
is_deeply(
$resolver
->processed_aliases, {},
'processed_aliases remains empty after extract_addresses_from_list with direct email'
);
};
subtest
'Tracking processed aliases'
=>
sub
{
my
$aliases
= {
'simple'
=>
'test@example.com'
,
};
my
$resolver
= Mail::Alias::LocalFile->new(
aliases
=>
$aliases
);
is_deeply(
$resolver
->processed_aliases, {},
'processed_aliases starts empty'
);
my
$result
=
$resolver
->resolve_recipients([
'simple'
]);
isnt(
scalar
(
keys
%{
$result
->{processed_aliases}}), 0,
'processed_aliases populated after processing a real alias'
);
ok(
exists
$result
->{processed_aliases}{
'simple'
},
'The alias was properly tracked in processed_aliases'
);
};
subtest
'Edge Cases'
=>
sub
{
my
$resolver
= Mail::Alias::LocalFile->new(
aliases
=> {});
is_deeply(
$resolver
->processed_aliases, {},
'processed_aliases starts empty with empty aliases'
);
my
$result
=
$resolver
->resolve_recipients([]);
is_deeply(
$result
->{processed_aliases}, {},
'processed_aliases remains empty with empty input and empty aliases'
);
$result
=
$resolver
->resolve_recipients([
'test@example.com'
]);
is_deeply(
$result
->{processed_aliases}, {},
'processed_aliases remains empty with direct email and empty aliases'
);
$result
=
$resolver
->resolve_recipients([
undef
,
''
, 0]);
is_deeply(
$result
->{processed_aliases}, {},
'processed_aliases remains empty with nil/undefined values'
);
};
done_testing();