89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?php
|
|
|
|
use App\Models\Dynamic;
|
|
use App\Models\PredefinedMutation;
|
|
use App\Models\User;
|
|
|
|
test('owner can view predefined mutations for dynamic', function () {
|
|
$owner = User::factory()->create();
|
|
$dynamic = Dynamic::factory()->create();
|
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
|
|
$predefined = PredefinedMutation::create([
|
|
'dynamic_id' => $dynamic->id,
|
|
'name' => 'Weekly Room Cleaning',
|
|
'description' => 'Cleaned up the master bedroom',
|
|
'amount' => 20,
|
|
]);
|
|
|
|
$this->actingAs($owner);
|
|
|
|
$response = $this->get(route('dynamics.predefined-mutations.index', $dynamic->uuid));
|
|
|
|
$response->assertOk();
|
|
$response->assertInertia(fn ($page) => $page
|
|
->component('Dynamics/PredefinedMutations/Index')
|
|
->has('predefined_mutations', 1)
|
|
->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
|
|
);
|
|
});
|
|
|
|
test('non-owner cannot view predefined mutations for dynamic', 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);
|
|
|
|
$response = $this->get(route('dynamics.predefined-mutations.index', $dynamic->uuid));
|
|
|
|
$response->assertStatus(403);
|
|
});
|
|
|
|
test('owner can create predefined mutations for dynamic', function () {
|
|
$owner = User::factory()->create();
|
|
$dynamic = Dynamic::factory()->create();
|
|
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
|
|
|
|
$this->actingAs($owner);
|
|
|
|
$response = $this->post(route('dynamics.predefined-mutations.store', $dynamic->uuid), [
|
|
'name' => 'Polished mirrors',
|
|
'description' => 'Mirror polishing in dungeon',
|
|
'amount' => 15,
|
|
'type' => 'reward',
|
|
]);
|
|
|
|
$response->assertRedirect();
|
|
$this->assertDatabaseHas('predefined_mutations', [
|
|
'dynamic_id' => $dynamic->id,
|
|
'name' => 'Polished mirrors',
|
|
'amount' => 15,
|
|
]);
|
|
});
|
|
|
|
test('non-owner cannot create predefined mutations for dynamic', 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);
|
|
|
|
$response = $this->post(route('dynamics.predefined-mutations.store', $dynamic->uuid), [
|
|
'name' => 'Polished mirrors',
|
|
'description' => 'Mirror polishing in dungeon',
|
|
'amount' => 15,
|
|
'type' => 'reward',
|
|
]);
|
|
|
|
$response->assertStatus(403);
|
|
$this->assertDatabaseMissing('predefined_mutations', [
|
|
'dynamic_id' => $dynamic->id,
|
|
'name' => 'Polished mirrors',
|
|
]);
|
|
});
|