tests:add tests for setting owner_id on new portfolio create

This commit is contained in:
hackerESQ
2024-10-28 16:59:58 -05:00
parent 9e6f879d16
commit 0e9bb1de0f
3 changed files with 54 additions and 6 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace Tests;
use Tests\TestCase;
use App\Models\User;
use App\Models\Portfolio;
use Illuminate\Foundation\Testing\RefreshDatabase;
class PortfoliosTest extends TestCase
{
use RefreshDatabase;
/**
*/
public function test_owner_is_assigned_to_portfolio_on_create(): void
{
$this->actingAs($user = User::factory()->create());
$portfolio = Portfolio::factory()->create();
$this->assertEquals($user->id, $portfolio->owner_id);
}
/**
*/
public function test_owner_can_be_forced_on_create(): void
{
$this->actingAs($user = User::factory()->create());
$portfolio = Portfolio::factory()->make();
$portfolio->owner_id = $user->id;
$portfolio->save();
$this->assertEquals($user->id, $portfolio->owner_id);
}
/**
*/
public function test_owner_cannot_be_changed_on_update(): void
{
$this->actingAs($owner = User::factory()->create());
$interloper = User::factory()->create();
$portfolio = Portfolio::factory()->create();
$portfolio->owner_id = $interloper->id;
$portfolio->save();
$this->assertEquals($owner->id, $portfolio->owner_id);
}
}