diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/admin.t | 1 | ||||
-rw-r--r-- | t/app/sendreport/inspection_required.t | 20 | ||||
-rw-r--r-- | t/utils.t | 36 | ||||
-rw-r--r-- | t/utils/email.t | 34 |
4 files changed, 91 insertions, 0 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 8c3cde4b7..7ba84b652 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -1165,6 +1165,7 @@ my %default_perms = ( "permissions[template_edit]" => undef, "permissions[responsepriority_edit]" => undef, "permissions[category_edit]" => undef, + trusted_bodies => undef, ); FixMyStreet::override_config { diff --git a/t/app/sendreport/inspection_required.t b/t/app/sendreport/inspection_required.t index 178fa2a1f..88a48e991 100644 --- a/t/app/sendreport/inspection_required.t +++ b/t/app/sendreport/inspection_required.t @@ -52,8 +52,28 @@ subtest 'Report is sent when inspected' => sub { ok $report->whensent, 'Report marked as sent'; }; +subtest 'Uninspected report is sent when made by trusted user' => sub { + $mech->clear_emails_ok; + $report->unset_extra_metadata('inspected'); + $report->whensent( undef ); + $report->update; + + $user->user_body_permissions->find_or_create({ + body => $body, + permission_type => 'trusted', + }); + ok $user->has_permission_to('trusted', $report->bodies_str_ids), 'User can make trusted reports'; + + FixMyStreet::DB->resultset('Problem')->send_reports(); + + $report->discard_changes; + $mech->email_count_is( 1 ); + ok $report->whensent, 'Report marked as sent'; +}; + done_testing(); END { + $mech->delete_user($user); $mech->delete_body($body); } @@ -4,6 +4,9 @@ use strict; use warnings; use Test::More; +use mySociety::Locale; +mySociety::Locale::gettext_domain('FixMyStreet'); + use Utils; my @truncate_tests = ( @@ -34,9 +37,14 @@ foreach my $test (@convert_en_to_latlon_tests) { [ Utils::convert_en_to_latlon_truncated( $e, $n ) ], # [ $lat, $lon ], # "convert ($e,$n) to ($lat,$lon)"; + is_deeply + [ Utils::convert_latlon_to_en( $lat, $lon ) ], + [ $e, $n ], + "convert ($lat,$lon) to ($e,$n)"; } my @cleanup_tests = ( + [ '', '', '' ], [ 'dog shit', 'Dog poo', 'dog poo' ], [ 'dog shit', 'Dog poo', 'with spaces' ], [ 'dog shite', 'Dog poo', 'with extra e' ], @@ -57,4 +65,32 @@ foreach my $test ( @cleanup_tests ) { is Utils::cleanup_text( "This has new\n\n\nlines in it", { allow_multiline => 1 } ), "This has new\n\nLines in it", 'new lines allowed'; + +is Utils::prettify_dt(), "[unknown time]"; +my $dt = DateTime->now; +is Utils::prettify_dt($dt), $dt->strftime("%H:%M today"); + +# Same week test +if ($dt->day_of_week == 7) { # Sunday + $dt = DateTime->now->add(days => 1); +} else { + $dt = DateTime->now->subtract(days => 1); +} +is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %A"); + +$dt = DateTime->now->subtract(days => 100); +is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %A %e %B %Y"); +is Utils::prettify_dt($dt, "date"), $dt->strftime("%A %e %B %Y"); +is Utils::prettify_dt($dt, "zurich"), $dt->strftime("%H:%M, %e. %B %Y"); +is Utils::prettify_dt($dt, "short"), $dt->strftime("%H:%M, %e %b %Y"); +is Utils::prettify_dt($dt, 1), $dt->strftime("%H:%M, %e %b %Y"); +$dt = DateTime->now->subtract(days => 400); +is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %a %e %B %Y"); + +is Utils::prettify_duration(7*86400+3600+60+1, 'week'), '1 week'; +is Utils::prettify_duration(86400+3600+60+1, 'day'), '1 day'; +is Utils::prettify_duration(86400+3600+60+1, 'hour'), '1 day, 1 hour'; +is Utils::prettify_duration(86400+3600+60+1, 'minute'), '1 day, 1 hour, 1 minute'; +is Utils::prettify_duration(20, 'minute'), 'less than a minute'; + done_testing(); diff --git a/t/utils/email.t b/t/utils/email.t new file mode 100644 index 000000000..23814c1d7 --- /dev/null +++ b/t/utils/email.t @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use Test::MockModule; + +use Utils::Email; + +my $resolver = Test::MockModule->new('Net::DNS::Resolver'); +$resolver->mock('send', sub { + my ($self, $domain, $type) = @_; + my @rrs; + is $type, 'TXT'; + if ($domain eq '_dmarc.yahoo.com') { + @rrs = ( + Net::DNS::RR->new(name => '_dmarc.yahoo.com', type => 'TXT', txtdata => 'p=reject'), + Net::DNS::RR->new(name => '_dmarc.yahoo.com', type => 'A'), + ); + } elsif ($domain eq 'cname.example.com') { + @rrs = Net::DNS::RR->new(name => 'cname.example.com', type => 'TXT', txtdata => 'p=none'); + } else { + @rrs = Net::DNS::RR->new(name => '_dmarc.example.net', type => 'CNAME', cname => 'cname.example.com'); + } + my $pkt = Net::DNS::Packet->new; + push @{$pkt->{answer}}, @rrs; + return $pkt; +}); + +is Utils::Email::test_dmarc('BAD'), undef; +is Utils::Email::test_dmarc('test@yahoo.com'), 1; +is Utils::Email::test_dmarc('test@example.net'), undef; + +done_testing(); |