ledgerrz/tests/Feature/NotificationDispatchTest.php
Daan Meijer 3d6a5362e6
Some checks failed
linter / quality (push) Failing after 1m4s
tests / ci (8.3) (push) Failing after 51s
tests / ci (8.4) (push) Failing after 1m7s
tests / ci (8.5) (push) Failing after 1m6s
notificationtest gerepareerd
2026-07-06 17:31:47 +02:00

111 lines
4.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Dynamic;
use App\Models\Ledger;
use App\Models\Mutation;
use App\Models\User;
use App\Notifications\NewActivityNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class NotificationDispatchTest extends TestCase
{
use RefreshDatabase;
public function test_notification_is_sent_on_mutation_suggestion()
{
Notification::fake();
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$this->actingAs($participant)
->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
'description' => 'A test suggestion',
'amount' => 10,
]);
Notification::assertSentTo($owner, NewActivityNotification::class);
Notification::assertNotSentTo($participant, NewActivityNotification::class);
}
public function test_notification_is_sent_on_mutation_approval()
{
Notification::fake();
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$mutation = Mutation::factory()->create([
'ledger_id' => $ledger->id,
'user_id' => $participant->id,
'status' => 'pending',
]);
$this->actingAs($owner)
->put(route('dynamics.ledgers.mutations.update', [$dynamic, $ledger, $mutation]), [
'status' => 'approved',
]);
Notification::assertSentTo($participant, NewActivityNotification::class);
Notification::assertNotSentTo($owner, NewActivityNotification::class);
}
public function test_notification_is_sent_on_mutation_void()
{
Notification::fake();
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$mutation = Mutation::factory()->create([
'ledger_id' => $ledger->id,
'user_id' => $participant->id,
'status' => 'approved',
]);
$this->actingAs($owner)
->put(route('dynamics.ledgers.mutations.void', [$dynamic, $ledger, $mutation]));
Notification::assertSentTo($participant, NewActivityNotification::class);
Notification::assertNotSentTo($owner, NewActivityNotification::class);
}
public function test_notification_is_sent_to_other_participants_when_owner_adds_mutation()
{
Notification::fake();
$owner = User::factory()->create();
$participant1 = User::factory()->create();
$participant2 = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant1->id, ['role' => 'participant']);
$dynamic->participants()->attach($participant2->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$this->actingAs($owner)
->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
'description' => 'A test mutation from owner',
'amount' => 25,
]);
Notification::assertSentTo($participant1, NewActivityNotification::class);
Notification::assertSentTo($participant2, NewActivityNotification::class);
Notification::assertNotSentTo($owner, NewActivityNotification::class);
}
}