Add HomeTest
This commit is contained in:
parent
6d9f7c6dce
commit
4e43c88fca
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Home\Queries;
|
||||||
|
|
||||||
|
use App\Member\Membership;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
class GroupQuery
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Builder<Membership>
|
||||||
|
*/
|
||||||
|
private Builder $query;
|
||||||
|
|
||||||
|
public function execute(): self
|
||||||
|
{
|
||||||
|
$this->query = Membership::select('subactivities.slug', 'subactivities.name')
|
||||||
|
->selectRaw('COUNT(member_id) AS count')
|
||||||
|
->join('activities', 'memberships.activity_id', 'activities.id')
|
||||||
|
->join('subactivities', 'memberships.subactivity_id', 'subactivities.id')
|
||||||
|
->isAgeGroup()
|
||||||
|
->isMember()
|
||||||
|
->groupBy('subactivities.slug', 'subactivities.name')
|
||||||
|
->orderBy('subactivity_id');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int, array{slug: string, name: string, count: int}>
|
||||||
|
*/
|
||||||
|
public function getResult(): array
|
||||||
|
{
|
||||||
|
return $this->query->get()->toArray();
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Views;
|
namespace App\Http\Views;
|
||||||
|
|
||||||
|
use App\Home\Queries\GroupQuery;
|
||||||
use App\Member\Member;
|
use App\Member\Member;
|
||||||
use App\Payment\Payment;
|
use App\Payment\Payment;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
@ -21,14 +22,7 @@ class HomeView
|
||||||
'all_users' => Member::count(),
|
'all_users' => Member::count(),
|
||||||
'amount' => number_format($amount->a / 100, 2, ',', '.').' €',
|
'amount' => number_format($amount->a / 100, 2, ',', '.').' €',
|
||||||
],
|
],
|
||||||
'groups' => Member::select('subactivities.slug', 'subactivities.name')->selectRaw('COUNT(members.id) AS count')->join('memberships', 'memberships.member_id', 'members.id')
|
'groups' => app(GroupQuery::class)->execute()->getResult(),
|
||||||
->join('activities', 'memberships.activity_id', 'activities.id')
|
|
||||||
->join('subactivities', 'memberships.subactivity_id', 'subactivities.id')
|
|
||||||
->where('subactivities.is_age_group', true)
|
|
||||||
->where('activities.is_member', true)
|
|
||||||
->groupBy('subactivities.name', 'subactivities.slug')
|
|
||||||
->orderBy('subactivities.id')
|
|
||||||
->get(),
|
|
||||||
'ending_tries' => MemberTriesResource::collection(Member::endingTries()->get()),
|
'ending_tries' => MemberTriesResource::collection(Member::endingTries()->get()),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Member\Member;
|
||||||
|
use App\Member\Membership;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class HomeTest extends TestCase
|
||||||
|
{
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function testItDisplaysAgeGroups(): void
|
||||||
|
{
|
||||||
|
$this->withoutExceptionHandling();
|
||||||
|
Member::factory()->count(3)
|
||||||
|
->has(Membership::factory()->in('€ Mitglied', 1, 'Biber', 2))
|
||||||
|
->defaults()
|
||||||
|
->create();
|
||||||
|
Member::factory()->count(4)
|
||||||
|
->has(Membership::factory()->in('€ Mitglied', 1, 'Wölfling', 3))
|
||||||
|
->defaults()
|
||||||
|
->create();
|
||||||
|
Member::factory()->has(Membership::factory()->in('€ LeiterIn', 2, 'Wölfling', 3))
|
||||||
|
->defaults()
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->login()->loginNami();
|
||||||
|
|
||||||
|
$response = $this->get('/');
|
||||||
|
|
||||||
|
$this->assertInertiaHas([
|
||||||
|
'slug' => 'biber',
|
||||||
|
'name' => 'Biber',
|
||||||
|
'count' => 3,
|
||||||
|
], $response, 'data.groups.0');
|
||||||
|
$this->assertInertiaHas([
|
||||||
|
'slug' => 'woelfling',
|
||||||
|
'name' => 'Wölfling',
|
||||||
|
'count' => 4,
|
||||||
|
], $response, 'data.groups.1');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue