aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/controller/admin.t2
-rw-r--r--t/open311.t20
-rw-r--r--t/open311/getservicerequestupdates.t22
-rw-r--r--t/open311/post-service-request-updates.t107
4 files changed, 140 insertions, 11 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index b69a711c8..a0a93d996 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -129,7 +129,7 @@ subtest 'check summary counts' => sub {
subtest "Check admin_base_url" => sub {
my $rs = FixMyStreet::App->model('DB::Problem');
- my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($report->cobrand)->new();
+ my $cobrand = $report->get_cobrand_logged;
is ($report->admin_url($cobrand),
(sprintf 'http://www.example.org/admin/report_edit/%d', $report_id),
diff --git a/t/open311.t b/t/open311.t
index e1ad578d7..ef52eb538 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -415,10 +415,26 @@ foreach my $test (
status => 'OPEN',
extended => 'IN_PROGRESS',
},
+ {
+ desc => 'comment that marks problem open sends OPEN if not mark_reopen',
+ state => 'confirmed',
+ status => 'OPEN',
+ extended => 'OPEN',
+ mark_open => 1,
+ },
+ {
+ desc => 'comment that marks problem open sends REOPEN if mark_reopen',
+ state => 'confirmed',
+ status => 'OPEN',
+ extended => 'REOPEN',
+ mark_open => 1,
+ mark_reopen => 1,
+ },
) {
subtest $test->{desc} => sub {
$comment->problem_state( $test->{state} );
$comment->problem->state( $test->{state} );
+ $comment->mark_open(1) if $test->{mark_open};
my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' );
@@ -426,7 +442,9 @@ foreach my $test (
is $c->param('status'), $test->{status}, 'correct status';
if ( $test->{extended} ) {
- my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', { extended_statuses => 1 } );
+ my $params = { extended_statuses => 1 };
+ $params->{mark_reopen} = 1 if $test->{mark_reopen};
+ my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', $params );
my $c = CGI::Simple->new( $results->{ req }->content );
is $c->param('status'), $test->{extended}, 'correct extended status';
}
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,
}
);
diff --git a/t/open311/post-service-request-updates.t b/t/open311/post-service-request-updates.t
new file mode 100644
index 000000000..5c8211bbf
--- /dev/null
+++ b/t/open311/post-service-request-updates.t
@@ -0,0 +1,107 @@
+#!/usr/bin/env perl
+
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
+
+use_ok( 'Open311::PostServiceRequestUpdates' );
+
+my $o = Open311::PostServiceRequestUpdates->new( site => 'fixmystreet.com' );
+
+my $params = {
+ send_method => 'Open311',
+ send_comments => 1,
+ api_key => 'KEY',
+ endpoint => 'endpoint',
+ jurisdiction => 'home',
+};
+my $bromley = $mech->create_body_ok(2482, 'Bromley', { %$params, send_extended_statuses => 1 });
+my $oxon = $mech->create_body_ok(2237, 'Oxfordshire', $params);
+my $bucks = $mech->create_body_ok(2217, 'Buckinghamshire', $params);
+my $lewisham = $mech->create_body_ok(2492, 'Lewisham', $params);
+
+subtest 'Check Open311 params' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => ['fixmystreet', 'bromley', 'buckinghamshire', 'lewisham', 'oxfordshire'],
+ }, sub {
+ my $result = {
+ endpoint => 'endpoint',
+ jurisdiction => 'home',
+ api_key => 'KEY',
+ extended_statuses => undef,
+ };
+ my %conf = $o->open311_params($bromley);
+ is_deeply \%conf, {
+ %$result,
+ extended_statuses => 1,
+ use_extended_updates => 1,
+ endpoints => { service_request_updates => 'update.xml', update => 'update.xml' },
+ }, 'Bromley params match';
+ %conf = $o->open311_params($oxon);
+ is_deeply \%conf, {
+ %$result,
+ use_customer_reference => 1
+ }, 'Oxfordshire params match';
+ %conf = $o->open311_params($bucks);
+ is_deeply \%conf, {
+ %$result,
+ mark_reopen => 1,
+ }, 'Bucks params match';
+ %conf = $o->open311_params($lewisham);
+ is_deeply \%conf, $result, 'Lewisham params match';
+ };
+};
+
+my $other_user = $mech->create_user_ok('test2@example.com', title => 'MRS');
+
+sub c {
+ my ($p, $user) = @_;
+ my $c = $mech->create_comment_for_problem($p, $user || $p->user, 'Name', 'Update text', 'f', 'confirmed', 'confirmed', { confirmed => \'current_timestamp' });
+ return $c;
+}
+
+sub p_and_c {
+ my ($body, $user) = @_;
+
+ my $prob_params = { send_method_used => 'Open311', whensent => \'current_timestamp', external_id => 1 };
+ my ($p) = $mech->create_problems_for_body(1, $body->id, 'Title', $prob_params);
+ my $c = c($p, $user);
+ return ($p, $c);
+}
+
+my ($p1, $c1) = p_and_c($bromley, $other_user);
+my ($p2, $c2) = p_and_c($oxon);
+my ($p3, $c3a) = p_and_c($bucks);
+my $c3b = c($p3, $other_user);
+my ($p4, $c4) = p_and_c($lewisham);
+
+subtest 'Send comments' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => ['fixmystreet', 'bromley', 'buckinghamshire', 'lewisham', 'oxfordshire'],
+ }, sub {
+ $o->send;
+ $c3a->discard_changes;
+ is $c3a->extra, undef, 'Bucks update by owner was sent';
+ $c3b->discard_changes;
+ is $c3b->extra->{cobrand_skipped_sending}, 1, 'Bucks update by other was not';
+ $c1->discard_changes;
+ is $c1->extra->{title}, "MRS", 'Title set on Bromley update';
+ $c2->discard_changes;
+ is $c2->send_fail_count, 0, 'Oxfordshire update skipped entirely';
+ };
+};
+
+subtest 'Oxfordshire gets an ID' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => ['fixmystreet', 'bromley', 'buckinghamshire', 'lewisham', 'oxfordshire'],
+ }, sub {
+ $p2->set_extra_metadata(customer_reference => 'ABC');
+ $p2->update;
+ $o->send;
+ $c2->discard_changes;
+ is $c2->send_fail_count, 1, 'Oxfordshire update tried to send, failed';
+ };
+};
+
+
+done_testing();