Compare commits

..

8 Commits

6 changed files with 40 additions and 105 deletions

View File

@ -2,52 +2,40 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class UserController extends Controller class UserController extends Controller
{ {
/** // GET /user
* Display a listing of the resource.
*/
public function index() public function index()
{ {
// return response(User::all());
return response("Get all users");
} }
/** // GET /user/{id}
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
return response("User store with data: " . $request->json());
}
/**
* Display the specified resource.
*/
public function show(string $id) public function show(string $id)
{ {
// $user = User::query()->findOrFail('id', $id);
return response("User with id " . $id);
return response($user);
} }
/** // POST /user
* Update the specified resource in storage. public function store(Request $request)
*/ {
return response("Create user");
}
// PUT /user/{id}
public function update(Request $request, string $id) public function update(Request $request, string $id)
{ {
//
return response("Update user " . $id); return response("Update user " . $id);
} }
/** // DELETE /user/{id}
* Remove the specified resource from storage.
*/
public function destroy(string $id) public function destroy(string $id)
{ {
//
return response("Destroy user " . $id); return response("Destroy user " . $id);
} }
} }

View File

@ -12,7 +12,6 @@ class User extends Authenticatable
protected $fillable = [ protected $fillable = [
'name', 'name',
'email',
'password', 'password',
]; ];
@ -24,7 +23,6 @@ class User extends Authenticatable
protected function casts(): array protected function casts(): array
{ {
return [ return [
'email_verified_at' => 'datetime',
'password' => 'hashed', 'password' => 'hashed',
]; ];
} }

View File

@ -16,18 +16,8 @@ class UserFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
'name' => fake()->name(), 'name' => Str::random(8),
'email' => fake()->unique()->safeEmail(), 'password' => Hash::make('password'),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
]; ];
} }
public function unverified(): static
{
return $this->state(fn(array $attributes) => [
'email_verified_at' => null,
]);
}
} }

View File

@ -9,5 +9,8 @@ class DatabaseSeeder extends Seeder
public function run(): void public function run(): void
{ {
// //
$this->call([
UserSeeder::class,
]);
} }
} }

View File

@ -0,0 +1,19 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Support\Str;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
class UserSeeder extends Seeder
{
public function run(): void
{
//
User::factory(15)->create();
}
}

View File

@ -18,7 +18,7 @@ public function test_success_get_users(): void
public function test_success_get_one_user(): void public function test_success_get_one_user(): void
{ {
$user = User::query()->first(); $user = User::factory()->create();
$this->get('/user/' . $user->id) $this->get('/user/' . $user->id)
->assertStatus(200); ->assertStatus(200);
@ -36,67 +36,4 @@ public function test_fail_get_user_not_exists(): void
$this->get('/user/sehtrgher') $this->get('/user/sehtrgher')
->assertNotFound(); ->assertNotFound();
} }
// FIXME: below tests should be in AuthTest
public function test_user_can_sign_up_with_validate_data(): void
{
//
}
public function test_user_cannot_sign_up_with_not_validate_data(): void
{
//
}
public function test_user_can_sign_in_with_validate_data(): void
{
//
}
public function test_user_cannot_sign_in_with_not_validate_data_or_wrong_credentials(): void
{
//
}
// FIXME: above tests should be in AuthTest
// FIXME: admin tests in separate file
public function test_admin_can_create_user_with_validate_data(): void
{
//
}
public function test_admin_cannot_create_user_with_not_validate_data(): void
{
//
}
public function test_admin_can_update_user_with_validate_data(): void
{
//
}
public function test_admin_cannot_update_user_with_not_validate_data(): void
{
//
}
public function test_admin_can_delete_user_that_exists(): void
{
//
}
public function test_admin_cannot_delete_user_that_not_exists(): void
{
//
}
public function test_unauthorized_cannot_do_admin_actions(): void
{
//
}
public function test_user_cannot_do_admin_actions(): void
{
//
}
} }