Compare commits

...

8 Commits

6 changed files with 40 additions and 105 deletions

View File

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

View File

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

View File

@ -16,18 +16,8 @@ class UserFactory extends Factory
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'name' => Str::random(8),
'password' => Hash::make('password'),
];
}
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
{
//
$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
{
$user = User::query()->first();
$user = User::factory()->create();
$this->get('/user/' . $user->id)
->assertStatus(200);
@ -36,67 +36,4 @@ 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
{
//
}
}