Get sums to show 0 instead of undef for no data

This commit is contained in:
Tom Bloor 2017-05-22 22:21:05 +01:00
parent 9586d1a637
commit 00e98f874a
2 changed files with 24 additions and 10 deletions

View file

@ -28,15 +28,15 @@ sub post_index {
return $c->render( json => {
success => Mojo::JSON->true,
today_sum => $today_sum,
today_sum => $today_sum || 0,
today_count => $today_count,
week_sum => $week_sum,
week_sum => $week_sum || 0,
week_count => $week_count,
month_sum => $month_sum,
month_sum => $month_sum || 0,
month_count => $month_count,
user_sum => $user_sum,
user_sum => $user_sum || 0,
user_count => $user_count,
global_sum => $global_sum,
global_sum => $global_sum || 0,
global_count => $global_count,
});
}

View file

@ -39,6 +39,25 @@ $framework->register_organisation($org);
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} });
my $user_result = $schema->resultset('User')->find({ email => $user->{email} });
my $session_key = $framework->login({
email => $user->{email},
password => $user->{password},
});
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
->status_is(200)
->json_is('/success', Mojo::JSON->true)
->json_is('/today_sum', 0)
->json_is('/today_count', 0)
->json_is('/week_sum', 0)
->json_is('/week_count', 0)
->json_is('/month_sum', 0)
->json_is('/month_count', 0)
->json_is('/user_sum', 0)
->json_is('/user_count', 0)
->json_is('/global_sum', 0)
->json_is('/global_count', 0);
for ( 1 .. 10 ) {
$user_result->create_related( 'transactions', {
seller_id => $org_result->id,
@ -93,11 +112,6 @@ is $user_result->transactions->search({
})->get_column('value')->sum, 55, 'Got correct sum';
is $user_result->transactions->today_rs->get_column('value')->sum, 55, 'Got correct sum through rs';
my $session_key = $framework->login({
email => $user->{email},
password => $user->{password},
});
$t->post_ok('/api/stats' => json => { session_key => $session_key } )
->status_is(200)
->json_is('/success', Mojo::JSON->true)