diff --git a/perllib/Open311/Endpoint/Integration/UK/Bristol/Passthrough.pm b/perllib/Open311/Endpoint/Integration/UK/Bristol/Passthrough.pm index 081d05a41..6cb946538 100644 --- a/perllib/Open311/Endpoint/Integration/UK/Bristol/Passthrough.pm +++ b/perllib/Open311/Endpoint/Integration/UK/Bristol/Passthrough.pm @@ -20,4 +20,11 @@ around BUILDARGS => sub { return $class->$orig(%args); }; +around post_service_request_update => sub { + my ($orig, $self, $args) = @_; + # Bristol's endpoint gets confused if it receives a service_code on an update + delete $args->{service_code}; + return $self->$orig($args); +}; + 1; diff --git a/t/open311/endpoint/bristol_passthrough.t b/t/open311/endpoint/bristol_passthrough.t new file mode 100644 index 000000000..922c157aa --- /dev/null +++ b/t/open311/endpoint/bristol_passthrough.t @@ -0,0 +1,52 @@ +use strict; +use warnings; + +BEGIN { $ENV{TEST_MODE} = 1; } + +use Test::More; +use Test::MockModule; +use JSON::MaybeXS; +use Path::Tiny; + +my $pt = Test::MockModule->new('Open311::Endpoint::Integration::UK::Bristol::Passthrough'); +$pt->mock(endpoint => sub { '' }); + +my $expected_update_post = < + + + 2002 + + +XML + +my $ua = Test::MockModule->new('LWP::UserAgent'); +$ua->mock(post => sub { + my $args = $_[2]; + is $args->{service_code}, undef; + return HTTP::Response->new(200, 'OK', [], $expected_update_post); +}); + +use_ok 'Open311::Endpoint::Integration::UK::Bristol::Passthrough'; + +my $endpoint = Open311::Endpoint::Integration::UK::Bristol::Passthrough->new; + +subtest 'POST update' => sub { + my $res = $endpoint->run_test_request( + POST => '/servicerequestupdates.xml', + api_key => 'test', + service_code => 'SE01', + service_request_id => 1001, + update_id => 123, + # first_name => 'Bob', + # last_name => 'Mould', + description => 'Update here', + status => 'OPEN', + updated_datetime => '2016-09-01T15:00:00Z', + # media_url => 'http://example.org/', + ); + ok $res->is_success, 'valid request' or diag $res->content; + is $res->content, $expected_update_post; +}; + +done_testing;