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 03b275c commit 0d79da9
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 16 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
135 changes: 123 additions & 12 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,13 +331,124 @@ 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 'renew garden subscription' => sub {
set_fixed_time('2024-02-01T00:00:00');

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 => [
{
CustomerExternalReference => 'CUSTOMER_123',
ServiceContracts => [
{
# 42 days away
EndDate => '14/03/2024 12:00',
Reference => $contract_id,
},
],
},
],
} } );

$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';

};

# subtest 'too early' => sub {

# };

# subtest 'subscription expired' => sub {

# };
};
};

subtest 'cancel garden subscription' => sub {
Expand Down

0 comments on commit 0d79da9

Please sign in to comment.