aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm24
-rw-r--r--t/open311/getservicerequestupdates.t22
2 files changed, 24 insertions, 22 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index bef1aca67..c6da37790 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -18,7 +18,7 @@ Readonly::Scalar my $AREA_ID_BROMLEY => 2482;
Readonly::Scalar my $AREA_ID_OXFORDSHIRE => 2237;
sub fetch {
- my $self = shift;
+ my ($self, $open311) = @_;
my $bodies = $self->schema->resultset('Body')->search(
{
@@ -31,25 +31,23 @@ sub fetch {
while ( my $body = $bodies->next ) {
- my $o = Open311->new(
- endpoint => $body->endpoint,
- api_key => $body->api_key,
- jurisdiction => $body->jurisdiction,
+ my %open311_conf = (
+ endpoint => $body->endpoint,
+ api_key => $body->api_key,
+ jurisdiction => $body->jurisdiction,
extended_statuses => $body->send_extended_statuses,
);
- # custom endpoint URLs because these councils have non-standard paths
- if ( $body->areas->{$AREA_ID_BROMLEY} ) {
- my $endpoints = $o->endpoints;
- $endpoints->{update} = 'update.xml';
- $endpoints->{service_request_updates} = 'update.xml';
- $o->endpoints( $endpoints );
- }
+ my $cobrand = $body->get_cobrand_handler;
+ $cobrand->call_hook(open311_config_updates => \%open311_conf)
+ if $cobrand;
+
+ $open311 //= Open311->new(%open311_conf);
$self->suppress_alerts( $body->suppress_alerts );
$self->blank_updates_permitted( $body->blank_updates_permitted );
$self->system_user( $body->comment_user );
- $self->update_comments( $o, $body );
+ $self->update_comments( $open311, $body );
}
}
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 2f7917946..7ebab3b3f 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -21,8 +21,15 @@ my $user = FixMyStreet::DB->resultset('User')->find_or_create(
my %bodies = (
2237 => FixMyStreet::DB->resultset("Body")->create({ name => 'Oxfordshire' }),
- 2482 => FixMyStreet::DB->resultset("Body")->create({ name=> 'Bromley', id => 2482 }),
- 2651 => FixMyStreet::DB->resultset("Body")->new({ id => 2651 }),
+ 2482 => FixMyStreet::DB->resultset("Body")->create({
+ name => 'Bromley',
+ send_method => 'Open311',
+ send_comments => 1,
+ endpoint => 'endpoint',
+ comment_user_id => $user->id,
+ blank_updates_permitted => 1,
+ }),
+ 2651 => FixMyStreet::DB->resultset("Body")->new({ id => 123 }),
);
$bodies{2237}->body_areas->create({ area_id => 2237 });
@@ -141,7 +148,7 @@ my $problem = $problem_rs->new(
lastupdate => DateTime->now()->subtract( days => 1 ),
anonymous => 1,
external_id => time(),
- bodies_str => 2482,
+ bodies_str => $bodies{2482}->id,
}
);
@@ -421,11 +428,8 @@ for my $test (
$problem->state( $test->{start_state} );
$problem->update;
- my $update = Open311::GetServiceRequestUpdates->new(
- system_user => $user,
- blank_updates_permitted => 1,
- );
- $update->update_comments( $o, $bodies{2482} );
+ my $update = Open311::GetServiceRequestUpdates->new;
+ $update->fetch($o);
is $problem->comments->count, 1, 'comment count';
$problem->discard_changes;
@@ -580,7 +584,7 @@ my $problem2 = $problem_rs->create(
lastupdate => DateTime->now(),
anonymous => 1,
external_id => $problem->external_id,
- bodies_str => 2651,
+ bodies_str => $bodies{2651}->id,
}
);