2022-11-18 15:55:44 +01:00
< ? php
namespace Tests\Feature\Member ;
2024-08-28 22:12:05 +02:00
use App\Activity ;
2024-08-30 21:06:16 +02:00
use App\Country ;
2022-11-22 00:37:34 +01:00
use App\Course\Models\Course ;
use App\Course\Models\CourseMember ;
2022-11-19 00:09:53 +01:00
use App\Gender ;
use App\Group ;
2023-12-19 02:00:42 +01:00
use App\Invoice\Models\Invoice ;
use App\Invoice\Models\InvoicePosition ;
2022-11-18 15:55:44 +01:00
use App\Member\Member ;
use App\Member\Membership ;
2022-11-19 00:09:53 +01:00
use App\Nationality ;
use App\Payment\Subscription ;
use App\Region ;
2024-08-28 22:12:05 +02:00
use App\Subactivity ;
2022-11-19 00:09:53 +01:00
use Carbon\Carbon ;
2023-09-05 16:29:22 +02:00
use Generator ;
2022-11-18 15:55:44 +01:00
use Illuminate\Foundation\Testing\DatabaseTransactions ;
use Tests\TestCase ;
class ShowTest extends TestCase
{
use DatabaseTransactions ;
2024-08-30 21:06:16 +02:00
public function setUp () : void
{
parent :: setUp ();
Country :: factory () -> create ([ 'name' => 'Deutschland' ]);
}
2023-09-06 23:19:02 +02:00
public function testItShowsSingleMember () : void
2022-11-19 00:09:53 +01:00
{
Carbon :: setTestNow ( Carbon :: parse ( '2006-01-01 15:00:00' ));
2022-11-18 15:55:44 +01:00
$this -> withoutExceptionHandling () -> login () -> loginNami ();
$member = Member :: factory ()
2022-11-19 00:09:53 +01:00
-> defaults ()
2023-11-24 13:43:52 +01:00
-> for ( Group :: factory () -> name ( 'Stamm Beispiel' ))
2023-02-27 22:15:46 +01:00
-> has ( Membership :: factory () -> promise ( now ()) -> in ( '€ LeiterIn' , 5 , 'Jungpfadfinder' , 88 ) -> from ( '2022-11-19' ))
2023-12-19 02:00:42 +01:00
-> has ( InvoicePosition :: factory () -> for ( Invoice :: factory ()) -> price ( 1050 ) -> description ( 'uu' ))
2024-06-12 00:04:13 +02:00
-> for ( Gender :: factory () -> male ())
2022-11-19 00:09:53 +01:00
-> for ( Region :: factory () -> name ( 'NRW' ))
2022-12-06 23:11:57 +01:00
-> postBillKind ()
2022-11-22 00:37:34 +01:00
-> inNami ( 123 )
2024-02-22 11:13:20 +01:00
-> for ( Subscription :: factory () -> name ( 'Sub' ) -> forFee ())
2022-11-22 00:37:34 +01:00
-> has ( CourseMember :: factory () -> for ( Course :: factory () -> name ( ' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ' )) -> state ([ 'organizer' => 'DPSG' , 'event_name' => 'Wochenende' , 'completed_at' => '2022-03-03' ]), 'courses' )
2022-11-19 00:09:53 +01:00
-> create ([
'birthday' => '1991-04-20' ,
'address' => 'Itterstr 3' ,
'zip' => '42719' ,
'location' => 'Solingen' ,
'firstname' => 'Max' ,
2022-11-19 00:21:58 +01:00
'lastname' => 'Muster' ,
2022-11-19 00:09:53 +01:00
'other_country' => 'other' ,
'main_phone' => '+49 212 1266775' ,
'mobile_phone' => '+49 212 1266776' ,
'work_phone' => '+49 212 1266777' ,
'children_phone' => '+49 212 1266778' ,
'email' => 'a@b.de' ,
'email_parents' => 'b@c.de' ,
'fax' => '+49 212 1255674' ,
2022-11-22 00:37:34 +01:00
'efz' => '2022-09-20' ,
'ps_at' => '2022-04-20' ,
'more_ps_at' => '2022-06-02' ,
2023-11-24 13:28:54 +01:00
'recertified_at' => '2022-06-13' ,
2022-11-22 00:37:34 +01:00
'without_education_at' => '2022-06-03' ,
'without_efz_at' => '2022-06-04' ,
'has_vk' => true ,
'has_svk' => true ,
'multiply_pv' => true ,
'multiply_more_pv' => true ,
'send_newspaper' => true ,
'joined_at' => '2022-06-11' ,
2023-03-02 23:14:25 +01:00
'mitgliedsnr' => 998 ,
2023-05-16 17:19:56 +02:00
'lon' => 19.05 ,
'lat' => 14.053 ,
2024-08-28 22:12:05 +02:00
'comment' => 'Lorem bla'
2022-11-19 00:09:53 +01:00
]);
2022-11-18 15:55:44 +01:00
2024-08-28 22:12:05 +02:00
$this -> getJson ( route ( 'member.show' , [ 'member' => $member ]))
-> assertJsonPath ( 'data.firstname' , 'Max' )
-> assertJsonPath ( 'data.birthday_human' , '20.04.1991' )
-> assertJsonPath ( 'data.age' , 14 )
-> assertJsonPath ( 'data.group_name' , 'Stamm Beispiel' )
-> assertJsonPath ( 'data.full_address' , 'Itterstr 3, 42719 Solingen' )
-> assertJsonPath ( 'data.region.name' , 'NRW' )
-> assertJsonPath ( 'data.other_country' , 'other' )
-> assertJsonPath ( 'data.main_phone' , '+49 212 1266775' )
-> assertJsonPath ( 'data.mobile_phone' , '+49 212 1266776' )
-> assertJsonPath ( 'data.work_phone' , '+49 212 1266777' )
-> assertJsonPath ( 'data.children_phone' , '+49 212 1266778' )
-> assertJsonPath ( 'data.email' , 'a@b.de' )
-> assertJsonPath ( 'data.email_parents' , 'b@c.de' )
-> assertJsonPath ( 'data.fax' , '+49 212 1255674' )
-> assertJsonPath ( 'data.fullname' , 'Herr Max Muster' )
-> assertJsonPath ( 'data.efz_human' , '20.09.2022' )
-> assertJsonPath ( 'data.ps_at_human' , '20.04.2022' )
-> assertJsonPath ( 'data.more_ps_at_human' , '02.06.2022' )
-> assertJsonPath ( 'data.without_education_at_human' , '03.06.2022' )
-> assertJsonPath ( 'data.without_efz_at_human' , '04.06.2022' )
-> assertJsonPath ( 'data.recertified_at_human' , '13.06.2022' )
-> assertJsonPath ( 'data.has_vk' , true )
-> assertJsonPath ( 'data.has_svk' , true )
-> assertJsonPath ( 'data.multiply_pv' , true )
-> assertJsonPath ( 'data.multiply_more_pv' , true )
-> assertJsonPath ( 'data.has_nami' , true )
-> assertJsonPath ( 'data.nami_id' , 123 )
-> assertJsonPath ( 'data.send_newspaper' , true )
-> assertJsonPath ( 'data.joined_at_human' , '11.06.2022' )
-> assertJsonPath ( 'data.bill_kind_name' , 'Post' )
-> assertJsonPath ( 'data.mitgliedsnr' , 998 )
-> assertJsonPath ( 'data.lon' , 19.05 )
-> assertJsonPath ( 'data.lat' , 14.053 )
-> assertJsonPath ( 'data.subscription.name' , 'Sub' )
-> assertJsonPath ( 'data.comment' , 'Lorem bla' )
-> assertJsonPath ( 'data.memberships.0.activity_name' , '€ LeiterIn' )
-> assertJsonPath ( 'data.memberships.0.subactivity_name' , 'Jungpfadfinder' )
-> assertJsonPath ( 'data.memberships.0.id' , $member -> memberships -> first () -> id )
-> assertJsonPath ( 'data.memberships.0.human_date' , '19.11.2022' )
-> assertJsonPath ( 'data.memberships.0.promised_at' , now () -> format ( 'Y-m-d' ))
-> assertJsonPath ( 'data.courses.0.organizer' , 'DPSG' )
-> assertJsonPath ( 'data.courses.0.event_name' , 'Wochenende' )
-> assertJsonPath ( 'data.courses.0.completed_at_human' , '03.03.2022' )
-> assertJsonPath ( 'data.courses.0.course.name' , ' Baustein 2e - Gewalt gegen Kinder und Jugendliche: Vertiefung, Prävention ' )
-> assertJsonPath ( 'data.courses.0.course.short_name' , '2e' )
-> assertJsonPath ( 'data.invoicePositions.0.description' , 'uu' )
-> assertJsonPath ( 'data.invoicePositions.0.price_human' , '10,50 €' )
2024-08-28 22:28:12 +02:00
-> assertJsonPath ( 'data.invoicePositions.0.invoice.status' , 'Neu' )
-> assertJsonPath ( 'data.links.update' , route ( 'member.update' , [ 'member' => $member ]));
2022-11-18 15:55:44 +01:00
}
2022-11-19 00:09:53 +01:00
public function testItShowsMinimalSingleMember () : void
{
$this -> withoutExceptionHandling () -> login () -> loginNami ();
$member = Member :: factory ()
-> for ( Group :: factory ())
-> for ( Nationality :: factory () -> name ( 'deutsch' ))
2024-02-22 11:13:20 +01:00
-> for ( Subscription :: factory () -> forFee ())
2022-11-19 00:21:58 +01:00
-> create ([ 'firstname' => 'Max' , 'lastname' => 'Muster' ]);
2022-11-19 00:09:53 +01:00
2024-08-28 22:12:05 +02:00
$this -> get ( route ( 'member.show' , [ 'member' => $member ]))
-> assertJsonPath ( 'data.has_vk' , false )
-> assertJsonPath ( 'data.has_svk' , false )
-> assertJsonPath ( 'data.multiply_pv' , false )
-> assertJsonPath ( 'data.multiply_more_pv' , false )
-> assertJsonPath ( 'data.nationality.name' , 'deutsch' )
-> assertJsonPath ( 'data.region.name' , '-- kein --' )
-> assertJsonPath ( 'data.fullname' , 'Max Muster' );
2022-11-19 00:09:53 +01:00
}
2023-09-05 16:29:22 +02:00
public function membershipDataProvider () : Generator
{
2023-09-07 00:22:44 +02:00
yield [ now () -> subMonths ( 2 ), null , true ];
yield [ now () -> subMonths ( 2 ), now () -> subDay (), false ];
yield [ now () -> addDays ( 2 ), null , false ];
2023-09-05 16:29:22 +02:00
}
/**
* @ dataProvider membershipDataProvider
*/
public function testItShowsIfMembershipIsActive ( Carbon $from , ? Carbon $to , bool $isActive ) : void
{
$this -> withoutExceptionHandling () -> login () -> loginNami ();
$member = Member :: factory ()
-> defaults ()
-> has ( Membership :: factory () -> in ( '€ LeiterIn' , 455 , 'Pfadfinder' , 15 ) -> state ([ 'from' => $from , 'to' => $to ]))
-> create ();
2024-08-28 22:12:05 +02:00
$this -> get ( route ( 'member.show' , [ 'member' => $member ]))
-> assertJsonPath ( 'data.memberships.0.is_active' , $isActive );
}
public function testItDisplaysMeta () : void
{
$this -> withoutExceptionHandling ();
$this -> login () -> loginNami ();
$member = Member :: factory () -> defaults () -> create ([ 'salutation' => 'Doktor' , 'firstname' => 'Max' , 'comment' => 'Lorem bla' ]);
$activity = Activity :: factory () -> inNami ( 66 ) -> hasAttached ( Subactivity :: factory () -> inNami ( 56 ) -> name ( 'Biber' )) -> name ( '€ Mitglied' ) -> create ();
$subactivity = $activity -> subactivities -> first ();
2023-09-05 16:29:22 +02:00
2024-08-28 22:12:05 +02:00
$this -> get ( route ( 'member.show' , [ 'member' => $member ]))
-> assertJsonPath ( " meta.formActivities. { $activity -> id } " , '€ Mitglied' )
-> assertJsonPath ( " meta.formSubactivities. { $activity -> id } . { $subactivity -> id } " , 'Biber' )
-> assertJsonPath ( " meta.billKinds.0 " , [ 'id' => 'E-Mail' , 'name' => 'E-Mail' ]);
2023-09-05 16:29:22 +02:00
}
2022-11-18 15:55:44 +01:00
}