Fixed schema leaderboard test for entity changes

This commit is contained in:
Tom Bloor 2017-08-31 18:26:19 +01:00
parent aa6cc63506
commit 66cc99b975

View file

@ -77,9 +77,9 @@ my $now = DateTime->today();
for my $user ( $user1, $user2, $user3, $user4 ) { for my $user ( $user1, $user2, $user3, $user4 ) {
$tweak ++; $tweak ++;
my $user_result = $schema->resultset('User')->find({ email => $user->{email} }); my $user_result = $schema->resultset('User')->find({ email => $user->{email} })->entity;
for ( 1 .. 10 ) { for ( 1 .. 10 ) {
$user_result->create_related( 'transactions', { $user_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_ + $tweak, value => $_ + $tweak,
proof_image => 'a', proof_image => 'a',
@ -87,7 +87,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) {
} }
for ( 11 .. 20 ) { for ( 11 .. 20 ) {
$user_result->create_related( 'transactions', { $user_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_ + $tweak, value => $_ + $tweak,
proof_image => 'a', proof_image => 'a',
@ -96,7 +96,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) {
} }
for ( 21 .. 30 ) { for ( 21 .. 30 ) {
$user_result->create_related( 'transactions', { $user_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_ + $tweak, value => $_ + $tweak,
proof_image => 'a', proof_image => 'a',
@ -105,7 +105,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) {
} }
for ( 31 .. 40 ) { for ( 31 .. 40 ) {
$user_result->create_related( 'transactions', { $user_result->create_related( 'purchases', {
seller_id => $org_result->id, seller_id => $org_result->id,
value => $_ + $tweak, value => $_ + $tweak,
proof_image => 'a', proof_image => 'a',
@ -113,7 +113,7 @@ for my $user ( $user1, $user2, $user3, $user4 ) {
}); });
} }
is $user_result->transactions->count, 40, 'correct count for user' . $tweak; is $user_result->purchases->count, 40, 'correct count for user' . $tweak;
} }
sub test_leaderboard { sub test_leaderboard {
@ -130,7 +130,7 @@ sub test_leaderboard {
{}, {},
{ {
order_by => { -desc => 'value' }, order_by => { -desc => 'value' },
columns => [ qw/ user_id value / ], columns => [ qw/ entity_id value / ],
}, },
); );
$today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' ); $today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
@ -144,10 +144,10 @@ test_leaderboard(
'daily_total', 'daily_total',
$now, $now,
[ [
{ user_id => 4, value => 95 }, { entity_id => 4, value => 95 },
{ user_id => 3, value => 85 }, { entity_id => 3, value => 85 },
{ user_id => 2, value => 75 }, { entity_id => 2, value => 75 },
{ user_id => 1, value => 65 }, { entity_id => 1, value => 65 },
] ]
); );
@ -156,10 +156,10 @@ test_leaderboard(
'daily_count', 'daily_count',
$now, $now,
[ [
{ user_id => 1, value => 10 }, { entity_id => 1, value => 10 },
{ user_id => 2, value => 10 }, { entity_id => 2, value => 10 },
{ user_id => 3, value => 10 }, { entity_id => 3, value => 10 },
{ user_id => 4, value => 10 }, { entity_id => 4, value => 10 },
] ]
); );
@ -168,10 +168,10 @@ test_leaderboard(
'weekly_total', 'weekly_total',
$now->clone->subtract( days => 7 ), $now->clone->subtract( days => 7 ),
[ [
{ user_id => 4, value => 195 }, { entity_id => 4, value => 195 },
{ user_id => 3, value => 185 }, { entity_id => 3, value => 185 },
{ user_id => 2, value => 175 }, { entity_id => 2, value => 175 },
{ user_id => 1, value => 165 }, { entity_id => 1, value => 165 },
] ]
); );
@ -180,10 +180,10 @@ test_leaderboard(
'weekly_count', 'weekly_count',
$now->clone->subtract( days => 7 ), $now->clone->subtract( days => 7 ),
[ [
{ user_id => 1, value => 10 }, { entity_id => 1, value => 10 },
{ user_id => 2, value => 10 }, { entity_id => 2, value => 10 },
{ user_id => 3, value => 10 }, { entity_id => 3, value => 10 },
{ user_id => 4, value => 10 }, { entity_id => 4, value => 10 },
] ]
); );
@ -192,10 +192,10 @@ test_leaderboard(
'monthly_total', 'monthly_total',
$now->clone->subtract( months => 1 ), $now->clone->subtract( months => 1 ),
[ [
{ user_id => 4, value => 490 }, { entity_id => 4, value => 490 },
{ user_id => 3, value => 470 }, { entity_id => 3, value => 470 },
{ user_id => 2, value => 450 }, { entity_id => 2, value => 450 },
{ user_id => 1, value => 430 }, { entity_id => 1, value => 430 },
] ]
); );
@ -204,10 +204,10 @@ test_leaderboard(
'monthly_count', 'monthly_count',
$now->clone->subtract( months => 1 ), $now->clone->subtract( months => 1 ),
[ [
{ user_id => 1, value => 20 }, { entity_id => 1, value => 20 },
{ user_id => 2, value => 20 }, { entity_id => 2, value => 20 },
{ user_id => 3, value => 20 }, { entity_id => 3, value => 20 },
{ user_id => 4, value => 20 }, { entity_id => 4, value => 20 },
] ]
); );
@ -216,10 +216,10 @@ test_leaderboard(
'all_time_total', 'all_time_total',
$now, $now,
[ [
{ user_id => 4, value => 885 }, { entity_id => 4, value => 885 },
{ user_id => 3, value => 855 }, { entity_id => 3, value => 855 },
{ user_id => 2, value => 825 }, { entity_id => 2, value => 825 },
{ user_id => 1, value => 795 }, { entity_id => 1, value => 795 },
] ]
); );
@ -228,10 +228,10 @@ test_leaderboard(
'all_time_count', 'all_time_count',
$now, $now,
[ [
{ user_id => 1, value => 30 }, { entity_id => 1, value => 30 },
{ user_id => 2, value => 30 }, { entity_id => 2, value => 30 },
{ user_id => 3, value => 30 }, { entity_id => 3, value => 30 },
{ user_id => 4, value => 30 }, { entity_id => 4, value => 30 },
] ]
); );
@ -249,16 +249,16 @@ subtest 'get_latest' => sub {
{}, {},
{ {
order_by => { -desc => 'value' }, order_by => { -desc => 'value' },
columns => [ qw/ user_id value / ], columns => [ qw/ entity_id value / ],
}, },
); );
$today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' ); $today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
my $expected = [ my $expected = [
{ user_id => 4, value => 95 }, { entity_id => 4, value => 95 },
{ user_id => 3, value => 85 }, { entity_id => 3, value => 85 },
{ user_id => 2, value => 75 }, { entity_id => 2, value => 75 },
{ user_id => 1, value => 65 }, { entity_id => 1, value => 65 },
]; ];
is_deeply [ $today_values->all ], $expected, 'array as expected'; is_deeply [ $today_values->all ], $expected, 'array as expected';