forked from eatvio/eatvio-infra
109 lines
3.7 KiB
PHP
109 lines
3.7 KiB
PHP
<?php
|
|
|
|
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;
|
|
|
|
class RegisterTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $user;
|
|
private UserDetailz $userDetails;
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->refreshApplicationWithLocale('en');
|
|
|
|
$this->user = User::factory()->make(['is_consultant' => true]);
|
|
$this->userDetails = UserDetailz::factory()->make();
|
|
}
|
|
|
|
public function test_register_success()
|
|
{
|
|
$response = $this->postJson('/api/register', [
|
|
'email' => $this->user->email,
|
|
'password' => $this->user->password,
|
|
'password_confirmation' => $this->user->password,
|
|
'first_name' => $this->userDetails->first_name,
|
|
'last_name' => $this->userDetails->last_name,
|
|
'birthdate' => $this->userDetails->birthdate,
|
|
'gender' => $this->userDetails->gender,
|
|
'country' => $this->userDetails->country,
|
|
'city' => $this->userDetails->city,
|
|
'lang' => $this->userDetails->lang,
|
|
'weight' => $this->userDetails->weight,
|
|
'height' => $this->userDetails->height,
|
|
'chest_circumference' => $this->userDetails->chest_circumference,
|
|
'waist_circumference' => $this->userDetails->waist_circumference,
|
|
'hip_circumference' => $this->userDetails->hip_circumference,
|
|
'has_hypo' => $this->userDetails->has_hypo,
|
|
'has_hyper' => $this->userDetails->has_hyper,
|
|
]);
|
|
|
|
$response
|
|
->assertStatus(200)
|
|
->assertJsonStructure(['token']);
|
|
}
|
|
|
|
public function test_register_failed_this_email_already_taken()
|
|
{
|
|
$user = User::factory()->create(['is_consultant' => true]);
|
|
|
|
$response = $this->postJson('/api/register', [
|
|
'email' => $user->email,
|
|
'password' => $this->user->password,
|
|
'password_confirmation' => $this->user->password,
|
|
'first_name' => $this->userDetails->first_name,
|
|
'last_name' => $this->userDetails->last_name,
|
|
'birthdate' => $this->userDetails->birthdate,
|
|
'gender' => $this->userDetails->gender,
|
|
'country' => $this->userDetails->country,
|
|
'city' => $this->userDetails->city,
|
|
'lang' => $this->userDetails->lang,
|
|
'weight' => $this->userDetails->weight,
|
|
'height' => $this->userDetails->height,
|
|
'chest_circumference' => $this->userDetails->chest_circumference,
|
|
'waist_circumference' => $this->userDetails->waist_circumference,
|
|
'hip_circumference' => $this->userDetails->hip_circumference,
|
|
'has_hypo' => $this->userDetails->has_hypo,
|
|
'has_hyper' => $this->userDetails->has_hypo,
|
|
]);
|
|
|
|
$response
|
|
->assertStatus(422);
|
|
}
|
|
|
|
public function test_register_failed_empty_data()
|
|
{
|
|
User::factory()->create(['is_consultant' => true]);
|
|
$response = $this->postJson('/api/register', [
|
|
'email' => '',
|
|
'password' => '',
|
|
'password_confirmation' => '',
|
|
'first_name' => '',
|
|
'last_name' => '',
|
|
'birthdate' => '',
|
|
'gender' => '',
|
|
'country' => '',
|
|
'city' => '',
|
|
'lang' => '',
|
|
'weight' => '',
|
|
'height' => '',
|
|
'chest_circumference' => '',
|
|
'waist_circumference' => '',
|
|
'hip_circumference' => '',
|
|
'has_hypo' => '',
|
|
'has_hyper' => '',
|
|
]);
|
|
|
|
$response
|
|
->assertStatus(422);
|
|
}
|
|
}
|