diff options
author | Chris Mytton <chrism@mysociety.org> | 2020-01-30 17:34:51 +0000 |
---|---|---|
committer | Chris Mytton <chrism@mysociety.org> | 2020-02-20 14:01:10 +0000 |
commit | ce5948821df7ce63c32181b419aa26a9de73f330 (patch) | |
tree | e86ccf6472b16029eabb4f08ba39f7bc684424ea /t | |
parent | c490a4a8fbeb66f559f3591691f48e0e3eccd4df (diff) |
[Peterborough] Add tests for custom Open311 behaviour
Checks that the correct bits of the problem's extra fields are sent when
creating the report in Open311, and that extra bits of info are sent
when sending comments to Open311.
Diffstat (limited to 't')
-rw-r--r-- | t/cobrand/peterborough.t | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/t/cobrand/peterborough.t b/t/cobrand/peterborough.t new file mode 100644 index 000000000..6a442a7c6 --- /dev/null +++ b/t/cobrand/peterborough.t @@ -0,0 +1,79 @@ +use FixMyStreet::TestMech; +use FixMyStreet::Script::Reports; +use CGI::Simple; + +my $mech = FixMyStreet::TestMech->new; + +my $params = { + send_method => 'Open311', + send_comments => 1, + api_key => 'KEY', + endpoint => 'endpoint', + jurisdiction => 'home', + can_be_devolved => 1, +}; +my $peterborough = $mech->create_body_ok(2566, 'Peterborough City Council', $params); + +subtest 'open311 request handling', sub { + FixMyStreet::override_config { + STAGING_FLAGS => { send_reports => 1 }, + ALLOWED_COBRANDS => ['peterborough' ], + MAPIT_URL => 'http://mapit.uk/', + }, sub { + my $contact = $mech->create_contact_ok(body_id => $peterborough->id, category => 'Trees', email => 'TREES'); + my ($p) = $mech->create_problems_for_body(1, $peterborough->id, 'Title', { category => 'Trees', latitude => 52.5608, longitude => 0.2405, cobrand => 'peterborough' }); + $p->set_extra_fields({ name => 'emergency', value => 'no'}); + $p->set_extra_fields({ name => 'private_land', value => 'no'}); + $p->set_extra_fields({ name => 'tree_code', value => 'tree-42'}); + $p->update; + + my $test_data = FixMyStreet::Script::Reports::send(); + + $p->discard_changes; + ok $p->whensent, 'Report marked as sent'; + is $p->send_method_used, 'Open311', 'Report sent via Open311'; + is $p->external_id, 248, 'Report has correct external ID'; + + my $req = $test_data->{test_req_used}; + my $c = CGI::Simple->new($req->content); + is $c->param('attribute[emergency]'), undef, 'no emergency param sent'; + is $c->param('attribute[private_land]'), undef, 'no private_land param sent'; + is $c->param('attribute[tree_code]'), 'tree-42', 'tree_code param sent'; + }; +}; + +subtest "extra update params are sent to open311" => sub { + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => 'peterborough', + }, sub { + my $contact = $mech->create_contact_ok(body_id => $peterborough->id, category => 'Trees', email => 'TREES'); + my $test_res = HTTP::Response->new(); + $test_res->code(200); + $test_res->message('OK'); + $test_res->content('<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>ezytreev-248</update_id></request_update></service_request_updates>'); + + my $o = Open311->new( + fixmystreet_body => $peterborough, + test_mode => 1, + test_get_returns => { 'servicerequestupdates.xml' => $test_res }, + ); + + my ($p) = $mech->create_problems_for_body(1, $peterborough->id, 'Title', { external_id => 1, category => 'Trees' }); + + my $c = FixMyStreet::DB->resultset('Comment')->create({ + problem => $p, user => $p->user, anonymous => 't', text => 'Update text', + problem_state => 'fixed - council', state => 'confirmed', mark_fixed => 0, + confirmed => DateTime->now(), + }); + + my $id = $o->post_service_request_update($c); + is $id, "ezytreev-248", 'correct update ID returned'; + my $cgi = CGI::Simple->new($o->test_req_used->content); + is $cgi->param('description'), '[Customer FMS update] Update text', 'FMS update prefix included'; + is $cgi->param('service_request_id_ext'), $p->id, 'Service request ID included'; + is $cgi->param('service_code'), $contact->email, 'Service code included'; + }; +}; + +done_testing; |