167 lines
5.7 KiB
PHP
167 lines
5.7 KiB
PHP
<?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->uuid, $ledger->uuid]));
|
|
|
|
$response->assertOk();
|
|
$response->assertInertia(fn ($page) => $page
|
|
->component('Ledgers/PredefinedMutations/Index')
|
|
->where('dynamic.id', $dynamic->id)
|
|
->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->uuid, $ledger->uuid]));
|
|
|
|
$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->uuid, $ledger->uuid]), [
|
|
'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->uuid, $ledger->uuid]), [
|
|
'name' => 'Polished mirrors',
|
|
'description' => 'Mirror polishing in dungeon',
|
|
'amount' => 15,
|
|
]);
|
|
|
|
$response->assertStatus(403);
|
|
$this->assertDatabaseMissing('predefined_mutations', [
|
|
'ledger_id' => $ledger->id,
|
|
'name' => 'Polished mirrors',
|
|
]);
|
|
});
|
|
|
|
test('owner can view edit form for predefined mutation', 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' => 'Polished mirrors',
|
|
'description' => 'Mirror polishing in dungeon',
|
|
'amount' => 15,
|
|
]);
|
|
|
|
$this->actingAs($owner);
|
|
|
|
$response = $this->get(route('dynamics.ledgers.predefined-mutations.edit', [$dynamic->uuid, $ledger->uuid, $predefined->uuid]));
|
|
|
|
$response->assertOk();
|
|
$response->assertInertia(fn ($page) => $page
|
|
->component('Ledgers/PredefinedMutations/Edit')
|
|
->where('predefined_mutation.id', $predefined->id)
|
|
);
|
|
});
|
|
|
|
test('owner can update predefined mutation', 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' => 'Old Name',
|
|
'amount' => 10,
|
|
]);
|
|
|
|
$this->actingAs($owner);
|
|
|
|
$response = $this->put(route('dynamics.ledgers.predefined-mutations.update', [$dynamic->uuid, $ledger->uuid, $predefined->uuid]), [
|
|
'name' => 'New Name',
|
|
'amount' => 20,
|
|
]);
|
|
|
|
$response->assertRedirect();
|
|
$this->assertDatabaseHas('predefined_mutations', [
|
|
'id' => $predefined->id,
|
|
'name' => 'New Name',
|
|
'amount' => 20,
|
|
]);
|
|
});
|
|
|
|
test('owner can delete predefined mutation', 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' => 'To Delete',
|
|
'amount' => 10,
|
|
]);
|
|
|
|
$this->actingAs($owner);
|
|
|
|
$response = $this->delete(route('dynamics.ledgers.predefined-mutations.destroy', [$dynamic->uuid, $ledger->uuid, $predefined->uuid]));
|
|
|
|
$response->assertRedirect();
|
|
$this->assertDatabaseMissing('predefined_mutations', [
|
|
'id' => $predefined->id,
|
|
]);
|
|
});
|