Lines 203-233
subtest 'cashup' => sub {
Link Here
|
203 |
subtest 'outstanding_accountlines' => sub { |
203 |
subtest 'outstanding_accountlines' => sub { |
204 |
plan tests => 4; |
204 |
plan tests => 4; |
205 |
|
205 |
|
206 |
# add_cashup should not happen simultaneously with any other action |
|
|
207 |
# that results in an accountline attached to the same cash register. |
208 |
# In testing, we need to sleep for a second after each action that |
209 |
# adds to the database. (We cannot use Time::Fake as timestamps are |
210 |
# being added at the DB level, not in perl. |
211 |
my $accountline1 = $builder->build_object( |
206 |
my $accountline1 = $builder->build_object( |
212 |
{ |
207 |
{ |
213 |
class => 'Koha::Account::Lines', |
208 |
class => 'Koha::Account::Lines', |
214 |
value => { register_id => $register->id }, |
209 |
value => { register_id => $register->id, timestamp => \'NOW() - INTERVAL 5 MINUTE' }, |
215 |
} |
210 |
} |
216 |
); |
211 |
); |
217 |
my $accountline2 = $builder->build_object( |
212 |
my $accountline2 = $builder->build_object( |
218 |
{ |
213 |
{ |
219 |
class => 'Koha::Account::Lines', |
214 |
class => 'Koha::Account::Lines', |
220 |
value => { register_id => $register->id }, |
215 |
value => { register_id => $register->id, timestamp => \'NOW() - INTERVAL 5 MINUTE'}, |
221 |
} |
216 |
} |
222 |
); |
217 |
); |
223 |
sleep 1; |
|
|
224 |
|
218 |
|
225 |
my $accountlines = $register->outstanding_accountlines; |
219 |
my $accountlines = $register->outstanding_accountlines; |
226 |
is( $accountlines->count, 2, 'No cashup, all accountlines returned' ); |
220 |
is( $accountlines->count, 2, 'No cashup, all accountlines returned' ); |
227 |
|
221 |
|
228 |
my $cashup3 = |
222 |
my $cashup3 = |
229 |
$register->add_cashup( { manager_id => $patron->id, amount => '2.50' } ); |
223 |
$register->add_cashup( { manager_id => $patron->id, amount => '2.50' } ); |
230 |
sleep 1; |
|
|
231 |
|
224 |
|
232 |
$accountlines = $register->outstanding_accountlines; |
225 |
$accountlines = $register->outstanding_accountlines; |
233 |
is( $accountlines->count, 0, 'Cashup added, no accountlines returned' ); |
226 |
is( $accountlines->count, 0, 'Cashup added, no accountlines returned' ); |
Lines 238-244
subtest 'cashup' => sub {
Link Here
|
238 |
value => { register_id => $register->id }, |
231 |
value => { register_id => $register->id }, |
239 |
} |
232 |
} |
240 |
); |
233 |
); |
241 |
sleep 1; |
234 |
|
|
|
235 |
# Fake the cashup timestamp to make sure it's before the accountline we just added, |
236 |
# we can't trust that these two actions are more than a second apart in a test |
237 |
$cashup3->timestamp(\'NOW() - INTERVAL 2 MINUTE')->store; |
242 |
|
238 |
|
243 |
$accountlines = $register->outstanding_accountlines; |
239 |
$accountlines = $register->outstanding_accountlines; |
244 |
is( $accountlines->count, 1, |
240 |
is( $accountlines->count, 1, |
245 |
- |
|
|