diff options
Diffstat (limited to 't/cobrand')
-rw-r--r-- | t/cobrand/bucks.t | 27 | ||||
-rw-r--r-- | t/cobrand/warwickshire.t | 84 |
2 files changed, 108 insertions, 3 deletions
diff --git a/t/cobrand/bucks.t b/t/cobrand/bucks.t index a894bd377..d9273fbf8 100644 --- a/t/cobrand/bucks.t +++ b/t/cobrand/bucks.t @@ -80,10 +80,31 @@ subtest 'flytipping off road sent to extra email' => sub { is $report->external_id, undef, 'Report has right external ID'; }; -}; - $cobrand = FixMyStreet::Cobrand::Buckinghamshire->new(); +subtest 'Flytipping extra question used if necessary' => sub { + my $errors = { 'road-placement' => 'This field is required' }; + + $report->update({ bodies_str => $body->id }); + $cobrand->flytipping_body_fix($report, 'road', $errors); + is $errors->{'road-placement'}, 'This field is required', 'Error stays if sent to county'; + + $report->update({ bodies_str => $district->id }); + $report->discard_changes; # As e.g. ->bodies has been remembered. + $cobrand->flytipping_body_fix($report, 'road', $errors); + is $errors->{'road-placement'}, undef, 'Error removed if sent to district'; + + $report->update({ bodies_str => $body->id . ',' . $district->id }); + $report->discard_changes; # As e.g. ->bodies has been remembered. + $cobrand->flytipping_body_fix($report, 'road', $errors); + is $report->bodies_str, $body->id, 'Sent to both becomes sent to county on-road'; + + $report->update({ bodies_str => $district->id . ',' . $body->id }); + $report->discard_changes; # As e.g. ->bodies has been remembered. + $cobrand->flytipping_body_fix($report, 'off-road', $errors); + is $report->bodies_str, $district->id, 'Sent to both becomes sent to district off-road'; +}; + for my $test ( { desc => 'filters basic emails', @@ -151,6 +172,6 @@ for my $test ( }; } - +}; done_testing(); diff --git a/t/cobrand/warwickshire.t b/t/cobrand/warwickshire.t new file mode 100644 index 000000000..79c9f31e0 --- /dev/null +++ b/t/cobrand/warwickshire.t @@ -0,0 +1,84 @@ +#!/usr/bin/env perl + +use FixMyStreet::Test; +use FixMyStreet::DB; + +use_ok( 'Open311::PopulateServiceList' ); +use_ok( 'Open311' ); + +my $processor = Open311::PopulateServiceList->new(); +ok $processor, 'created object'; + +my $warks = FixMyStreet::DB->resultset('Body')->create({ + name => 'Warwickshire County Council', +}); +$warks->body_areas->create({ area_id => 2243 }); + +subtest 'check Warwickshire override' => sub { + my $processor = Open311::PopulateServiceList->new(); + + my $meta_xml = '<?xml version="1.0" encoding="utf-8"?> +<service_definition> + <service_code>100</service_code> + <attributes> + <attribute> + <variable>true</variable> + <code>closest_address</code> + <datatype>string</datatype> + <required>true</required> + <order>1</order> + <description>Closest address</description> + </attribute> + <attribute> + <variable>true</variable> + <code>size</code> + <datatype>string</datatype> + <required>true</required> + <order>2</order> + <description>How big is the pothole</description> + </attribute> + </attributes> +</service_definition> + '; + + my $contact = FixMyStreet::DB->resultset('Contact')->create({ + body_id => $warks->id, + email => '100', + category => 'Pothole', + state => 'confirmed', + editor => $0, + whenedited => \'current_timestamp', + note => 'test contact', + }); + + my $o = Open311->new( + jurisdiction => 'mysociety', + endpoint => 'http://example.com', + test_mode => 1, + test_get_returns => { 'services/100.xml' => $meta_xml } + ); + + $processor->_current_open311( $o ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'warwickshire' ], + }, sub { + $processor->_current_body( $warks ); + }; + $processor->_current_service( { service_code => 100, service_name => 'Pothole' } ); + $processor->_add_meta_to_contact( $contact ); + + my $extra = [ { + variable => 'true', + code => 'size', + datatype => 'string', + required => 'true', + order => 2, + description => 'How big is the pothole', + } ]; + + $contact->discard_changes; + is_deeply $contact->get_extra_fields, $extra, 'No closest_address field returned for Warks'; + is $contact->get_extra_metadata('id_field'), 'external_id', 'id_field set correctly'; +}; + +done_testing(); |