From a897690e7af7343efec5f468ab2d51088cfedb7e Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 7 Nov 2024 01:29:26 +0100 Subject: [PATCH] Add keepdata to member form --- app/Actions/InsertMemberAction.php | 1 + app/Member/Actions/NamiPutMemberAction.php | 2 +- app/Member/Member.php | 3 +- app/Member/MemberRequest.php | 1 + app/Member/MemberResource.php | 2 + database/factories/Member/MemberFactory.php | 1 + ..._07_004559_add_members_keepdata_column.php | 28 +++ resources/js/views/member/VForm.vue | 3 +- tests/Feature/Member/EditTest.php | 1 + .../Member/NamiPutMemberActionTest.php | 19 +- tests/Feature/Member/PullMemberActionTest.php | 232 +++++++++--------- tests/Feature/Member/StoreTest.php | 29 +++ tests/Feature/Member/UpdateTest.php | 17 ++ 13 files changed, 211 insertions(+), 128 deletions(-) create mode 100644 database/migrations/2024_11_07_004559_add_members_keepdata_column.php diff --git a/app/Actions/InsertMemberAction.php b/app/Actions/InsertMemberAction.php index 4ad73ac7..9f0e6182 100644 --- a/app/Actions/InsertMemberAction.php +++ b/app/Actions/InsertMemberAction.php @@ -50,6 +50,7 @@ class InsertMemberAction 'nationality_id' => Nationality::where('nami_id', $member->nationalityId)->firstOrFail()->id, 'mitgliedsnr' => $member->memberId, 'version' => $member->version, + 'keepdata' => $member->keepdata, ]); } diff --git a/app/Member/Actions/NamiPutMemberAction.php b/app/Member/Actions/NamiPutMemberAction.php index 51067087..9898c2c6 100644 --- a/app/Member/Actions/NamiPutMemberAction.php +++ b/app/Member/Actions/NamiPutMemberAction.php @@ -46,7 +46,7 @@ class NamiPutMemberAction 'groupId' => $member->group->nami_id, 'id' => $member->nami_id, 'version' => $member->version, - 'keepdata' => false, + 'keepdata' => $member->keepdata, ]); $response = $api->putMember($namiMember, $activity ? $activity->nami_id : null, $subactivity ? $subactivity->nami_id : null); Member::withoutEvents(function () use ($response, $member) { diff --git a/app/Member/Member.php b/app/Member/Member.php index 3437595e..f92d0375 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -58,7 +58,7 @@ class Member extends Model implements Geolocatable /** * @var array */ - public static array $namiFields = ['firstname', 'lastname', 'joined_at', 'birthday', 'send_newspaper', 'address', 'zip', 'location', 'nickname', 'other_country', 'further_address', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'gender_id', 'confession_id', 'region_id', 'country_id', 'fee_id', 'nationality_id', 'slug', 'subscription_id']; + public static array $namiFields = ['firstname', 'lastname', 'joined_at', 'birthday', 'send_newspaper', 'address', 'zip', 'location', 'nickname', 'other_country', 'further_address', 'main_phone', 'mobile_phone', 'work_phone', 'fax', 'email', 'email_parents', 'gender_id', 'confession_id', 'region_id', 'country_id', 'fee_id', 'nationality_id', 'slug', 'subscription_id', 'keepdata']; /** * @var array @@ -77,6 +77,7 @@ class Member extends Model implements Geolocatable 'multiply_pv' => 'boolean', 'multiply_more_pv' => 'boolean', 'is_leader' => 'boolean', + 'keepdata' => 'boolean', 'bill_kind' => BillKind::class, 'mitgliedsnr' => 'integer', diff --git a/app/Member/MemberRequest.php b/app/Member/MemberRequest.php index 85edc93c..ab37a609 100644 --- a/app/Member/MemberRequest.php +++ b/app/Member/MemberRequest.php @@ -83,6 +83,7 @@ class MemberRequest extends FormRequest 'other_country' => '', 'salutation' => '', 'comment' => '', + 'keepdata' => 'boolean', ]; } diff --git a/app/Member/MemberResource.php b/app/Member/MemberResource.php index 4d68d368..b81b58b9 100644 --- a/app/Member/MemberResource.php +++ b/app/Member/MemberResource.php @@ -106,6 +106,7 @@ class MemberResource extends JsonResource 'lat' => $this->lat, 'lon' => $this->lon, 'group_name' => $this->group->name, + 'keepdata' => $this->keepdata, 'links' => [ 'membership_index' => route('member.membership.index', ['member' => $this->getModel()]), 'invoiceposition_index' => route('member.invoice-position.index', ['member' => $this->getModel()]), @@ -202,6 +203,7 @@ class MemberResource extends JsonResource 'has_svk' => false, 'multiply_pv' => false, 'multiply_more_pv' => false, + 'keepdata' => false, ] ]; } diff --git a/database/factories/Member/MemberFactory.php b/database/factories/Member/MemberFactory.php index 24321cd4..059262cf 100644 --- a/database/factories/Member/MemberFactory.php +++ b/database/factories/Member/MemberFactory.php @@ -36,6 +36,7 @@ class MemberFactory extends Factory 'location' => $this->faker->city, 'email' => $this->faker->safeEmail(), 'recertified_at' => null, + 'keepdata' => false, ]; } diff --git a/database/migrations/2024_11_07_004559_add_members_keepdata_column.php b/database/migrations/2024_11_07_004559_add_members_keepdata_column.php new file mode 100644 index 00000000..7a73f005 --- /dev/null +++ b/database/migrations/2024_11_07_004559_add_members_keepdata_column.php @@ -0,0 +1,28 @@ +boolean('keepdata')->after('email_parents')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('members', function (Blueprint $table) { + $table->dropColumn('keepdata'); + }); + } +}; diff --git a/resources/js/views/member/VForm.vue b/resources/js/views/member/VForm.vue index b202a9e6..34ead47e 100644 --- a/resources/js/views/member/VForm.vue +++ b/resources/js/views/member/VForm.vue @@ -58,7 +58,8 @@ - + +
assertInertiaHas('Biber', $response, "meta.formSubactivities.{$activity->id}.{$subactivity->id}"); $this->assertInertiaHas('€ Mitglied', $response, "meta.formActivities.{$activity->id}"); $this->assertInertiaHas('Max', $response, 'data.firstname'); + $this->assertInertiaHas(false, $response, 'data.keepdata'); $this->assertInertiaHas('Doktor', $response, 'data.salutation'); $this->assertInertiaHas('Lorem bla', $response, 'data.comment'); $this->assertInertiaHas('edit', $response, 'mode'); diff --git a/tests/Feature/Member/NamiPutMemberActionTest.php b/tests/Feature/Member/NamiPutMemberActionTest.php index 5e1eb2a3..bd1d642b 100644 --- a/tests/Feature/Member/NamiPutMemberActionTest.php +++ b/tests/Feature/Member/NamiPutMemberActionTest.php @@ -17,12 +17,11 @@ use App\Region; use App\Subactivity; use Illuminate\Foundation\Testing\DatabaseTransactions; use Phake; -use Tests\TestCase; use Zoomyboy\LaravelNami\Fakes\MemberFake; uses(DatabaseTransactions::class); -it('testItPutsAMember', function () { +it('testItPutsAMember', function (array $memberAttributes, array $storedAttributes) { Fee::factory()->create(); $this->stubIo(PullMemberAction::class, fn ($mock) => $mock); $this->stubIo(PullMembershipsAction::class, fn ($mock) => $mock); @@ -44,7 +43,7 @@ it('testItPutsAMember', function () { ->for($nationality) ->for($group) ->emailBillKind() - ->create(['email_parents' => 'a@b.de']); + ->create($memberAttributes); NamiPutMemberAction::run($member, $activity, $subactivity); @@ -52,11 +51,21 @@ it('testItPutsAMember', function () { 'ersteTaetigkeitId' => 6, 'ersteUntergliederungId' => 55, 'konfessionId' => 567, - 'emailVertretungsberechtigter' => 'a@b.de', + ...$storedAttributes, ]); $this->assertDatabaseHas('members', [ 'nami_id' => 993, ]); Phake::verify(app(PullMemberAction::class))->handle(55, 993); Phake::verify(app(PullMembershipsAction::class))->handle($member); -}); +})->with([ + [ + ['email_parents' => 'a@b.de'], ['emailVertretungsberechtigter' => 'a@b.de'], + ], + [ + ['keepdata' => true], ['wiederverwendenFlag' => true], + ], + [ + ['keepdata' => false], ['wiederverwendenFlag' => false], + ], +]); diff --git a/tests/Feature/Member/PullMemberActionTest.php b/tests/Feature/Member/PullMemberActionTest.php index df941f71..9e457ce9 100644 --- a/tests/Feature/Member/PullMemberActionTest.php +++ b/tests/Feature/Member/PullMemberActionTest.php @@ -11,142 +11,134 @@ use App\Nationality; use App\Payment\Subscription; use App\Region; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Tests\TestCase; use Zoomyboy\LaravelNami\Fakes\MemberFake; -class PullMemberActionTest extends TestCase -{ - use DatabaseTransactions; +uses(DatabaseTransactions::class); - public function setUp(): void - { - parent::setUp(); +beforeEach(function () { + Subscription::factory()->name('test')->forFee(300)->create(); + Gender::factory()->inNami(303)->create(); + Country::factory()->inNami(302)->create(); + Nationality::factory()->inNami(1054)->create(); +}); - Subscription::factory()->name('test')->forFee(300)->create(); - Gender::factory()->inNami(303)->create(); - Country::factory()->inNami(302)->create(); - Nationality::factory()->inNami(1054)->create(); - $this->loginNami(); - } +it('testFetchNormalMember', function () { + $this->loginNami(); + app(MemberFake::class)->shows(1000, 1001, [ + 'vorname' => '::firstname::', + 'nachname' => '::lastname::', + 'beitragsartId' => 300, + 'geburtsDatum' => '2014-07-11 00:00:00', + 'gruppierungId' => 1000, + 'geschlechtId' => 303, + 'id' => 1001, + 'eintrittsdatum' => '2020-11-17 00:00:00', + 'landId' => 302, + 'staatsangehoerigkeitId' => 1054, + 'zeitschriftenversand' => true, + 'strasse' => '::street::', + 'plz' => '12346', + 'ort' => '::location::', + 'version' => 40, + 'gruppierung' => 'SG Wald', + 'mitgliedsNummer' => 53, + ]); - public function testFetchNormalMember(): void - { - app(MemberFake::class)->shows(1000, 1001, [ - 'vorname' => '::firstname::', - 'nachname' => '::lastname::', - 'beitragsartId' => 300, - 'geburtsDatum' => '2014-07-11 00:00:00', - 'gruppierungId' => 1000, - 'geschlechtId' => 303, - 'id' => 1001, - 'eintrittsdatum' => '2020-11-17 00:00:00', - 'landId' => 302, - 'staatsangehoerigkeitId' => 1054, - 'zeitschriftenversand' => true, - 'strasse' => '::street::', - 'plz' => '12346', - 'ort' => '::location::', - 'version' => 40, - 'gruppierung' => 'SG Wald', - 'mitgliedsNummer' => 53, - ]); + $member = app(PullMemberAction::class)->handle(1000, 1001); - $member = app(PullMemberAction::class)->handle(1000, 1001); + $this->assertDatabaseHas('members', [ + 'firstname' => '::firstname::', + 'lastname' => '::lastname::', + 'subscription_id' => Subscription::firstWhere('name', 'test')->id, + 'birthday' => '2014-07-11', + 'group_id' => Group::nami(1000)->id, + 'gender_id' => Gender::nami(303)->id, + 'nami_id' => 1001, + 'joined_at' => '2020-11-17', + 'country_id' => Country::nami(302)->id, + 'nationality_id' => Nationality::nami(1054)->id, + 'send_newspaper' => 1, + 'address' => '::street::', + 'zip' => '12346', + 'location' => '::location::', + 'version' => '40', + 'mitgliedsnr' => 53, + ]); - $this->assertDatabaseHas('members', [ - 'firstname' => '::firstname::', - 'lastname' => '::lastname::', - 'subscription_id' => Subscription::firstWhere('name', 'test')->id, - 'birthday' => '2014-07-11', - 'group_id' => Group::nami(1000)->id, - 'gender_id' => Gender::nami(303)->id, - 'nami_id' => 1001, - 'joined_at' => '2020-11-17', - 'country_id' => Country::nami(302)->id, - 'nationality_id' => Nationality::nami(1054)->id, - 'send_newspaper' => 1, - 'address' => '::street::', - 'zip' => '12346', - 'location' => '::location::', - 'version' => '40', - 'mitgliedsnr' => 53, - ]); + $this->assertDatabaseHas('groups', [ + 'name' => 'SG Wald', + 'nami_id' => 1000, + 'inner_name' => 'SG Wald', + ]); + $this->assertEquals(1001, $member->nami_id); +}); - $this->assertDatabaseHas('groups', [ - 'name' => 'SG Wald', - 'nami_id' => 1000, - 'inner_name' => 'SG Wald', - ]); - $this->assertEquals(1001, $member->nami_id); - } +it('testFetchWiederverwendenFlag', function (array $memberAttributes, array $storedAttributes) { + $this->loginNami(); + Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]); + app(MemberFake::class)->shows(1000, 1001, $memberAttributes); - public function testRegionIdIsSetToNull(): void - { - Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]); - app(MemberFake::class)->shows(1000, 1001, [ - 'regionId' => 999, - ]); + app(PullMemberAction::class)->handle(1000, 1001); - app(PullMemberAction::class)->handle(1000, 1001); + $this->assertDatabaseHas('members', $storedAttributes); +})->with([ + [['wiederverwendenFlag' => false], ['keepdata' => false]], + [['wiederverwendenFlag' => true], ['keepdata' => true]], + [['regionId' => 999], ['region_id' => null]] +]); - $this->assertDatabaseHas('members', [ - 'region_id' => null, - ]); - } +it('testItSetsFirstSubscriptionFromFee', function () { + $this->loginNami(); + Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]); + $should = Subscription::factory()->forFee(55)->create(); + app(MemberFake::class)->shows(1000, 1001, [ + 'beitragsartId' => 55, + ]); - public function testItSetsFirstSubscriptionFromFee(): void - { - Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]); - $should = Subscription::factory()->forFee(55)->create(); - app(MemberFake::class)->shows(1000, 1001, [ - 'beitragsartId' => 55, - ]); + app(PullMemberAction::class)->handle(1000, 1001); - app(PullMemberAction::class)->handle(1000, 1001); + $this->assertDatabaseHas('members', [ + 'subscription_id' => $should->id, + ]); +}); - $this->assertDatabaseHas('members', [ - 'subscription_id' => $should->id, - ]); - } +it('testItCreatesSubscriptionOnTheFly', function () { + $this->loginNami(); + Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]); + app(MemberFake::class)->shows(1000, 1001, [ + 'beitragsartId' => 55, + 'beitragsart' => 'Lala', + ]); - public function testItCreatesSubscriptionOnTheFly(): void - { - Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]); - app(MemberFake::class)->shows(1000, 1001, [ - 'beitragsartId' => 55, - 'beitragsart' => 'Lala', - ]); + app(PullMemberAction::class)->handle(1000, 1001); - app(PullMemberAction::class)->handle(1000, 1001); + $fee = Fee::where('nami_id', 55)->firstOrFail(); + $subscription = Subscription::where('fee_id', $fee->id)->firstOrFail(); + $this->assertDatabaseHas('subscriptions', [ + 'fee_id' => $fee->id, + 'name' => 'Lala', + ]); + $this->assertDatabaseHas('subscription_children', [ + 'name' => 'Lala', + 'amount' => 1000, + 'parent_id' => $subscription->id, + ]); + $this->assertDatabaseHas('members', [ + 'subscription_id' => $subscription->id, + ]); +}); - $fee = Fee::where('nami_id', 55)->firstOrFail(); - $subscription = Subscription::where('fee_id', $fee->id)->firstOrFail(); - $this->assertDatabaseHas('subscriptions', [ - 'fee_id' => $fee->id, - 'name' => 'Lala', - ]); - $this->assertDatabaseHas('subscription_children', [ - 'name' => 'Lala', - 'amount' => 1000, - 'parent_id' => $subscription->id, - ]); - $this->assertDatabaseHas('members', [ - 'subscription_id' => $subscription->id, - ]); - } +it('testItPullsMemberWithNoSubscription', function () { + $this->loginNami(); + Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]); + app(MemberFake::class)->shows(1000, 1001, [ + 'beitragsartId' => null, + 'beitragsart' => null, + ]); - public function testItPullsMemberWithNoSubscription(): void - { - Region::factory()->inNami(999)->name('nicht-de')->create(['is_null' => true]); - app(MemberFake::class)->shows(1000, 1001, [ - 'beitragsartId' => null, - 'beitragsart' => null, - ]); + app(PullMemberAction::class)->handle(1000, 1001); - app(PullMemberAction::class)->handle(1000, 1001); - - $this->assertDatabaseHas('members', [ - 'subscription_id' => null, - ]); - } -} + $this->assertDatabaseHas('members', [ + 'subscription_id' => null, + ]); +}); diff --git a/tests/Feature/Member/StoreTest.php b/tests/Feature/Member/StoreTest.php index 174a2717..5089870b 100644 --- a/tests/Feature/Member/StoreTest.php +++ b/tests/Feature/Member/StoreTest.php @@ -89,6 +89,35 @@ class StoreTest extends TestCase ]); } + public function testItStoresWiederverwendenFlag(): void + { + 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(); + $confesstion = Confession::factory()->create(['is_null' => true]); + PullMemberAction::shouldRun(); + PullMembershipsAction::shouldRun(); + + $this + ->from('/member/create') + ->post('/member', $this->attributes([ + 'first_activity_id' => $activity->id, + 'first_subactivity_id' => $subactivity->id, + 'subscription_id' => $subscription->id, + 'keepdata' => true, + ]))->assertSessionHasNoErrors(); + + $this->assertDatabaseHas('members', [ + 'keepdata' => true, + ]); + app(MemberFake::class)->assertStored(55, [ + 'wiederverwendenFlag' => true, + ]); + } + public function testItCanStoreAMemberWithoutNami(): void { $this->withoutExceptionHandling()->login()->loginNami(); diff --git a/tests/Feature/Member/UpdateTest.php b/tests/Feature/Member/UpdateTest.php index de716140..f7747cd3 100644 --- a/tests/Feature/Member/UpdateTest.php +++ b/tests/Feature/Member/UpdateTest.php @@ -77,6 +77,23 @@ class UpdateTest extends TestCase ]); } + 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();