feat: locale
This commit is contained in:
@@ -21,6 +21,7 @@ it('sends a verification email when a user registers', function () {
|
||||
'name' => 'Leon',
|
||||
'email' => 'leon@example.com',
|
||||
'password' => 'password',
|
||||
'locale' => 'fr-FR',
|
||||
'physicalActivityLevel' => PhysicalActivityLevel::LIGHTLY_ACTIVE->value,
|
||||
'weightGoal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pacePreference' => PacePreference::NORMAL->value,
|
||||
@@ -29,6 +30,7 @@ it('sends a verification email when a user registers', function () {
|
||||
])
|
||||
->assertCreated()
|
||||
->assertJsonPath('user.email', 'leon@example.com')
|
||||
->assertJsonPath('user.locale', 'fr')
|
||||
->assertJsonPath('user.emailVerified', false)
|
||||
->assertJsonPath('user.physicalActivityLevel', PhysicalActivityLevel::LIGHTLY_ACTIVE->value)
|
||||
->assertJsonPath('user.weightGoal', WeightGoal::MAINTAIN_WEIGHT->value)
|
||||
@@ -42,6 +44,7 @@ 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,
|
||||
@@ -54,7 +57,9 @@ it('sends a verification email when a user registers', function () {
|
||||
});
|
||||
|
||||
it('uses the custom account verification mailable', function () {
|
||||
$user = User::factory()->unverified()->create();
|
||||
$user = User::factory()->unverified()->create([
|
||||
'locale' => 'fr',
|
||||
]);
|
||||
|
||||
$mailable = (new VerifyEmail)->toMail($user);
|
||||
|
||||
@@ -65,6 +70,21 @@ it('uses the custom account verification mailable', function () {
|
||||
->assertSeeInHtml($user->name);
|
||||
});
|
||||
|
||||
it('uses the user locale for account verification emails', function () {
|
||||
$user = User::factory()->unverified()->create([
|
||||
'locale' => 'en',
|
||||
]);
|
||||
|
||||
$mailable = (new VerifyEmail)->toMail($user);
|
||||
|
||||
expect($mailable)->toBeInstanceOf(VerifyAccount::class);
|
||||
|
||||
$mailable
|
||||
->assertSeeInHtml('Verify my account')
|
||||
->assertSeeInHtml('Confirm your email address')
|
||||
->assertDontSeeInHtml('Vérifier mon compte');
|
||||
});
|
||||
|
||||
it('generates verification links with a relative signature', function () {
|
||||
$user = User::factory()->unverified()->create();
|
||||
|
||||
@@ -132,17 +152,22 @@ it('blocks login for unverified users', function () {
|
||||
|
||||
it('allows login for verified users', function () {
|
||||
$user = User::factory()->create([
|
||||
'locale' => 'en',
|
||||
'password' => 'password',
|
||||
]);
|
||||
|
||||
$this->postJson('/api/auth/login', [
|
||||
'email' => $user->email,
|
||||
'locale' => 'fr-FR',
|
||||
'password' => 'password',
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('user.email', $user->email)
|
||||
->assertJsonPath('user.locale', 'fr')
|
||||
->assertJsonPath('user.emailVerified', true)
|
||||
->assertCookie('token');
|
||||
|
||||
expect($user->fresh()->locale)->toBe('fr');
|
||||
});
|
||||
|
||||
it('resends a verification email for an unverified user without authentication', function () {
|
||||
|
||||
@@ -22,6 +22,7 @@ it('sends a password reset email with a clickable api web url', function () {
|
||||
|
||||
$user = User::factory()->create([
|
||||
'email' => 'leon@example.com',
|
||||
'locale' => 'fr',
|
||||
]);
|
||||
|
||||
$this
|
||||
@@ -58,6 +59,38 @@ it('sends a password reset email with a clickable api web url', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the user locale for password reset emails', function () {
|
||||
Notification::fake();
|
||||
|
||||
$user = User::factory()->create([
|
||||
'email' => 'leon@example.com',
|
||||
'locale' => 'en',
|
||||
]);
|
||||
|
||||
$this
|
||||
->postJson('/api/auth/forgot-password', [
|
||||
'email' => $user->email,
|
||||
])
|
||||
->assertOk();
|
||||
|
||||
Notification::assertSentTo(
|
||||
$user,
|
||||
ResetPassword::class,
|
||||
function (ResetPassword $notification) use ($user): bool {
|
||||
$mail = $notification->toMail($user);
|
||||
|
||||
expect($mail)->toBeInstanceOf(ResetPasswordMail::class);
|
||||
|
||||
$mail
|
||||
->assertSeeInHtml('Reset your password')
|
||||
->assertSeeInHtml('Choose a new password')
|
||||
->assertDontSeeInHtml('Réinitialise ton mot de passe');
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('does not reveal whether a reset email can be sent', function () {
|
||||
Notification::fake();
|
||||
|
||||
@@ -100,6 +133,7 @@ it('resets the password and invalidates existing api tokens', function () {
|
||||
it('shows the api password reset form from the email link', function () {
|
||||
$user = User::factory()->create([
|
||||
'email' => 'leon@example.com',
|
||||
'locale' => 'fr',
|
||||
]);
|
||||
$token = Password::broker()->createToken($user);
|
||||
|
||||
@@ -114,9 +148,29 @@ it('shows the api password reset form from the email link', function () {
|
||||
->assertSee($user->email);
|
||||
});
|
||||
|
||||
it('shows the api password reset form in the user locale', function () {
|
||||
$user = User::factory()->create([
|
||||
'email' => 'leon@example.com',
|
||||
'locale' => 'en',
|
||||
]);
|
||||
$token = Password::broker()->createToken($user);
|
||||
|
||||
$this
|
||||
->get(route('password.reset', [
|
||||
'email' => $user->email,
|
||||
'token' => $token,
|
||||
], absolute: false))
|
||||
->assertOk()
|
||||
->assertViewIs('auth.reset-password')
|
||||
->assertSee('New password')
|
||||
->assertSee('Update password')
|
||||
->assertDontSee('Nouveau mot de passe');
|
||||
});
|
||||
|
||||
it('resets the password from the api web form', function () {
|
||||
$user = User::factory()->create([
|
||||
'email' => 'leon@example.com',
|
||||
'locale' => 'fr',
|
||||
'password' => 'old-password',
|
||||
]);
|
||||
$token = Password::broker()->createToken($user);
|
||||
|
||||
@@ -22,6 +22,7 @@ it('returns nutrition goals with the authenticated user', function () {
|
||||
|
||||
$this->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.locale', 'en')
|
||||
->assertJsonPath('data.nutritionGoals.calories', 2400)
|
||||
->assertJsonPath('data.nutritionGoals.proteins', 140)
|
||||
->assertJsonPath('data.nutritionGoals.carbs', 280)
|
||||
@@ -103,16 +104,19 @@ it('updates profile preferences for the authenticated user', function () {
|
||||
'pacePreference' => PacePreference::NORMAL->value,
|
||||
'sex' => UserSex::MAN->value,
|
||||
'dateOfBirth' => '2003-04-24',
|
||||
'locale' => 'fr-FR',
|
||||
])
|
||||
->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.locale', 'fr')
|
||||
->assertJsonPath('data.dateOfBirth', '2003-04-24');
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'locale' => 'fr',
|
||||
'physical_activity_level' => PhysicalActivityLevel::MODERATELY_ACTIVE->value,
|
||||
'weight_goal' => WeightGoal::MAINTAIN_WEIGHT->value,
|
||||
'pace_preference' => PacePreference::NORMAL->value,
|
||||
@@ -130,6 +134,7 @@ it('validates profile preferences', function () {
|
||||
'weightGoal' => 'bulk',
|
||||
'pacePreference' => 'urgent',
|
||||
'sex' => 'x',
|
||||
'locale' => 'es',
|
||||
'dateOfBirth' => 'tomorrow',
|
||||
])
|
||||
->assertUnprocessable()
|
||||
@@ -138,6 +143,7 @@ it('validates profile preferences', function () {
|
||||
'weightGoal',
|
||||
'pacePreference',
|
||||
'sex',
|
||||
'locale',
|
||||
'dateOfBirth',
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user