diff options
Diffstat (limited to 't/open311/endpoint')
-rw-r--r-- | t/open311/endpoint/Endpoint1.pm | 4 | ||||
-rw-r--r-- | t/open311/endpoint/Endpoint2.pm | 4 | ||||
-rw-r--r-- | t/open311/endpoint/Endpoint_Warwick.pm | 36 | ||||
-rw-r--r-- | t/open311/endpoint/warwick.t | 291 |
4 files changed, 328 insertions, 7 deletions
diff --git a/t/open311/endpoint/Endpoint1.pm b/t/open311/endpoint/Endpoint1.pm index 257a94b64..c4119075c 100644 --- a/t/open311/endpoint/Endpoint1.pm +++ b/t/open311/endpoint/Endpoint1.pm @@ -9,8 +9,6 @@ use t::open311::endpoint::ServiceType1; use Open311::Endpoint::Service::Attribute; use Open311::Endpoint::Service::Request; -use constant request_class => 'Open311::Endpoint::Service::Request'; - sub services { return ( t::open311::endpoint::ServiceType1->new( @@ -76,7 +74,7 @@ sub services { sub post_service_request { my ($self, $service, $args) = @_; - my $request = $self->request_class->new( + my $request = $self->new_request( # NB: possible race condition between next_request_id and _add_request # (this is fine for synchronous test-cases) diff --git a/t/open311/endpoint/Endpoint2.pm b/t/open311/endpoint/Endpoint2.pm index 2b55b1e10..664a7f3d6 100644 --- a/t/open311/endpoint/Endpoint2.pm +++ b/t/open311/endpoint/Endpoint2.pm @@ -3,10 +3,6 @@ use Web::Simple; extends 't::open311::endpoint::Endpoint1'; with 'Open311::Endpoint::Role::mySociety'; -use Open311::Endpoint::Service::Request::mySociety; - -use constant request_class => 'Open311::Endpoint::Service::Request::mySociety'; - sub get_service_request_updates { my ($self, $args) = @_; diff --git a/t/open311/endpoint/Endpoint_Warwick.pm b/t/open311/endpoint/Endpoint_Warwick.pm new file mode 100644 index 000000000..f4710f63b --- /dev/null +++ b/t/open311/endpoint/Endpoint_Warwick.pm @@ -0,0 +1,36 @@ +package t::open311::endpoint::Endpoint_Warwick; +use Web::Simple; + +use Module::Loaded; +BEGIN { + mark_as_loaded('DBD::Oracle'); +} + +our %BINDINGS; +our $UPDATES_SQL; + +extends 'Open311::Endpoint::Integration::Warwick'; + +sub insert_into_db { + my ($self, $bindings) = @_; + + %BINDINGS = %$bindings; + # return ($pem_id, $error_value, $error_product); + return (1001); +} + +sub get_updates_from_sql { + my ($self, $sql) = @_; + $UPDATES_SQL = $sql; + return ( + { + row_id => 999, + service_request_id => 1001, + updated_datetime => '2014-07-23 11:07:00', + status => 'closed', + description => 'Closed the ticket', + } + ); +} + +1; diff --git a/t/open311/endpoint/warwick.t b/t/open311/endpoint/warwick.t new file mode 100644 index 000000000..7021a37d7 --- /dev/null +++ b/t/open311/endpoint/warwick.t @@ -0,0 +1,291 @@ +use strict; use warnings; + +use Test::More; +use Test::LongString; +use Test::MockTime ':all'; + +use Data::Dumper; +use JSON; + +use t::open311::endpoint::Endpoint_Warwick; + +my $endpoint = t::open311::endpoint::Endpoint_Warwick->new; +my $json = JSON->new; + +subtest "GET Service List" => sub { + my $res = $endpoint->run_test_request( GET => '/services.xml' ); + ok $res->is_success, 'xml success'; + my $expected = <<XML; +<?xml version="1.0" encoding="utf-8"?> +<services> + <service> + <description>Bridges</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>BR</service_code> + <service_name>Bridges</service_name> + <type>realtime</type> + </service> + <service> + <description>Carriageway Defect</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>CD</service_code> + <service_name>Carriageway Defect</service_name> + <type>realtime</type> + </service> + <service> + <description>Roads/Highways</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>CD</service_code> + <service_name>Roads/Highways</service_name> + <type>realtime</type> + </service> + <service> + <description>Drainage</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>DR</service_code> + <service_name>Drainage</service_name> + <type>realtime</type> + </service> + <service> + <description>Debris/Spillage</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>DS</service_code> + <service_name>Debris/Spillage</service_name> + <type>realtime</type> + </service> + <service> + <description>Fences</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>FE</service_code> + <service_name>Fences</service_name> + <type>realtime</type> + </service> + <service> + <description>Pavements</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>F D</service_code> + <service_name>Pavements</service_name> + <type>realtime</type> + </service> + <service> + <description>Gully & Catchpits</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>GC</service_code> + <service_name>Gully & Catchpits</service_name> + <type>realtime</type> + </service> + <service> + <description>Ice/Snow</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>IS</service_code> + <service_name>Ice/Snow</service_name> + <type>realtime</type> + </service> + <service> + <description>Mud & Debris</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>MD</service_code> + <service_name>Mud & Debris</service_name> + <type>realtime</type> + </service> + <service> + <description>Manhole</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>MH</service_code> + <service_name>Manhole</service_name> + <type>realtime</type> + </service> + <service> + <description>Oil Spillage</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>OS</service_code> + <service_name>Oil Spillage</service_name> + <type>realtime</type> + </service> + <service> + <description>Other</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>OT</service_code> + <service_name>Other</service_name> + <type>realtime</type> + </service> + <service> + <description>Pothole</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>PO</service_code> + <service_name>Pothole</service_name> + <type>realtime</type> + </service> + <service> + <description>Property Damage</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>PD</service_code> + <service_name>Property Damage</service_name> + <type>realtime</type> + </service> + <service> + <description>Road Marking</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>RM</service_code> + <service_name>Road Marking</service_name> + <type>realtime</type> + </service> + <service> + <description>Road traffic signs</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>SN</service_code> + <service_name>Road traffic signs</service_name> + <type>realtime</type> + </service> + <service> + <description>Traffic</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>SP</service_code> + <service_name>Traffic</service_name> + <type>realtime</type> + </service> + <service> + <description>Utilities</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>UT</service_code> + <service_name>Utilities</service_name> + <type>realtime</type> + </service> + <service> + <description>Vegetation</description> + <group>highways</group> + <keywords></keywords> + <metadata>true</metadata> + <service_code>VG</service_code> + <service_name>Vegetation</service_name> + <type>realtime</type> + </service> +</services> +XML + is $res->content, $expected + or diag $res->content; +}; + +subtest "POST OK" => sub { + set_fixed_time('2014-01-01T12:00:00Z'); + my $res = $endpoint->run_test_request( + POST => '/requests.json', + api_key => 'test', + service_code => 'PO', + address_string => '22 Acacia Avenue', + first_name => 'Bob', + last_name => 'Mould', + 'attribute[easting]' => 100, + 'attribute[northing]' => 100, + 'attribute[external_id]' => 1001, + 'attribute[closest_address]' => '22 Acacia Avenue', + ); + ok $res->is_success, 'valid request' + or diag $res->content; + + is_deeply $json->decode($res->content), + [ { + "service_notice" => "Warwickshire Open311 Endpoint", + "service_request_id" => 1001 + } ], 'correct json returned'; + + is_deeply \%t::open311::endpoint::Endpoint_Warwick::BINDINGS, + { + ':ce_surname' => 'MOULD', + ':ce_y' => '100', + ':ce_x' => '100', + ':ce_work_phone' => '', + ':ce_contact_type' => 'ENQUIRER', + ':ce_source' => 'FMS', + ':ce_doc_reference' => '1001', + ':ce_enquiry_type' => 'PO', + ':ce_email' => '', + ':ce_description' => '', + ':ce_location' => '22 Acacia Avenue', + ':ce_incident_datetime' => '2014-01-01T12:00:00Z', + ':ce_class' => 'SERV', + ':ce_compl_user_type' => 'USER', + ':ce_status_code' => 'RE', + ':ce_cat' => 'REQS', + ':ce_forename' => 'BOB' + }, + 'bindings as expected'; +}; + +subtest 'updates' => sub { + my $res = $endpoint->run_test_request( GET => '/servicerequestupdates.xml', ); + ok $res->is_success, 'valid request' or diag $res->content; + +my $expected = <<XML; +<?xml version="1.0" encoding="utf-8"?> +<service_request_updates> + <request_updates> + <description>Closed the ticket</description> + <media_url></media_url> + <service_request_id>1001</service_request_id> + <status>closed</status> + <update_id>999</update_id> + <updated_datetime>2014-07-23T11:07:00+01:00</updated_datetime> + </request_updates> +</service_request_updates> +XML + + is_string $res->content, $expected, 'xml string ok' + or diag $res->content; + + chomp (my $expected_sql = <<SQL); +SELECT * FROM ( + SELECT + row_id, + service_request_id, + to_char(updated_timedate, 'YYYY-MM-DD HH24:MI:SS'), + status, + description + FROM higatlas.fms_update + WHERE updated_timedate >= to_date(2013-12-31 12:00:00, YYYY-MM-DD HH24:MI:SS) AND (status='OPEN' OR status='CLOSED') + ORDER BY updated_timedate DESC) WHERE ROWNUM <= 1000 +SQL + + is_string $t::open311::endpoint::Endpoint_Warwick::UPDATES_SQL, $expected_sql, 'SQL as expected'; +}; + +restore_time(); +done_testing; |