forked from rafl/metabase-claimid
/
basic.t
59 lines (45 loc) · 1.93 KB
/
basic.t
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
use strict;
use warnings;
use Test::More;
use Test::Exception;
use Email::Sender::Transport::Test;
use FindBin;
use Metabase::ClaimID;
my $transport = Email::Sender::Transport::Test->new;
my $claimer = Metabase::ClaimID->new({
index_file => "$FindBin::Bin/share/data/test_index.json",
data_root => "$FindBin::Bin/share/data/test_ids",
kit_source => "$FindBin::Bin/../share/mkits/metabase_id.mkit",
transport => $transport,
sender_address => 'metabase-claimid@ata.local',
});
isa_ok($claimer, 'Metabase::ClaimID');
lives_ok(sub {
ok($claimer->resolve('rafl@debian.org'), 'resolving an existing entry');
}, 'no exception for existing entry');
throws_ok(sub {
$claimer->resolve('someone@nonexistanthost');
}, qr/No entry for someone\@nonexistanthost/);
throws_ok(sub {
$claimer->resolve('existingbut@missingfile.com');
}, qr/No metabase id for existingbut\@missingfile\.com/);
lives_ok(sub {
$claimer->send_id('rafl@debian.org');
}, 'sending out an id');
my @sent = $transport->deliveries;
is(scalar @sent, 1, 'one mail sent');
my $msg = $sent[0];
is_deeply($msg->{successes}, ['rafl@debian.org'], 'sent to the right recipient');
is($msg->{envelope}->{from}, 'metabase-claimid@ata.local', 'right sender address');
my $mail = $msg->{email}->cast('Email::MIME');
is($mail->header('To'), 'rafl@debian.org', 'right To header');
is($mail->header('From'), 'Metabase ID Claimer <metabase-claimid@ata.local>', 'right From header');
is($mail->header('Subject'), 'Metabase ID for rafl@debian.org', 'right Subject header');
my @parts = $mail->parts;
is(scalar @parts, 2, 'a body and an attachment');
my ($body, $attachment) = @parts;
is($body->content_type, 'text/plain', 'plaintext body');
like($body->body, qr/rafl\@debian\.org/, 'body mentions recipient');
like($attachment->content_type, qr{^application/json;}, 'json attachment');
is($attachment->body, "moo\n", 'attachment contains content of id file');
done_testing;