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
|
use strict;
use warnings;
use Test::More;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
subtest 'check /ajax defaults to open reports only' => sub {
my $categories = [ 'Bridges', 'Fences', 'Manhole' ];
my $params = {
postcode => 'OX28 4DS',
latitude => 51.7847208192,
longitude => -1.49445264029,
};
my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01)
. ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01);
# Create one open and one fixed report in each category
foreach my $category ( @$categories ) {
foreach my $state ( 'confirmed', 'fixed' ) {
my %report_params = (
%$params,
category => $category,
state => $state,
);
$mech->create_problems_for_body( 1, 2237, 'Around page', \%report_params );
}
}
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'oxfordshire' => '.' } ],
MAPIT_URL => 'http://mapit.mysociety.org/',
}, sub {
my $json = $mech->get_ok_json( '/ajax?status=all&bbox=' . $bbox );
my $pins = $json->{pins};
is scalar @$pins, 6, 'correct number of reports created';
$json = $mech->get_ok_json( '/ajax?bbox=' . $bbox );
$pins = $json->{pins};
is scalar @$pins, 3, 'correct number of reports returned with no filters';
$json = $mech->get_ok_json( '/ajax?filter_category=Fences&bbox=' . $bbox );
$pins = $json->{pins};
is scalar @$pins, 1, 'only one Fences report by default';
}
};
# Clean up
$mech->delete_problems_for_body( 2237 );
done_testing();
|