-
-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User bio #286
User bio #286
Conversation
@eduardostuart thank you for sending this in! I was already reviewing but saw you pushed some more commits. Request a review from me when you're done. |
@driesvints ok! Should I also add |
@driesvints can you review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all: thank you for sending this in and helping out! The screenshots really helped, good job :)
I have some changes I'd like you to make. First, it might be best to increase the bio length to 160 characters to match Twitter's max bio length. Second, it's best if we just always have bio be a string, that way you don't need to deal with null
values.
Also, something went wrong with the yarn.lock file, can you please revert those changes?
There is more feedback, feel free to take your time to go through it and get back to me when you made the changes 🙂
@@ -12,9 +12,15 @@ public function rules() | |||
'name' => 'required|max:255', | |||
'email' => 'required|email|max:255|unique:users,email,'.Auth::id(), | |||
'username' => 'required|max:255|unique:users,username,'.Auth::id(), | |||
'bio' => 'sometimes|max:144', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Increase this to 160. I also don't think we need to use sometimes
here?
]; | ||
} | ||
|
||
public function bio(): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the nullable return type
]; | ||
} | ||
|
||
public function bio(): ?string | ||
{ | ||
return $this->get('bio'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a default value of an empty string here
app/Jobs/UpdateProfile.php
Outdated
@@ -29,6 +29,7 @@ public static function fromRequest(User $user, UpdateProfileRequest $request): s | |||
'name' => $request->name(), | |||
'email' => $request->email(), | |||
'username' => strtolower($request->username()), | |||
'bio' => $request->bio(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this with 'bio' => trim(strip_tags($request->bio()),
app/User.php
Outdated
static::creating($eventHandler); | ||
static::updating($eventHandler); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this, we can do this in the job.
tests/CreatesUsers.php
Outdated
@@ -38,6 +38,7 @@ protected function createUser(array $attributes = []): User | |||
'email' => 'john@example.com', | |||
'password' => bcrypt('password'), | |||
'github_username' => 'johndoe', | |||
'bio' => 'John Doe bio content', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed here, remove it.
tests/Feature/SettingsTest.php
Outdated
]) | ||
->seePageIs('/settings') | ||
->see('Something went wrong. Please review the fields below.') | ||
->see('The email has already been taken.') | ||
->see('The username has already been taken.'); | ||
->see('The username has already been taken.') | ||
->see('My short bio text'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this from this test.
tests/Feature/SettingsTest.php
Outdated
@@ -46,11 +48,13 @@ public function users_cannot_choose_duplicate_usernames_or_email_addresses() | |||
'name' => 'Freek Murze', | |||
'email' => 'freek@example.com', | |||
'username' => 'freekmurze', | |||
'bio' => 'My short bio text', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this from this test.
yarn.lock
Outdated
os-locale "^1.4.0" | ||
window-size "^0.1.2" | ||
y18n "^3.2.0" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what went wrong here but please revert the changes to the yarn.lock
file.
app/User.php
Outdated
public function hasBio(): bool | ||
{ | ||
return ! empty($this->bio()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this method.
@driesvints all done 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job. Some last feedback.
Btw, one more thing: when I said to remove those things from the SettingsTest
feature test I meant only for the users_cannot_choose_duplicate_usernames_or_email_addresses
method. You can add the changes of the users_can_update_their_profile
back.
*/ | ||
public function down() | ||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the down method entirely :)
@@ -10,6 +10,12 @@ | |||
@endcan | |||
|
|||
<h2>{{ $user->name() }}</h2> | |||
@if ($bio = $user->bio()) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this white line.
@@ -10,6 +10,12 @@ | |||
@endcan | |||
|
|||
<h2>{{ $user->name() }}</h2> | |||
@if ($bio = $user->bio()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a white line above the if statement.
|
||
$this->assertEquals('my bio', $user->bio()); | ||
$this->assertEquals('John Doe Junior', $user->name()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed to login the user. Since you're testing a component no "state" of the active user is needed. You can re-write this as follow:
/** @test */
public function we_can_update_a_user_profile()
{
$user = (new UpdateProfile($this->createUser(), ['bio' => 'my bio', 'name' => 'John Doe Junior']))->handle();
$this->assertEquals('my bio', $user->bio());
$this->assertEquals('John Doe Junior', $user->name());
}
Make sure that the handle
method returns the updated user.
@driesvints Done! 👍 Can you check? |
Thank you for your work on this! :) |
Allow users to add a short bio of 140 characters. (reference: #283)
user profile
page.UpdateProfileRequest
updated. Addedsometimes|max:144
for bio field.Preview