Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Feb 17, 2025
1 parent 5735604 commit 9a10b99
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 114 deletions.
6 changes: 2 additions & 4 deletions perllib/FixMyStreet/Cobrand/Bexley/Garden.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ sub lookup_subscription_for_uprn {
my $customer = $results->{Customers}[0];
return undef unless $customer && $customer->{ServiceContracts};
# Assume there is only one active subscription
my ($contract) = grep {
$_->{ServiceContractStatus} eq 'ACTIVE'
|| $_->{ServiceContractStatus} eq 'PRECONTRACT'
} @{ $customer->{ServiceContracts} // [] };
my $contract = $customer->{ServiceContracts}[0];
return unless $contract;

# XXX should maybe sort by CreatedDate rather than assuming first is OK
Expand Down Expand Up @@ -129,6 +126,7 @@ sub garden_current_subscription {
service_name => "Brown wheelie bin",
service_id => "GA-240",
schedule => "Pending",
round_schedule => '',
next => { pending => 1 },
};
push @$services, $service;
Expand Down
331 changes: 221 additions & 110 deletions t/app/controller/waste_bexley_garden.t
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ FixMyStreet::override_config {

FixMyStreet::Script::Reports::send();
my @emails = $mech->get_email;
my $body = $mech->get_text_body_from_email($emails[1]);
my $email_body = $mech->get_text_body_from_email($emails[1]);
TODO: {
local $TODO = 'Quantity not yet read in _garden_data.html';
like $body, qr/Number of bin subscriptions: 2/;
like $email_body, qr/Number of bin subscriptions: 2/;
}
like $body, qr/Bins to be delivered: 2/;
like $body, qr/Total:.*?$test->{pounds_cost}/;
like $email_body, qr/Bins to be delivered: 2/;
like $email_body, qr/Total:.*?$test->{pounds_cost}/;
$mech->clear_emails_ok;
};

Expand Down Expand Up @@ -296,13 +296,13 @@ FixMyStreet::override_config {
$mech->clear_emails_ok;
FixMyStreet::Script::Reports::send();
my @emails = $mech->get_email;
my $body = $mech->get_text_body_from_email($emails[1]);
my $email_body = $mech->get_text_body_from_email($emails[1]);
TODO: {
local $TODO = 'Quantity not yet read in _garden_data.html';
like $body, qr/Number of bin subscriptions: 1/;
like $email_body, qr/Number of bin subscriptions: 1/;
}
unlike $body, qr/Bins to be delivered/;
like $body, qr/Total:.*?75.00/;
unlike $email_body, qr/Bins to be delivered/;
like $email_body, qr/Total:.*?75.00/;
};

subtest 'check new sub credit card payment with one less bin required' => sub {
Expand Down Expand Up @@ -331,126 +331,237 @@ FixMyStreet::override_config {
$mech->clear_emails_ok;
FixMyStreet::Script::Reports::send();
my @emails = $mech->get_email;
my $body = $mech->get_text_body_from_email($emails[1]);
my $email_body = $mech->get_text_body_from_email($emails[1]);
TODO: {
local $TODO = 'Quantity not yet read in _garden_data.html';
like $body, qr/Number of bin subscriptions: 1/;
like $email_body, qr/Number of bin subscriptions: 1/;
}
like $body, qr/Bins to be removed: 1/;
like $body, qr/Total:.*?75.00/;
like $email_body, qr/Bins to be removed: 1/;
like $email_body, qr/Total:.*?75.00/;
};

subtest 'cancel garden subscription' => sub {
subtest 'renew garden subscription' => sub {
set_fixed_time('2024-02-01T00:00:00');

$agile_mock->mock( 'CustomerSearch', sub { {
Customers => [
{
CustomerExternalReference => 'CUSTOMER_123',
ServiceContracts => [
my $uprn = 10001;
my $contract_id = 'CONTRACT_123';

# subtest 'with Agile data only' => sub {
# subtest 'within renewal window' => sub {
# $agile_mock->mock( 'CustomerSearch', sub { {
# Customers => [
# {
# CustomerExternalReference => 'CUSTOMER_123',
# ServiceContracts => [
# {
# # One month away
# EndDate => '01/03/2024 12:00',
# Reference => $contract_id,
# },
# ],
# },
# ],
# } } );

# $mech->get_ok("/waste/$uprn");

# };

# # subtest 'too early' => sub {
# # $agile_mock->mock( 'CustomerSearch', sub { {
# # Customers => [
# # {
# # CustomerExternalReference => 'CUSTOMER_123',
# # ServiceContracts => [
# # {
# # # 2 months away
# # EndDate => '01/04/2024 12:00',
# # },
# # ],
# # },
# # ],
# # } } );
# # };

# # subtest 'subscription expired' => sub {
# # $agile_mock->mock( 'CustomerSearch', sub { {
# # Customers => [
# # {
# # CustomerExternalReference => 'CUSTOMER_123',
# # ServiceContracts => [
# # {
# # # 1 month ago
# # EndDate => '01/01/2024 12:00',
# # },
# # ],
# # },
# # ],
# # } } );
# # };
# };

subtest 'with DB data' => sub {
my ($new_sub_report) = $mech->create_problems_for_body(
1,
$body->id,
'Garden Subscription - New',
{ category => 'Garden Subscription',
external_id => "Agile-$contract_id",
},
);
$new_sub_report->set_extra_fields(
{ name => 'uprn', value => $uprn } );
$new_sub_report->update;

subtest 'within renewal window' => sub {
$agile_mock->mock( 'CustomerSearch', sub { {
Customers => [
{
EndDate => '12/12/2025 12:21',
CustomerExternalReference => 'CUSTOMER_123',
ServiceContracts => [
{
# 42 days away
EndDate => '14/03/2024 12:00',
Reference => $contract_id,
},
],
},
],
},
],
} } );

$mech->log_in_ok( $user->email );
} } );

subtest 'with Agile data only' => sub {
$mech->get_ok('/waste/10001');
like $mech->text, qr/Brown wheelie bin/;
like $mech->text, qr/Next collectionPending/;
$mech->get_ok("/waste/$uprn");
# warn "====\n\t" . $mech->text . "\n=÷===";
# warn "====\n\t" . $mech->content . "\n====";
like $mech->content, qr/14 March 2024, soon due for renewal/,
'"Due soon" message shown';
like $mech->content,
qr/Renew your brown wheelie bin subscription/,
'Renewal link available';
like $mech->text, qr/Frequency.*Pending/, 'Pending details because no Whitespace data';

$mech->get_ok('/waste/10001/garden_cancel');
like $mech->text, qr/Cancel your garden waste subscription/;

$mech->submit_form_ok(
{ with_fields => {
reason => 'Other',
reason_further_details => 'Burnt all my leaves',
confirm => 1,
},
}
);
like $mech->text, qr/Your subscription has been cancelled/,
'form submitted OK';

my $report
= FixMyStreet::DB->resultset('Problem')->order_by('-id')
->first;

is $report->get_extra_field_value('customer_external_ref'),
'CUSTOMER_123';
is $report->get_extra_field_value('due_date'),
'12/12/2025';
is $report->get_extra_field_value('reason'),
'Other: Burnt all my leaves';

$mech->clear_emails_ok;
FixMyStreet::Script::Reports::send();

my @emails = $mech->get_email;
my $body = $mech->get_text_body_from_email($emails[1]);
like $body, qr/You have cancelled your garden waste collection service/;
};
};

subtest 'with Whitespace data' => sub {
$whitespace_mock->mock(
'GetSiteCollections',
sub {
[ { SiteServiceID => 1,
ServiceItemDescription => 'Garden waste',
ServiceItemName => 'GA-140', # Garden 140 ltr Bin
ServiceName => 'Brown Wheelie Bin',
NextCollectionDate => '2024-02-07T00:00:00',
SiteServiceValidFrom => '2024-01-01T00:00:00',
SiteServiceValidTo => '0001-01-01T00:00:00',

RoundSchedule => 'RND-1 Mon',
}
];
}
);
# subtest 'too early' => sub {

$mech->get_ok('/waste/10001');
like $mech->content, qr/waste-service-subtitle.*Garden waste/s;
# };

$mech->get_ok('/waste/10001/garden_cancel');
like $mech->text, qr/Cancel your garden waste subscription/;
# subtest 'subscription expired' => sub {

$mech->submit_form_ok(
{ with_fields => {
reason => 'Other',
reason_further_details => 'Burnt all my leaves',
confirm => 1,
},
}
);
like $mech->text, qr/Your subscription has been cancelled/,
'form submitted OK';

my $report
= FixMyStreet::DB->resultset('Problem')->order_by('-id')
->first;

is $report->get_extra_field_value('customer_external_ref'),
'CUSTOMER_123';
is $report->get_extra_field_value('due_date'),
'12/12/2025';
is $report->get_extra_field_value('reason'),
'Other: Burnt all my leaves';

$mech->clear_emails_ok;
FixMyStreet::Script::Reports::send();

my @emails = $mech->get_email;
my $body = $mech->get_text_body_from_email($emails[1]);
like $body, qr/You have cancelled your garden waste collection service/;
# };
};

};

# subtest 'cancel garden subscription' => sub {
# set_fixed_time('2024-02-01T00:00:00');

# $agile_mock->mock( 'CustomerSearch', sub { {
# Customers => [
# {
# CustomerExternalReference => 'CUSTOMER_123',
# ServiceContracts => [
# {
# EndDate => '12/12/2025 12:21',
# },
# ],
# },
# ],
# } } );

# $mech->log_in_ok( $user->email );

# subtest 'with Agile data only' => sub {
# $mech->get_ok('/waste/10001');
# like $mech->text, qr/Brown wheelie bin/;
# like $mech->text, qr/Next collectionPending/;

# $mech->get_ok('/waste/10001/garden_cancel');
# like $mech->text, qr/Cancel your garden waste subscription/;

# $mech->submit_form_ok(
# { with_fields => {
# reason => 'Other',
# reason_further_details => 'Burnt all my leaves',
# confirm => 1,
# },
# }
# );
# like $mech->text, qr/Your subscription has been cancelled/,
# 'form submitted OK';

# my $report
# = FixMyStreet::DB->resultset('Problem')->order_by('-id')
# ->first;

# is $report->get_extra_field_value('customer_external_ref'),
# 'CUSTOMER_123';
# is $report->get_extra_field_value('due_date'),
# '12/12/2025';
# is $report->get_extra_field_value('reason'),
# 'Other: Burnt all my leaves';

# $mech->clear_emails_ok;
# FixMyStreet::Script::Reports::send();

# my @emails = $mech->get_email;
# my $body = $mech->get_text_body_from_email($emails[1]);
# like $body, qr/You have cancelled your garden waste collection service/;
# };

# subtest 'with Whitespace data' => sub {
# $whitespace_mock->mock(
# 'GetSiteCollections',
# sub {
# [ { SiteServiceID => 1,
# ServiceItemDescription => 'Garden waste',
# ServiceItemName => 'GA-140', # Garden 140 ltr Bin
# ServiceName => 'Brown Wheelie Bin',
# NextCollectionDate => '2024-02-07T00:00:00',
# SiteServiceValidFrom => '2024-01-01T00:00:00',
# SiteServiceValidTo => '0001-01-01T00:00:00',

# RoundSchedule => 'RND-1 Mon',
# }
# ];
# }
# );

# $mech->get_ok('/waste/10001');
# like $mech->content, qr/waste-service-subtitle.*Garden waste/s;

# $mech->get_ok('/waste/10001/garden_cancel');
# like $mech->text, qr/Cancel your garden waste subscription/;

# $mech->submit_form_ok(
# { with_fields => {
# reason => 'Other',
# reason_further_details => 'Burnt all my leaves',
# confirm => 1,
# },
# }
# );
# like $mech->text, qr/Your subscription has been cancelled/,
# 'form submitted OK';

# my $report
# = FixMyStreet::DB->resultset('Problem')->order_by('-id')
# ->first;

# is $report->get_extra_field_value('customer_external_ref'),
# 'CUSTOMER_123';
# is $report->get_extra_field_value('due_date'),
# '12/12/2025';
# is $report->get_extra_field_value('reason'),
# 'Other: Burnt all my leaves';

# $mech->clear_emails_ok;
# FixMyStreet::Script::Reports::send();

# my @emails = $mech->get_email;
# my $body = $mech->get_text_body_from_email($emails[1]);
# like $body, qr/You have cancelled your garden waste collection service/;
# };

# };
};

sub get_report_from_redirect {
Expand Down

0 comments on commit 9a10b99

Please sign in to comment.