feat: add user fields
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PacePreference;
|
||||
use App\Enums\PhysicalActivityLevel;
|
||||
use App\Enums\UserSex;
|
||||
use App\Enums\WeightGoal;
|
||||
use App\Mail\VerifyAccount;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Notifications\VerifyEmail;
|
||||
@@ -17,15 +21,35 @@ it('sends a verification email when a user registers', function () {
|
||||
'name' => 'Léon',
|
||||
'email' => 'leon@example.com',
|
||||
'password' => 'password',
|
||||
'physicalActivityLevel' => PhysicalActivityLevel::LIGHTLY_ACTIVE->value,
|
||||
'weightGoal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pacePreference' => PacePreference::NORMAL->value,
|
||||
'sex' => UserSex::WOMAN->value,
|
||||
'dateOfBirth' => '2003-04-24',
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('user.email', 'leon@example.com')
|
||||
->assertJsonPath('user.emailVerified', false);
|
||||
->assertJsonPath('user.emailVerified', false)
|
||||
->assertJsonPath('user.physicalActivityLevel', PhysicalActivityLevel::LIGHTLY_ACTIVE->value)
|
||||
->assertJsonPath('user.weightGoal', WeightGoal::MAINTAIN_WEIGHT->value)
|
||||
->assertJsonPath('user.pacePreference', PacePreference::NORMAL->value)
|
||||
->assertJsonPath('user.sex', UserSex::WOMAN->value)
|
||||
->assertJsonPath('user.dateOfBirth', '2003-04-24');
|
||||
|
||||
$user = User::where('email', 'leon@example.com')->firstOrFail();
|
||||
|
||||
expect($user->hasVerifiedEmail())->toBeFalse();
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'physical_activity_level' => PhysicalActivityLevel::LIGHTLY_ACTIVE->value,
|
||||
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pace_preference' => PacePreference::NORMAL->value,
|
||||
'sex' => UserSex::WOMAN->value,
|
||||
]);
|
||||
|
||||
expect($user->date_of_birth?->toDateString())->toBe('2003-04-24');
|
||||
|
||||
Notification::assertSentTo($user, VerifyEmail::class);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\PacePreference;
|
||||
use App\Enums\PhysicalActivityLevel;
|
||||
use App\Enums\UserSex;
|
||||
use App\Enums\WeightGoal;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
@@ -71,3 +75,69 @@ it('validates nutrition goals', function () {
|
||||
'nutritionGoals.fats',
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns profile preferences with the authenticated user', function () {
|
||||
$user = User::factory()->create([
|
||||
'physical_activity_level' => PhysicalActivityLevel::VERY_ACTIVE->value,
|
||||
'weight_goal' => WeightGoal::GAIN_WEIGHT->value,
|
||||
'pace_preference' => PacePreference::FAST->value,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.physicalActivityLevel', PhysicalActivityLevel::VERY_ACTIVE->value)
|
||||
->assertJsonPath('data.weightGoal', WeightGoal::GAIN_WEIGHT->value)
|
||||
->assertJsonPath('data.pacePreference', PacePreference::FAST->value);
|
||||
});
|
||||
|
||||
it('updates profile preferences for the authenticated user', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->patchJson('/api/auth/me', [
|
||||
'physicalActivityLevel' => PhysicalActivityLevel::MODERATELY_ACTIVE->value,
|
||||
'weightGoal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pacePreference' => PacePreference::NORMAL->value,
|
||||
'sex' => UserSex::MAN->value,
|
||||
'dateOfBirth' => '2003-04-24',
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.physicalActivityLevel', PhysicalActivityLevel::MODERATELY_ACTIVE->value)
|
||||
->assertJsonPath('data.weightGoal', WeightGoal::MAINTAIN_WEIGHT->value)
|
||||
->assertJsonPath('data.pacePreference', PacePreference::NORMAL->value)
|
||||
->assertJsonPath('data.sex', UserSex::MAN->value)
|
||||
->assertJsonPath('data.dateOfBirth', '2003-04-24');
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'physical_activity_level' => PhysicalActivityLevel::MODERATELY_ACTIVE->value,
|
||||
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pace_preference' => PacePreference::NORMAL->value,
|
||||
'sex' => UserSex::MAN->value,
|
||||
]);
|
||||
|
||||
expect($user->fresh()->date_of_birth?->toDateString())->toBe('2003-04-24');
|
||||
});
|
||||
|
||||
it('validates profile preferences', function () {
|
||||
Sanctum::actingAs(User::factory()->create());
|
||||
|
||||
$this->patchJson('/api/auth/me', [
|
||||
'physicalActivityLevel' => 'daily',
|
||||
'weightGoal' => 'bulk',
|
||||
'pacePreference' => 'urgent',
|
||||
'sex' => 'x',
|
||||
'dateOfBirth' => 'tomorrow',
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors([
|
||||
'physicalActivityLevel',
|
||||
'weightGoal',
|
||||
'pacePreference',
|
||||
'sex',
|
||||
'dateOfBirth',
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user