53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Spatie\Permission\Models\Role;
|
|
use Tests\TestCase;
|
|
|
|
class SsoApiTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_user_can_login_and_get_jwt_token(): void
|
|
{
|
|
$password = 'secret123';
|
|
$user = User::factory()->create([
|
|
'email' => 'admin@example.com',
|
|
'password' => bcrypt($password),
|
|
]);
|
|
$role = Role::query()->create(['name' => 'tester', 'guard_name' => 'api']);
|
|
$permission = Permission::query()->create(['name' => 'platform.dashboard.view', 'guard_name' => 'api']);
|
|
$role->givePermissionTo($permission);
|
|
$user->assignRole($role);
|
|
|
|
$response = $this->postJson('/auth/login', [
|
|
'email' => 'admin@example.com',
|
|
'password' => $password,
|
|
]);
|
|
|
|
$response
|
|
->assertOk()
|
|
->assertJsonPath('code', 0)
|
|
->assertJsonStructure(['data' => ['token', 'type', 'expires_in']]);
|
|
}
|
|
|
|
public function test_apply_account_validates_email_and_phone_format(): void
|
|
{
|
|
$response = $this->postJson('/auth/apply-account', [
|
|
'nickname' => 'Tester',
|
|
'email' => 'bad-email',
|
|
'phone' => '12345',
|
|
'password' => 'secret123',
|
|
'password_confirmation' => 'secret123',
|
|
]);
|
|
|
|
$response
|
|
->assertStatus(422)
|
|
->assertJsonValidationErrors(['email', 'phone']);
|
|
}
|
|
}
|