100 lines
2.7 KiB
PHP
100 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
use App\Models\Province;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Foundation\Testing\WithFaker;
|
|
use Tests\TestCase;
|
|
|
|
class LoginTest extends TestCase
|
|
{
|
|
use RefreshDatabase, WithFaker;
|
|
|
|
// public function test_user_can_login()
|
|
// {
|
|
// $this->withoutExceptionHandling();
|
|
//
|
|
// $this->artisan('passport:install');
|
|
//
|
|
// $user = User::factory()->create();
|
|
//
|
|
// $response = $this->postJson('/api/auth/login', [
|
|
// 'username' => $user->username,
|
|
// 'password' => 'password',
|
|
// ]);
|
|
//
|
|
// $token = Token::where('user_id', $user->id)->first();
|
|
//
|
|
// $response->assertStatus(200)
|
|
// ->assertJson([
|
|
// 'message' => __('messages.successful')
|
|
// ]);
|
|
//
|
|
// $this->assertDatabaseHas('oauth_access_tokens' , [
|
|
// 'user_id' => $user->id,
|
|
// ]);
|
|
//
|
|
// $this->assertInstanceOf(Token::class, $token);
|
|
// }
|
|
|
|
public function test_user_can_login()
|
|
{
|
|
$user = User::factory()
|
|
->create([
|
|
'password' => bcrypt('password'),
|
|
'province_id' => Province::factory()
|
|
]);
|
|
|
|
$response = $this->postJson('/server/auth/login', [
|
|
'username' => $user->username,
|
|
'password' => 'password',
|
|
'telephone_id' => $this->faker->numerify('TID####')
|
|
]);
|
|
|
|
$response->assertOk()
|
|
->assertJson([
|
|
'message' => __('messages.successful'),
|
|
]);
|
|
|
|
$this->assertAuthenticatedAs($user);
|
|
}
|
|
|
|
public function test_username_is_required()
|
|
{
|
|
$response = $this->postJson('/server/auth/login', [
|
|
'password' => 'password',
|
|
]);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'username' => __('validation.required', ['attribute' => 'نام کاربری']),
|
|
]);
|
|
}
|
|
|
|
|
|
public function test_password_is_required()
|
|
{
|
|
$response = $this->postJson('/server/auth/login', [
|
|
'username' => $this->faker->lexify('?????'),
|
|
]);
|
|
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'password' => __('validation.required', ['attribute' => 'رمز عبور'])
|
|
]);
|
|
}
|
|
public function test_telephone_id_is_required()
|
|
{
|
|
$response = $this->postJson('/server/auth/login', [
|
|
'username' => $this->faker->lexify('?????'),
|
|
'password' => 'password',
|
|
]);
|
|
$response->assertUnprocessable()
|
|
->assertInvalid([
|
|
'telephone_id' => __('validation.required', ['attribute' => 'کد تلفن'])
|
|
]);
|
|
}
|
|
}
|