Skip to content

Commit

Permalink
fixup! [Bexley][WW] Fetch successful collections alongside other in-c…
Browse files Browse the repository at this point in the history
…ab logs
  • Loading branch information
nephila-nacrea committed May 22, 2024
1 parent 0a850f0 commit 6aedd9c
Showing 1 changed file with 61 additions and 21 deletions.
82 changes: 61 additions & 21 deletions t/app/controller/waste_bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,34 @@ $dbi_mock->mock( 'connect', sub {
} );

my $whitespace_mock = Test::MockModule->new('Integrations::Whitespace');
sub default_mocks {
# These are overridden for some tests
$whitespace_mock->mock(
'GetSiteCollections',
sub {
my ( $self, $uprn ) = @_;
return _site_collections()->{$uprn};
}
);
$whitespace_mock->mock( 'GetInCabLogsByUprn', sub {
my ( $self, $uprn ) = @_;
return [ grep { $_->{Uprn} eq $uprn } @{ _in_cab_logs() } ];
});
$whitespace_mock->mock( 'GetInCabLogsByUsrn', sub {
my ( $self, $usrn ) = @_;
return _in_cab_logs();
});
};

default_mocks();

$whitespace_mock->mock(
'GetSiteInfo',
sub {
my ( $self, $uprn ) = @_;
return _site_info()->{$uprn};
}
);
$whitespace_mock->mock(
'GetSiteCollections',
sub {
my ( $self, $uprn ) = @_;
return _site_collections()->{$uprn};
}
);
$whitespace_mock->mock( 'GetAccountSiteID', &_account_site_id );
$whitespace_mock->mock( 'GetCollectionByUprnAndDate',
sub {
Expand All @@ -121,14 +135,6 @@ $whitespace_mock->mock(
return _worksheet_detail_service_items()->{$worksheet_id};
}
);
$whitespace_mock->mock( 'GetInCabLogsByUprn', sub {
my ( $self, $uprn ) = @_;
return [ grep { $_->{Uprn} eq $uprn } @{ _in_cab_logs() } ];
});
$whitespace_mock->mock( 'GetInCabLogsByUsrn', sub {
my ( $self, $usrn ) = @_;
return _in_cab_logs();
});
my $body = $mech->create_body_ok(2494, 'London Borough of Bexley', {}, { cobrand => 'bexley' });
my $contact = $mech->create_contact_ok(
body => $body,
Expand Down Expand Up @@ -425,17 +431,51 @@ FixMyStreet::override_config {
};

subtest 'Shows when a collection is due today' => sub {
$whitespace_mock->mock( 'GetSiteCollections', sub {
return [
{ SiteServiceID => 8,
ServiceItemDescription => 'Service 8',
ServiceItemName => 'PC-55', # Blue Recycling Box
ServiceName => 'Blue Recycling Box',
NextCollectionDate => '2024-04-01T00:00:00',
SiteServiceValidFrom => '2024-03-31T00:59:59',
SiteServiceValidTo => '0001-01-01T00:00:00',

RoundSchedule => 'RND-8-9 Mon, RND-8-9 Wed',
},
];
} );
$whitespace_mock->mock( 'GetInCabLogsByUprn', sub { [] } );
$whitespace_mock->mock( 'GetInCabLogsByUsrn', sub { [] } );

set_fixed_time('2024-04-01T07:00:00'); # April 1st, 08:00 BST
$mech->get_ok('/waste/10001');
$mech->content_contains('Being collected today');
$mech->content_lacks('Collection completed or attempted earlier today');

$mech->get_ok('/waste');
$mech->submit_form_ok( { with_fields => { postcode => 'DA1 3LD' } } );
$mech->submit_form_ok( { with_fields => { address => 10001 } } );
# Set time to later in the day
set_fixed_time('2024-04-01T16:01:00'); # April 1st, 17:01 BST

# Blue and green recycling boxes are due today
$mech->content_contains('Being collected today');
# Successful collection has occurred
$whitespace_mock->mock( 'GetInCabLogsByUsrn', sub {
return [
{
LogID => 1,
Reason => 'N/A',
RoundCode => 'RND-8-9',
LogDate => '2024-04-01T12:00:00.417',
Uprn => '',
Usrn => '321',
},
];
});
$mech->get_ok('/waste/10001');
$mech->content_lacks('Being collected today');
$mech->content_contains('Collection completed or attempted earlier today');

# Put time back to previous value
# Reinstate original mocks
set_fixed_time('2024-03-31T01:00:00'); # March 31st, 02:00 BST
default_mocks();
};

subtest 'Asks user for location of bins on missed collection form' => sub {
Expand Down

0 comments on commit 6aedd9c

Please sign in to comment.