customer snippet test amended

This commit is contained in:
Finn 2018-03-21 16:37:40 +00:00
parent a02c74d830
commit 358c0ca99b
2 changed files with 15 additions and 6 deletions

View file

@ -10,7 +10,8 @@
* Added API ability to edit and delete transactions * Added API ability to edit and delete transactions
* Added test for above * Added test for above
* Made test dumping more sane * Made test dumping more sane
* Fixed category view on postgres * Fixed quantised transaction calcuations for weeks on sqlite
* Amended customer snippet, category list and customer stats tests
# v0.10.5 # v0.10.5

View file

@ -1,5 +1,9 @@
use Mojo::Base -strict; use Mojo::Base -strict;
BEGIN {
use Test::MockTime qw/ set_absolute_time /;
}
use FindBin qw/ $Bin /; use FindBin qw/ $Bin /;
use Test::More; use Test::More;
@ -15,7 +19,7 @@ $framework->install_fixtures('users');
my $t = $framework->framework; my $t = $framework->framework;
my $schema = $t->app->schema; my $schema = $t->app->schema;
$t->app->schema->resultset('Leaderboard')->create_new( 'monthly_total', DateTime->now->truncate(to => 'month' )->subtract( months => 1) ); set_absolute_time('2017-01-02T00:00:00Z');
my $start = DateTime->today->subtract( hours => 12 ); my $start = DateTime->today->subtract( hours => 12 );
@ -25,15 +29,19 @@ for my $count ( 0 .. 60 ) {
create_random_transaction( 'test1@example.com', $trans_day ); create_random_transaction( 'test1@example.com', $trans_day );
if ( $count % 2 ) { if ( $count % 2 ) {
create_random_transaction( 'test2@example.com', $trans_day ); create_random_transaction( 'test1@example.com', $trans_day );
} }
if ( $count % 3 ) { if ( $count % 3 ) {
create_random_transaction( 'test3@example.com', $trans_day ); create_random_transaction( 'test1@example.com', $trans_day );
} }
if ( $count % 4 ) { if ( $count % 4 ) {
create_random_transaction( 'test4@example.com', $trans_day ); create_random_transaction( 'test1@example.com', $trans_day );
} }
} }
my $lb_start = $start->clone->truncate( to => 'month' )->subtract( months => 1);
#use Devel::Dwarn; Dwarn({ $_->get_columns }) for $schema->resultset('Transaction')->all;
$schema->resultset('Leaderboard')->create_new( 'monthly_total', $lb_start );
my $session_key = $framework->login({ my $session_key = $framework->login({
email => 'test1@example.com', email => 'test1@example.com',
@ -45,7 +53,7 @@ $t->post_ok('/api/v1/customer/snippets' => json => {
}) })
->status_is(200)->or($framework->dump_error) ->status_is(200)->or($framework->dump_error)
->json_is('/snippets', { ->json_is('/snippets', {
user_sum => 610, user_sum => 1760,
user_position => 1, user_position => 1,
}); });