fixed resultset_leaderboard schema test for entity changes
This commit is contained in:
parent
44c29ad7a2
commit
96c8fa16c8
1 changed files with 45 additions and 45 deletions
|
@ -69,7 +69,7 @@ $framework->register_customer($_)
|
||||||
|
|
||||||
$framework->register_organisation($org);
|
$framework->register_organisation($org);
|
||||||
|
|
||||||
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} });
|
my $org_result = $schema->resultset('Organisation')->find({ name => $org->{name} })->entity;
|
||||||
|
|
||||||
my $tweak = 0;
|
my $tweak = 0;
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
@ -132,7 +132,7 @@ sub test_leaderboard {
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
order_by => { -desc => 'value' },
|
order_by => { -desc => 'value' },
|
||||||
columns => [ qw/ user_id value position / ],
|
columns => [ qw/ entity_id value position / ],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
$today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
|
$today_values->result_class( 'DBIx::Class::ResultClass::HashRefInflator' );
|
||||||
|
@ -146,10 +146,10 @@ test_leaderboard(
|
||||||
'daily_total',
|
'daily_total',
|
||||||
$now,
|
$now,
|
||||||
[
|
[
|
||||||
{ user_id => 4, value => 95, position => 1 },
|
{ entity_id => 4, value => 95, position => 1 },
|
||||||
{ user_id => 3, value => 85, position => 2 },
|
{ entity_id => 3, value => 85, position => 2 },
|
||||||
{ user_id => 2, value => 75, position => 3 },
|
{ entity_id => 2, value => 75, position => 3 },
|
||||||
{ user_id => 1, value => 65, position => 4 },
|
{ entity_id => 1, value => 65, position => 4 },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -158,10 +158,10 @@ test_leaderboard(
|
||||||
'daily_count',
|
'daily_count',
|
||||||
$now,
|
$now,
|
||||||
[
|
[
|
||||||
{ user_id => 1, value => 10, position => 1 },
|
{ entity_id => 1, value => 10, position => 1 },
|
||||||
{ user_id => 2, value => 10, position => 2 },
|
{ entity_id => 2, value => 10, position => 2 },
|
||||||
{ user_id => 3, value => 10, position => 3 },
|
{ entity_id => 3, value => 10, position => 3 },
|
||||||
{ user_id => 4, value => 10, position => 4 },
|
{ entity_id => 4, value => 10, position => 4 },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -170,10 +170,10 @@ test_leaderboard(
|
||||||
'weekly_total',
|
'weekly_total',
|
||||||
$now->clone->subtract( days => 7 ),
|
$now->clone->subtract( days => 7 ),
|
||||||
[
|
[
|
||||||
{ user_id => 4, value => 195, position => 1 },
|
{ entity_id => 4, value => 195, position => 1 },
|
||||||
{ user_id => 3, value => 185, position => 2 },
|
{ entity_id => 3, value => 185, position => 2 },
|
||||||
{ user_id => 2, value => 175, position => 3 },
|
{ entity_id => 2, value => 175, position => 3 },
|
||||||
{ user_id => 1, value => 165, position => 4 },
|
{ entity_id => 1, value => 165, position => 4 },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -182,10 +182,10 @@ test_leaderboard(
|
||||||
'weekly_count',
|
'weekly_count',
|
||||||
$now->clone->subtract( days => 7 ),
|
$now->clone->subtract( days => 7 ),
|
||||||
[
|
[
|
||||||
{ user_id => 1, value => 10, position => 1 },
|
{ entity_id => 1, value => 10, position => 1 },
|
||||||
{ user_id => 2, value => 10, position => 2 },
|
{ entity_id => 2, value => 10, position => 2 },
|
||||||
{ user_id => 3, value => 10, position => 3 },
|
{ entity_id => 3, value => 10, position => 3 },
|
||||||
{ user_id => 4, value => 10, position => 4 },
|
{ entity_id => 4, value => 10, position => 4 },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -194,10 +194,10 @@ test_leaderboard(
|
||||||
'monthly_total',
|
'monthly_total',
|
||||||
$now->clone->subtract( months => 1 ),
|
$now->clone->subtract( months => 1 ),
|
||||||
[
|
[
|
||||||
{ user_id => 4, value => 490, position => 1 },
|
{ entity_id => 4, value => 490, position => 1 },
|
||||||
{ user_id => 3, value => 470, position => 2 },
|
{ entity_id => 3, value => 470, position => 2 },
|
||||||
{ user_id => 2, value => 450, position => 3 },
|
{ entity_id => 2, value => 450, position => 3 },
|
||||||
{ user_id => 1, value => 430, position => 4 },
|
{ entity_id => 1, value => 430, position => 4 },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -206,10 +206,10 @@ test_leaderboard(
|
||||||
'monthly_count',
|
'monthly_count',
|
||||||
$now->clone->subtract( months => 1 ),
|
$now->clone->subtract( months => 1 ),
|
||||||
[
|
[
|
||||||
{ user_id => 1, value => 20, position => 1 },
|
{ entity_id => 1, value => 20, position => 1 },
|
||||||
{ user_id => 2, value => 20, position => 2 },
|
{ entity_id => 2, value => 20, position => 2 },
|
||||||
{ user_id => 3, value => 20, position => 3 },
|
{ entity_id => 3, value => 20, position => 3 },
|
||||||
{ user_id => 4, value => 20, position => 4 },
|
{ entity_id => 4, value => 20, position => 4 },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -218,10 +218,10 @@ test_leaderboard(
|
||||||
'all_time_total',
|
'all_time_total',
|
||||||
$now,
|
$now,
|
||||||
[
|
[
|
||||||
{ user_id => 4, value => 885, position => 1 },
|
{ entity_id => 4, value => 885, position => 1 },
|
||||||
{ user_id => 3, value => 855, position => 2 },
|
{ entity_id => 3, value => 855, position => 2 },
|
||||||
{ user_id => 2, value => 825, position => 3 },
|
{ entity_id => 2, value => 825, position => 3 },
|
||||||
{ user_id => 1, value => 795, position => 4 },
|
{ entity_id => 1, value => 795, position => 4 },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -230,10 +230,10 @@ test_leaderboard(
|
||||||
'all_time_count',
|
'all_time_count',
|
||||||
$now,
|
$now,
|
||||||
[
|
[
|
||||||
{ user_id => 1, value => 30, position => 1 },
|
{ entity_id => 1, value => 30, position => 1 },
|
||||||
{ user_id => 2, value => 30, position => 2 },
|
{ entity_id => 2, value => 30, position => 2 },
|
||||||
{ user_id => 3, value => 30, position => 3 },
|
{ entity_id => 3, value => 30, position => 3 },
|
||||||
{ user_id => 4, value => 30, position => 4 },
|
{ entity_id => 4, value => 30, position => 4 },
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -251,16 +251,16 @@ subtest 'get_latest' => sub {
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
order_by => { -desc => 'value' },
|
order_by => { -desc => 'value' },
|
||||||
columns => [ qw/ user_id value position / ],
|
columns => [ qw/ entity_id value position / ],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
$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, position => 1 },
|
{ entity_id => 4, value => 95, position => 1 },
|
||||||
{ user_id => 3, value => 85, position => 2 },
|
{ entity_id => 3, value => 85, position => 2 },
|
||||||
{ user_id => 2, value => 75, position => 3 },
|
{ entity_id => 2, value => 75, position => 3 },
|
||||||
{ user_id => 1, value => 65, position => 4 },
|
{ entity_id => 1, value => 65, position => 4 },
|
||||||
];
|
];
|
||||||
|
|
||||||
is_deeply [ $today_values->all ], $expected, 'array as expected';
|
is_deeply [ $today_values->all ], $expected, 'array as expected';
|
||||||
|
|
Reference in a new issue