Compare commits
	
		
			9 Commits
		
	
	
		
			37c9021e76
			...
			5a48c983cd
		
	
	| Author | SHA1 | Date | 
|---|---|---|
|  | 5a48c983cd | |
|  | be771af35e | |
|  | 629797c03f | |
|  | 7206c88998 | |
|  | 31f398f7d4 | |
|  | 22aa303311 | |
|  | f2fb583797 | |
|  | 2e010aece1 | |
|  | 793f916581 | 
|  | @ -84,6 +84,9 @@ class MemberRequest extends FormRequest | ||||||
|             'salutation' => '', |             'salutation' => '', | ||||||
|             'comment' => '', |             'comment' => '', | ||||||
|             'keepdata' => 'boolean', |             'keepdata' => 'boolean', | ||||||
|  |             'bank_account' => 'array|exclude', | ||||||
|  |             'bank_account.iban' => 'nullable|string|max:255', | ||||||
|  |             'bank_account.bic' => 'nullable|string|max:255', | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -94,6 +97,7 @@ class MemberRequest extends FormRequest | ||||||
|             'group_id' => Group::where('nami_id', $settings->default_group_id)->firstOrFail()->id, |             'group_id' => Group::where('nami_id', $settings->default_group_id)->firstOrFail()->id, | ||||||
|         ]); |         ]); | ||||||
|         $member->updatePhoneNumbers()->save(); |         $member->updatePhoneNumbers()->save(); | ||||||
|  |         $member->bankAccount->update($this->input('bank_account')); | ||||||
| 
 | 
 | ||||||
|         if ($this->input('has_nami')) { |         if ($this->input('has_nami')) { | ||||||
|             $this->storeFreshMemberInNami($member); |             $this->storeFreshMemberInNami($member); | ||||||
|  | @ -117,6 +121,7 @@ class MemberRequest extends FormRequest | ||||||
|         $namiSync = $member->isDirty(Member::$namiFields); |         $namiSync = $member->isDirty(Member::$namiFields); | ||||||
| 
 | 
 | ||||||
|         $member->save(); |         $member->save(); | ||||||
|  |         $member->bankAccount->update($this->input('bank_account')); | ||||||
| 
 | 
 | ||||||
|         if ($this->input('has_nami') && null === $member->nami_id) { |         if ($this->input('has_nami') && null === $member->nami_id) { | ||||||
|             $this->storeFreshMemberInNami($member); |             $this->storeFreshMemberInNami($member); | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| #!/bin/bash | #!/bin/bash | ||||||
| 
 | 
 | ||||||
| echo "drop database scoutrobot;" | sudo mysql | echo "drop database adrema;" | sudo mysql | ||||||
| echo "create database scoutrobot;" | sudo mysql | echo "create database adrema;" | sudo mysql | ||||||
| 
 | 
 | ||||||
| ssh -l stamm-silva zoomyboy.de "cd /usr/share/webapps/adrema_silva && docker compose exec db mysqldump -udb -p$SCOUTROBOT_DB_PASSWORD db" > db.tmp | ssh -l stamm-silva zoomyboy.de "cd /usr/share/webapps/adrema_silva && docker compose exec db mysqldump -udb -p$SCOUTROBOT_DB_PASSWORD db" > db.tmp | ||||||
| sudo mysql adrema < db.tmp | sudo mysql adrema < db.tmp | ||||||
|  |  | ||||||
|  | @ -93,6 +93,11 @@ class MemberFactory extends Factory | ||||||
|         return $this->state(['nami_id' => $namiId]); |         return $this->state(['nami_id' => $namiId]); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public function notInNami(): self | ||||||
|  |     { | ||||||
|  |         return $this->state(['nami_id' => null]); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public function withBankAccount(BankAccountFactory $factory): self |     public function withBankAccount(BankAccountFactory $factory): self | ||||||
|     { |     { | ||||||
|         return $this->afterCreating(function ($member) use ($factory) { |         return $this->afterCreating(function ($member) use ($factory) { | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| <?php | <?php | ||||||
| 
 | 
 | ||||||
|  | use App\Member\Member; | ||||||
| use Illuminate\Database\Migrations\Migration; | use Illuminate\Database\Migrations\Migration; | ||||||
| use Illuminate\Database\Schema\Blueprint; | use Illuminate\Database\Schema\Blueprint; | ||||||
| use Illuminate\Support\Facades\Schema; | use Illuminate\Support\Facades\Schema; | ||||||
|  | @ -22,6 +23,10 @@ return new class extends Migration | ||||||
|             $table->string('account_number')->nullable(); |             $table->string('account_number')->nullable(); | ||||||
|             $table->timestamps(); |             $table->timestamps(); | ||||||
|         }); |         }); | ||||||
|  | 
 | ||||||
|  |         foreach (Member::get() as $member) { | ||||||
|  |             $member->bankAccount()->create([]); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  |  | ||||||
|  | @ -1 +1 @@ | ||||||
| Subproject commit f905c316ee7913cbf85c386021fbaa28b4b2a158 | Subproject commit c20cf930f2037ddda4400dd7d35bf9ef707356eb | ||||||
|  | @ -17,277 +17,242 @@ use App\Region; | ||||||
| use App\Subactivity; | use App\Subactivity; | ||||||
| use Illuminate\Foundation\Testing\DatabaseTransactions; | use Illuminate\Foundation\Testing\DatabaseTransactions; | ||||||
| use Tests\Lib\MergesAttributes; | use Tests\Lib\MergesAttributes; | ||||||
|  | use Tests\RequestFactories\MemberStoreRequestFactory; | ||||||
| use Tests\TestCase; | use Tests\TestCase; | ||||||
| use Zoomyboy\LaravelNami\Fakes\MemberFake; | use Zoomyboy\LaravelNami\Fakes\MemberFake; | ||||||
| 
 | 
 | ||||||
| class StoreTest extends TestCase | uses(DatabaseTransactions::class); | ||||||
| { |  | ||||||
|     use DatabaseTransactions; |  | ||||||
|     use MergesAttributes; |  | ||||||
| 
 | 
 | ||||||
|     public function testItCanStoreAMember(): void | beforeEach(function () { | ||||||
|     { |     Confession::factory()->create(['is_null' => true]); | ||||||
|         app(MemberFake::class)->stores(55, 103); |     PullMemberAction::shouldRun(); | ||||||
|         Fee::factory()->create(); |     PullMembershipsAction::shouldRun(); | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); | }); | ||||||
|         $country = Country::factory()->create(); |  | ||||||
|         $gender = Gender::factory()->create(); |  | ||||||
|         $region = Region::factory()->create(); |  | ||||||
|         $nationality = Nationality::factory()->create(); |  | ||||||
|         $activity = Activity::factory()->inNami(89)->create(); |  | ||||||
|         $subactivity = Subactivity::factory()->inNami(90)->create(); |  | ||||||
|         $subscription = Subscription::factory()->forFee()->create(); |  | ||||||
|         $confesstion = Confession::factory()->create(['is_null' => true]); |  | ||||||
|         PullMemberAction::shouldRun(); |  | ||||||
|         PullMembershipsAction::shouldRun(); |  | ||||||
| 
 | 
 | ||||||
|         $response = $this | it('can store a member', function () { | ||||||
|             ->from('/member/create') |     app(MemberFake::class)->stores(55, 103); | ||||||
|             ->post('/member', $this->attributes([ |     Fee::factory()->create(); | ||||||
|                 'country_id' => $country->id, |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|                 'gender_id' => $gender->id, |     $country = Country::factory()->create(); | ||||||
|                 'region_id' => $region->id, |     $gender = Gender::factory()->create(); | ||||||
|                 'nationality_id' => $nationality->id, |     $region = Region::factory()->create(); | ||||||
|                 'first_activity_id' => $activity->id, |     $nationality = Nationality::factory()->create(); | ||||||
|                 'first_subactivity_id' => $subactivity->id, |     $activity = Activity::factory()->inNami(89)->create(); | ||||||
|                 'subscription_id' => $subscription->id, |     $subactivity = Subactivity::factory()->inNami(90)->create(); | ||||||
|                 'bill_kind' => 'Post', |     $subscription = Subscription::factory()->forFee()->create(); | ||||||
|                 'salutation' => 'Doktor', |  | ||||||
|                 'comment' => 'Lorem bla', |  | ||||||
|             ]))->assertSessionHasNoErrors(); |  | ||||||
| 
 | 
 | ||||||
|         $response->assertRedirect('/member')->assertSessionHasNoErrors(); |     $response = $this | ||||||
|         $member = Member::firstWhere('firstname', 'Joe'); |         ->from('/member/create') | ||||||
|         $this->assertDatabaseHas('members', [ |         ->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|             'address' => 'Bavert 50', |  | ||||||
|             'bill_kind' => 'Post', |  | ||||||
|             'birthday' => '2013-02-19', |  | ||||||
|             'children_phone' => '+49 176 70512778', |  | ||||||
|             'country_id' => $country->id, |             'country_id' => $country->id, | ||||||
|             'email_parents' => 'osloot@aol.com', |  | ||||||
|             'firstname' => 'Joe', |  | ||||||
|             'gender_id' => $gender->id, |             'gender_id' => $gender->id, | ||||||
|             'joined_at' => '2022-08-12', |  | ||||||
|             'lastname' => 'Muster', |  | ||||||
|             'letter_address' => null, |  | ||||||
|             'location' => 'Solingen', |  | ||||||
|             'main_phone' => '+49 212 337056', |  | ||||||
|             'mobile_phone' => '+49 176 70512774', |  | ||||||
|             'nationality_id' => $nationality->id, |  | ||||||
|             'region_id' => $region->id, |             'region_id' => $region->id, | ||||||
|             'send_newspaper' => '1', |             'nationality_id' => $nationality->id, | ||||||
|  |             'first_activity_id' => $activity->id, | ||||||
|  |             'first_subactivity_id' => $subactivity->id, | ||||||
|             'subscription_id' => $subscription->id, |             'subscription_id' => $subscription->id, | ||||||
|             'zip' => '42719', |             'bill_kind' => 'Post', | ||||||
|             'fax' => '+49 212 4732223', |  | ||||||
|             'salutation' => 'Doktor', |             'salutation' => 'Doktor', | ||||||
|             'comment' => 'Lorem bla', |             'comment' => 'Lorem bla', | ||||||
|         ]); |         ]))->assertSessionHasNoErrors(); | ||||||
| 
 | 
 | ||||||
|         app(MemberFake::class)->assertStored(55, [ |     $response->assertRedirect('/member')->assertSessionHasNoErrors(); | ||||||
|             'ersteTaetigkeitId' => 89, |     $this->assertDatabaseHas('members', [ | ||||||
|             'ersteUntergliederungId' => 90, |         'address' => 'Bavert 50', | ||||||
|         ]); |         'bill_kind' => 'Post', | ||||||
|     } |         'birthday' => '2013-02-19', | ||||||
|  |         'children_phone' => '+49 176 70512778', | ||||||
|  |         'country_id' => $country->id, | ||||||
|  |         'email_parents' => 'osloot@aol.com', | ||||||
|  |         'firstname' => 'Joe', | ||||||
|  |         'gender_id' => $gender->id, | ||||||
|  |         'joined_at' => '2022-08-12', | ||||||
|  |         'lastname' => 'Muster', | ||||||
|  |         'letter_address' => null, | ||||||
|  |         'location' => 'Solingen', | ||||||
|  |         'main_phone' => '+49 212 337056', | ||||||
|  |         'mobile_phone' => '+49 176 70512774', | ||||||
|  |         'nationality_id' => $nationality->id, | ||||||
|  |         'region_id' => $region->id, | ||||||
|  |         'send_newspaper' => '1', | ||||||
|  |         'subscription_id' => $subscription->id, | ||||||
|  |         'zip' => '42719', | ||||||
|  |         'fax' => '+49 212 4732223', | ||||||
|  |         'salutation' => 'Doktor', | ||||||
|  |         'comment' => 'Lorem bla', | ||||||
|  |     ]); | ||||||
| 
 | 
 | ||||||
|     public function testItStoresWiederverwendenFlag(): void |     app(MemberFake::class)->assertStored(55, [ | ||||||
|     { |         'ersteTaetigkeitId' => 89, | ||||||
|         app(MemberFake::class)->stores(55, 103); |         'ersteUntergliederungId' => 90, | ||||||
|         Fee::factory()->create(); |     ]); | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); | }); | ||||||
|         $activity = Activity::factory()->inNami(89)->create(); |  | ||||||
|         $subactivity = Subactivity::factory()->inNami(90)->create(); |  | ||||||
|         $subscription = Subscription::factory()->forFee()->create(); |  | ||||||
|         $confesstion = Confession::factory()->create(['is_null' => true]); |  | ||||||
|         PullMemberAction::shouldRun(); |  | ||||||
|         PullMembershipsAction::shouldRun(); |  | ||||||
| 
 | 
 | ||||||
|         $this | it('can store iban and bic', function () { | ||||||
|             ->from('/member/create') |     app(MemberFake::class)->stores(55, 103); | ||||||
|             ->post('/member', $this->attributes([ |     Fee::factory()->create(); | ||||||
|                 'first_activity_id' => $activity->id, |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|                 'first_subactivity_id' => $subactivity->id, |  | ||||||
|                 'subscription_id' => $subscription->id, |  | ||||||
|                 'keepdata' => true, |  | ||||||
|             ]))->assertSessionHasNoErrors(); |  | ||||||
| 
 | 
 | ||||||
|         $this->assertDatabaseHas('members', [ |     $this->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|  |         'bank_account.iban' => '666', | ||||||
|  |         'bank_account.bic' => 'SOLSDE', | ||||||
|  |     ]))->assertSessionHasNoErrors(); | ||||||
|  | 
 | ||||||
|  |     $this->assertDatabaseHas('bank_accounts', [ | ||||||
|  |         'iban' => '666', | ||||||
|  |         'bic' => 'SOLSDE', | ||||||
|  |         'member_id' => Member::first()->id, | ||||||
|  |     ]); | ||||||
|  | 
 | ||||||
|  |     app(MemberFake::class)->assertStored(55, function ($payload) { | ||||||
|  |         $bank = json_decode($payload['kontoverbindung'], true); | ||||||
|  |         return $bank['iban'] === '666' && $bank['bic'] === 'SOLSDE'; | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItStoresWiederverwendenFlag', function () { | ||||||
|  |     app(MemberFake::class)->stores(55, 103); | ||||||
|  |     Fee::factory()->create(); | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $activity = Activity::factory()->inNami(89)->create(); | ||||||
|  |     $subactivity = Subactivity::factory()->inNami(90)->create(); | ||||||
|  |     $subscription = Subscription::factory()->forFee()->create(); | ||||||
|  | 
 | ||||||
|  |     $this | ||||||
|  |         ->from('/member/create') | ||||||
|  |         ->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|  |             'first_activity_id' => $activity->id, | ||||||
|  |             'first_subactivity_id' => $subactivity->id, | ||||||
|  |             'subscription_id' => $subscription->id, | ||||||
|             'keepdata' => true, |             'keepdata' => true, | ||||||
|         ]); |         ]))->assertSessionHasNoErrors(); | ||||||
|         app(MemberFake::class)->assertStored(55, [ |  | ||||||
|             'wiederverwendenFlag' => true, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     public function testItCanStoreAMemberWithoutNami(): void |     $this->assertDatabaseHas('members', [ | ||||||
|     { |         'keepdata' => true, | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); |     ]); | ||||||
|         $activity = Activity::factory()->create(); |     app(MemberFake::class)->assertStored(55, [ | ||||||
|         $subactivity = Subactivity::factory()->create(); |         'wiederverwendenFlag' => true, | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
| 
 | 
 | ||||||
|         $response = $this | it('testItCanStoreAMemberWithoutNami', function () { | ||||||
|             ->from('/member/create') |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|             ->post('/member', $this->attributes([ |     $activity = Activity::factory()->create(); | ||||||
|                 'first_activity_id' => $activity->id, |     $subactivity = Subactivity::factory()->create(); | ||||||
|                 'first_subactivity_id' => $subactivity->id, |  | ||||||
|                 'has_nami' => false, |  | ||||||
|             ])); |  | ||||||
| 
 | 
 | ||||||
|         $response->assertSessionHasNoErrors(); |     $response = $this | ||||||
|         $this->assertDatabaseHas('members', [ |         ->from('/member/create') | ||||||
|             'nami_id' => null, |         ->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|         ]); |             'first_activity_id' => $activity->id, | ||||||
|         NamiPutMemberAction::spy()->shouldNotHaveReceived('handle'); |             'first_subactivity_id' => $subactivity->id, | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItUpdatesPhoneNumber(): void |  | ||||||
|     { |  | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); |  | ||||||
| 
 |  | ||||||
|         $this->post('/member', $this->attributes([ |  | ||||||
|             'has_nami' => false, |             'has_nami' => false, | ||||||
|             'main_phone' => '02103 4455129', |  | ||||||
|             'fax' => '02103 4455130', |  | ||||||
|             'children_phone' => '02103 4455130', |  | ||||||
|         ])); |         ])); | ||||||
| 
 | 
 | ||||||
|         $this->assertDatabaseHas('members', [ |     $response->assertSessionHasNoErrors(); | ||||||
|             'main_phone' => '+49 2103 4455129', |     $this->assertDatabaseHas('members', [ | ||||||
|             'fax' => '+49 2103 4455130', |         'nami_id' => null, | ||||||
|             'children_phone' => '+49 2103 4455130', |     ]); | ||||||
|         ]); |     NamiPutMemberAction::spy()->shouldNotHaveReceived('handle'); | ||||||
|     } | }); | ||||||
| 
 | 
 | ||||||
|     public function testItHasErrorWhenPhoneNumberIsInvalid(): void | it('testItUpdatesPhoneNumber', function () { | ||||||
|     { |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|         $this->login()->loginNami(); |  | ||||||
| 
 | 
 | ||||||
|         $response = $this->post('/member', $this->attributes([ |     $this->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|             'has_nami' => false, |         'has_nami' => false, | ||||||
|             'main_phone' => '1111111111111111', |         'main_phone' => '02103 4455129', | ||||||
|             'mobile_phone' => '1111111111111111', |         'fax' => '02103 4455130', | ||||||
|             'fax' => '1111111111111111', |         'children_phone' => '02103 4455130', | ||||||
|             'children_phone' => '1111111111111111', |     ])); | ||||||
|         ])); |  | ||||||
| 
 | 
 | ||||||
|         $response->assertSessionHasErrors([ |     $this->assertDatabaseHas('members', [ | ||||||
|             'main_phone' => 'Telefon (Eltern) ist keine valide Nummer.', |         'main_phone' => '+49 2103 4455129', | ||||||
|             'mobile_phone' => 'Handy (Eltern) ist keine valide Nummer.', |         'fax' => '+49 2103 4455130', | ||||||
|             'children_phone' => 'Telefon (Kind) ist keine valide Nummer.', |         'children_phone' => '+49 2103 4455130', | ||||||
|             'fax' => 'Fax ist keine valide Nummer.', |     ]); | ||||||
|         ]); | }); | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     public function testItDoesntRequireBirthdayWhenNotInNami(): void | it('testItHasErrorWhenPhoneNumberIsInvalid', function () { | ||||||
|     { |     $this->login()->loginNami(); | ||||||
|         $this->login()->loginNami(); |  | ||||||
| 
 | 
 | ||||||
|         $this |     $response = $this->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|             ->post('/member', $this->attributes([ |         'has_nami' => false, | ||||||
|                 'nationality_id' => null, |         'main_phone' => '1111111111111111', | ||||||
|                 'birthday' => null, |         'mobile_phone' => '1111111111111111', | ||||||
|                 'has_nami' => false, |         'fax' => '1111111111111111', | ||||||
|                 'address' => null, |         'children_phone' => '1111111111111111', | ||||||
|                 'zip' => null, |     ])); | ||||||
|                 'location' => null, | 
 | ||||||
|                 'joined_at' => null, |     $response->assertSessionHasErrors([ | ||||||
|             ]))->assertSessionDoesntHaveErrors(); |         'main_phone' => 'Telefon (Eltern) ist keine valide Nummer.', | ||||||
|         $this->assertDatabaseHas('members', [ |         'mobile_phone' => 'Handy (Eltern) ist keine valide Nummer.', | ||||||
|  |         'children_phone' => 'Telefon (Kind) ist keine valide Nummer.', | ||||||
|  |         'fax' => 'Fax ist keine valide Nummer.', | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItDoesntRequireBirthdayWhenNotInNami', function () { | ||||||
|  |     $this->login()->loginNami(); | ||||||
|  | 
 | ||||||
|  |     $this | ||||||
|  |         ->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|             'nationality_id' => null, |             'nationality_id' => null, | ||||||
|             'birthday' => null, |             'birthday' => null, | ||||||
|  |             'has_nami' => false, | ||||||
|             'address' => null, |             'address' => null, | ||||||
|             'zip' => null, |             'zip' => null, | ||||||
|             'location' => null, |             'location' => null, | ||||||
|             'joined_at' => null, |             'joined_at' => null, | ||||||
|         ]); |         ]))->assertSessionDoesntHaveErrors(); | ||||||
|     } |     $this->assertDatabaseHas('members', [ | ||||||
|  |         'nationality_id' => null, | ||||||
|  |         'birthday' => null, | ||||||
|  |         'address' => null, | ||||||
|  |         'zip' => null, | ||||||
|  |         'location' => null, | ||||||
|  |         'joined_at' => null, | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
| 
 | 
 | ||||||
|     public function testItDoesntNeedSubscription(): void | it('testItDoesntNeedSubscription', function () { | ||||||
|     { |     $this->login()->loginNami(); | ||||||
|         $this->login()->loginNami(); |  | ||||||
| 
 | 
 | ||||||
|         $this |     $this | ||||||
|             ->post('/member', $this->attributes([ |         ->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|                 'has_nami' => false, |             'has_nami' => false, | ||||||
|                 'subscription_id' => null, |  | ||||||
|             ]))->assertSessionDoesntHaveErrors(); |  | ||||||
|         $this->assertDatabaseHas('members', [ |  | ||||||
|             'subscription_id' => null, |             'subscription_id' => null, | ||||||
|         ]); |         ]))->assertSessionDoesntHaveErrors(); | ||||||
|     } |     $this->assertDatabaseHas('members', [ | ||||||
|  |         'subscription_id' => null, | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
| 
 | 
 | ||||||
|     public function testItRequiresFields(): void | it('testItRequiresFields', function () { | ||||||
|     { |     $this->login()->loginNami(); | ||||||
|         $this->login()->loginNami(); |  | ||||||
| 
 | 
 | ||||||
|         $this |     $this | ||||||
|             ->post('/member', $this->attributes([ |         ->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|                 'nationality_id' => null, |             'nationality_id' => null, | ||||||
|                 'birthday' => '', |             'birthday' => '', | ||||||
|                 'address' => '', |             'address' => '', | ||||||
|                 'zip' => '', |             'zip' => '', | ||||||
|                 'location' => '', |             'location' => '', | ||||||
|                 'joined_at' => '', |             'joined_at' => '', | ||||||
|             ])) |         ])) | ||||||
|             ->assertSessionHasErrors(['nationality_id', 'birthday', 'address', 'zip', 'location', 'joined_at']); |         ->assertSessionHasErrors(['nationality_id', 'birthday', 'address', 'zip', 'location', 'joined_at']); | ||||||
|     } | }); | ||||||
| 
 | 
 | ||||||
|     public function testSubscriptionIsRequiredIfFirstActivityIsPaid(): void | it('testSubscriptionIsRequiredIfFirstActivityIsPaid', function () { | ||||||
|     { |     $this->login()->loginNami(); | ||||||
|         $this->login()->loginNami(); |     $activity = Activity::factory()->name('€ Mitglied')->create(); | ||||||
|         $activity = Activity::factory()->name('€ Mitglied')->create(); |     $subactivity = Subactivity::factory()->create(); | ||||||
|         $subactivity = Subactivity::factory()->create(); |  | ||||||
| 
 | 
 | ||||||
|         $this |     $this | ||||||
|             ->from('/member/create') |         ->from('/member/create') | ||||||
|             ->post('/member', $this->attributes([ |         ->post('/member', MemberStoreRequestFactory::new()->create([ | ||||||
|                 'first_activity_id' => $activity->id, |             'first_activity_id' => $activity->id, | ||||||
|                 'first_subactivity_id' => $subactivity->id, |             'first_subactivity_id' => $subactivity->id, | ||||||
|                 'subscription_id' => null, |             'subscription_id' => null, | ||||||
|             ])) |         ])) | ||||||
|             ->assertSessionHasErrors(['subscription_id' => 'Beitragsart ist erforderlich.']); |         ->assertSessionHasErrors(['subscription_id' => 'Beitragsart ist erforderlich.']); | ||||||
|     } | }); | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @return array<string, mixed> |  | ||||||
|      */ |  | ||||||
|     public function defaults(): array |  | ||||||
|     { |  | ||||||
|         $country = Country::factory()->create(); |  | ||||||
|         $nationality = Nationality::factory()->create(); |  | ||||||
|         $subscription = Subscription::factory()->forFee()->create(); |  | ||||||
| 
 |  | ||||||
|         return [ |  | ||||||
|             'address' => 'Bavert 50', |  | ||||||
|             'birthday' => '2013-02-19', |  | ||||||
|             'children_phone' => '+49 176 70512778', |  | ||||||
|             'efz' => '', |  | ||||||
|             'email' => '', |  | ||||||
|             'email_parents' => 'osloot@aol.com', |  | ||||||
|             'fax' => '+49 212 4732223', |  | ||||||
|             'firstname' => 'Joe', |  | ||||||
|             'further_address' => '', |  | ||||||
|             'has_nami' => true, |  | ||||||
|             'has_svk' => false, |  | ||||||
|             'has_vk' => false, |  | ||||||
|             'joined_at' => '2022-08-12', |  | ||||||
|             'lastname' => 'Muster', |  | ||||||
|             'letter_address' => '', |  | ||||||
|             'location' => 'Solingen', |  | ||||||
|             'main_phone' => '+49 212 337056', |  | ||||||
|             'mobile_phone' => '+49 176 70512774', |  | ||||||
|             'more_ps_at' => '', |  | ||||||
|             'multiply_more_pv' => false, |  | ||||||
|             'multiply_pv' => false, |  | ||||||
|             'other_country' => '', |  | ||||||
|             'ps_at' => '', |  | ||||||
|             'send_newspaper' => true, |  | ||||||
|             'without_education_at' => '', |  | ||||||
|             'without_efz_at' => '', |  | ||||||
|             'work_phone' => '', |  | ||||||
|             'zip' => '42719', |  | ||||||
|             'country_id' => $country->id, |  | ||||||
|             'nationality_id' => $nationality->id, |  | ||||||
|             'subscription_id' => $subscription->id, |  | ||||||
|         ]; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -6,238 +6,239 @@ use App\Actions\PullMemberAction; | ||||||
| use App\Actions\PullMembershipsAction; | use App\Actions\PullMembershipsAction; | ||||||
| use App\Activity; | use App\Activity; | ||||||
| use App\Confession; | use App\Confession; | ||||||
| use App\Country; |  | ||||||
| use App\Fee; |  | ||||||
| use App\Group; | use App\Group; | ||||||
| use App\Member\Actions\NamiPutMemberAction; | use App\Member\Actions\NamiPutMemberAction; | ||||||
| use App\Member\Member; | use App\Member\Member; | ||||||
| use App\Nationality; |  | ||||||
| use App\Payment\Subscription; |  | ||||||
| use App\Subactivity; | use App\Subactivity; | ||||||
| use Illuminate\Foundation\Testing\DatabaseTransactions; | use Illuminate\Foundation\Testing\DatabaseTransactions; | ||||||
| use Illuminate\Support\Facades\Http; | use Illuminate\Support\Facades\Http; | ||||||
| use Tests\TestCase; | use Tests\RequestFactories\MemberUpdateRequestFactory; | ||||||
| use Zoomyboy\LaravelNami\Fakes\MemberFake; | use Zoomyboy\LaravelNami\Fakes\MemberFake; | ||||||
| 
 | 
 | ||||||
| class UpdateTest extends TestCase | uses(DatabaseTransactions::class); | ||||||
|  | 
 | ||||||
|  | function singleMemberUrl(int $gruppierungId, int $memberId): string | ||||||
| { | { | ||||||
|     use DatabaseTransactions; |     return "https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{$gruppierungId}/{$memberId}"; | ||||||
| 
 |  | ||||||
|     public function testItRedirectsToMemberOverview(): void |  | ||||||
|     { |  | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); |  | ||||||
|         $member = $this->member(); |  | ||||||
|         $this->fakeRequest(); |  | ||||||
|         NamiPutMemberAction::allowToRun(); |  | ||||||
| 
 |  | ||||||
|         $response = $this |  | ||||||
|             ->from("/member/{$member->id}") |  | ||||||
|             ->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true])); |  | ||||||
| 
 |  | ||||||
|         $response->assertRedirect('/member'); |  | ||||||
|         NamiPutMemberAction::spy()->shouldHaveReceived('handle')->withArgs( |  | ||||||
|             fn (Member $memberParam, ?Activity $activityParam, ?Subactivity $subactivityParam) => $memberParam->is($member) |  | ||||||
|                 && null === $activityParam |  | ||||||
|                 && null === $subactivityParam |  | ||||||
|         )->once(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItChecksVersion(): void |  | ||||||
|     { |  | ||||||
|         $this->login()->loginNami()->withoutExceptionHandling(); |  | ||||||
|         $member = $this->member(); |  | ||||||
|         $member->update(['version' => 43]); |  | ||||||
|         $this->fakeRequest(); |  | ||||||
| 
 |  | ||||||
|         $response = $this |  | ||||||
|             ->from("/member/{$member->id}") |  | ||||||
|             ->patch("/member/{$member->id}", array_merge($member->getAttributes(), ['has_nami' => true, 'firstname' => '::firstname::'])); |  | ||||||
| 
 |  | ||||||
|         $response->assertRedirect("/member/{$member->id}/edit?conflict=1"); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItUpdatesPhoneNumber(): void |  | ||||||
|     { |  | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); |  | ||||||
|         $member = $this->member(); |  | ||||||
|         $this->fakeRequest(); |  | ||||||
|         NamiPutMemberAction::allowToRun(); |  | ||||||
| 
 |  | ||||||
|         $this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [ |  | ||||||
|             'main_phone' => '02103 4455129', |  | ||||||
|             'fax' => '02103 4455130', |  | ||||||
|             'children_phone' => '02103 4455130', |  | ||||||
|             'has_nami' => true, |  | ||||||
|         ])); |  | ||||||
| 
 |  | ||||||
|         $this->assertDatabaseHas('members', [ |  | ||||||
|             'main_phone' => '+49 2103 4455129', |  | ||||||
|             'fax' => '+49 2103 4455130', |  | ||||||
|             'children_phone' => '+49 2103 4455130', |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItUpdatesWiederverwendenFlag(): void |  | ||||||
|     { |  | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); |  | ||||||
|         $member = $this->member(); |  | ||||||
|         $this->fakeRequest(); |  | ||||||
|         NamiPutMemberAction::allowToRun(); |  | ||||||
| 
 |  | ||||||
|         $this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [ |  | ||||||
|             'keepdata' => true, |  | ||||||
|             'has_nami' => true, |  | ||||||
|         ])); |  | ||||||
| 
 |  | ||||||
|         $this->assertDatabaseHas('members', [ |  | ||||||
|             'keepdata' => true, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItSetsLocationToNull(): void |  | ||||||
|     { |  | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); |  | ||||||
|         $member = $this->member(['location' => 'Hilden', 'nami_id' => null]); |  | ||||||
|         $this->fakeRequest(); |  | ||||||
|         NamiPutMemberAction::allowToRun(); |  | ||||||
| 
 |  | ||||||
|         $this->patch("/member/{$member->id}", array_merge($member->getAttributes(), [ |  | ||||||
|             'location' => null, |  | ||||||
|         ])); |  | ||||||
| 
 |  | ||||||
|         $this->assertDatabaseHas('members', [ |  | ||||||
|             'location' => null, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItUpdatesContact(): void |  | ||||||
|     { |  | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); |  | ||||||
|         $member = $this->member(['nami_id' => null]); |  | ||||||
|         $this->fakeRequest(); |  | ||||||
| 
 |  | ||||||
|         $response = $this |  | ||||||
|             ->from("/member/{$member->id}") |  | ||||||
|             ->patch("/member/{$member->id}", array_merge($member->getAttributes(), [ |  | ||||||
|                 'other_country' => 'englisch', |  | ||||||
|             ])); |  | ||||||
| 
 |  | ||||||
|         $this->assertEquals('englisch', $member->fresh()->other_country); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItCreatesMemberWithFirstActivityId(): void |  | ||||||
|     { |  | ||||||
|         $this->login()->loginNami()->withoutExceptionHandling(); |  | ||||||
|         $member = Member::factory()->defaults()->create(); |  | ||||||
|         app(MemberFake::class)->stores($member->group->nami_id, 103); |  | ||||||
|         $activity = Activity::factory()->inNami(89)->create(); |  | ||||||
|         $subactivity = Subactivity::factory()->inNami(90)->create(); |  | ||||||
|         Confession::factory()->create(['is_null' => true]); |  | ||||||
|         PullMemberAction::shouldRun(); |  | ||||||
|         PullMembershipsAction::shouldRun(); |  | ||||||
| 
 |  | ||||||
|         $this->patch("/member/{$member->id}", [ |  | ||||||
|             ...$member->getAttributes(), |  | ||||||
|             'has_nami' => true, |  | ||||||
|             'first_activity_id' => $activity->id, |  | ||||||
|             'first_subactivity_id' => $subactivity->id, |  | ||||||
|         ])->assertSessionHasNoErrors(); |  | ||||||
| 
 |  | ||||||
|         app(MemberFake::class)->assertStored($member->group->nami_id, [ |  | ||||||
|             'ersteTaetigkeitId' => 89, |  | ||||||
|             'ersteUntergliederungId' => 90, |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItRequiresFirstActivityId(): void |  | ||||||
|     { |  | ||||||
|         $this->login()->loginNami(); |  | ||||||
|         $member = Member::factory()->defaults()->create(); |  | ||||||
|         app(MemberFake::class)->stores($member->group->nami_id, 103); |  | ||||||
|         Confession::factory()->create(['is_null' => true]); |  | ||||||
|         PullMemberAction::shouldRun(); |  | ||||||
|         PullMembershipsAction::shouldRun(); |  | ||||||
| 
 |  | ||||||
|         $this->patch("/member/{$member->id}", [ |  | ||||||
|             ...$member->getAttributes(), |  | ||||||
|             'has_nami' => true, |  | ||||||
|             'first_activity_id' => null, |  | ||||||
|             'first_subactivity_id' => null, |  | ||||||
|         ])->assertSessionHasErrors([ |  | ||||||
|             'first_activity_id' => 'Erste Tätigkeit ist erforderlich.', |  | ||||||
|             'first_subactivity_id' => 'Erste Untergliederung ist erforderlich.', |  | ||||||
|         ]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public function testItUpdatesCriminalRecord(): void |  | ||||||
|     { |  | ||||||
|         $this->withoutExceptionHandling()->login()->loginNami(); |  | ||||||
|         $member = $this->member(['nami_id' => null]); |  | ||||||
|         $this->fakeRequest(); |  | ||||||
| 
 |  | ||||||
|         $response = $this |  | ||||||
|             ->from("/member/{$member->id}") |  | ||||||
|             ->patch("/member/{$member->id}", array_merge($member->getAttributes(), [ |  | ||||||
|                 'ps_at' => '2021-02-01', |  | ||||||
|                 'more_ps_at' => '2021-02-02', |  | ||||||
|                 'has_svk' => true, |  | ||||||
|                 'has_vk' => true, |  | ||||||
|                 'efz' => '2021-02-03', |  | ||||||
|                 'without_education_at' => '2021-02-04', |  | ||||||
|                 'without_efz_at' => '2021-02-05', |  | ||||||
|                 'recertified_at' => '2021-02-08', |  | ||||||
|                 'has_nami' => false, |  | ||||||
|                 'multiply_pv' => true, |  | ||||||
|                 'multiply_more_pv' => true, |  | ||||||
|                 'salutation' => 'Doktor', |  | ||||||
|             ])); |  | ||||||
| 
 |  | ||||||
|         $this->assertEquals('2021-02-01', $member->fresh()->ps_at->format('Y-m-d')); |  | ||||||
|         $this->assertEquals('2021-02-02', $member->fresh()->more_ps_at->format('Y-m-d')); |  | ||||||
|         $this->assertTrue($member->fresh()->has_svk); |  | ||||||
|         $this->assertTrue($member->fresh()->has_vk); |  | ||||||
|         $this->assertTrue($member->fresh()->multiply_pv); |  | ||||||
|         $this->assertTrue($member->fresh()->multiply_more_pv); |  | ||||||
|         $this->assertEquals('2021-02-03', $member->fresh()->efz->format('Y-m-d')); |  | ||||||
|         $this->assertEquals('2021-02-04', $member->fresh()->without_education_at->format('Y-m-d')); |  | ||||||
|         $this->assertEquals('2021-02-05', $member->fresh()->without_efz_at->format('Y-m-d')); |  | ||||||
|         $this->assertEquals('2021-02-08', $member->fresh()->recertified_at->format('Y-m-d')); |  | ||||||
|         $this->assertEquals('Doktor', $member->fresh()->salutation); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * @param array<string, string|Activity|null> $overwrites |  | ||||||
|      */ |  | ||||||
|     private function member(array $overwrites = []): Member |  | ||||||
|     { |  | ||||||
|         return Member::factory() |  | ||||||
|             ->for(Group::factory()->state(['nami_id' => 10])) |  | ||||||
|             ->for(Confession::factory()) |  | ||||||
|             ->for(Nationality::factory()) |  | ||||||
|             ->for(Subscription::factory()->forFee()) |  | ||||||
|             ->for(Country::factory()) |  | ||||||
|             ->create(['nami_id' => 135, ...$overwrites]); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private function fakeRequest(): void |  | ||||||
|     { |  | ||||||
|         Http::fake(function ($request) { |  | ||||||
|             if ($request->url() === $this->singleMemberUrl(10, 135) && 'GET' === $request->method()) { |  | ||||||
|                 return Http::response('{ "success": true, "data": {"missingkey": "missingvalue", "kontoverbindung": {"a": "b"} } }', 200); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             if ($request->url() === $this->singleMemberUrl(10, 135) && 'PUT' === $request->method() && 43 === $request['version']) { |  | ||||||
|                 return Http::response('{ "success": false, "message": "Update nicht möglich. Der Datensatz wurde zwischenzeitlich verändert." }', 200); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             if ($request->url() === $this->singleMemberUrl(10, 135) && 'PUT' === $request->method()) { |  | ||||||
|                 return Http::response('{ "success": true, "data": { "version": 44 } }', 200); |  | ||||||
|             } |  | ||||||
|         }); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     private function singleMemberUrl(int $gruppierungId, int $memberId): string |  | ||||||
|     { |  | ||||||
|         return "https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/{$gruppierungId}/{$memberId}"; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | beforeEach(function () { | ||||||
|  |     Confession::factory()->create(['is_null' => true]); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | function fakeRequest(): void | ||||||
|  | { | ||||||
|  |     Http::fake(function ($request) { | ||||||
|  |         if ($request->url() === singleMemberUrl(10, 135) && 'GET' === $request->method()) { | ||||||
|  |             return Http::response('{ "success": true, "data": {"missingkey": "missingvalue", "kontoverbindung": {"a": "b"} } }', 200); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if ($request->url() === singleMemberUrl(10, 135) && 'PUT' === $request->method() && 43 === $request['version']) { | ||||||
|  |             return Http::response('{ "success": false, "message": "Update nicht möglich. Der Datensatz wurde zwischenzeitlich verändert." }', 200); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if ($request->url() === singleMemberUrl(10, 135) && 'PUT' === $request->method()) { | ||||||
|  |             return Http::response('{ "success": true, "data": { "version": 44 } }', 200); | ||||||
|  |         } | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function factory() | ||||||
|  | { | ||||||
|  |     return Member::factory() | ||||||
|  |         ->defaults() | ||||||
|  |         ->for(Group::factory()->state(['nami_id' => 10])) | ||||||
|  |         ->state(['nami_id' => 135]); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | it('calls put action', function () { | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $member = factory()->create(); | ||||||
|  |     fakeRequest(); | ||||||
|  |     NamiPutMemberAction::allowToRun(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->create()); | ||||||
|  | 
 | ||||||
|  |     NamiPutMemberAction::spy()->shouldHaveReceived('handle')->withArgs( | ||||||
|  |         fn (Member $memberParam, ?Activity $activityParam, ?Subactivity $subactivityParam) => $memberParam->is($member) | ||||||
|  |             && null === $activityParam | ||||||
|  |             && null === $subactivityParam | ||||||
|  |     )->once(); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('redirects to member overview', function () { | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $member = factory()->create(); | ||||||
|  |     fakeRequest(); | ||||||
|  |     NamiPutMemberAction::allowToRun(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->create()) | ||||||
|  |         ->assertRedirect('/member'); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItChecksVersion', function () { | ||||||
|  |     $this->login()->loginNami()->withoutExceptionHandling(); | ||||||
|  |     $member = tap(factory()->create(), fn ($member) => $member->update(['version' => 43])); | ||||||
|  |     fakeRequest(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", array_merge($member->getAttributes(), MemberUpdateRequestFactory::new()->create())) | ||||||
|  |         ->assertRedirect("/member/{$member->id}/edit?conflict=1"); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItUpdatesPhoneNumber', function () { | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $member = factory()->create(); | ||||||
|  |     fakeRequest(); | ||||||
|  |     NamiPutMemberAction::allowToRun(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->create([ | ||||||
|  |         'main_phone' => '02103 4455129', | ||||||
|  |         'fax' => '02103 4455130', | ||||||
|  |         'children_phone' => '02103 4455130', | ||||||
|  |     ])); | ||||||
|  | 
 | ||||||
|  |     $this->assertDatabaseHas('members', [ | ||||||
|  |         'main_phone' => '+49 2103 4455129', | ||||||
|  |         'fax' => '+49 2103 4455130', | ||||||
|  |         'children_phone' => '+49 2103 4455130', | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItUpdatesBankAccount', function () { | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $member = factory()->create(); | ||||||
|  |     fakeRequest(); | ||||||
|  |     NamiPutMemberAction::allowToRun(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->create([ | ||||||
|  |         'bank_account' => [ | ||||||
|  |             'iban' => 'DE1122', | ||||||
|  |             'bic' => 'SOLSDE', | ||||||
|  |             'person' => 'Max' | ||||||
|  |         ] | ||||||
|  |     ])); | ||||||
|  | 
 | ||||||
|  |     $this->assertDatabaseHas('bank_accounts', [ | ||||||
|  |         'iban' => 'DE1122', | ||||||
|  |         'bic' => 'SOLSDE', | ||||||
|  |         'person' => 'Max', | ||||||
|  |         'member_id' => $member->id, | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItUpdatesWiederverwendenFlag', function () { | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $member = factory()->create(); | ||||||
|  |     fakeRequest(); | ||||||
|  |     NamiPutMemberAction::allowToRun(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->create([ | ||||||
|  |         'keepdata' => true, | ||||||
|  |     ])); | ||||||
|  | 
 | ||||||
|  |     $this->assertDatabaseHas('members', [ | ||||||
|  |         'keepdata' => true, | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItSetsLocationToNull', function () { | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $member = factory()->notInNami()->create(['location' => 'Hilden']); | ||||||
|  |     fakeRequest(); | ||||||
|  |     NamiPutMemberAction::allowToRun(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->noNami()->create([ | ||||||
|  |         'location' => null, | ||||||
|  |         'bank_account' => [] | ||||||
|  |     ])); | ||||||
|  | 
 | ||||||
|  |     $this->assertDatabaseHas('members', [ | ||||||
|  |         'location' => null, | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItUpdatesContact', function () { | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $member = factory()->notInNami()->create(); | ||||||
|  |     fakeRequest(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->noNami()->create([ | ||||||
|  |         'other_country' => 'englisch', | ||||||
|  |         'bank_account' => [] | ||||||
|  |     ])); | ||||||
|  | 
 | ||||||
|  |     $this->assertEquals('englisch', $member->fresh()->other_country); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItCreatesMemberWithFirstActivityId', function () { | ||||||
|  |     $this->login()->loginNami()->withoutExceptionHandling(); | ||||||
|  |     $member = factory()->new()->defaults()->create(); | ||||||
|  |     app(MemberFake::class)->stores($member->group->nami_id, 103); | ||||||
|  |     $activity = Activity::factory()->inNami(89)->create(); | ||||||
|  |     $subactivity = Subactivity::factory()->inNami(90)->create(); | ||||||
|  |     Confession::factory()->create(['is_null' => true]); | ||||||
|  |     PullMemberAction::shouldRun(); | ||||||
|  |     PullMembershipsAction::shouldRun(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->create([ | ||||||
|  |         'first_activity_id' => $activity->id, | ||||||
|  |         'first_subactivity_id' => $subactivity->id, | ||||||
|  |     ]))->assertSessionHasNoErrors(); | ||||||
|  | 
 | ||||||
|  |     app(MemberFake::class)->assertStored($member->group->nami_id, [ | ||||||
|  |         'ersteTaetigkeitId' => 89, | ||||||
|  |         'ersteUntergliederungId' => 90, | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItRequiresFirstActivityId', function () { | ||||||
|  |     $this->login()->loginNami(); | ||||||
|  |     $member = factory()->new()->defaults()->create(); | ||||||
|  |     app(MemberFake::class)->stores($member->group->nami_id, 103); | ||||||
|  |     Confession::factory()->create(['is_null' => true]); | ||||||
|  |     PullMemberAction::shouldRun(); | ||||||
|  |     PullMembershipsAction::shouldRun(); | ||||||
|  | 
 | ||||||
|  |     $this->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->create([ | ||||||
|  |         'first_activity_id' => null, | ||||||
|  |         'first_subactivity_id' => null, | ||||||
|  |     ]))->assertSessionHasErrors([ | ||||||
|  |         'first_activity_id' => 'Erste Tätigkeit ist erforderlich.', | ||||||
|  |         'first_subactivity_id' => 'Erste Untergliederung ist erforderlich.', | ||||||
|  |     ]); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | it('testItUpdatesCriminalRecord', function () { | ||||||
|  |     $this->withoutExceptionHandling()->login()->loginNami(); | ||||||
|  |     $member = factory()->notInNami()->create(); | ||||||
|  |     fakeRequest(); | ||||||
|  | 
 | ||||||
|  |     $this | ||||||
|  |         ->patch("/member/{$member->id}", MemberUpdateRequestFactory::new()->noNami()->create([ | ||||||
|  |             'ps_at' => '2021-02-01', | ||||||
|  |             'more_ps_at' => '2021-02-02', | ||||||
|  |             'has_svk' => true, | ||||||
|  |             'has_vk' => true, | ||||||
|  |             'efz' => '2021-02-03', | ||||||
|  |             'without_education_at' => '2021-02-04', | ||||||
|  |             'without_efz_at' => '2021-02-05', | ||||||
|  |             'recertified_at' => '2021-02-08', | ||||||
|  |             'has_nami' => false, | ||||||
|  |             'multiply_pv' => true, | ||||||
|  |             'multiply_more_pv' => true, | ||||||
|  |             'salutation' => 'Doktor', | ||||||
|  |             'bank_account' => [] | ||||||
|  |         ])); | ||||||
|  | 
 | ||||||
|  |     $this->assertEquals('2021-02-01', $member->fresh()->ps_at->format('Y-m-d')); | ||||||
|  |     $this->assertEquals('2021-02-02', $member->fresh()->more_ps_at->format('Y-m-d')); | ||||||
|  |     $this->assertTrue($member->fresh()->has_svk); | ||||||
|  |     $this->assertTrue($member->fresh()->has_vk); | ||||||
|  |     $this->assertTrue($member->fresh()->multiply_pv); | ||||||
|  |     $this->assertTrue($member->fresh()->multiply_more_pv); | ||||||
|  |     $this->assertEquals('2021-02-03', $member->fresh()->efz->format('Y-m-d')); | ||||||
|  |     $this->assertEquals('2021-02-04', $member->fresh()->without_education_at->format('Y-m-d')); | ||||||
|  |     $this->assertEquals('2021-02-05', $member->fresh()->without_efz_at->format('Y-m-d')); | ||||||
|  |     $this->assertEquals('2021-02-08', $member->fresh()->recertified_at->format('Y-m-d')); | ||||||
|  |     $this->assertEquals('Doktor', $member->fresh()->salutation); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | @ -2,6 +2,9 @@ | ||||||
| 
 | 
 | ||||||
| namespace Tests\RequestFactories; | namespace Tests\RequestFactories; | ||||||
| 
 | 
 | ||||||
|  | use App\Country; | ||||||
|  | use App\Nationality; | ||||||
|  | use App\Payment\Subscription; | ||||||
| use Worksome\RequestFactories\RequestFactory; | use Worksome\RequestFactories\RequestFactory; | ||||||
| 
 | 
 | ||||||
| class MemberRequestFactory extends RequestFactory | class MemberRequestFactory extends RequestFactory | ||||||
|  | @ -11,14 +14,18 @@ class MemberRequestFactory extends RequestFactory | ||||||
|      */ |      */ | ||||||
|     public function definition(): array |     public function definition(): array | ||||||
|     { |     { | ||||||
|  |         $country = Country::factory()->create(); | ||||||
|  |         $nationality = Nationality::factory()->create(); | ||||||
|  |         $subscription = Subscription::factory()->forFee()->create(); | ||||||
|  | 
 | ||||||
|         return [ |         return [ | ||||||
|             'address' => 'Bavert 50', |             'address' => 'Bavert 50', | ||||||
|             'birthday' => '2013-02-19', |             'birthday' => '2013-02-19', | ||||||
|             'children_phone' => '+49 123 44444', |             'children_phone' => '+49 176 70512778', | ||||||
|             'efz' => '', |             'efz' => '', | ||||||
|             'email' => '', |             'email' => '', | ||||||
|             'email_parents' => 'osloot@aol.com', |             'email_parents' => 'osloot@aol.com', | ||||||
|             'fax' => '+49 666', |             'fax' => '+49 212 4732223', | ||||||
|             'firstname' => 'Joe', |             'firstname' => 'Joe', | ||||||
|             'further_address' => '', |             'further_address' => '', | ||||||
|             'has_nami' => true, |             'has_nami' => true, | ||||||
|  | @ -28,8 +35,8 @@ class MemberRequestFactory extends RequestFactory | ||||||
|             'lastname' => 'Muster', |             'lastname' => 'Muster', | ||||||
|             'letter_address' => '', |             'letter_address' => '', | ||||||
|             'location' => 'Solingen', |             'location' => 'Solingen', | ||||||
|             'main_phone' => '+49 212 2334322', |             'main_phone' => '+49 212 337056', | ||||||
|             'mobile_phone' => '+49 157 53180451', |             'mobile_phone' => '+49 176 70512774', | ||||||
|             'more_ps_at' => '', |             'more_ps_at' => '', | ||||||
|             'multiply_more_pv' => false, |             'multiply_more_pv' => false, | ||||||
|             'multiply_pv' => false, |             'multiply_pv' => false, | ||||||
|  | @ -40,6 +47,13 @@ class MemberRequestFactory extends RequestFactory | ||||||
|             'without_efz_at' => '', |             'without_efz_at' => '', | ||||||
|             'work_phone' => '', |             'work_phone' => '', | ||||||
|             'zip' => '42719', |             'zip' => '42719', | ||||||
|  |             'bank_account' => [ | ||||||
|  |                 'iban' => '', | ||||||
|  |                 'bic' => '', | ||||||
|  |             ], | ||||||
|  |             'country_id' => $country->id, | ||||||
|  |             'nationality_id' => $nationality->id, | ||||||
|  |             'subscription_id' => $subscription->id, | ||||||
|         ]; |         ]; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,21 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace Tests\RequestFactories; | ||||||
|  | 
 | ||||||
|  | use App\Activity; | ||||||
|  | use App\Subactivity; | ||||||
|  | 
 | ||||||
|  | class MemberStoreRequestFactory extends MemberRequestFactory | ||||||
|  | { | ||||||
|  |     public function definition(): array | ||||||
|  |     { | ||||||
|  |         $activity = Activity::factory()->inNami(89)->create(); | ||||||
|  |         $subactivity = Subactivity::factory()->inNami(90)->create(); | ||||||
|  | 
 | ||||||
|  |         return [ | ||||||
|  |             ...parent::definition(), | ||||||
|  |             'first_activity_id' => $activity->id, | ||||||
|  |             'first_subactivity_id' => $subactivity->id, | ||||||
|  |         ]; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,11 @@ | ||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace Tests\RequestFactories; | ||||||
|  | 
 | ||||||
|  | class MemberUpdateRequestFactory extends MemberRequestFactory | ||||||
|  | { | ||||||
|  |     public function noNami(): self | ||||||
|  |     { | ||||||
|  |         return $this->state(['has_nami' => false]); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue