aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/helpers/send_email.t
blob: 5ab84e017632df282776d5e62bb0e4fde6cae96e (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
#!/usr/bin/perl

use strict;
use warnings;
use utf8;

BEGIN {
    use FixMyStreet;
    FixMyStreet->test_mode(1);
}

use Test::More tests => 5;

use Email::Send::Test;
use Path::Class;

use_ok 'FixMyStreet::App';
my $c = FixMyStreet::App->new(
    {
        request => Catalyst::Request->new(
            {
                base => URI->new('http://fixmystreet.com/'),
                uri  => URI->new('http://fixmystreet.com/')
            }
        ),
    }
);
$c->setup_request();

# set some values in the stash
$c->stash->{foo} = 'bar';

# clear the email queue
Email::Send::Test->clear;

# send the test email
ok $c->send_email( 'test.txt', { to => 'test@recipient.com' } ),
  "sent an email";

# check it got templated and sent correctly
my @emails = Email::Send::Test->emails;
is scalar(@emails), 1, "caught one email";

# Get the email, check it has a date and then strip it out
my $email_as_string = $emails[0]->as_string;
ok $email_as_string =~ s{\s+Date:\s+\S.*?$}{}xms, "Found and stripped out date";

my $expected_email_content =   file(__FILE__)->dir->file('send_email_sample.txt')->slurp;
my $sender = '"' . FixMyStreet->config('CONTACT_NAME') . '" <' . FixMyStreet->config('CONTACT_EMAIL') . '>';
$expected_email_content =~ s{CONTACT_EMAIL}{$sender};

is $email_as_string,
$expected_email_content,
  "email is as expected";