diff --git a/tests/Feature/Api/Auth/LoginTest.php b/tests/Feature/Api/Auth/LoginTest.php new file mode 100644 index 0000000..5dc8d7d --- /dev/null +++ b/tests/Feature/Api/Auth/LoginTest.php @@ -0,0 +1,67 @@ +refreshApplicationWithLocale('en'); + + $this->user = User::factory()->create(); + } + + public function test_login_success() + { + $response = $this + ->actingAs($this->user) + ->postJson('/api/login', [ + 'email' => $this->user->email, + 'password' => 'password', + ]); + + // Assert a token was returned + $response->assertStatus(200); + $response->assertJsonStructure(['token']); + } + + + public function test_login_failed_no_register_user() + { + $user = User::factory()->make(); + + $response = $this + ->postJson('/api/login', [ + 'email' => $user->email, + 'password' => 'password', + ]); + + // Assert a token was returned + $response->assertStatus(401); + } + + + public function test_login_failed_error_password() + { + $response = $this + ->actingAs($this->user) + ->postJson('/api/login', [ + 'email' => $this->user->email, + 'password' => '1234567890', + ]); + + // Assert a token was returned + $response->assertStatus(401); + } +} diff --git a/tests/Feature/Api/Auth/RegisterTest.php b/tests/Feature/Api/Auth/RegisterTest.php index 1b75897..c82d5af 100644 --- a/tests/Feature/Api/Auth/RegisterTest.php +++ b/tests/Feature/Api/Auth/RegisterTest.php @@ -5,6 +5,7 @@ namespace Tests\Feature\Api\Auth; use App\Models\User; use App\Models\UserDetailz; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\Auth; use Illuminate\Testing\Fluent\AssertableJson; use Tests\TestCase; @@ -42,14 +43,12 @@ class RegisterTest extends TestCase 'waist_circumference' => $this->userDetails->waist_circumference, 'hip_circumference' => $this->userDetails->hip_circumference, 'has_hypo' => $this->userDetails->has_hypo, - 'has_hyper' => $this->userDetails->has_hypo, + 'has_hyper' => $this->userDetails->has_hyper, ]); $response ->assertStatus(200) - ->assertJson(fn(AssertableJson $json) => - $json->has('token') - ); + ->assertJsonStructure(['token']); } public function test_register_failed_this_email_already_taken() @@ -77,10 +76,8 @@ class RegisterTest extends TestCase $response ->assertStatus(422); - } - public function test_register_failed_empty_data() { $user = User::factory()->create(['is_consultant' => true]); @@ -106,6 +103,5 @@ class RegisterTest extends TestCase $response ->assertStatus(422); - } }