aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand/get_body_sender.t
blob: 245cb1a138409e68e949dec1e6ac1f7ae7e5eded (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
use strict;
use warnings;

use Test::More;

use mySociety::Locale;
use FixMyStreet::App;

use_ok 'FixMyStreet::Cobrand';

mySociety::Locale::gettext_domain( 'FixMyStreet' );

my $c = FixMyStreet::Cobrand::FixMyStreet->new();

FixMyStreet::App->model('DB::BodyArea')->search( { body_id => 1000 } )->delete;
FixMyStreet::App->model('DB::Body')->search( { name => 'Body of a Thousand' } )->delete;

my $body = FixMyStreet::App->model('DB::Body')->find_or_create({
    id => 1000,
    name => 'Body of a Thousand',
});
my $body_area = $body->body_areas->find_or_create({ area_id => 1000 });

is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email';

$body_area->update({ area_id => 2481 }); # Croydon LBO
is_deeply $c->get_body_sender( $body ), { method => 'London' }, 'returns london report it if London borough';

$body->send_method( 'TestMethod' );
is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to London';

$body_area->update({ area_id => 1000 }); # Nothing
is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to Email';

$body_area->delete;
$body->delete;

done_testing();