aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/model
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-08-22 11:22:33 +0100
committerStruan Donald <struan@exo.org.uk>2011-08-22 11:22:33 +0100
commit44c31ab8efbd97086e17d26c819b1d5b4946ce43 (patch)
tree5a509a5006afd50f4c48f52fdf45ac9ac86ac054 /t/app/model
parentf93ff062c986847f97aef76673c2ca7742f1f125 (diff)
parenta9a4fed583d7467c9c1f1fa56d42bcb75b4b488c (diff)
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet into open311-consumer
Conflicts: t/app/model/problem.t templates/web/default/report/new/fill_in_details.html web/css/core.css
Diffstat (limited to 't/app/model')
-rw-r--r--t/app/model/alert_type.t144
-rw-r--r--t/app/model/problem.t88
-rw-r--r--t/app/model/questionnaire.t106
3 files changed, 338 insertions, 0 deletions
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
new file mode 100644
index 000000000..c7bfe171c
--- /dev/null
+++ b/t/app/model/alert_type.t
@@ -0,0 +1,144 @@
+use strict;
+use warnings;
+use Test::More;
+use FixMyStreet::TestMech;
+
+mySociety::Locale::gettext_domain( 'FixMyStreet' );
+
+my $mech = FixMyStreet::TestMech->new();
+
+# this is the easiest way to make sure we're not going
+# to get any emails sent by data kicking about in the database
+FixMyStreet::App->model('DB::AlertType')->email_alerts();
+$mech->clear_emails_ok;
+
+my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+ok $user, "created test user";
+
+my $user2 =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'commenter@example.com', name => 'Commenter' } );
+ok $user2, "created comment user";
+
+
+my $dt = DateTime->new(
+ year => 2011,
+ month => 04,
+ day => 16,
+ hour => 15,
+ minute => 47,
+ second => 23
+);
+
+my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'SW1A 1AA',
+ council => '2504',
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => 'Test 2',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $dt->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 $comment2 = 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 other update text',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ anonymous => 'f',
+ }
+);
+
+$comment->confirmed( \"ms_current_timestamp() - '3 days'::interval" );
+$comment->update;
+
+my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
+ {
+ user => $user,
+ parameter => $report_id,
+ alert_type => 'new_updates',
+ whensubscribed => $dt->ymd . ' ' . $dt->hms,
+ confirmed => 1,
+ }
+);
+
+for my $test (
+ {
+ state => 'closed',
+ msg => 'This report is currently marked as closed',
+ },
+ {
+ state => 'fixed',
+ msg => 'This report is currently marked as fixed',
+ },
+ {
+ state => 'confirmed',
+ msg => 'This report is currently marked as open',
+ },
+) {
+ subtest "correct summary for state of $test->{state}" => sub {
+ $mech->clear_emails_ok;
+
+ my $sent = FixMyStreet::App->model('DB::AlertSent')->search(
+ {
+ alert_id => $alert->id,
+ parameter => $comment->id,
+ }
+ )->delete;
+
+ $report->state( $test->{state} );
+ $report->update;
+
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+
+ $mech->email_count_is( 1 );
+ my $email = $mech->get_email;
+ my $msg = $test->{msg};
+ my $body = $email->body;
+
+ like $body, qr/$msg/, 'email says problem is ' . $test->{state};
+ like $body, qr{report/$report_id}, 'contains problem url';
+ like $body, qr/This is some update text/, 'contains update text';
+ unlike $body, qr/This is other update text/, 'does not contains other update text';
+
+ my $comments = $body =~ s/(------)//gs;
+ is $comments, 1, 'only 1 update';
+ };
+}
+
+done_testing();
+
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index ed5207c2b..ad42c5fdf 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -257,6 +257,94 @@ for my $test (
};
}
+for my $test (
+ {
+ state => 'partial',
+ is_visible => 0,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'hidden',
+ is_visible => 0,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'unconfirmed',
+ is_visible => 0,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'confirmed',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
+ state => 'investigating',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
+ state => 'planned',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
+ state => 'in progress',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
+ state => 'fixed',
+ is_visible => 1,
+ is_fixed => 1,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'fixed - council',
+ is_visible => 1,
+ is_fixed => 1,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'fixed - user',
+ is_visible => 1,
+ is_fixed => 1,
+ is_open => 0,
+ is_closed => 0,
+ },
+ {
+ state => 'closed',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 1,
+ },
+) {
+ subtest $test->{state} . ' is fixed/open/closed/visible' => sub {
+ $problem->state( $test->{state} );
+ is $problem->is_visible, $test->{is_visible}, 'is_visible';
+ is $problem->is_fixed, $test->{is_fixed}, 'is_fixed';
+ is $problem->is_closed, $test->{is_closed}, 'is_closed';
+ is $problem->is_open, $test->{is_open}, 'is_open';
+ };
+}
+
$problem->comments->delete;
$problem->delete;
$user->delete;
diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t
new file mode 100644
index 000000000..60b52043a
--- /dev/null
+++ b/t/app/model/questionnaire.t
@@ -0,0 +1,106 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+use FixMyStreet;
+use FixMyStreet::TestMech;
+
+my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => 'test@example.com' } );
+
+my $problem = FixMyStreet::App->model('DB::Problem')->create(
+ {
+ postcode => 'EH99 1SP',
+ latitude => 1,
+ longitude => 1,
+ areas => 1,
+ title => 'to be sent',
+ detail => 'detail',
+ used_map => 1,
+ user_id => 1,
+ name => 'A Name',
+ state => 'confirmed',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ confirmed => \"ms_current_timestamp() - '5 weeks'::interval",
+ whensent => \"ms_current_timestamp() - '5 weeks'::interval",
+ user => $user,
+ anonymous => 0,
+ }
+);
+
+diag $problem->id;
+
+my $mech = FixMyStreet::TestMech->new;
+
+for my $test (
+ {
+ state => 'unconfirmed',
+ send_email => 0,
+ },
+ {
+ state => 'partial',
+ send_email => 0,
+ },
+ {
+ state => 'hidden',
+ send_email => 0,
+ },
+ {
+ state => 'confirmed',
+ send_email => 1,
+ },
+ {
+ state => 'investigating',
+ send_email => 1,
+ },
+ {
+ state => 'planned',
+ send_email => 1,
+ },
+ {
+ state => 'in progress',
+ send_email => 1,
+ },
+ {
+ state => 'fixed',
+ send_email => 1,
+ },
+ {
+ state => 'fixed - council',
+ send_email => 1,
+ },
+ {
+ state => 'fixed - user',
+ send_email => 1,
+ },
+ {
+ state => 'closed',
+ send_email => 1,
+ },
+) {
+ subtest "correct questionnaire behviour for state $test->{state}" => sub {
+ $problem->discard_changes;
+ $problem->state( $test->{state} );
+ $problem->send_questionnaire( 1 );
+ $problem->update;
+
+ $problem->questionnaires->delete;
+
+ $mech->email_count_is(0);
+
+ FixMyStreet::App->model('DB::Questionnaire')
+ ->send_questionnaires( { site => 'fixmystreet' } );
+
+ $mech->email_count_is( $test->{send_email} );
+
+ $mech->clear_emails_ok();
+ }
+}
+
+$mech->delete_user( $user );
+
+done_testing();