diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-03-06 17:08:19 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2019-03-08 17:22:19 +0000 |
commit | 435d15a06bd845bbcadc603b5a9a7ca88b7b403d (patch) | |
tree | d83f45613275b9a8f732c299212cc60e3ff6cf8a /t | |
parent | 36487240bae63833e7e82ac673be92eb9c033d4c (diff) |
[Open311] Use cobrand hook for extra update params
The test has to now create a new comment object each time as
`get_cobrand_logged` is cached on the object.
Diffstat (limited to 't')
-rw-r--r-- | t/app/sendreport/open311.t | 1 | ||||
-rw-r--r-- | t/open311.t | 63 | ||||
-rw-r--r-- | t/open311/post-service-request-updates.t | 11 |
3 files changed, 45 insertions, 30 deletions
diff --git a/t/app/sendreport/open311.t b/t/app/sendreport/open311.t index df2166ab4..54aaa39d0 100644 --- a/t/app/sendreport/open311.t +++ b/t/app/sendreport/open311.t @@ -14,7 +14,6 @@ sub test_overrides; # defined below use constant TEST_USER_EMAIL => 'fred@example.com'; my %standard_open311_parameters = ( - 'use_extended_updates' => 0, 'send_notpinpointed' => 0, 'extended_description' => 1, 'use_service_as_deviceid' => 0, diff --git a/t/open311.t b/t/open311.t index ef52eb538..3bb85f595 100644 --- a/t/open311.t +++ b/t/open311.t @@ -70,6 +70,8 @@ my $problem = FixMyStreet::DB->resultset('Problem')->new( { cobrand => 'fixmystreet', } ); +my $bromley = FixMyStreet::DB->resultset('Body')->new({ name => 'Bromley' }); + subtest 'posting service request' => sub { my $extra = { url => 'http://example.com/report/1', @@ -261,19 +263,23 @@ for my $test ( }; } - -my $comment = FixMyStreet::DB->resultset('Comment')->new( { - id => 38362, - user => $user, - problem => $problem, - anonymous => 0, - text => 'this is a comment', - confirmed => $dt, - problem_state => 'confirmed', - extra => { title => 'Mr', email_alerts_requested => 0 }, -} ); +sub make_comment { + my $cobrand = shift; + FixMyStreet::DB->resultset('Comment')->new( { + id => 38362, + user => $user, + problem => $problem, + anonymous => 0, + text => 'this is a comment', + confirmed => $dt, + problem_state => 'confirmed', + cobrand => $cobrand || 'default', + extra => { title => 'Mr', email_alerts_requested => 0 }, + } ); +} subtest 'basic request update post parameters' => sub { + my $comment = make_comment(); my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); is $results->{ res }, 248, 'got update id'; @@ -292,7 +298,13 @@ subtest 'basic request update post parameters' => sub { }; subtest 'extended request update post parameters' => sub { - my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', { use_extended_updates => 1 } ); + my $comment = make_comment('bromley'); + my $results; + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'bromley', + }, sub { + $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); + }; is $results->{ res }, 248, 'got update id'; @@ -318,8 +330,8 @@ subtest 'check media url set' => sub { my $image_path = path('t/app/controller/sample.jpg'); $image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) ); + my $comment = make_comment('fixmystreet'); $comment->photo("0123456789012345678901234567890123456789"); - $comment->cobrand('fixmystreet'); FixMyStreet::override_config { PHOTO_STORAGE_BACKEND => 'FileSystem', @@ -335,7 +347,6 @@ subtest 'check media url set' => sub { my $expected_path = '/c/' . $comment->id . '.0.full.jpeg'; like $c->param('media_url'), qr/$expected_path/, 'image url included'; }; - $comment->photo(undef); }; foreach my $test ( @@ -432,6 +443,7 @@ foreach my $test ( }, ) { subtest $test->{desc} => sub { + my $comment = make_comment(); $comment->problem_state( $test->{state} ); $comment->problem->state( $test->{state} ); $comment->mark_open(1) if $test->{mark_open}; @@ -466,11 +478,17 @@ for my $test ( }, ) { subtest $test->{desc} => sub { + my $comment = make_comment('bromley'); $comment->problem_state( $test->{state} ); $comment->problem->state( $test->{state} ); $comment->anonymous( $test->{anon} ); - my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', { use_extended_updates => 1 } ); + my $results; + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'bromley', + }, sub { + $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); + }; my $c = CGI::Simple->new( $results->{ req }->content ); is $c->param('public_anonymity_required'), $test->{anon} ? 'TRUE' : 'FALSE', 'correct anonymity'; @@ -480,17 +498,6 @@ for my $test ( my $dt2 = $dt->clone; $dt2->add( 'minutes' => 1 ); -my $comment2 = FixMyStreet::DB->resultset('Comment')->new( { - id => 38363, - user => $user, - problem => $problem, - anonymous => 0, - text => 'this is a comment', - confirmed => $dt, - problem_state => 'confirmed', - extra => { title => 'Mr', email_alerts_requested => 0 }, -} ); - for my $test ( { desc => 'comment with fixed - council state sends status of CLOSED even if problem is open', @@ -515,6 +522,7 @@ for my $test ( }, ) { subtest $test->{desc} => sub { + my $comment = make_comment(); $comment->problem_state( $test->{state} ); $comment->problem->state( $test->{problem_state} ); my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' ); @@ -559,6 +567,7 @@ for my $test ( ) { subtest $test->{desc} => sub { + my $comment = make_comment(); $comment->name( $test->{comment_name} ); $user->name( $test->{user_name} ); $comment->extra( $test->{ extra } ); @@ -647,6 +656,7 @@ for my $test ( } $problem->send_fail_count(1); +my $comment = make_comment(); $comment->send_fail_count(1); subtest 'No request id in reponse' => sub { @@ -812,6 +822,7 @@ sub _make_req { $open311_conf{'test_mode'} = 1; $open311_conf{'end_point'} = 'http://localhost/o311'; + $open311_conf{fixmystreet_body} = $bromley; my $o = Open311->new( %open311_conf ); diff --git a/t/open311/post-service-request-updates.t b/t/open311/post-service-request-updates.t index 5c8211bbf..000bf3a2b 100644 --- a/t/open311/post-service-request-updates.t +++ b/t/open311/post-service-request-updates.t @@ -34,21 +34,26 @@ subtest 'Check Open311 params' => sub { is_deeply \%conf, { %$result, extended_statuses => 1, - use_extended_updates => 1, endpoints => { service_request_updates => 'update.xml', update => 'update.xml' }, + fixmystreet_body => $bromley, }, 'Bromley params match'; %conf = $o->open311_params($oxon); is_deeply \%conf, { %$result, - use_customer_reference => 1 + use_customer_reference => 1, + fixmystreet_body => $oxon, }, 'Oxfordshire params match'; %conf = $o->open311_params($bucks); is_deeply \%conf, { %$result, mark_reopen => 1, + fixmystreet_body => $bucks, }, 'Bucks params match'; %conf = $o->open311_params($lewisham); - is_deeply \%conf, $result, 'Lewisham params match'; + is_deeply \%conf, { + %$result, + fixmystreet_body => $lewisham, + }, 'Lewisham params match'; }; }; |