further development of the predefinedmutations
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Dynamic;
|
||||
use App\Models\Ledger;
|
||||
use App\Models\PredefinedMutation;
|
||||
|
||||
test('owner can view predefined mutations for ledger', function () {
|
||||
$owner = User::factory()->create();
|
||||
$dynamic = Dynamic::factory()->create();
|
||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||
|
||||
$predefined = PredefinedMutation::create([
|
||||
'ledger_id' => $ledger->id,
|
||||
'name' => 'Weekly Room Cleaning',
|
||||
'description' => 'Cleaned up the master bedroom',
|
||||
'amount' => 20,
|
||||
]);
|
||||
|
||||
$this->actingAs($owner);
|
||||
|
||||
$response = $this->get(route('dynamics.ledgers.predefined-mutations.index', [$dynamic->id, $ledger->id]));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertInertia(fn ($page) => $page
|
||||
->component('Ledgers/PredefinedMutations/Index')
|
||||
->where('ledger.id', $ledger->id)
|
||||
->has('predefined_mutations', 1)
|
||||
->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
|
||||
);
|
||||
});
|
||||
|
||||
test('non-owner cannot view predefined mutations for ledger', 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']);
|
||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||
|
||||
$this->actingAs($participant);
|
||||
|
||||
$response = $this->get(route('dynamics.ledgers.predefined-mutations.index', [$dynamic->id, $ledger->id]));
|
||||
|
||||
$response->assertStatus(403);
|
||||
});
|
||||
|
||||
test('owner can create predefined mutations for ledger', function () {
|
||||
$owner = User::factory()->create();
|
||||
$dynamic = Dynamic::factory()->create();
|
||||
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||
|
||||
$this->actingAs($owner);
|
||||
|
||||
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->id, $ledger->id]), [
|
||||
'name' => 'Polished mirrors',
|
||||
'description' => 'Mirror polishing in dungeon',
|
||||
'amount' => 15,
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
$this->assertDatabaseHas('predefined_mutations', [
|
||||
'ledger_id' => $ledger->id,
|
||||
'name' => 'Polished mirrors',
|
||||
'amount' => 15,
|
||||
]);
|
||||
});
|
||||
|
||||
test('non-owner cannot create predefined mutations for ledger', 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']);
|
||||
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
|
||||
|
||||
$this->actingAs($participant);
|
||||
|
||||
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->id, $ledger->id]), [
|
||||
'name' => 'Polished mirrors',
|
||||
'description' => 'Mirror polishing in dungeon',
|
||||
'amount' => 15,
|
||||
]);
|
||||
|
||||
$response->assertStatus(403);
|
||||
$this->assertDatabaseMissing('predefined_mutations', [
|
||||
'ledger_id' => $ledger->id,
|
||||
'name' => 'Polished mirrors',
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user