Compare commits

..

No commits in common. "c37c37d6e54279db1ce7befe005f42fb9f50f343" and "998ed253151afe8021e8b7b49438195c21175cd3" have entirely different histories.

6 changed files with 105 additions and 40 deletions

View File

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

View File

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

View File

@ -16,8 +16,18 @@ class UserFactory extends Factory
public function definition(): array
{
return [
'name' => Str::random(8),
'password' => Hash::make('password'),
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'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,8 +9,5 @@ class DatabaseSeeder extends Seeder
public function run(): void
{
//
$this->call([
UserSeeder::class,
]);
}
}

View File

@ -1,19 +0,0 @@
<?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
{
$user = User::factory()->create();
$user = User::query()->first();
$this->get('/user/' . $user->id)
->assertStatus(200);
@ -36,4 +36,67 @@ public function test_fail_get_user_not_exists(): void
$this->get('/user/sehtrgher')
->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
{
//
}
}