ledgerrz/tests/Feature/LedgerTest.php
Daan Meijer 10bd46a53e
Some checks failed
linter / quality (push) Failing after 1m2s
tests / ci (8.3) (push) Failing after 48s
tests / ci (8.4) (push) Failing after 1m5s
tests / ci (8.5) (push) Failing after 1m5s
formatting, juiste use voor UpdateDynamicRequest
2026-06-22 00:10:39 +02:00

58 lines
1.8 KiB
PHP

<?php
use App\Models\Dynamic;
use App\Models\Ledger;
use App\Models\User;
test('dynamic owners can view ledger creation form and create ledgers', function () {
$owner = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$this->actingAs($owner);
// Can view form
$this->get(route('dynamics.ledgers.create', $dynamic->uuid))->assertOk();
// Can store ledger
$response = $this->post(route('dynamics.ledgers.store', $dynamic->uuid), [
'name' => 'Chores Ledger',
'rules' => 'Do the tasks.',
'alignment' => 'positive',
]);
$response->assertSessionHasNoErrors();
$response->assertRedirect(route('dynamics.show', $dynamic->uuid));
$this->assertDatabaseHas('ledgers', [
'dynamic_id' => $dynamic->id,
'name' => 'Chores Ledger',
'alignment' => 'positive',
]);
});
test('non-owners cannot view ledger creation form or store ledgers', function () {
$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']);
$this->actingAs($participant);
// Cannot view form
$this->get(route('dynamics.ledgers.create', $dynamic->uuid))->assertStatus(403);
// Cannot store ledger
$response = $this->post(route('dynamics.ledgers.store', $dynamic->uuid), [
'name' => 'Illegal Ledger',
'rules' => 'This should fail.',
'alignment' => 'positive',
]);
$response->assertStatus(403);
$this->assertDatabaseMissing('ledgers', [
'name' => 'Illegal Ledger',
]);
});