From 0d79da92bd2b61dd5c35c2bd60e54a0465778c6f Mon Sep 17 00:00:00 2001 From: Victoria Mihell-Hale Date: Mon, 17 Feb 2025 13:22:44 +0000 Subject: [PATCH] WIP tests --- perllib/FixMyStreet/Cobrand/Bexley/Garden.pm | 6 +- t/app/controller/waste_bexley_garden.t | 135 +++++++++++++++++-- 2 files changed, 125 insertions(+), 16 deletions(-) diff --git a/perllib/FixMyStreet/Cobrand/Bexley/Garden.pm b/perllib/FixMyStreet/Cobrand/Bexley/Garden.pm index 1645babf88..3078215737 100644 --- a/perllib/FixMyStreet/Cobrand/Bexley/Garden.pm +++ b/perllib/FixMyStreet/Cobrand/Bexley/Garden.pm @@ -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 @@ -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; diff --git a/t/app/controller/waste_bexley_garden.t b/t/app/controller/waste_bexley_garden.t index 835d8568c6..810b46c8f8 100644 --- a/t/app/controller/waste_bexley_garden.t +++ b/t/app/controller/waste_bexley_garden.t @@ -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; }; @@ -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 { @@ -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 {