From b14319e75b61ce1ee21ebb7d6fa924ebe18ceee9 Mon Sep 17 00:00:00 2001 From: pezholio Date: Tue, 17 Jan 2017 16:44:50 +0000 Subject: Add Problem->time_ago for pretty-printed duration --- t/app/model/problem.t | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 1130078c0..e2c407ffb 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -774,6 +774,50 @@ subtest 'check duplicate reports' => sub { is $problem2->duplicates->[0]->title, $problem1->title, 'problem2 includes problem1 in duplicates'; }; +subtest 'get report time ago in appropriate format' => sub { + my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE'); + + $problem->update( { + confirmed => DateTime->now->subtract( minutes => 2) + } ); + is $problem->time_ago, '2 minutes', 'problem returns time ago in minutes'; + + $problem->update( { + confirmed => DateTime->now->subtract( hours => 18) + } ); + is $problem->time_ago, '18 hours', 'problem returns time ago in hours'; + + $problem->update( { + confirmed => DateTime->now->subtract( days => 4) + } ); + is $problem->time_ago, '4 days', 'problem returns time ago in days'; + + $problem->update( { + confirmed => DateTime->now->subtract( weeks => 3 ) + } ); + is $problem->time_ago, '3 weeks', 'problem returns time ago in weeks'; + + $problem->update( { + confirmed => DateTime->now->subtract( months => 4 ) + } ); + is $problem->time_ago, '4 months', 'problem returns time ago in months'; + + $problem->update( { + confirmed => DateTime->now->subtract( years => 2 ) + } ); + is $problem->time_ago, '2 years', 'problem returns time ago in years'; + +}; + +subtest 'time ago works with other dates' => sub { + my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE'); + + $problem->update( { + lastupdate => DateTime->now->subtract( days => 4) + } ); + is $problem->time_ago('lastupdate'), '4 days', 'problem returns last updated time ago in days'; +}; + END { $problem->comments->delete if $problem; $problem->delete if $problem; -- cgit v1.2.3 From 3010d13823de9833700b18bf4ac3e71437d9001f Mon Sep 17 00:00:00 2001 From: pezholio Date: Wed, 18 Jan 2017 14:44:04 +0000 Subject: Add Problem->tokenised_url for logging user in This method creates a token that logs the reporting user in, optionally with some parameters which are stored with the token for use when redirecting after login. --- t/app/model/problem.t | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index e2c407ffb..52213ed51 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -5,6 +5,7 @@ use Test::More; use FixMyStreet::TestMech; use FixMyStreet; +use FixMyStreet::App; use FixMyStreet::DB; use mySociety::Locale; use Sub::Override; @@ -53,7 +54,7 @@ is $problem->whensent, undef, 'inflating null confirmed ok'; is $problem->lastupdate, undef, 'inflating null confirmed ok'; is $problem->created, undef, 'inflating null confirmed ok'; -for my $test ( +for my $test ( { desc => 'more or less empty problem', changed => {}, @@ -242,7 +243,7 @@ for my $test ( }; } -for my $test ( +for my $test ( { state => 'partial', is_visible => 0, @@ -774,6 +775,32 @@ subtest 'check duplicate reports' => sub { is $problem2->duplicates->[0]->title, $problem1->title, 'problem2 includes problem1 in duplicates'; }; +subtest 'generates a tokenised url for a user' => sub { + my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE'); + my $url = $problem->tokenised_url($user); + (my $token = $url) =~ s/\/M\///g; + + like $url, qr/\/M\//, 'problem generates tokenised url'; + + my $token_obj = FixMyStreet::App->model('DB::Token')->find( { + scope => 'email_sign_in', token => $token + } ); + is $token, $token_obj->token, 'token is generated in database with correct scope'; + is $token_obj->data->{r}, $problem->url, 'token has correct redirect data'; +}; + +subtest 'stores params in a token' => sub { + my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE'); + my $url = $problem->tokenised_url($user, { foo => 'bar', baz => 'boo'}); + (my $token = $url) =~ s/\/M\///g; + + my $token_obj = FixMyStreet::App->model('DB::Token')->find( { + scope => 'email_sign_in', token => $token + } ); + + is_deeply $token_obj->data->{p}, { foo => 'bar', baz => 'boo'}, 'token has correct params'; +}; + subtest 'get report time ago in appropriate format' => sub { my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE'); -- cgit v1.2.3 From 587a125c46f229ed23aaf68d3308f6755e2d8299 Mon Sep 17 00:00:00 2001 From: pezholio Date: Tue, 24 Jan 2017 16:20:48 +0000 Subject: [Oxfordshire] Use 'days ago' format on problem lists Fixes mysociety/fixmystreetforcouncils#98 --- t/app/model/problem.t | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 52213ed51..b942a5333 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -833,7 +833,6 @@ subtest 'get report time ago in appropriate format' => sub { confirmed => DateTime->now->subtract( years => 2 ) } ); is $problem->time_ago, '2 years', 'problem returns time ago in years'; - }; subtest 'time ago works with other dates' => sub { @@ -845,6 +844,20 @@ subtest 'time ago works with other dates' => sub { is $problem->time_ago('lastupdate'), '4 days', 'problem returns last updated time ago in days'; }; +subtest 'return how many days ago a problem was reported' => sub { + my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE'); + $problem->update( { + confirmed => DateTime->now->subtract( weeks => 2 ) + } ); + is $problem->days_ago, 14, 'days_ago returns the amount of days'; + + $problem->update( { + lastupdate => DateTime->now->subtract( days => 4) + } ); + + is $problem->days_ago('lastupdate'), 4, 'days_ago allows other dates to be specified'; +}; + END { $problem->comments->delete if $problem; $problem->delete if $problem; -- cgit v1.2.3 From a91d9562c6c0ec836f10290df779e2012f18ddec Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Mar 2017 17:58:31 +0000 Subject: Add is_in_progress Problem helper. --- t/app/model/problem.t | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index b942a5333..e9ec22b77 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -249,6 +249,7 @@ for my $test ( is_visible => 0, is_fixed => 0, is_open => 0, + is_in_progress => 0, is_closed => 0, }, { @@ -256,6 +257,7 @@ for my $test ( is_visible => 0, is_fixed => 0, is_open => 0, + is_in_progress => 0, is_closed => 0, }, { @@ -263,6 +265,7 @@ for my $test ( is_visible => 0, is_fixed => 0, is_open => 0, + is_in_progress => 0, is_closed => 0, }, { @@ -270,6 +273,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 1, + is_in_progress => 0, is_closed => 0, }, { @@ -277,6 +281,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 1, + is_in_progress => 1, is_closed => 0, }, { @@ -284,6 +289,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 1, + is_in_progress => 1, is_closed => 0, }, { @@ -291,6 +297,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 1, + is_in_progress => 1, is_closed => 0, }, { @@ -298,6 +305,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 1, + is_in_progress => 1, is_closed => 0, }, { @@ -305,6 +313,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 0, + is_in_progress => 0, is_closed => 1, }, { @@ -312,6 +321,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 0, + is_in_progress => 0, is_closed => 1, }, { @@ -319,6 +329,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 0, + is_in_progress => 0, is_closed => 1, }, { @@ -326,6 +337,7 @@ for my $test ( is_visible => 1, is_fixed => 1, is_open => 0, + is_in_progress => 0, is_closed => 0, }, { @@ -333,6 +345,7 @@ for my $test ( is_visible => 1, is_fixed => 1, is_open => 0, + is_in_progress => 0, is_closed => 0, }, { @@ -340,6 +353,7 @@ for my $test ( is_visible => 1, is_fixed => 1, is_open => 0, + is_in_progress => 0, is_closed => 0, }, { @@ -347,6 +361,7 @@ for my $test ( is_visible => 1, is_fixed => 0, is_open => 0, + is_in_progress => 0, is_closed => 1, }, ) { @@ -356,6 +371,7 @@ for my $test ( 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'; + is $problem->is_in_progress, $test->{is_in_progress}, 'is_in_progress'; }; } -- cgit v1.2.3 From 74a7ed654369cb3ebd282c01d4a0de87a646c4ce Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 8 Mar 2017 14:13:48 +0000 Subject: Use sender in From if From and To domains match. To deal with a recipient mail server not allowing inbound email using the same domain as an internal domain, e.g. https://community.mimecast.com/docs/DOC-1419 --- t/app/model/problem.t | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 't/app/model/problem.t') diff --git a/t/app/model/problem.t b/t/app/model/problem.t index e9ec22b77..6b1be0a76 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -148,7 +148,7 @@ for my $test ( my $user = FixMyStreet::DB->resultset('User')->find_or_create( { - email => 'system_user@example.com' + email => 'system_user@example.net' } ); @@ -428,7 +428,7 @@ for my $contact ( { }, { body_id => $body_ids{14279}[0], # Ballymoney category => 'Graffiti', - email => 'highways@example.com', + email => 'highways@example.net', }, { confirmed => 0, body_id => $body_ids{2636}, # Isle of Wight @@ -439,7 +439,7 @@ for my $contact ( { } my %common = ( - email => 'system_user@example.com', + email => 'system_user@example.net', name => 'Andrew Smith', ); foreach my $test ( { @@ -505,6 +505,9 @@ foreach my $test ( { body => $body_ids{14279}[0], category => 'Graffiti', longitude => -6.5, + # As Ballmoney contact has same domain as reporter, the From line will + # become a unique reply address and Reply-To will become the reporter + reply_to => 1, }, { %common, desc => 'directs NI correctly, 2', @@ -563,7 +566,12 @@ foreach my $test ( { if ( $test->{ email_count } ) { my $email = $mech->get_email; like $email->header('To'), $test->{ to }, 'to line looks correct'; - is $email->header('From'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'from line looks correct'; + if ($test->{reply_to}) { + is $email->header('Reply-To'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'Reply-To line looks correct'; + like $email->header('From'), qr/"$test->{name}" /, 'from line looks correct'; + } else { + is $email->header('From'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'from line looks correct'; + } like $email->header('Subject'), qr/A Title/, 'subject line looks correct'; my $body = $mech->get_text_body_from_email($email); like $body, qr/A user of FixMyStreet/, 'email body looks a bit like a report'; @@ -671,7 +679,7 @@ subtest 'check can turn on report sent email alerts' => sub { my $email = $emails[0]; like $email->header('To'),qr/City of Edinburgh Council/, 'to line looks correct'; - is $email->header('From'), '"Test User" ', 'from line looks correct'; + is $email->header('From'), '"Test User" ', 'from line looks correct'; like $email->header('Subject'), qr/A Title/, 'subject line looks correct'; my $body = $mech->get_text_body_from_email($email); like $body, qr/A user of FixMyStreet/, 'email body looks a bit like a report'; -- cgit v1.2.3