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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1);
$mech->log_in_ok( $superuser->email );
my $body = $mech->create_body_ok(2650, 'Aberdeen City Council');
# This override is wrapped around ALL the /admin/body tests
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
MAPIT_TYPES => [ 'UTA' ],
BASE_URL => 'http://www.example.org',
}, sub {
$mech->get_ok('/admin/body/' . $body->id);
$mech->content_contains('Aberdeen City Council');
$mech->content_like(qr{AB\d\d});
$mech->content_contains("http://www.example.org/around");
subtest 'check contact creation' => sub {
$mech->get_ok('/admin/body/' . $body->id);
$mech->submit_form_ok( { with_fields => {
category => 'test category',
email => 'test@example.com',
note => 'test note',
non_public => undef,
state => 'unconfirmed',
} } );
$mech->content_contains( 'test category' );
$mech->content_contains( 'test@example.com' );
$mech->content_contains( '<td>test note' );
$mech->content_like( qr/<td>\s*unconfirmed\s*<\/td>/ ); # No private
$mech->submit_form_ok( { with_fields => {
category => 'private category',
email => 'test@example.com',
note => 'test note',
non_public => 'on',
} } );
$mech->content_contains( 'private category' );
$mech->content_like( qr{test\@example.com\s*</td>\s*<td>\s*confirmed\s*<br>\s*<small>\s*Private\s*</small>\s*</td>} );
$mech->submit_form_ok( { with_fields => {
category => 'test/category',
email => 'test@example.com',
note => 'test/note',
non_public => 'on',
} } );
$mech->get_ok('/admin/body/' . $body->id . '/test/category');
$mech->content_contains('test/category');
};
subtest 'check contact editing' => sub {
$mech->get_ok('/admin/body/' . $body->id .'/test%20category');
$mech->content_lacks( 'group</strong> is used for the top-level category' );
$mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
note => 'test2 note',
non_public => undef,
} } );
$mech->content_contains( 'test category' );
$mech->content_like( qr{test2\@example.com\s*</td>\s*<td>\s*unconfirmed\s*</td>} );
$mech->content_contains( '<td>test2 note' );
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->submit_form_ok( { with_fields => {
email => 'test2@example.com, test3@example.com',
note => 'test3 note',
} } );
$mech->content_contains( 'test2@example.com,test3@example.com' );
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_contains( '<td><strong>test2@example.com,test3@example.com' );
$mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
note => 'test2 note',
non_public => 'on',
} } );
$mech->content_like( qr{test2\@example.com\s*</td>\s*<td>\s*unconfirmed\s*<br>\s*<small>\s*Private\s*</small>\s*</td>} );
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_contains( '<td><strong>test2@example.com' );
};
subtest 'check contact renaming' => sub {
my ($report) = $mech->create_problems_for_body(1, $body->id, 'Title', { category => 'test category' });
$mech->get_ok('/admin/body/' . $body->id .'/test%20category');
$mech->submit_form_ok( { with_fields => { category => 'private category' } } );
$mech->content_contains('You cannot rename');
$mech->submit_form_ok( { with_fields => { category => 'testing category' } } );
$mech->content_contains( 'testing category' );
$mech->get('/admin/body/' . $body->id . '/test%20category');
is $mech->res->code, 404;
$mech->get_ok('/admin/body/' . $body->id . '/testing%20category');
$report->discard_changes;
is $report->category, 'testing category';
$mech->submit_form_ok( { with_fields => { category => 'test category' } } );
};
subtest 'check contact updating' => sub {
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_like(qr{test2\@example.com</strong>[^<]*</td>[^<]*<td>unconfirmed}s);
$mech->get_ok('/admin/body/' . $body->id);
$mech->form_number( 1 );
$mech->tick( 'confirmed', 'test category' );
$mech->submit_form_ok({form_number => 1});
$mech->content_like(qr'test2@example.com</td>[^<]*<td>\s*confirmed's);
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_like(qr{test2\@example.com[^<]*</td>[^<]*<td><strong>confirmed}s);
};
$body->update({ send_method => undef });
subtest 'check open311 configuring' => sub {
$mech->get_ok('/admin/body/' . $body->id);
$mech->content_lacks('Council contacts configured via Open311');
$mech->form_number(3);
$mech->submit_form_ok(
{
with_fields => {
api_key => 'api key',
endpoint => 'http://example.com/open311',
jurisdiction => 'mySociety',
send_comments => 0,
send_method => 'Open311',
}
}
);
$mech->content_contains('Council contacts configured via Open311');
$mech->content_contains('Values updated');
my $conf = FixMyStreet::DB->resultset('Body')->find( $body->id );
is $conf->endpoint, 'http://example.com/open311', 'endpoint configured';
is $conf->api_key, 'api key', 'api key configured';
is $conf->jurisdiction, 'mySociety', 'jurisdiction configures';
$mech->form_number(3);
$mech->submit_form_ok(
{
with_fields => {
api_key => 'new api key',
endpoint => 'http://example.org/open311',
jurisdiction => 'open311',
send_comments => 0,
send_method => 'Open311',
}
}
);
$mech->content_contains('Values updated');
$conf = FixMyStreet::DB->resultset('Body')->find( $body->id );
is $conf->endpoint, 'http://example.org/open311', 'endpoint updated';
is $conf->api_key, 'new api key', 'api key updated';
is $conf->jurisdiction, 'open311', 'jurisdiction configures';
ok !$conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems unset';
$mech->form_number(3);
$mech->submit_form_ok(
{
with_fields => {
api_key => 'new api key',
endpoint => 'http://example.org/open311',
jurisdiction => 'open311',
send_comments => 0,
send_method => 'Open311',
'extra[fetch_all_problems]' => 1,
}
}
);
$mech->content_contains('Values updated');
$conf = FixMyStreet::DB->resultset('Body')->find( $body->id );
ok $conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems set';
$mech->form_number(3);
$mech->submit_form_ok(
{
with_fields => {
api_key => 'new api key',
endpoint => 'http://example.org/open311',
jurisdiction => 'open311',
send_comments => 0,
send_method => 'Open311',
'extra[fetch_all_problems]' => 0,
can_be_devolved => 1, # for next test
}
}
);
$mech->content_contains('Values updated');
$conf = FixMyStreet::DB->resultset('Body')->find( $body->id );
ok !$conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems unset';
};
subtest 'check open311 devolved editing' => sub {
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->submit_form_ok( { with_fields => {
send_method => 'Email',
email => 'testing@example.org',
note => 'Updating contact to email',
} } );
$mech->content_contains('Values updated');
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->submit_form_ok( { with_fields => {
send_method => '',
email => 'open311-code',
note => 'Removing email send method',
} } );
$mech->content_contains('Values updated');
};
subtest 'check text output' => sub {
$mech->get_ok('/admin/body/' . $body->id . '?text=1');
is $mech->content_type, 'text/plain';
$mech->content_contains('test category');
$mech->content_lacks('<body');
};
subtest 'disable form message editing' => sub {
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->submit_form_ok( { with_fields => {
disable => 1,
disable_message => 'Please ring us!',
note => 'Adding emergency message',
} } );
$mech->content_contains('Values updated');
my $contact = $body->contacts->find({ category => 'test category' });
is_deeply $contact->get_extra_fields, [{
description => 'Please ring us!',
code => '_fms_disable_',
protected => 'true',
variable => 'false',
disable_form => 'true',
}], 'right message added';
};
}; # END of override wrap
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
MAPIT_TYPES => [ 'UTA' ],
BASE_URL => 'http://www.example.org',
COBRAND_FEATURES => {
category_groups => { default => 1 },
}
}, sub {
subtest 'group editing works' => sub {
$mech->get_ok('/admin/body/' . $body->id);
$mech->content_contains('Parent categories');
$mech->submit_form_ok( { with_fields => {
category => 'grouped category',
email => 'test@example.com',
note => 'test note',
group => 'group a',
non_public => undef,
state => 'unconfirmed',
} } );
my $contact = $body->contacts->find({ category => 'grouped category' });
is_deeply $contact->get_extra_metadata('group'), ['group a'], "group stored correctly";
};
subtest 'group can be unset' => sub {
$mech->get_ok('/admin/body/' . $body->id);
$mech->content_contains('Parent categories');
$mech->submit_form_ok( { with_fields => {
category => 'grouped category',
email => 'test@example.com',
note => 'test note',
group => undef,
non_public => undef,
state => 'unconfirmed',
} } );
my $contact = $body->contacts->find({ category => 'grouped category' });
is $contact->get_extra_metadata('group'), undef, "group unset correctly";
};
};
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
MAPIT_TYPES => [ 'UTA' ],
BASE_URL => 'http://www.example.org',
COBRAND_FEATURES => {
category_groups => { default => 1 },
}
}, sub {
subtest 'multi group editing works' => sub {
$mech->get_ok('/admin/body/' . $body->id);
$mech->content_contains('Parent categories');
# have to do this as a post as adding a second group requires
# javascript
$mech->post_ok( '/admin/body/' . $body->id, {
posted => 'new',
token => $mech->form_id('category_edit')->value('token'),
category => 'grouped category',
email => 'test@example.com',
note => 'test note',
'group' => [ 'group a', 'group b'],
non_public => undef,
state => 'unconfirmed',
} );
my $contact = $body->contacts->find({ category => 'grouped category' });
is_deeply $contact->get_extra_metadata('group'), ['group a', 'group b'], "group stored correctly";
};
};
subtest 'check log of the above' => sub {
$mech->get_ok('/admin/users/' . $superuser->id . '/log');
$mech->content_contains('Added category <a href="/admin/body/' . $body->id . '/test/category">test/category</a>');
$mech->content_contains('Edited category <a href="/admin/body/' . $body->id . '/test category">test category</a>');
$mech->content_contains('Edited body <a href="/admin/body/' . $body->id . '">Aberdeen City Council</a>');
};
done_testing();
|