aboutsummaryrefslogtreecommitdiffstats
path: root/lib/json.h
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2015-10-27 02:36:34 -0300
committerdequis <dx@dxzone.com.ar>2015-10-30 07:31:09 -0300
commit0edc2fb9f963a735cbd02d944bc3f5dd0f0768bf (patch)
tree59c804519eeec895b74ca4a62df6a7d7c82d16ad /lib/json.h
parent884577f0bc3ceedebb68f3df1c5b60a131b5baa8 (diff)
log: Refactor log_link() to be less redundant.
"I didn't feel like messing with pointer to function pointers", said the comment. Well, I do, comment. It wasn't a big deal either.
Diffstat (limited to 'lib/json.h')
0 files changed, 0 insertions, 0 deletions
'>62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
use strict;
use warnings;

use Test::More;

use FixMyStreet;
use FixMyStreet::DB;
use FixMyStreet::SendReport::Email;
use FixMyStreet::TestMech;
use mySociety::Locale;

ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );

my $e = FixMyStreet::SendReport::Email->new();

# area id 1000
my $params = { id => 1000, name => 'Council of the Thousand' };
my $body = FixMyStreet::DB->resultset('Body')->find_or_create($params);
ok $body, "found/created body";

my $contact = $mech->create_contact_ok(
    email => 'council@example.com',
    body_id => 1000,
    category => 'category',
    note => '',
);

my $row = FixMyStreet::DB->resultset('Problem')->new( {
    bodies_str => '1000',
    category => 'category',
    cobrand => '',
} );

ok $e;

foreach my $test ( {
        desc => 'no councils added means no receipients',
        count => 0,
        add_council => 0,
    },
    {
        desc => 'adding a council results in receipients',
        count => 1,
        add_council => 1,
    },
    {
        desc => 'unconfirmed contact results in no receipients',
        count => 0,
        add_council => 1,
        unconfirmed => 1,
        expected_note => 'Body 1000 deleted',
    },
    {
        desc => 'unconfirmed contact note uses note from contact table',
        count => 0,
        add_council => 1,
        unconfirmed => 1,
        note => 'received bounced so unconfirmed',
        expected_note => 'received bounced so unconfirmed',
    },
) {
    subtest $test->{desc} => sub {
        my $e = FixMyStreet::SendReport::Email->new;
        $contact->update( { confirmed => 0 } ) if $test->{unconfirmed};
        $contact->update( { note => $test->{note} } ) if $test->{note};
        $e->add_body( $body ) if $test->{add_council};
        is $e->build_recipient_list( $row, {} ), $test->{count}, 'correct recipient list count';

        if ( $test->{unconfirmed} ) {
            is_deeply $e->unconfirmed_counts, { 'council@example.com' => { 'category' => 1 } }, 'correct unconfirmed_counts count';
            is_deeply $e->unconfirmed_notes, { 'council@example.com' => { 'category' => $test->{expected_note} } }, 'correct note used';
        }
    };
}

done_testing();

END {
    $mech->delete_body($body);
}