Fixed: Add group to membership
This commit is contained in:
parent
de4daf705f
commit
58fdfe1e81
|
@ -19,7 +19,7 @@ class Membership extends Model
|
|||
use HasNamiField;
|
||||
|
||||
/** @var array<int, string> */
|
||||
public $fillable = ['subactivity_id', 'activity_id', 'group_id', 'member_id', 'nami_id', 'from', 'to', 'promised_at'];
|
||||
public $guarded = [];
|
||||
|
||||
/** @var array<string, string> */
|
||||
public $casts = [
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Membership\Actions;
|
||||
|
||||
use App\Activity;
|
||||
use App\Group;
|
||||
use App\Member\Member;
|
||||
use App\Member\Membership;
|
||||
use App\Setting\NamiSettings;
|
||||
|
@ -21,7 +22,7 @@ class MembershipStoreAction
|
|||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(Member $member, Activity $activity, ?Subactivity $subactivity, ?Carbon $promisedAt, NamiSettings $settings): Membership
|
||||
public function handle(Member $member, Activity $activity, ?Subactivity $subactivity, Group $group, ?Carbon $promisedAt, NamiSettings $settings): Membership
|
||||
{
|
||||
$from = now()->startOfDay();
|
||||
|
||||
|
@ -31,7 +32,7 @@ class MembershipStoreAction
|
|||
try {
|
||||
$namiId = $settings->login()->putMembership($member->nami_id, NamiMembership::from([
|
||||
'startsAt' => $from,
|
||||
'groupId' => $member->group->nami_id,
|
||||
'groupId' => $group->nami_id,
|
||||
'activityId' => $activity->nami_id,
|
||||
'subactivityId' => $subactivity->nami_id,
|
||||
]));
|
||||
|
@ -44,7 +45,9 @@ class MembershipStoreAction
|
|||
'activity_id' => $activity->id,
|
||||
'subactivity_id' => $subactivity->id,
|
||||
'promised_at' => $promisedAt,
|
||||
...['nami_id' => $namiId ?? null, 'group_id' => $member->group->id, 'from' => $from],
|
||||
'group_id' => $group->id,
|
||||
'from' => $from,
|
||||
'nami_id' => $namiId ?? null,
|
||||
]);
|
||||
|
||||
if ($activity->hasNami && ($subactivity->id === null || $subactivity->hasNami)) {
|
||||
|
@ -85,6 +88,7 @@ class MembershipStoreAction
|
|||
$member,
|
||||
Activity::find($request->activity_id),
|
||||
$request->subactivity_id ? Subactivity::find($request->subactivity_id) : null,
|
||||
Group::findOrFail($request->input('group_id', -1)),
|
||||
$request->promised_at ? Carbon::parse($request->promised_at) : null,
|
||||
$settings,
|
||||
);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 0ee77550774715324e2fa66ca2b821d8a0e19880
|
||||
Subproject commit 315be84cf38f1a01f890180099d3b2156bf344b9
|
|
@ -42,7 +42,7 @@ class StoreTest extends TestCase
|
|||
|
||||
$response = $this->from('/member')->post(
|
||||
"/member/{$member->id}/membership",
|
||||
MembershipRequestFactory::new()->promise(now())->in($activity, $activity->subactivities->first())->create()
|
||||
MembershipRequestFactory::new()->promise(now())->in($activity, $activity->subactivities->first())->group($member->group)->create()
|
||||
);
|
||||
|
||||
$response->assertRedirect('/member');
|
||||
|
@ -53,6 +53,7 @@ class StoreTest extends TestCase
|
|||
'subactivity_id' => $activity->subactivities->first()->id,
|
||||
'nami_id' => 133,
|
||||
'promised_at' => now()->format('Y-m-d'),
|
||||
'group_id' => $member->group->id,
|
||||
]);
|
||||
app(MembershipFake::class)->assertCreated(6, [
|
||||
'untergliederungId' => 4,
|
||||
|
@ -75,7 +76,7 @@ class StoreTest extends TestCase
|
|||
|
||||
$this->from('/member')->post(
|
||||
"/member/{$member->id}/membership",
|
||||
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->create()
|
||||
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->group($member->group)->create()
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('memberships', [
|
||||
|
@ -98,7 +99,7 @@ class StoreTest extends TestCase
|
|||
|
||||
$this->from('/member')->post(
|
||||
"/member/{$member->id}/membership",
|
||||
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->create()
|
||||
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->group($member->group)->create()
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('memberships', [
|
||||
|
@ -157,6 +158,27 @@ class StoreTest extends TestCase
|
|||
$this->assertErrors(['subactivity_id' => 'Untertätigkeit ist nicht vorhanden.'], $response);
|
||||
}
|
||||
|
||||
public function testItCanAddAnotherGroup(): void
|
||||
{
|
||||
app(MembershipFake::class)->createsSuccessfully(6, 133);
|
||||
app(MemberFake::class)->shows(1400, 6, ['version' => 1506]);
|
||||
$member = Member::factory()->defaults()->for(Group::factory()->inNami(1400))->inNami(6)->create();
|
||||
$group = Group::factory()->inNami(1401)->create();
|
||||
$activity = Activity::factory()->inNami(7)->hasAttached(Subactivity::factory()->inNami(8))->create();
|
||||
|
||||
$this->post(
|
||||
"/member/{$member->id}/membership",
|
||||
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->group($group)->create()
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('memberships', [
|
||||
'group_id' => $group->id,
|
||||
]);
|
||||
app(MembershipFake::class)->assertCreated(6, [
|
||||
'gruppierungId' => 1401,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSubactivityCanBeEmpty(): void
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
|
@ -173,7 +195,7 @@ class StoreTest extends TestCase
|
|||
|
||||
$this->post(
|
||||
"/member/{$member->id}/membership",
|
||||
MembershipRequestFactory::new()->in($activity, null)->create()
|
||||
MembershipRequestFactory::new()->in($activity, null)->group($member->group)->create()
|
||||
);
|
||||
|
||||
$this->assertEquals(1506, $member->fresh()->version);
|
||||
|
@ -211,7 +233,7 @@ class StoreTest extends TestCase
|
|||
|
||||
$response = $this->post(
|
||||
"/member/{$member->id}/membership",
|
||||
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->create()
|
||||
MembershipRequestFactory::new()->in($activity, $activity->subactivities->first())->group($member->group)->create()
|
||||
);
|
||||
|
||||
$this->assertErrors(['nami' => $validationError], $response);
|
||||
|
|
|
@ -24,7 +24,7 @@ class UpdateTest extends TestCase
|
|||
$this->login()->loginNami();
|
||||
}
|
||||
|
||||
public function testItCreatesAMembership(): void
|
||||
public function testItUpdatesAMembership(): void
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$activity = Activity::factory()->hasAttached(Subactivity::factory())->create();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Tests\RequestFactories;
|
||||
|
||||
use App\Activity;
|
||||
use App\Group;
|
||||
use App\Subactivity;
|
||||
use Carbon\Carbon;
|
||||
use Worksome\RequestFactories\RequestFactory;
|
||||
|
@ -54,4 +55,9 @@ class MembershipRequestFactory extends RequestFactory
|
|||
'promised_at' => $value->format('Y-m-d'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function group(Group $group): self
|
||||
{
|
||||
return $this->state(['group_id' => $group->id]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue