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

use strict;
use warnings;

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

use Test::More tests => 4;

use Email::Send::Test;

use_ok 'FixMyStreet::App';
my $c = FixMyStreet::App->new;

# fake up the request a little
$c->req->uri( URI->new('http://localhost/') );
$c->req->base( $c->req->uri );


# 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', { 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";

is $emails[0]->as_string, << 'END_OF_BODY', "email is as expected";
Subject: test email
From: evdb@ecclestoad.co.uk
To: test@recipient.com

Hello,

This is a test email where foo: bar.

Yours,
  FixMyStreet.
END_OF_BODY