From a7d69671e7b3276551c644877707107bde3cddef Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 12 Sep 2023 13:52:42 +0100 Subject: [PATCH] [SLWP] Submit cancellation action upon update. --- perllib/Open311/Endpoint/Role/SLWP.pm | 5 +++++ t/open311/endpoint/kingston.t | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/perllib/Open311/Endpoint/Role/SLWP.pm b/perllib/Open311/Endpoint/Role/SLWP.pm index cd5d84e70..df090f4cc 100644 --- a/perllib/Open311/Endpoint/Role/SLWP.pm +++ b/perllib/Open311/Endpoint/Role/SLWP.pm @@ -30,6 +30,11 @@ around post_service_request_update => sub { $args->{datatype_id} = 0; } + if ($args->{description} eq 'Booking cancelled by customer') { + $args->{actiontype_id} = 8; + $args->{datatype_id} = 0; + } + my $result = $class->$orig($args); if ($args->{description} =~ /Payment confirmed, reference (.*), amount (.*)/) { diff --git a/t/open311/endpoint/kingston.t b/t/open311/endpoint/kingston.t index a6470d822..0f07b3369 100644 --- a/t/open311/endpoint/kingston.t +++ b/t/open311/endpoint/kingston.t @@ -91,6 +91,8 @@ $soap_lite->mock(call => sub { my $actiontype_id = $params[0]->value; if ($ref eq '123pay') { is $actiontype_id, 348; + } elsif ($ref eq '123cancel') { + is $actiontype_id, 8; } return SOAP::Result->new(result => { EventActionGuid => 'ABC' }); } else { @@ -162,4 +164,25 @@ subtest "POST a successful payment" => sub { } ], 'correct json returned'; }; +subtest "POST a cancellation" => sub { + my $res = $endpoint->run_test_request( + POST => '/servicerequestupdates.json', + api_key => 'test', + updated_datetime => '2023-09-01T19:00:00+01:00', + service_request_id => '123cancel', + update_id => 456, + status => 'OPEN', + description => 'Booking cancelled by customer', + first_name => 'Bob', + last_name => 'Mould', + ); + ok $res->is_success, 'valid request' + or diag $res->content; + + is_deeply decode_json($res->content), + [ { + "update_id" => 'ABC', + } ], 'correct json returned'; +}; + done_testing;