1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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();
|