Skip to content

Commit 0d79da9

Browse files
WIP tests
1 parent 03b275c commit 0d79da9

File tree

2 files changed

+125
-16
lines changed

2 files changed

+125
-16
lines changed

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ sub lookup_subscription_for_uprn {
4949
my $customer = $results->{Customers}[0];
5050
return undef unless $customer && $customer->{ServiceContracts};
5151
# Assume there is only one active subscription
52-
my ($contract) = grep {
53-
$_->{ServiceContractStatus} eq 'ACTIVE'
54-
|| $_->{ServiceContractStatus} eq 'PRECONTRACT'
55-
} @{ $customer->{ServiceContracts} // [] };
52+
my $contract = $customer->{ServiceContracts}[0];
5653
return unless $contract;
5754

5855
# XXX should maybe sort by CreatedDate rather than assuming first is OK
@@ -129,6 +126,7 @@ sub garden_current_subscription {
129126
service_name => "Brown wheelie bin",
130127
service_id => "GA-240",
131128
schedule => "Pending",
129+
round_schedule => '',
132130
next => { pending => 1 },
133131
};
134132
push @$services, $service;

t/app/controller/waste_bexley_garden.t

Lines changed: 123 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ FixMyStreet::override_config {
258258

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

@@ -296,13 +296,13 @@ FixMyStreet::override_config {
296296
$mech->clear_emails_ok;
297297
FixMyStreet::Script::Reports::send();
298298
my @emails = $mech->get_email;
299-
my $body = $mech->get_text_body_from_email($emails[1]);
299+
my $email_body = $mech->get_text_body_from_email($emails[1]);
300300
TODO: {
301301
local $TODO = 'Quantity not yet read in _garden_data.html';
302-
like $body, qr/Number of bin subscriptions: 1/;
302+
like $email_body, qr/Number of bin subscriptions: 1/;
303303
}
304-
unlike $body, qr/Bins to be delivered/;
305-
like $body, qr/Total:.*?75.00/;
304+
unlike $email_body, qr/Bins to be delivered/;
305+
like $email_body, qr/Total:.*?75.00/;
306306
};
307307

308308
subtest 'check new sub credit card payment with one less bin required' => sub {
@@ -331,13 +331,124 @@ FixMyStreet::override_config {
331331
$mech->clear_emails_ok;
332332
FixMyStreet::Script::Reports::send();
333333
my @emails = $mech->get_email;
334-
my $body = $mech->get_text_body_from_email($emails[1]);
334+
my $email_body = $mech->get_text_body_from_email($emails[1]);
335335
TODO: {
336336
local $TODO = 'Quantity not yet read in _garden_data.html';
337-
like $body, qr/Number of bin subscriptions: 1/;
337+
like $email_body, qr/Number of bin subscriptions: 1/;
338338
}
339-
like $body, qr/Bins to be removed: 1/;
340-
like $body, qr/Total:.*?75.00/;
339+
like $email_body, qr/Bins to be removed: 1/;
340+
like $email_body, qr/Total:.*?75.00/;
341+
};
342+
343+
subtest 'renew garden subscription' => sub {
344+
set_fixed_time('2024-02-01T00:00:00');
345+
346+
my $uprn = 10001;
347+
my $contract_id = 'CONTRACT_123';
348+
349+
# subtest 'with Agile data only' => sub {
350+
# subtest 'within renewal window' => sub {
351+
# $agile_mock->mock( 'CustomerSearch', sub { {
352+
# Customers => [
353+
# {
354+
# CustomerExternalReference => 'CUSTOMER_123',
355+
# ServiceContracts => [
356+
# {
357+
# # One month away
358+
# EndDate => '01/03/2024 12:00',
359+
# Reference => $contract_id,
360+
# },
361+
# ],
362+
# },
363+
# ],
364+
# } } );
365+
366+
# $mech->get_ok("/waste/$uprn");
367+
368+
# };
369+
370+
# # subtest 'too early' => sub {
371+
# # $agile_mock->mock( 'CustomerSearch', sub { {
372+
# # Customers => [
373+
# # {
374+
# # CustomerExternalReference => 'CUSTOMER_123',
375+
# # ServiceContracts => [
376+
# # {
377+
# # # 2 months away
378+
# # EndDate => '01/04/2024 12:00',
379+
# # },
380+
# # ],
381+
# # },
382+
# # ],
383+
# # } } );
384+
# # };
385+
386+
# # subtest 'subscription expired' => sub {
387+
# # $agile_mock->mock( 'CustomerSearch', sub { {
388+
# # Customers => [
389+
# # {
390+
# # CustomerExternalReference => 'CUSTOMER_123',
391+
# # ServiceContracts => [
392+
# # {
393+
# # # 1 month ago
394+
# # EndDate => '01/01/2024 12:00',
395+
# # },
396+
# # ],
397+
# # },
398+
# # ],
399+
# # } } );
400+
# # };
401+
# };
402+
403+
subtest 'with DB data' => sub {
404+
my ($new_sub_report) = $mech->create_problems_for_body(
405+
1,
406+
$body->id,
407+
'Garden Subscription - New',
408+
{ category => 'Garden Subscription',
409+
external_id => "Agile-$contract_id",
410+
},
411+
);
412+
$new_sub_report->set_extra_fields(
413+
{ name => 'uprn', value => $uprn } );
414+
$new_sub_report->update;
415+
416+
subtest 'within renewal window' => sub {
417+
$agile_mock->mock( 'CustomerSearch', sub { {
418+
Customers => [
419+
{
420+
CustomerExternalReference => 'CUSTOMER_123',
421+
ServiceContracts => [
422+
{
423+
# 42 days away
424+
EndDate => '14/03/2024 12:00',
425+
Reference => $contract_id,
426+
},
427+
],
428+
},
429+
],
430+
} } );
431+
432+
$mech->get_ok("/waste/$uprn");
433+
# warn "====\n\t" . $mech->text . "\n=÷===";
434+
# warn "====\n\t" . $mech->content . "\n====";
435+
like $mech->content, qr/14 March 2024, soon due for renewal/,
436+
'"Due soon" message shown';
437+
like $mech->content,
438+
qr/Renew your brown wheelie bin subscription/,
439+
'Renewal link available';
440+
like $mech->text, qr/Frequency.*Pending/, 'Pending details because no Whitespace data';
441+
442+
};
443+
444+
# subtest 'too early' => sub {
445+
446+
# };
447+
448+
# subtest 'subscription expired' => sub {
449+
450+
# };
451+
};
341452
};
342453

343454
subtest 'cancel garden subscription' => sub {

0 commit comments

Comments
 (0)