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); } }