aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
Diffstat (limited to 't/app')
-rw-r--r--t/app/controller/alert_new.t3
-rw-r--r--t/app/controller/auth.t12
-rw-r--r--t/app/controller/report_new.t50
-rw-r--r--t/app/controller/rss.t125
-rw-r--r--t/app/model/alert_type.t209
5 files changed, 392 insertions, 7 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 580a5ad9a..950666d2d 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -452,8 +452,9 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
$count++ if $_->body =~ /The following updates have been left on this problem:/;
$count++ if $_->body =~ /The following new problems have been reported to City of\s*Edinburgh Council:/;
$count++ if $_->body =~ /The following nearby problems have been added:/;
+ $count++ if $_->body =~ / - Testing, EH1 1BB/;
}
- is $count, 3, 'Three emails with the right things in them';
+ is $count, 5, 'Five emails with the right things in them';
my $email = $emails[0];
like $email->body, qr/Other User/, 'Update name given';
diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t
index fef45ac90..efc5e60e6 100644
--- a/t/app/controller/auth.t
+++ b/t/app/controller/auth.t
@@ -24,16 +24,16 @@ $mech->not_logged_in_ok;
$mech->get_ok('/auth');
for my $test (
- [ '' => 'enter your email' ],
- [ 'not an email' => 'check your email address is correct' ],
- [ 'bob@foo' => 'check your email address is correct' ],
- [ 'bob@foonaoedudnueu.co.uk' => 'check your email address is correct' ],
+ [ '' => 'Please enter your email' ],
+ [ 'not an email' => 'Please check your email address is correct' ],
+ [ 'bob@foo' => 'Please check your email address is correct' ],
+ [ 'bob@foonaoedudnueu.co.uk' => 'Please check your email address is correct' ],
)
{
my ( $email, $error_message ) = @$test;
pass "--- testing bad email '$email' gives error '$error_message'";
$mech->get_ok('/auth');
- $mech->content_lacks($error_message);
+ is_deeply $mech->form_errors, [], 'no errors initially';
$mech->submit_form_ok(
{
form_name => 'general_auth',
@@ -43,7 +43,7 @@ for my $test (
"try to create an account with email '$email'"
);
is $mech->uri->path, '/auth', "still on auth page";
- $mech->content_contains($error_message);
+ is_deeply $mech->form_errors, [ $error_message ], 'no errors initially';
}
# create a new account
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 9ec8fa4a8..15237e041 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -1,4 +1,5 @@
use strict;
+use utf8; # sign in error message has – in it
use warnings;
use Test::More;
use utf8;
@@ -428,6 +429,55 @@ foreach my $test (
};
}
+# this test to make sure that we don't see spurious error messages about
+# the name being blank when there is a sign in error
+subtest "test password errors for a user who is signing in as they report" => sub {
+ $mech->log_out_ok;
+ $mech->clear_emails_ok;
+
+ # check that the user does not exist
+ my $test_email = 'test-2@example.com';
+
+ my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => $test_email } );
+ ok $user, "test user does exist";
+
+ # setup the user.
+ ok $user->update( {
+ name => 'Joe Bloggs',
+ phone => '01234 567 890',
+ password => 'secret2',
+ } ), "set user details";
+
+ # submit initial pc form
+ $mech->get_ok('/around');
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } },
+ "submit location" );
+
+ # click through to the report page
+ $mech->follow_link_ok( { text => 'skip this step', },
+ "follow 'skip this step' link" );
+
+ $mech->submit_form_ok(
+ {
+ button => 'submit_sign_in',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ photo => '',
+ email => 'test-2@example.com',
+ password_sign_in => 'secret1',
+ category => 'Street lighting',
+ }
+ },
+ "submit with wrong password"
+ );
+
+ # check that we got the errors expected
+ is_deeply $mech->form_errors, [
+ 'There was a problem with your email/password combination. Passwords and user accounts are a brand new service, so you probably do not have one yet – please fill in the right hand side of this form to get one.'
+ ], "check there were errors";
+};
+
subtest "test report creation for a user who is signing in as they report" => sub {
$mech->log_out_ok;
$mech->clear_emails_ok;
diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t
new file mode 100644
index 000000000..c6ab20574
--- /dev/null
+++ b/t/app/controller/rss.t
@@ -0,0 +1,125 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $dt = DateTime->new(
+ year => 2011,
+ month => 10,
+ day => 10
+);
+
+my $user1 = FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } );
+
+my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
+ postcode => 'eh1 1BB',
+ council => '2651',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user1->name,
+ anonymous => 0,
+ state => 'confirmed',
+ confirmed => $dt,
+ lastupdate => $dt,
+ whensent => $dt->clone->add( minutes => 5 ),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user1->id,
+} );
+
+
+$mech->get_ok("/rss/pc/EH11BB/2");
+$mech->content_contains( "Testing, 10th October, EH1 1BB" );
+$mech->content_lacks( 'Nearest road to the pin' );
+
+$report->geocode(
+{
+ 'traceId' => 'ae7c4880b70b423ebc8ab4d80961b3e9|LTSM001158|02.00.71.1600|LTSMSNVM002010, LTSMSNVM001477',
+ 'statusDescription' => 'OK',
+ 'brandLogoUri' => 'http://dev.virtualearth.net/Branding/logo_powered_by.png',
+ 'resourceSets' => [
+ {
+ 'resources' => [
+ {
+ 'geocodePoints' => [
+ {
+ 'calculationMethod' => 'Interpolation',
+ 'coordinates' => [
+ '55.9532357007265',
+ '-3.18906001746655'
+ ],
+ 'usageTypes' => [
+ 'Display',
+ 'Route'
+ ],
+ 'type' => 'Point'
+ }
+ ],
+ 'entityType' => 'Address',
+ 'name' => '18 N Bridge, Edinburgh EH1 1',
+ 'point' => {
+ 'coordinates' => [
+ '55.9532357007265',
+ '-3.18906001746655'
+ ],
+ 'type' => 'Point'
+ },
+ 'bbox' => [
+ '55.9493729831558',
+ '-3.19825819222605',
+ '55.9570984182972',
+ '-3.17986184270704'
+ ],
+ 'matchCodes' => [
+ 'Good'
+ ],
+ 'address' => {
+ 'countryRegion' => 'United Kingdom',
+ 'adminDistrict2' => 'Edinburgh City',
+ 'adminDistrict' => 'Scotland',
+ 'addressLine' => '18 North Bridge',
+ 'formattedAddress' => '18 N Bridge, Edinburgh EH1 1',
+ 'postalCode' => 'EH1 1',
+ 'locality' => 'Edinburgh'
+ },
+ 'confidence' => 'Medium',
+ '__type' => 'Location:http://schemas.microsoft.com/search/local/ws/rest/v1'
+ }
+ ],
+ 'estimatedTotal' => 1
+ }
+ ],
+ 'copyright' => "Copyright \x{a9} 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
+ 'statusCode' => 200,
+ 'authenticationResultCode' => 'ValidCredentials'
+ }
+);
+$report->postcode('eh11bb');
+$report->update();
+
+$mech->get_ok("/rss/pc/EH11BB/2");
+$mech->content_contains( "Testing, 10th October, EH1 1BB" );
+$mech->content_contains( '18 North Bridge, Edinburgh' );
+
+$report->postcode('Princes St, Edinburgh');
+$report->update();
+
+$mech->get_ok("/rss/pc/EH11BB/2");
+$mech->content_contains( "Testing, 10th October, Princes St, Edinburgh" );
+
+$report->delete();
+$user1->delete();
+
+done_testing();
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index c7bfe171c..1adc584d7 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -140,5 +140,214 @@ for my $test (
};
}
+my $now = DateTime->now();
+$report->confirmed( $now->ymd . ' ' . $now->hms );
+$report->update();
+
+my $council_alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
+ {
+ user => $user2,
+ parameter => 2504,
+ parameter2 => 2504,
+ alert_type => 'council_problems',
+ whensubscribed => $dt->ymd . ' ' . $dt->hms,
+ confirmed => 1,
+ }
+);
+
+for my $test (
+ {
+ postcode => 'SW1A 1AA',
+ expected_postcode => 'SW1A 1AA',
+ },
+ {
+ postcode => 'sw1a 1AA',
+ expected_postcode => 'SW1A 1AA',
+ },
+ {
+ postcode => 'SW1A 1aa',
+ expected_postcode => 'SW1A 1AA',
+ },
+ {
+ postcode => 'SW1A1AA',
+ expected_postcode => 'SW1A 1AA',
+ },
+ {
+ postcode => 'Buckingham Gate',
+ expected_postcode => 'Buckingham Gate',
+ },
+ {
+ postcode => 'Buckingham gate',
+ expected_postcode => 'Buckingham gate',
+ },
+) {
+ subtest "correct text for postcode $test->{postcode}" => sub {
+ $mech->clear_emails_ok;
+
+ my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
+ {
+ alert_id => $council_alert->id,
+ parameter => $report->id,
+ }
+ )->delete;
+
+ $report->postcode( $test->{postcode} );
+ $report->update;
+
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+
+ $mech->email_count_is( 1 );
+ my $email = $mech->get_email;
+ my $pc = $test->{expected_postcode};
+ my $title = $report->title;
+ my $body = $email->body;
+
+ like $body, qr#report/$report_id - $title, $pc#, 'email contains expected postcode';
+ };
+}
+
+$report->postcode( 'SW1A 1AA' );
+$report->update;
+
+$report->geocode(
+{
+ 'traceId' => 'ae7c4880b70b423ebc8ab4d80961b3e9|LTSM001158|02.00.71.1600|LTSMSNVM002010, LTSMSNVM001477',
+ 'statusDescription' => 'OK',
+ 'brandLogoUri' => 'http://dev.virtualearth.net/Branding/logo_powered_by.png',
+ 'resourceSets' => [
+ {
+ 'resources' => [
+ {
+ 'geocodePoints' => [
+ {
+ 'calculationMethod' => 'Interpolation',
+ 'coordinates' => [
+ '55.9532357007265',
+ '-3.18906001746655'
+ ],
+ 'usageTypes' => [
+ 'Display',
+ 'Route'
+ ],
+ 'type' => 'Point'
+ }
+ ],
+ 'entityType' => 'Address',
+ 'name' => '18 N Bridge, Edinburgh EH1 1',
+ 'point' => {
+ 'coordinates' => [
+ '55.9532357007265',
+ '-3.18906001746655'
+ ],
+ 'type' => 'Point'
+ },
+ 'bbox' => [
+ '55.9493729831558',
+ '-3.19825819222605',
+ '55.9570984182972',
+ '-3.17986184270704'
+ ],
+ 'matchCodes' => [
+ 'Good'
+ ],
+ 'address' => {
+ 'countryRegion' => 'United Kingdom',
+ 'adminDistrict2' => 'Edinburgh City',
+ 'adminDistrict' => 'Scotland',
+ 'addressLine' => '18 North Bridge',
+ 'formattedAddress' => '18 N Bridge, Edinburgh EH1 1',
+ 'postalCode' => 'EH1 1',
+ 'locality' => 'Edinburgh'
+ },
+ 'confidence' => 'Medium',
+ '__type' => 'Location:http://schemas.microsoft.com/search/local/ws/rest/v1'
+ }
+ ],
+ 'estimatedTotal' => 1
+ }
+ ],
+ 'copyright' => "Copyright \x{a9} 2011 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
+ 'statusCode' => 200,
+ 'authenticationResultCode' => 'ValidCredentials'
+ }
+);
+$report->update();
+
+foreach my $test (
+ {
+ desc => 'all fields',
+ addressLine => '18 North Bridge',
+ locality => 'Edinburgh',
+ nearest => qr/18 North Bridge, Edinburgh/,
+ },
+ {
+ desc => 'address with Street only',
+ addressLine => 'Street',
+ locality => 'Edinburgh',
+ nearest => qr/: Edinburgh/,
+ },
+ {
+ desc => 'locality only',
+ addressLine => undef,
+ locality => 'Edinburgh',
+ nearest => qr/: Edinburgh/,
+ },
+ {
+ desc => 'address only',
+ addressLine => '18 North Bridge',
+ locality => undef,
+ nearest => qr/: 18 North Bridge\n/,
+ },
+ {
+ desc => 'no fields',
+ addressLine => undef,
+ locality => undef,
+ nearest => '',
+ },
+ {
+ desc => 'no address',
+ no_address => 1,
+ nearest => '',
+ },
+) {
+ subtest "correct Nearest Road text with $test->{desc}" => sub {
+ $mech->clear_emails_ok;
+
+ my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
+ {
+ alert_id => $council_alert->id,
+ parameter => $report->id,
+ }
+ )->delete;
+
+ my $g = $report->geocode;
+ if ( $test->{no_address} ) {
+ $g->{resourceSets}[0]{resources}[0]{address} = undef;
+ } else {
+ $g->{resourceSets}[0]{resources}[0]{address}->{addressLine} = $test->{addressLine};
+ $g->{resourceSets}[0]{resources}[0]{address}->{locality} = $test->{locality};
+ }
+
+ # if we don't do this then it ignores the change
+ $report->geocode( undef );
+ $report->geocode( $g );
+ $report->update();
+
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+
+ $mech->email_count_is( 1 );
+ my $email = $mech->get_email;
+ my $body = $email->body;
+
+ if ( $test->{nearest} ) {
+ like $body, $test->{nearest}, 'correct nearest line';
+ } else {
+ unlike $body, qr/Nearest Road/, 'no nearest line';
+ }
+ };
+}
+
+$report->comments->delete();
+$report->delete();
done_testing();