feat: history and calculate needs for user
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
<?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;
|
||||
@@ -22,11 +18,6 @@ it('sends a verification email when a user registers', function () {
|
||||
'email' => 'leon@example.com',
|
||||
'password' => 'Motsdfdepasse123*',
|
||||
'locale' => 'fr-FR',
|
||||
'physicalActivityLevel' => PhysicalActivityLevel::LIGHTLY_ACTIVE->value,
|
||||
'weightGoal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pacePreference' => PacePreference::NORMAL->value,
|
||||
'sex' => UserSex::WOMAN->value,
|
||||
'dateOfBirth' => '2003-04-24',
|
||||
'termsAccepted' => true,
|
||||
])
|
||||
->assertCreated()
|
||||
@@ -35,11 +26,8 @@ it('sends a verification email when a user registers', function () {
|
||||
->assertJsonPath('user.emailVerified', false)
|
||||
->assertJsonPath('user.analysisAccessLevel', 'free')
|
||||
->assertJsonPath('user.canAnalyzeMeals', 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')
|
||||
->assertJsonPath('user.onboardingStatus', 'required')
|
||||
->assertJsonPath('user.nutritionGoals', null)
|
||||
->assertCookieMissing('token');
|
||||
|
||||
$user = User::where('email', 'leon@example.com')->firstOrFail();
|
||||
@@ -51,13 +39,13 @@ it('sends a verification email when a user registers', function () {
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'locale' => 'fr',
|
||||
'physical_activity_level' => PhysicalActivityLevel::LIGHTLY_ACTIVE->value,
|
||||
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pace_preference' => PacePreference::NORMAL->value,
|
||||
'sex' => UserSex::WOMAN->value,
|
||||
'physical_activity_level' => null,
|
||||
'weight_goal' => null,
|
||||
'pace_preference' => null,
|
||||
'sex' => null,
|
||||
]);
|
||||
|
||||
expect($user->date_of_birth?->toDateString())->toBe('2003-04-24');
|
||||
expect($user->date_of_birth)->toBeNull();
|
||||
|
||||
Notification::assertSentTo($user, VerifyEmail::class);
|
||||
});
|
||||
@@ -75,7 +63,7 @@ it('returns a temporary error when the verification email cannot be sent during
|
||||
'termsAccepted' => true,
|
||||
])
|
||||
->assertServiceUnavailable()
|
||||
->assertJsonPath('message', __('api.auth.verification_email_failed'));
|
||||
->assertJsonPath('code', 'VERIFICATION_EMAIL_FAILED');
|
||||
|
||||
$this->assertDatabaseMissing('users', [
|
||||
'email' => 'leon@example.com',
|
||||
@@ -91,16 +79,12 @@ it('registers mobile users with a bearer token', function () {
|
||||
'password' => 'Motsdfdepasse123*',
|
||||
'deviceName' => 'Bowli Android',
|
||||
'locale' => 'fr-FR',
|
||||
'physicalActivityLevel' => PhysicalActivityLevel::LIGHTLY_ACTIVE->value,
|
||||
'weightGoal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pacePreference' => PacePreference::NORMAL->value,
|
||||
'sex' => UserSex::MAN->value,
|
||||
'dateOfBirth' => '2003-04-24',
|
||||
'termsAccepted' => true,
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('user.email', 'mobile.leon@example.com')
|
||||
->assertJsonPath('user.emailVerified', false)
|
||||
->assertJsonPath('user.onboardingStatus', 'required')
|
||||
->assertJsonStructure(['token'])
|
||||
->assertCookieMissing('token');
|
||||
|
||||
@@ -183,7 +167,7 @@ it('generates verification links with a relative signature', function () {
|
||||
->withServerVariables(['HTTP_HOST' => 'different-host.test'])
|
||||
->getJson($requestUrl)
|
||||
->assertOk()
|
||||
->assertJsonPath('message', __('api.auth.verified'));
|
||||
->assertJsonPath('code', 'EMAIL_VERIFIED');
|
||||
|
||||
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
|
||||
});
|
||||
@@ -197,7 +181,7 @@ it('verifies a user from a signed email link', function () {
|
||||
|
||||
$this->getJson($url)
|
||||
->assertOk()
|
||||
->assertJsonPath('message', __('api.auth.verified'))
|
||||
->assertJsonPath('code', 'EMAIL_VERIFIED')
|
||||
->assertJsonPath('user.emailVerified', true);
|
||||
|
||||
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
|
||||
@@ -225,7 +209,7 @@ it('blocks login for unverified users', function () {
|
||||
'password' => 'password',
|
||||
])
|
||||
->assertForbidden()
|
||||
->assertJsonPath('message', __('api.auth.email_not_verified'))
|
||||
->assertJsonPath('code', 'EMAIL_NOT_VERIFIED')
|
||||
->assertCookieMissing('token');
|
||||
|
||||
$this->assertDatabaseMissing('personal_access_tokens', [
|
||||
@@ -288,7 +272,7 @@ it('logs out mobile users by deleting the current bearer token', function () {
|
||||
->withToken($token)
|
||||
->postJson('/api/auth/logout')
|
||||
->assertOk()
|
||||
->assertJsonPath('message', __('api.auth.logout'));
|
||||
->assertJsonPath('code', 'LOGGED_OUT');
|
||||
|
||||
$this->assertDatabaseMissing('personal_access_tokens', [
|
||||
'name' => 'Bowli iOS',
|
||||
@@ -305,7 +289,7 @@ it('resends a verification email for an unverified user without authentication',
|
||||
'email' => $user->email,
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('message', __('api.auth.verification_sent_if_unverified'));
|
||||
->assertJsonPath('code', 'VERIFICATION_EMAIL_SENT_IF_UNVERIFIED');
|
||||
|
||||
Notification::assertSentTo($user, VerifyEmail::class);
|
||||
});
|
||||
@@ -319,13 +303,13 @@ it('does not reveal whether an email can receive a verification email', function
|
||||
'email' => $verifiedUser->email,
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('message', __('api.auth.verification_sent_if_unverified'));
|
||||
->assertJsonPath('code', 'VERIFICATION_EMAIL_SENT_IF_UNVERIFIED');
|
||||
|
||||
$this->postJson('/api/auth/email/verification-notification', [
|
||||
'email' => 'missing@example.com',
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('message', __('api.auth.verification_sent_if_unverified'));
|
||||
->assertJsonPath('code', 'VERIFICATION_EMAIL_SENT_IF_UNVERIFIED');
|
||||
|
||||
Notification::assertNothingSent();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user