aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/alert.t
blob: 41aee5bbcf60bd39bcb628531fa7eafa9117770c (plain)
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
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;

use t::Mock::Nominatim;

# check that we can get the page
$mech->get_ok('/alert');
$mech->title_like(qr/^Local RSS feeds and email alerts/);
$mech->content_contains('Local RSS feeds and email alerts');
$mech->content_contains('html class="no-js" lang="en-gb"');

my $body = $mech->create_body_ok(2651, 'Edinburgh');
$mech->create_body_ok(2504, 'Birmingham City Council');
$mech->create_body_ok(2226, 'Gloucestershire County Council');
$mech->create_body_ok(2326, 'Cheltenham Borough Council');

# check that we can get list page
FixMyStreet::override_config {
    ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
    MAPIT_URL => 'http://mapit.uk/',
    GEOCODER => '',
}, sub {
    $mech->get_ok('/alert/list');
    $mech->title_like(qr/^Local RSS feeds and email alerts/);
    $mech->content_contains('Local RSS feeds and email alerts');
    $mech->content_contains('html class="no-js" lang="en-gb"');

    $mech->get_ok('/alert/list?pc=EH1 1BB');
    $mech->title_like(qr/^Local RSS feeds and email alerts/);
    $mech->content_like(qr/Local RSS feeds and email alerts for .EH1 1BB/);
    $mech->content_contains('html class="no-js" lang="en-gb"');
    $mech->content_contains('Problems within 10.0km');
    $mech->content_contains('rss/pc/EH11BB/2');
    $mech->content_contains('rss/pc/EH11BB/5');
    $mech->content_contains('rss/pc/EH11BB/10');
    $mech->content_contains('rss/pc/EH11BB/20');
    $mech->content_contains('Problems within Edinburgh City');
    $mech->content_contains('Problems within City Centre ward');
    $mech->content_contains('/rss/reports/Edinburgh');
    $mech->content_contains('/rss/reports/Edinburgh/City+Centre');
    $mech->content_contains('council:' . $body->id . ':Edinburgh');
    $mech->content_contains('ward:' . $body->id . ':20728:Edinburgh:City_Centre');

    subtest "Test Nominatim lookup" => sub {
        $mech->get_ok('/alert/list?pc=High Street');
        $mech->content_contains('We found more than one match for that location');
    };

    $mech->get_ok('/alert/list?pc=');
    $mech->content_contains('To find out what local alerts we have for you');

    # Two-tier council
    $mech->get_ok('/alert/list?pc=GL502PR');
    $mech->content_contains('Problems in an area');
    $mech->content_contains('Reports by destination');

    $mech->get_ok('/alert/subscribe?rss=1&type=local&pc=EH1+1BB&rss=Give+me+an+RSS+feed&rznvy=' );
    $mech->content_contains('Please select the feed you want');

    $mech->get_ok('/alert/subscribe?rss=1&feed=invalid:1000:A_Locationtype=local&pc=EH1+1BB&rss=Give+me+an+RSS+feed&rznvy=');
    $mech->content_contains('Illegal feed selection');

    $mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:Birmingham');
    is $mech->uri->path, '/rss/reports/Birmingham';

    $mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:1001:Cheltenham:Lansdown');
    is $mech->uri->path, '/rss/area/Cheltenham/Lansdown';

    $mech->get_ok('/alert/subscribe?rss=1&feed=council:1000:Gloucestershire');
    is $mech->uri->path, '/rss/reports/Gloucestershire';

    $mech->get_ok('/alert/subscribe?rss=1&feed=ward:1000:1001:Cheltenham:Lansdown');
    is $mech->uri->path, '/rss/reports/Cheltenham/Lansdown';
};

done_testing();
pan>->ymd . ' ' . $dt->hms, lang => 'en-gb', service => '', cobrand => 'default', cobrand_data => '', send_questionnaire => 't', latitude => '51.5016605453401', longitude => '-0.142497580865087', user_id => $user->id, } ); my $report_id = $report->id; ok $report, "created test report - $report_id"; my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( { problem_id => $report_id, user_id => $user2->id, name => 'Other User', mark_fixed => 'false', text => 'This is some update text', state => 'confirmed', confirmed => $dt->ymd . ' ' . $dt->hms, anonymous => 'f', }); my $comment_id = $comment->id; ok $comment, "created test update - $comment_id"; for my $test ( { desc => 'Invalid phone', fields => { username => '01214960000000', update => 'Update', name => 'Name', photo1 => '', photo2 => '', photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, password_sign_in => '', password_register => '', }, changes => {}, field_errors => [ 'Please check your phone number is correct' ] }, { desc => 'landline number', fields => { username => '01214960000', update => 'Update', name => 'Name', photo1 => '', photo2 => '', photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, password_register => '', password_sign_in => '', }, changes => { username => '0121 496 0000', }, field_errors => [ 'Please enter a mobile number' ] }, ) { subtest "submit an update - $test->{desc}" => sub { $mech->get_ok("/report/$report_id"); FixMyStreet::override_config { SMS_AUTHENTICATION => 1, PHONE_COUNTRY => 'GB', }, sub { $mech->submit_form_ok( { with_fields => $test->{fields} }, 'submit update' ); }; is_deeply $mech->page_errors, $test->{field_errors}, 'field errors'; my $values = { %{ $test->{fields} }, %{ $test->{changes} }, }; is_deeply $mech->visible_form_values('updateForm'), $values, 'form changes'; }; } my $test_phone = '+61491570156'; for my $test ( { desc => 'submit an update, unregistered, logged out', form_values => { submit_update => 1, username => $test_phone, update => 'Update from an unregistered user', add_alert => undef, name => 'Unreg User', may_show_name => undef, }, }, { desc => 'submit an update, unregistered, logged out, sign up for alerts', form_values => { submit_update => 1, username => $test_phone, update => 'Update from an unregistered user', add_alert => 1, name => 'Unreg User', may_show_name => undef, }, }, { desc => 'submit an update, registered, logged out, confirming by text', registered => 1, form_values => { submit_update => 1, username => $test_phone, update => 'Update from a registered user', add_alert => undef, name => 'Reg User', password_register => 'new_secret', }, }, ) { subtest $test->{desc} => sub { $mech->log_out_ok(); my $user; if ($test->{registered}) { $user = $mech->create_user_ok( $test_phone ); $user->update( { name => 'Mr Reg', password => 'secret2' } ); } $mech->get_ok("/report/$report_id"); FixMyStreet::override_config { SMS_AUTHENTICATION => 1, TWILIO_ACCOUNT_SID => 'AC123', }, sub { $mech->submit_form_ok( { with_fields => $test->{form_values} }, 'submit update'); }; $mech->content_contains('Nearly done! Now check your phone'); if ($user) { $user->discard_changes; ok $user->check_password( 'secret2' ), 'password unchanged'; is $user->name, 'Mr Reg', 'name unchanged'; } my ($token) = $mech->content =~ /name="token" value="([^"]*)"/; $token = FixMyStreet::App->model('DB::Token')->find({ token => $token, scope => 'comment' }); ok $token, 'Token found in database'; my $update_id = $token->data->{id}; my $add_alerts = $token->data->{add_alert}; my $update = FixMyStreet::App->model('DB::Comment')->find( { id => $update_id } ); ok $update, 'found update in database'; is $update->state, 'unconfirmed', 'update unconfirmed'; my $details = $test->{form_values}; is $update->user->phone, $details->{username}, 'update phone'; is $update->user->phone_verified, 1; is $update->text, $details->{update}, 'update text'; is $add_alerts, $details->{add_alert} ? 1 : 0, 'do not sign up for alerts'; my $code = $twilio->get_text_code; $mech->submit_form_ok( { with_fields => { code => '00000' } }); $mech->content_contains('Try again'); $mech->submit_form_ok( { with_fields => { code => $code } }); $mech->content_contains("/report/$report_id#update_$update_id"); if ($user) { $user->discard_changes; ok $user->check_password( 'new_secret' ), 'password changed'; is $user->name, 'Reg User', 'name changed'; } else { $user = FixMyStreet::App->model( 'DB::User' )->find( { phone => $details->{username} } ); ok $user, 'found user'; } my $alert = FixMyStreet::App->model( 'DB::Alert' )->find( { user => $user, alert_type => 'new_updates', confirmed => 1, } ); ok $details->{add_alert} ? defined( $alert ) : !defined( $alert ), 'sign up for alerts'; $update->discard_changes; is $update->state, 'confirmed', 'update confirmed'; $mech->delete_user( $user ); }; } for my $test ( { desc => 'submit an update for a registered user, signing in with wrong password', form_values => { submit_update => 1, username => $test_phone, update => 'Update from a user', add_alert => undef, password_sign_in => 'secret', }, field_errors => [ "There was a problem with your login information. If you cannot remember your password, or do not have one, please fill in the \x{2018}No\x{2019} section of the form.", 'Please enter your name', # FIXME Not really necessary error ], }, { desc => 'submit an update for a registered user and sign in', form_values => { submit_update => 1, username => $test_phone, update => 'Update from a user', add_alert => undef, password_sign_in => 'secret2', }, message => 'You have successfully signed in; please check and confirm your details are accurate:', } ) { subtest $test->{desc} => sub { # Set things up my $user = $mech->create_user_ok( $test->{form_values}->{username} ); my $pw = 'secret2'; $user->update( { name => 'Mr Reg', password => $pw } ); $report->comments->delete; $mech->log_out_ok(); $mech->clear_emails_ok(); $mech->get_ok("/report/$report_id"); FixMyStreet::override_config { SMS_AUTHENTICATION => 1, }, sub { $mech->submit_form_ok( { button => 'submit_sign_in', with_fields => $test->{form_values} }, 'submit update' ); }; $mech->content_contains($test->{message}) if $test->{message}; is_deeply $mech->page_errors, $test->{field_errors}, 'check there were errors' if $test->{field_errors}; SKIP: { skip( "Incorrect password", 4 ) unless $test->{form_values}{password_sign_in} eq $pw; # Now submit with a name $mech->submit_form_ok( { with_fields => { name => 'Joe Bloggs', } }, "submit good details" ); $mech->content_contains('Thank you for updating this issue'); my $update = $report->comments->first; ok $update, 'found update'; is $update->text, $test->{form_values}->{update}, 'update text'; is $update->user->phone, $test->{form_values}->{username}, 'update user'; is $update->state, 'confirmed', 'update confirmed'; $mech->delete_user( $update->user ); } }; } done_testing();