adrema/tests/EndToEnd/MassstoreActionTest.php

84 lines
3.2 KiB
PHP
Raw Normal View History

2023-08-25 00:23:38 +02:00
<?php
namespace Tests\EndToEnd;
use App\Activity;
use App\Group;
use App\Maildispatcher\Actions\ResyncAction;
use App\Member\Member;
use App\Member\Membership;
2023-12-30 18:46:47 +01:00
use App\Membership\Actions\MassStoreAction;
2023-08-25 00:23:38 +02:00
use App\Membership\Actions\MembershipDestroyAction;
use App\Membership\Actions\MembershipStoreAction;
use App\Subactivity;
use Illuminate\Support\Facades\Queue;
2024-01-28 11:42:32 +01:00
use Tests\EndToEndTestCase;
2023-08-25 00:23:38 +02:00
use Throwable;
use Zoomyboy\LaravelNami\Fakes\MembershipFake;
2024-01-28 11:42:32 +01:00
class MassstoreActionTest extends EndToEndTestCase
2023-08-25 00:23:38 +02:00
{
public function testItFiresActionJobWhenUsingController(): void
{
Queue::fake();
$this->login()->loginNami()->withoutExceptionHandling();
$member = Member::factory()->defaults()->create();
$activity = Activity::factory()->create();
$subactivity = Subactivity::factory()->create();
$group = Group::factory()->create();
2023-12-30 18:46:47 +01:00
$this->postJson(route('membership.masslist.store'), [
2023-08-25 00:23:38 +02:00
'members' => [$member->id],
'activity_id' => $activity->id,
'subactivity_id' => $subactivity->id,
'group_id' => $group->id,
]);
2023-12-30 18:46:47 +01:00
MassStoreAction::assertPushed(fn ($action, $params) => $params[0]->is($group) && $params[1]->is($activity) && $params[2]->is($subactivity) && $params[3][0] === $member->id);
2023-08-25 00:23:38 +02:00
}
public function testItCreatesAMembership(): void
{
MembershipDestroyAction::partialMock()->shouldReceive('handle')->never();
MembershipStoreAction::partialMock()->shouldReceive('handle')->once();
$member = Member::factory()->defaults()->create();
$activity = Activity::factory()->create();
$subactivity = Subactivity::factory()->create();
$group = Group::factory()->create();
2023-12-30 18:46:47 +01:00
MassStoreAction::run($group, $activity, $subactivity, [$member->id]);
2023-08-25 00:23:38 +02:00
}
public function testItDeletesAMembership(): void
{
MembershipDestroyAction::partialMock()->shouldReceive('handle')->once();
MembershipStoreAction::partialMock()->shouldReceive('handle')->never();
ResyncAction::partialMock()->shouldReceive('handle')->once();
$member = Member::factory()->defaults()->has(Membership::factory()->inLocal('Leiter*in', 'Rover'))->create();
2023-12-30 18:46:47 +01:00
MassStoreAction::run($member->memberships->first()->group, $member->memberships->first()->activity, $member->memberships->first()->subactivity, []);
2023-08-25 00:23:38 +02:00
}
public function testItRollsbackWhenDeletionFails(): void
{
app(MembershipFake::class)
->shows(3, ['id' => 55])
->shows(3, ['id' => 56])
->destroysSuccessfully(3, 55)
->failsDeleting(3, 56);
$this->login()->loginNami();
$member = Member::factory()->defaults()->inNami(3)
->has(Membership::factory()->in('Leiter*in', 10, 'Rover', 11)->inNami(55))
->has(Membership::factory()->in('Leiter*in', 10, 'Jungpfadfinder', 12)->inNami(56))
->create();
try {
2023-12-30 18:46:47 +01:00
MassStoreAction::run($member->memberships->first()->group, $member->memberships->first()->activity, $member->memberships->first()->subactivity, []);
2023-08-25 00:23:38 +02:00
} catch (Throwable $e) {
}
$this->assertDatabaseCount('memberships', 2);
}
}