|
| 1 | +package Open311::Endpoint::Integration::UK::BANES::Passthrough::Dummy; |
| 2 | +use Path::Tiny; |
| 3 | +use Moo; |
| 4 | +extends 'Open311::Endpoint::Integration::UK::BANES::Passthrough'; |
| 5 | + |
| 6 | +around BUILDARGS => sub { |
| 7 | + my ($orig, $class, %args) = @_; |
| 8 | + $args{jurisdiction_id} = 'dummy'; |
| 9 | + $args{config_file} = path(__FILE__)->sibling("www.banes.gov.uk.yml")->stringify; |
| 10 | + $args{endpoint} = ''; |
| 11 | + return $class->$orig(%args); |
| 12 | +}; |
| 13 | + |
| 14 | +package main; |
| 15 | + |
| 16 | +use strict; |
| 17 | +use warnings; |
| 18 | + |
| 19 | +BEGIN { $ENV{TEST_MODE} = 1; } |
| 20 | + |
| 21 | +use Test::More; |
| 22 | +use Test::MockModule; |
| 23 | +use JSON::MaybeXS; |
| 24 | +use Path::Tiny; |
| 25 | + |
| 26 | +my $test_request = { |
| 27 | + jurisdiction_id => 'dummy', |
| 28 | + api_key => 'api-key', |
| 29 | + service_code => 'Trees_and_woodland', |
| 30 | + address_string => '22 Acacia Avenue', |
| 31 | + first_name => 'Bob', |
| 32 | + last_name => 'Mould', |
| 33 | + email => 'test@example.com', |
| 34 | + description => 'title: Tree blocking light detail: Tree overhanging garden and blocking light', |
| 35 | + media_url => ['https://localhost/one.jpeg?123', 'https://localhost/two.jpeg?123'], |
| 36 | + lat => '50', |
| 37 | + long => '0.1', |
| 38 | + 'attribute[description]' => 'Tree overhanging garden and blocking light', |
| 39 | + 'attribute[title]' => 'Tree blocking light', |
| 40 | + 'attribute[report_url]' => 'http://localhost/1', |
| 41 | + 'attribute[easting]' => 1, |
| 42 | + 'attribute[northing]' => 2, |
| 43 | + 'attribute[category]' => 'Trees and woodland', |
| 44 | + 'attribute[fixmystreet_id]' => 1, |
| 45 | +}; |
| 46 | + |
| 47 | +my $expected_confirm_service_request_post = <<XML; |
| 48 | +<?xml version="1.0" encoding="utf-8"?> |
| 49 | +<service_requests> |
| 50 | + <request> |
| 51 | + <service_request_id>293944</service_request_id> |
| 52 | + <service_notice> |
| 53 | + The City will inspect and require the responsible party to correct within 24 hours and/or issue a Correction Notice or Notice of Violation of the Public Works Code |
| 54 | + </service_notice> |
| 55 | + <account_id/> |
| 56 | + </request> |
| 57 | +</service_requests> |
| 58 | +XML |
| 59 | + |
| 60 | +my $ua = Test::MockModule->new('LWP::UserAgent'); |
| 61 | +$ua->mock(post => sub { |
| 62 | + my ($self, $url, $args) = @_; |
| 63 | + |
| 64 | + if ($url =~ /token\/api/) { |
| 65 | + is $args->{username}, 'FMS', "Username picked up from config"; |
| 66 | + is $args->{password}, 'FMSPassword', "Password picked up from config"; |
| 67 | + return HTTP::Response->new(200, 'OK', [], '12345678910'); |
| 68 | + } else { |
| 69 | + is $args->{Authorization}, 'Bearer 12345678910', 'Authorisation header set'; |
| 70 | + is_deeply $args->{Content}, $test_request; |
| 71 | + return HTTP::Response->new(200, 'OK', [], $expected_confirm_service_request_post); |
| 72 | + } |
| 73 | +}); |
| 74 | + |
| 75 | +use_ok 'Open311::Endpoint::Integration::UK::BANES::Passthrough'; |
| 76 | + |
| 77 | +my $endpoint = Open311::Endpoint::Integration::UK::BANES::Passthrough::Dummy->new; |
| 78 | + |
| 79 | +subtest 'POST service request' => sub { |
| 80 | + my $res = $endpoint->run_test_request( |
| 81 | + POST => '/requests.json', |
| 82 | + %{ $test_request } |
| 83 | + ); |
| 84 | + |
| 85 | + ok $res->is_success, 'valid request' or diag $res->content; |
| 86 | + is_deeply decode_json($res->content), [ { service_request_id => '293944' } ], 'correct return'; |
| 87 | +}; |
| 88 | + |
| 89 | +done_testing; |
0 commit comments