From bcf9858a20adbf75f09a6a3b54d63c8012f54fe9 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 12 Mar 2014 14:21:44 +0000 Subject: Add test for de47a7f. This tests that the default string used by the old-style Open311 update code if there is no incoming string and the report is marked fixed, is translated. --- perllib/Open311/GetUpdates.pm | 2 +- t/open311/getupdates.t | 78 ++++++++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/perllib/Open311/GetUpdates.pm b/perllib/Open311/GetUpdates.pm index db5d8ef35..7441f7f6d 100644 --- a/perllib/Open311/GetUpdates.pm +++ b/perllib/Open311/GetUpdates.pm @@ -73,7 +73,7 @@ sub update_reports { if (my $p = $problem->first) { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($p->cobrand)->new(); - $cobrand->set_lang_and_domain($p->lang, 1); + $cobrand->set_lang_and_domain($p->lang, 1, FixMyStreet->path_to('locale')->stringify ); $p->update_from_open311_service_request( $request, $council_details, $self->system_user ); } } diff --git a/t/open311/getupdates.t b/t/open311/getupdates.t index 500ac97d2..4376e2f4b 100644 --- a/t/open311/getupdates.t +++ b/t/open311/getupdates.t @@ -4,9 +4,7 @@ use strict; use warnings; use Test::More; -use FindBin; -use lib "$FindBin::Bin/../perllib"; -use lib "$FindBin::Bin/../commonlib/perllib"; +use FixMyStreet; use_ok( 'Open311::GetUpdates' ); use_ok( 'Open311' ); @@ -51,12 +49,9 @@ my $problem = $problem_rs->new( title => '', detail => '', used_map => 1, - user_id => 1, name => '', state => 'confirmed', - service => '', cobrand => 'default', - cobrand_data => '', user => $user, created => DateTime->now()->subtract( days => 1 ), lastupdate => DateTime->now()->subtract( days => 1 ), @@ -155,12 +150,9 @@ my $problem2 = $problem_rs->create( title => '', detail => '', used_map => 1, - user_id => 1, name => '', state => 'confirmed', - service => '', cobrand => 'default', - cobrand_data => '', user => $user, created => DateTime->now()->subtract( days => 1 ), lastupdate => DateTime->now()->subtract( days => 1 ), @@ -189,10 +181,66 @@ subtest 'update with two requests' => sub { is $problem2->comments->count, 1, 'added a comment to second problem'; }; -$problem->comments->delete; -$problem->delete; -$user->comments->delete; -$user->problems->delete; -$user->delete; +# No status_notes field now, so that static string in code is used. +$requests_xml = qq{ + + +638346 +closed +Sidewalk and Curb Issues +006 + + + +2010-04-14T06:37:38-08:00 +UPDATED_DATETIME +2010-04-15T06:37:38-08:00 +37.762221815 +-122.4651145 + + +}; -done_testing(); +my $problem3 = $problem_rs->create( { + postcode => 'EH99 1SP', + latitude => 1, + longitude => 1, + areas => 1, + title => 'Title', + detail => 'Details', + used_map => 1, + name => '', + state => 'confirmed', + cobrand => 'fixamingata', + user => $user, + created => DateTime->now()->subtract( days => 1 ), + lastupdate => DateTime->now()->subtract( days => 1 ), + anonymous => 1, + external_id => 638346, +} ); + +subtest 'test translation of auto-added comment from old-style Open311 update' => sub { + my $dt = sprintf( '%s', DateTime->now ); + $requests_xml =~ s/UPDATED_DATETIME/$dt/; + + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $requests_xml } ); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixamingata' ], + }, sub { + ok $updates->update_reports( [ 638346 ], $o, { name => 'Test Council' } ); + }; + is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638346', 'get url'; + + is $problem3->comments->count, 1, 'added a comment'; + is $problem3->comments->first->text, "St\xe4ngd av kommunen", 'correct comment text'; +}; + +END { + if ($user) { + $user->comments->delete; + $user->problems->delete; + $user->delete; + } + done_testing(); +} -- cgit v1.2.3