aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
Diffstat (limited to 't/app')
-rw-r--r--t/app/controller/alert_new.t5
-rw-r--r--t/app/controller/report_new.t129
2 files changed, 131 insertions, 3 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 4e8fd1b29..27371e4a9 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -451,9 +451,8 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
is $count, 5, 'Three emails, with five matching lines in them';
my $email = $emails[0];
- my $body = $mech->get_text_body_from_email($email);
- like $body, qr/Other User/, 'Update name given';
- unlike $body, qr/Anonymous User/, 'Update name not given';
+ is +(my $c = () = $email->as_string =~ /Other User/g), 2, 'Update name given, twice';
+ unlike $email->as_string, qr/Anonymous User/, 'Update name not given';
# The update alert was to the problem reporter, so has a special update URL
$mech->log_out_ok;
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 32d86d803..0e7547a85 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -86,6 +86,16 @@ my $contact8 = $mech->create_contact_ok(
category => 'Street lighting',
email => 'highways@example.com'
);
+my $contact9 = $mech->create_contact_ok(
+ body_id => $body_ids{2226}, # Gloucestershire
+ category => 'Street lighting',
+ email => 'streetlights-2226@example.com',
+);
+my $contact10 = $mech->create_contact_ok(
+ body_id => $body_ids{2326}, # Cheltenham
+ category => 'Street lighting',
+ email => 'streetlights-2326@example.com',
+);
# test that the various bit of form get filled in and errors correctly
# generated.
@@ -932,6 +942,125 @@ foreach my $test (
}
+# XXX add test for category with multiple bodies
+foreach my $test (
+ {
+ desc => "test report creation for multiple bodies",
+ category => 'Street lighting',
+ councils => [ 2226, 2326 ],
+ extra_fields => {},
+ email_count => 2,
+ },
+ {
+ desc => "test single_body_only means only one report body",
+ category => 'Street lighting',
+ councils => [ 2326 ],
+ extra_fields => { single_body_only => 'Cheltenham Borough Council' },
+ email_count => 1,
+ },
+ {
+ desc => "test invalid single_body_only means multiple report bodies",
+ category => 'Street lighting',
+ councils => [ 2226, 2326 ],
+ extra_fields => { single_body_only => 'Invalid council' },
+ email_count => 1,
+ },
+) {
+ subtest $test->{desc} => sub {
+
+ # check that the user does not exist
+ my $test_email = 'test-2@example.com';
+
+ $mech->clear_emails_ok;
+ my $user = $mech->log_in_ok($test_email);
+
+ # setup the user.
+ ok $user->update(
+ {
+ name => 'Test User',
+ phone => '01234 567 890',
+ }
+ ),
+ "set users details";
+
+ # submit initial pc form
+ $mech->get_ok('/around');
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, },
+ "follow 'skip this step' link" );
+
+ # check that the fields are correctly prefilled
+ is_deeply(
+ $mech->visible_form_values,
+ {
+ title => '',
+ detail => '',
+ may_show_name => '1',
+ name => 'Test User',
+ phone => '01234 567 890',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
+ category => '-- Pick a category --',
+ },
+ "user's details prefilled"
+ );
+
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ title => "Test Report at café",
+ detail => 'Test report details.',
+ photo1 => '',
+ name => 'Joe Bloggs',
+ may_show_name => '1',
+ phone => '07903 123 456',
+ category => $test->{category},
+ %{$test->{extra_fields}}
+ }
+ },
+ "submit good details"
+ );
+ };
+
+ # find the report
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+
+ # Check the report has been assigned appropriately
+ is $report->bodies_str, join(',', @body_ids{@{$test->{councils}}});
+
+ $mech->content_contains('Thank you for reporting this issue');
+
+ # check that no emails have been sent
+ $mech->email_count_is(0);
+
+ # check report is confirmed and available
+ is $report->state, 'confirmed', "report is now confirmed";
+ $mech->get_ok( '/report/' . $report->id );
+
+ # Test that AJAX pages return the right data
+ $mech->get_ok(
+ '/around?ajax=1&bbox=' . ($report->longitude - 0.01) . ',' . ($report->latitude - 0.01)
+ . ',' . ($report->longitude + 0.01) . ',' . ($report->latitude + 0.01)
+ );
+ $mech->content_contains( "Test Report at caf\xc3\xa9" );
+ $saved_lat = $report->latitude;
+ $saved_lon = $report->longitude;
+
+ # cleanup
+ $mech->delete_user($user);
+ };
+
+}
+
subtest "Test inactive categories" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],