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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
use strict;
use warnings;
use Test::More;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
subtest "check that if no query we get sent back to the homepage" => sub {
$mech->get_ok('/around');
is $mech->uri->path, '/', "redirected to '/'";
};
# x,y requests were generated by the old map code. We keep the behavior for
# historic links
subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub {
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.mysociety.org/',
}, sub {
$mech->get_ok('/around?x=3281&y=1113');
};
# did we redirect to lat,lon?
is $mech->uri->path, '/around', "still on /around";
is_deeply { $mech->uri->query_form },
{ lat => 51.499825, lon => -0.140137, zoom => 3 },
"lat,lon correctly set";
# was it a 301?
is $mech->res->code, 200, "got 200 for final destination";
is $mech->res->previous->code, 301, "got 301 for redirect";
};
# test various locations on inital search box
foreach my $test (
{
pc => '', #
errors => [],
pc_alternatives => [],
},
{
pc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
errors => ['Sorry, we could not find that location.'],
pc_alternatives => [],
},
{
pc => 'Glenthorpe Ct, Katy, TX 77494, USA',
errors =>
['Sorry, we could not find that location.'],
pc_alternatives => [],
},
)
{
subtest "test bad pc value '$test->{pc}'" => sub {
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
"bad location" );
is_deeply $mech->page_errors, $test->{errors},
"expected errors for pc '$test->{pc}'";
is_deeply $mech->pc_alternatives, $test->{pc_alternatives},
"expected alternatives for pc '$test->{pc}'";
};
}
# check that exact queries result in the correct lat,lng
foreach my $test (
{
pc => 'SW1A 1AA',
latitude => '51.50101',
longitude => '-0.141587',
},
{
pc => 'TQ 388 773',
latitude => '51.478074',
longitude => '-0.001966',
},
)
{
subtest "check lat/lng for '$test->{pc}'" => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.mysociety.org/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
"good location" );
};
is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'";
is_deeply $mech->extract_location, $test,
"got expected location for pc '$test->{pc}'";
};
}
subtest 'check non public reports are not displayed on around page' => sub {
my $params = {
postcode => 'EH99 1SP',
latitude => 55.9519637512,
longitude => -3.17492254484,
};
my @edinburgh_problems =
$mech->create_problems_for_body( 5, 2651, 'Around page', $params );
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.mysociety.org/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } },
"good location" );
};
$mech->content_contains( 'Around page Test 3 for 2651',
'problem to be marked non public visible' );
my $private = $edinburgh_problems[2];
ok $private->update( { non_public => 1 } ), 'problem marked non public';
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } },
"good location" );
$mech->content_lacks( 'Around page Test 3 for 2651',
'problem marked non public is not visible' );
};
done_testing();
|