Skip to content

Commit

Permalink
[Camden] Resend if backend changes.
Browse files Browse the repository at this point in the history
If a category change means the backend system has changed.
  • Loading branch information
dracos committed Aug 29, 2024
1 parent 3f05259 commit 075bed2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
44 changes: 44 additions & 0 deletions perllib/FixMyStreet/Cobrand/Camden.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ sub disambiguate_location {
};
}

=over 4
=item * We customise the default report title field label and hint
=cut

sub new_report_title_field_label {
"Location of the problem"
}
Expand All @@ -51,16 +57,54 @@ sub new_report_title_field_hint {
"e.g. outside no.18, or near postbox"
}

=item * We do not send questionnaires
=cut

sub send_questionnaires {
return 0;
}

=item * We link to Camden's site for the privacy policy
=cut

sub privacy_policy_url {
'https://www.camden.gov.uk/data-protection-privacy-and-cookies'
}

=item * camden.gov.uk users can always be found in the admin
=cut

sub admin_user_domain { 'camden.gov.uk' }

=item * A category change from one backend type to another is auto-resent
=back
=cut

sub _contact_type {
my $contact = shift;
return 'Confirm' if $contact->email =~ /^ConfirmTrees-/;
return 'Email' if ($_->send_method || '') eq 'Email';
return 'Symology';
}

sub category_change_force_resend {
my ($self, $old, $new) = @_;

# Get the Open311 identifiers
my $contacts = $self->{c}->stash->{contacts};
($old) = map { _contact_type($_) } grep { $_->category eq $old } @$contacts;
($new) = map { _contact_type($_) } grep { $_->category eq $new } @$contacts;

return 0 if $old eq 'Confirm' && $new eq 'Confirm';
return 0 if $old eq 'Symology' && $new eq 'Symology';
return 1;
}

sub lookup_site_code_config {
my ($self, $property) = @_;

Expand Down
35 changes: 23 additions & 12 deletions t/cobrand/camden.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ my $camden = $mech->create_body_ok(CAMDEN_MAPIT_ID, 'Camden Council', {

$mech->create_contact_ok(body_id => $camden->id, category => 'Potholes', email => '[email protected]');
my $staffuser = $mech->create_user_ok( '[email protected]', name => 'Staffer', from_body => $camden );
$staffuser->user_body_permissions->create( { body => $camden, permission_type => 'report_edit' } );

$mech->create_contact_ok(
body_id => $camden->id,
Expand All @@ -33,6 +34,12 @@ $mech->create_contact_ok(
group => 'Hired e-bike or e-scooter',
);

$mech->create_contact_ok(
body_id => $camden->id,
category => 'Tree',
email => 'ConfirmTrees-trees',
);

my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'camden', 'tfl' ],
Expand All @@ -49,7 +56,7 @@ FixMyStreet::override_config {
ok $mech->host('camden.fixmystreet.com'), 'set host';

my $json = $mech->get_ok_json('/report/new/ajax?latitude=51.529432&longitude=-0.124514');
is_deeply [sort keys %{$json->{by_category}}], ['Abandoned yellow bike', 'Potholes'], "Camden doesn't have River Piers category";
is_deeply [sort keys %{$json->{by_category}}], ['Abandoned yellow bike', 'Potholes', 'Tree'], "Camden doesn't have River Piers category";
};

subtest "show my name publicly checkbox doesn't appear on Camden's cobrand" => sub {
Expand Down Expand Up @@ -96,17 +103,7 @@ FixMyStreet::override_config {
$mech->get_ok('/report/' . $report->id);
$mech->content_lacks('Show my name publicly');
$mech->content_lacks('may_show_name');
};

subtest "reports that aren't anonymous still don't show the name" => sub {
my ($report) = $mech->create_problems_for_body(1, $camden->id, {
anonymous => 0,
cobrand => 'camden',
name => 'Test User',
});

$mech->get_ok('/report/' . $report->id);
$mech->content_lacks('Test User');
$mech->content_lacks('Test User', "still don't show the name");
};

subtest "updates that aren't anonymous still don't show the name" => sub {
Expand Down Expand Up @@ -136,6 +133,7 @@ FixMyStreet::override_config {
my ($p) = $mech->create_problems_for_body(1, $camden->id, 'Title', {
cobrand => 'camden',
category => 'Abandoned yellow bike',
areas => ',2505,', # So admin categories_for_point can get Camden results
} );

FixMyStreet::Script::Reports::send();
Expand All @@ -149,6 +147,19 @@ FixMyStreet::override_config {

$mech->email_count_is(1);
};

subtest 're-categorising auto-resends' => sub {
my $report = FixMyStreet::DB->resultset('Problem')->order_by('-id')->first;
is $report->send_state, 'sent';
$mech->get_ok('/admin/report_edit/' . $report->id);
$mech->submit_form_ok({ with_fields => { category => 'Tree' } });
$report->discard_changes;
is $report->send_state, 'unprocessed';
$report->update({ send_state => 'sent' });
$mech->submit_form_ok({ with_fields => { category => 'Potholes' } });
$report->discard_changes;
is $report->send_state, 'unprocessed';
};
};

done_testing;

0 comments on commit 075bed2

Please sign in to comment.