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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
use Test::MockModule;
use CGI::Simple;
use FixMyStreet::TestMech;
use FixMyStreet::Script::Alerts;
use FixMyStreet::Script::Reports;
use Open311;
my $mech = FixMyStreet::TestMech->new;
my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council');
my $counciluser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $oxon);
subtest 'check /around?ajax defaults to open reports only' => sub {
my $categories = [ 'Bridges', 'Fences', 'Manhole' ];
my $params = {
postcode => 'OX28 4DS',
cobrand => 'oxfordshire',
latitude => 51.784721,
longitude => -1.494453,
};
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, $oxon->id, 'Around page', \%report_params );
}
}
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'oxfordshire',
}, sub {
my $json = $mech->get_ok_json( '/around?ajax=1&status=all&bbox=' . $bbox );
my $pins = $json->{pins};
is scalar @$pins, 6, 'correct number of reports created';
$json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox );
$pins = $json->{pins};
is scalar @$pins, 3, 'correct number of reports returned with no filters';
$json = $mech->get_ok_json( '/around?ajax=1&filter_category=Fences&bbox=' . $bbox );
$pins = $json->{pins};
is scalar @$pins, 1, 'only one Fences report by default';
}
};
my @problems = FixMyStreet::DB->resultset('Problem')->search({}, { rows => 3, order_by => 'id' })->all;
FixMyStreet::override_config {
STAGING_FLAGS => { send_reports => 1, skip_checks => 1 },
ALLOWED_COBRANDS => 'oxfordshire',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
subtest 'can use customer reference to search for reports' => sub {
my $problem = $problems[0];
$problem->set_extra_metadata( customer_reference => 'ENQ12456' );
$problem->update;
$mech->get_ok('/around?pc=ENQ12456');
is $mech->uri->path, '/report/' . $problem->id, 'redirects to report';
};
my $user = $mech->create_user_ok( 'user@example.com', name => 'Test User' );
my $user2 = $mech->create_user_ok( 'user2@example.com', name => 'Test User2' );
subtest 'check unable to fix label' => sub {
my $problem = $problems[0];
$problem->state( 'unable to fix' );
$problem->update;
my $alert = FixMyStreet::DB->resultset('Alert')->create( {
parameter => $problem->id,
alert_type => 'new_updates',
cobrand => 'oxfordshire',
user => $user,
} )->confirm;
FixMyStreet::DB->resultset('Comment')->create( {
problem_state => 'unable to fix',
problem_id => $problem->id,
user_id => $user2->id,
name => 'User',
mark_fixed => 'f',
text => "this is an update",
state => 'confirmed',
confirmed => 'now()',
anonymous => 'f',
} );
$mech->get_ok('/report/' . $problem->id);
$mech->content_contains('Investigation complete');
FixMyStreet::Script::Alerts::send();
$mech->email_count_is(1);
my $email = $mech->get_email;
my $body = $mech->get_text_body_from_email($email);
like $body, qr/Investigation complete/, 'state correct in email';
};
subtest 'extra CSV columns are present' => sub {
$problems[1]->update({ external_id => $problems[1]->id });
$problems[2]->update({ external_id => "123098123" });
$mech->log_in_ok( $counciluser->email );
$mech->get_ok('/dashboard?export=1');
my @rows = $mech->content_as_csv;
is scalar @rows, 7, '1 (header) + 6 (reports) = 7 lines';
is scalar @{$rows[0]}, 21, '21 columns present';
is_deeply $rows[0],
[
'Report ID', 'Title', 'Detail', 'User Name', 'Category',
'Created', 'Confirmed', 'Acknowledged', 'Fixed', 'Closed',
'Status', 'Latitude', 'Longitude', 'Query', 'Ward',
'Easting', 'Northing', 'Report URL', 'Site Used',
'Reported As', 'HIAMS/Exor Ref',
],
'Column headers look correct';
is $rows[1]->[20], 'ENQ12456', 'HIAMS reference included in row';
is $rows[2]->[20], '', 'Report without HIAMS ref has empty ref field';
is $rows[3]->[20], '123098123', 'Older Exor report has correct ref';
};
$oxon->update({
send_method => 'Open311',
endpoint => 'endpoint',
api_key => 'key',
jurisdiction => 'home',
});
my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Gullies and Catchpits', email => 'GC' );
$contact->set_extra_fields( (
{ code => 'feature_id', datatype => 'hidden', variable => 'true' },
{ code => 'usrn', datatype => 'hidden', variable => 'true' },
) );
$contact->update;
FixMyStreet::Script::Reports::send(); # Make sure no waiting reports
for my $test (
{
field => 'feature_id',
value => '12345',
text => 'Asset Id',
},
) {
subtest 'Check special Open311 request handling of ' . $test->{text}, sub {
my ($p) = $mech->create_problems_for_body( 1, $oxon->id, 'Test', {
cobrand => 'oxfordshire',
category => 'Gullies and Catchpits',
user => $user,
latitude => 51.754926,
longitude => -1.256179,
});
$p->set_extra_fields({ name => $test->{field}, value => $test->{value}});
$p->update;
my $test_data = FixMyStreet::Script::Reports::send();
$p->discard_changes;
ok $p->whensent, 'Report marked as sent';
is $p->send_method_used, 'Open311', 'Report sent via Open311';
is $p->external_id, 248, 'Report has right external ID';
unlike $p->detail, qr/$test->{text}:/, $test->{text} . ' not saved to report detail';
my $req = $test_data->{test_req_used};
my $c = CGI::Simple->new($req->content);
like $c->param('description'), qr/$test->{text}: $test->{value}/, $test->{text} . ' included in body';
};
}
subtest 'extra data sent with defect update' => sub {
my $comment = FixMyStreet::DB->resultset('Comment')->first;
$comment->set_extra_metadata(defect_raised => 1);
$comment->update;
$comment->problem->external_id('hey');
$comment->problem->set_extra_metadata(defect_location_description => 'Location');
$comment->problem->set_extra_metadata(defect_item_category => 'Kerbing');
$comment->problem->set_extra_metadata(defect_item_type => 'Damaged');
$comment->problem->set_extra_metadata(defect_item_detail => '1 kerb unit or 1 linear m');
$comment->problem->set_extra_metadata(traffic_information => 'Signs and Cones');
$comment->problem->set_extra_metadata(detailed_information => '100x100');
$comment->problem->update;
my $cbr = Test::MockModule->new('FixMyStreet::Cobrand::Oxfordshire');
$cbr->mock('_fetch_features', sub {
my ($self, $cfg, $x, $y) = @_;
[ {
type => 'Feature',
geometry => { type => 'LineString', coordinates => [ [ 1, 2 ], [ 3, 4 ] ] },
properties => { TYPE1_2_USRN => 13579 },
} ];
});
my $test_res = HTTP::Response->new();
$test_res->code(200);
$test_res->message('OK');
$test_res->content('<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>');
my $o = Open311->new(
fixmystreet_body => $oxon,
test_mode => 1,
test_get_returns => { 'servicerequestupdates.xml' => $test_res },
);
$o->post_service_request_update($comment);
my $cgi = CGI::Simple->new($o->test_req_used->content);
is $cgi->param('attribute[usrn]'), 13579, 'USRN sent with update';
is $cgi->param('attribute[raise_defect]'), 1, 'Defect flag sent with update';
is $cgi->param('attribute[defect_item_category]'), 'Kerbing';
is $cgi->param('attribute[extra_details]'), $user2->email . ' TM1 Damaged 100x100';
# Now set a USRN on the problem (found at submission)
$comment->problem->push_extra_fields({ name => 'usrn', value => '12345' });
$comment->problem->update;
$o->post_service_request_update($comment);
$cgi = CGI::Simple->new($o->test_req_used->content);
is $cgi->param('attribute[usrn]'), 12345, 'USRN sent with update';
is $cgi->param('attribute[raise_defect]'), 1, 'Defect flag sent with update';
};
};
done_testing();
|