adrema/tests/Feature/Membership/UpdateTest.php

53 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2022-12-11 21:00:48 +01:00
<?php
namespace Tests\Feature\Membership;
use App\Activity;
use App\Group;
use App\Member\Member;
use App\Member\Membership;
use App\Subactivity;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\RequestFactories\MembershipRequestFactory;
use Tests\TestCase;
class UpdateTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
Carbon::setTestNow(Carbon::parse('2022-02-03 03:00:00'));
$this->login()->loginNami();
}
2023-02-21 13:02:31 +01:00
public function testItUpdatesAMembership(): void
2022-12-11 21:00:48 +01:00
{
$this->withoutExceptionHandling();
$activity = Activity::factory()->hasAttached(Subactivity::factory())->create();
$member = Member::factory()
->defaults()
->has(Membership::factory()->for($activity)->for($activity->subactivities->first()))
->for(Group::factory()->inNami(1400))
->inNami(6)
->create();
$membership = $member->memberships->first();
$response = $this->from('/member')->patch(
2023-09-12 16:54:13 +02:00
"/membership/{$membership->id}",
2022-12-11 21:00:48 +01:00
MembershipRequestFactory::new()->promise(now())->in($membership->activity, $membership->subactivity)->create()
);
2023-09-12 16:54:13 +02:00
$response->assertOk();
2022-12-11 21:00:48 +01:00
$this->assertDatabaseHas('memberships', [
'member_id' => $member->id,
'activity_id' => $activity->id,
'subactivity_id' => $activity->subactivities->first()->id,
'promised_at' => now()->format('Y-m-d'),
]);
}
}