app/tests/Feature/User/DeleteUserTest.php

52 lines
1.5 KiB
PHP

<?php
namespace Tests\Feature\User;
use App\Models\Planner;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
use Tests\Traits\HasPlanner;
class DeleteUserTest extends TestCase
{
use HasPlanner;
use RefreshDatabase;
public function test_planner_can_delete_user(): void
{
$planner = $this->planner;
$user = User::factory()->planner($planner)->create();
$this
->actingAs($planner)
->delete(route('api.users.delete', $user))
->assertStatus(201)
->assertJson(fn (AssertableJson $json) => $json
->where('success', true)
->where('payload', null)
->where('errors', null)
);
}
public function test_planner_cannot_update_user_of_other_planner(): void
{
$planner = $this->planner;
$otherPlanner = Planner::factory()->create();
$newUserName = fake()->name;
$user = User::factory()->planner($otherPlanner)->create();
$this
->actingAs($planner)
->put(route('api.users.update', $user), [
'name' => $newUserName,
])
->assertStatus(404)
->assertJson(fn (AssertableJson $json) => $json
->where('success', false)
->where('payload', null)
->where('errors', ["MODEL_NOT_FOUND"])
);
}
}