Skip to content

Commit

Permalink
[Peterborough] Bulky text updates/staff only.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Oct 25, 2024
1 parent cea77c2 commit fdf0144
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 41 deletions.
3 changes: 2 additions & 1 deletion perllib/FixMyStreet/App/Form/Waste/Bulky.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ has_page about_you => (
next => 'choose_date_earlier',
update_field_list => sub {
my $form = shift;
if ($form->{c}->stash->{waste_features}->{bulky_offer_text_updates}) {
my $c = $form->{c};
if ($c->stash->{waste_features}->{bulky_offer_text_updates} && $c->stash->{is_staff}) {
$form->field('extra_bulky_text_reminders')->inactive(0);
};
},
Expand Down
5 changes: 3 additions & 2 deletions perllib/FixMyStreet/Cobrand/Peterborough.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1326,12 +1326,13 @@ sub _bulky_send_optional_text {
Date: %s
Items: %d
%s
View more details or cancel: %s",
Reference: %d
Please note the items put out for collection must be the items you specified when you booked.",
$title,
$self->bulky_nice_collection_date($report->get_extra_field_value('DATE')),
scalar grep ({ $_->{name} =~ /^ITEM/ && $_->{value} } @{$report->get_extra_fields}),
$address,
$url);
$report->id);
FixMyStreet::SMS->new(cobrand => $self, notify_choice => 'waste')->send(

Check warning on line 1336 in perllib/FixMyStreet/Cobrand/Peterborough.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Peterborough.pm#L1336

Added line #L1336 was not covered by tests
%message_data,
);
Expand Down
101 changes: 63 additions & 38 deletions t/app/controller/waste_peterborough_bulky.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FixMyStreet::App->log->disable('info');
END { FixMyStreet::App->log->enable('info'); }

my $notify = Test::MockModule->new('FixMyStreet::SMS');
my $sent_sms = 0;

my $mock = Test::MockModule->new('FixMyStreet::Cobrand::Peterborough');
$mock->mock('_fetch_features', sub { ok 0, 'This should not be called by waste'; });
Expand Down Expand Up @@ -378,15 +379,10 @@ FixMyStreet::override_config {
$mech->content_contains('Aragon Direct Services may contact you to obtain more');
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge' } });
$mech->content_contains('Please provide an email address');
$mech->content_contains('Do you want to receive reminders about this collection by text message?');
$mech->content_lacks('Do you want to receive reminders about this collection by text message?'); # Reminder staff only
$mech->submit_form(with_fields => { name => 'Bob Marge', email => '', phone => '44 07 111 111 111' });
$mech->content_contains('Please provide an email address', 'Can not proceed without email if text notifications unchecked');
$mech->submit_form(with_fields => { name => 'Bob Marge', email => $user->email, phone => '', extra_bulky_text_reminders => '1' });
$mech->content_contains('Please enter a mobile phone number to receive text updates', 'Can not proceed without mobile number if text notifications checked');
$mech->submit_form(with_fields => { name => 'Bob Marge', email => '', phone => '44 07 111 111 111', extra_bulky_text_reminders => '1' });
$mech->content_contains('Choose date for collection', "Can proceed without email if mobile number and text notifications checked");
$mech->back;
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge', email => $user->email, phone => '44 07 111 111 111', extra_bulky_text_reminders => '1' }});
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge', email => $user->email, phone => '44 07 111 111 111' }});
};

subtest 'Choose date page' => sub {
Expand Down Expand Up @@ -891,22 +887,8 @@ FixMyStreet::override_config {
};

subtest 'Bulky goods email confirmation and reminders' => sub {

my $report_id = $report->id;

$notify->mock('send', sub {
my $self = shift;
my %params = @_;

is $params{'to'} eq '44 07 111 111 111', 1, "Correct text 'to' value";
is $params{'body'} =~ /^Bulky waste booking/, 1, 'Correct text title';
is $params{'body'} =~ /Date: Friday 26 August 2022/, 1, 'Correct text date';
is $params{'body'} =~ /Items: 2/, 1, 'Correct text item count';
is $params{'body'} =~ /Address: 1 Pope Way, Peterborough, PE1 3NA/, 1, 'Correct text address';
is $params{'body'} =~ m#View more details or cancel: http://peterborough.example.org/report/$report_id#, 1, 'Correct text link';
return 1;
});

subtest 'Email confirmation of booking' => sub {
FixMyStreet::Script::Reports::send();
my $email = $mech->get_email->as_string;
Expand All @@ -917,21 +899,6 @@ FixMyStreet::override_config {
};

sub reminder_check {

$notify->mock('send', sub {
my $self = shift;
my %params = @_;

is $params{'to'} eq '44 07 111 111 111', 1, "Correct text 'to' value";
is $params{'body'} =~ /^Bulky waste reminder/, 1, 'Correct text title';
is $params{'body'} =~ /Date: Friday 26 August 2022/, 1, 'Correct text date';
is $params{'body'} =~ /Items: 2/, 1, 'Correct text item count';
is $params{'body'} =~ /Address: 1 Pope Way, Peterborough, PE1 3NA/, 1, 'Correct text address';
is $params{'body'} =~ m#View more details or cancel: http://peterborough.example.org/M.*#, 1, 'Correct text link';
is $params{'body'} =~ /^Bulky waste reminder/, 1, 'Correct text title';
return 1;
});

my ($day, $time, $days, $report_id) = @_;
set_fixed_time("2022-08-$day" . "T$time:00:00Z");
$cobrand->bulky_reminders;
Expand Down Expand Up @@ -982,7 +949,10 @@ FixMyStreet::override_config {

$mech->submit_form_ok;
$mech->submit_form_ok({ with_fields => { resident => 'Yes' } });
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge', email => $user->email }});
$mech->submit_form(with_fields => { name => 'Bob Marge', email => $user->email, phone => '', extra_bulky_text_reminders => '1' });
$mech->content_contains('Please enter a mobile phone number to receive text updates', 'Can not proceed without mobile number if text notifications checked');
$mech->submit_form(with_fields => { name => 'Bob Marge', email => '', phone => '44 07 111 111 111', extra_bulky_text_reminders => '1' });
$mech->content_contains('Choose date for collection', "Can proceed without email if mobile number and text notifications checked");
$mech->content_contains('05 August');
$mech->content_lacks('12 August'); # Still full from above
$mech->content_contains('19 August'); # Max of 2 dates fetched
Expand Down Expand Up @@ -1031,7 +1001,62 @@ FixMyStreet::override_config {
$mech->submit_form_ok({ with_fields => { show_later_dates => 1 } });
$mech->content_like(qr/name="chosen_date" value="2022-08-26T00:00:00"\s+disabled/, 'Already booked date disabled');
$mech->content_like(qr/name="chosen_date" value="2022-09-02T00:00:00"\s+checked\s+>/, 'Existing booked date not disabled');
$report2->update({ external_id => undef, send_state => 'sent' });
$report2->update({ external_id => undef });
};

subtest 'Text message confirmation/reminders' => sub {
my $report_id = $report2->id;

$notify->mock('send', sub {
my $self = shift;
my %params = @_;
$sent_sms++;

is $params{'to'}, '+44 7111 111111', "Correct text 'to' value";
like $params{'body'}, qr/^Bulky waste booking/, 'Correct text title';
like $params{'body'}, qr/Date: Friday 02 September 2022/, 'Correct text date';
like $params{'body'}, qr/Items: 1/, 'Correct text item count';
like $params{'body'}, qr/Address: 1 Pope Way, Peterborough, PE1 3NA/, 'Correct text address';
like $params{'body'}, qr#Reference: $report_id#, 'Correct text link';
return 1;
});

subtest 'Text confirmation of booking' => sub {
FixMyStreet::Script::Reports::send();
is $sent_sms, 1;
};

$notify->mock('send', sub {
my $self = shift;
my %params = @_;
$sent_sms++;

is $params{'to'}, '+44 7111 111111', "Correct text 'to' value";
like $params{'body'}, qr/^Bulky waste reminder/, 'Correct text title';
like $params{'body'}, qr/Date: Friday 02 September 2022/, 'Correct text date';
like $params{'body'}, qr/Items: 1/, 'Correct text item count';
like $params{'body'}, qr/Address: 1 Pope Way, Peterborough, PE1 3NA/, 'Correct text address';
like $params{'body'}, qr#Reference: $report_id#, 'Correct text link';
return 1;
});

sub reminder_check2 {
my ($day, $time, $days) = @_;
set_fixed_time("2022-$day" . "T$time:00:00Z");
$cobrand->bulky_reminders;
}
subtest 'Text reminders' => sub {
reminder_check2('08-29', 10, 0);
reminder_check2('08-30', 10, 3);
reminder_check2('08-30', 11, 0);
reminder_check2('08-31', 10, 0);
reminder_check2('09-01', 10, 1);
reminder_check2('09-01', 11, 0);
reminder_check2('09-02', 10, 0);
is $sent_sms, 3;
};
$report2->discard_changes;
$report2->update({ external_id => undef });
};

subtest 'Cancellation' => sub {
Expand Down

0 comments on commit fdf0144

Please sign in to comment.