aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm28
-rw-r--r--perllib/Integrations/Echo.pm58
-rw-r--r--t/app/controller/waste.t12
3 files changed, 98 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index 6441180e3..ed96eb1bb 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -561,5 +561,33 @@ sub _parse_schedules {
};
}
+sub bin_future_collections {
+ my $self = shift;
+
+ my $services = $self->{c}->stash->{service_data};
+ my @tasks;
+ my %names;
+ foreach (@$services) {
+ push @tasks, $_->{service_task_id};
+ $names{$_->{service_task_id}} = $_->{service_name};
+ }
+
+ my $echo = $self->feature('echo');
+ $echo = Integrations::Echo->new(%$echo);
+ my $result = $echo->GetServiceTaskInstances(@tasks);
+
+ my $events = [];
+ foreach (@$result) {
+ my $task_id = $_->{ServiceTaskRef}{Value}{anyType};
+ my $tasks = Integrations::Echo::force_arrayref($_->{Instances}, 'ScheduledTaskInfo');
+ foreach (@$tasks) {
+ my $dt = construct_bin_date($_->{CurrentScheduledDate});
+ my $summary = $names{$task_id} . ' collection';
+ my $desc = '';
+ push @$events, { date => $dt, summary => $summary, desc => $desc };
+ }
+ }
+ return $events;
+}
1;
diff --git a/perllib/Integrations/Echo.pm b/perllib/Integrations/Echo.pm
index 3bcbfc69b..7dc2e6948 100644
--- a/perllib/Integrations/Echo.pm
+++ b/perllib/Integrations/Echo.pm
@@ -2,8 +2,10 @@ package Integrations::Echo;
use strict;
use warnings;
+use DateTime;
use Moo;
use Tie::IxHash;
+use FixMyStreet;
has attr => ( is => 'ro', default => 'http://www.twistedfish.com/xmlns/echo/api/v1' );
has action => ( is => 'lazy', default => sub { $_[0]->attr . "/Service/" } );
@@ -21,6 +23,7 @@ has endpoint => (
SOAP::Lite->soapversion(1.2);
my $soap = SOAP::Lite->on_action( sub { $self->action . $_[1]; } )->proxy($self->url);
$soap->serializer->register_ns("http://schemas.microsoft.com/2003/10/Serialization/Arrays", 'msArray'),
+ $soap->serializer->register_ns("http://schemas.datacontract.org/2004/07/System", 'dataContract');
return $soap;
},
);
@@ -248,6 +251,61 @@ sub GetServiceUnitsForObject {
return force_arrayref($res, 'ServiceUnit');
}
+sub GetServiceTaskInstances {
+ my ($self, @tasks) = @_;
+
+ my @objects;
+ foreach (@tasks) {
+ my $obj = ixhash(
+ Key => 'Id',
+ Type => 'ServiceTask',
+ Value => [
+ { 'msArray:anyType' => $_ },
+ ],
+ );
+ push @objects, { ObjectRef => $obj };
+ }
+ my $start = DateTime->now->set_time_zone(FixMyStreet->local_time_zone)->truncate( to => 'day' );
+ my $end = $start->clone->add(months => 3);
+ my $query = ixhash(
+ From => dt_to_hash($start),
+ To => dt_to_hash($end),
+ );
+ return [
+ { ServiceTaskRef => { Value => { anyType => 401 } },
+ Instances => { ScheduledTaskInfo => [
+ { CurrentScheduledDate => { DateTime => '2020-07-01T00:00:00Z' } },
+ ] }
+ },
+ { ServiceTaskRef => { Value => { anyType => 402 } },
+ Instances => { ScheduledTaskInfo => [
+ { CurrentScheduledDate => { DateTime => '2020-07-08T00:00:00Z' } },
+ ] }
+ },
+ ] if $self->sample_data;
+ # uncoverable statement
+ my $res = $self->call('GetServiceTaskInstances',
+ serviceTaskRefs => \@objects,
+ query => $query,
+ );
+ return force_arrayref($res, 'ServiceTaskInstances');
+}
+
+sub ixhash {
+ tie (my %data, 'Tie::IxHash', @_);
+ return \%data;
+}
+
+sub dt_to_hash {
+ my $dt = shift;
+ my $utc = $dt->clone->set_time_zone('UTC');
+ $dt = ixhash(
+ 'dataContract:DateTime' => $utc->ymd . 'T' . $utc->hms . 'Z',
+ 'dataContract:OffsetMinutes' => $dt->offset / 60,
+ );
+ return $dt;
+}
+
sub force_arrayref {
my ($res, $key) = @_;
return [] unless $res;
diff --git a/t/app/controller/waste.t b/t/app/controller/waste.t
index bbd0cd00a..9bc03e169 100644
--- a/t/app/controller/waste.t
+++ b/t/app/controller/waste.t
@@ -116,6 +116,18 @@ FixMyStreet::override_config {
$mech->get_ok('/waste/uprn/1000000002/enquiry?service=1');
is $mech->uri->path, '/waste/uprn/1000000002';
};
+ subtest 'Checking calendar' => sub {
+ $mech->follow_link_ok({ text => 'Add to your calendar (.ics file)' });
+ $mech->content_contains('BEGIN:VCALENDAR');
+ my @events = split /BEGIN:VEVENT/, $mech->encoded_content;
+ shift @events; # Header
+ my $i = 0;
+ foreach (@events) {
+ $i++ if /DTSTART;VALUE=DATE:20200701/ && /SUMMARY:Refuse collection/;
+ $i++ if /DTSTART;VALUE=DATE:20200708/ && /SUMMARY:Paper & Cardboard/;
+ }
+ is $i, 2, 'Two events from the sample data in the calendar';
+ };
subtest 'General enquiry, on behalf of someone else' => sub {
$mech->log_in_ok($staff_user->email);
$mech->get_ok('/waste/uprn/1000000002/enquiry?category=General+enquiry&service_id=537');