Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

koel/koel

16858 stars
1 code files
View koel/koel on GitHub

tests/Feature/ProfileTest.php

Open in GitHub
use App\Models\User;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Hash;
 
class ProfileTest extends TestCase
{
private $user;
 
public function setUp(): void
{
parent::setUp();
 
$this->user = User::factory()->create(['password' => Hash::make('secret')]);
}
 
public function testUpdateProfileRequiresCurrentPassword(): void
{
$this->putAsUser('api/me', [
'name' => 'Foo',
'email' => '[email protected]',
], $this->user)
->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
}
 
public function testUpdateProfileWithoutNewPassword(): void
{
$this->putAsUser('api/me', [
'name' => 'Foo',
'email' => '[email protected]',
'current_password' => 'secret',
], $this->user);
 
$this->user->refresh();
 
self::assertSame('Foo', $this->user->name);
self::assertSame('[email protected]', $this->user->email);
self::assertTrue(Hash::check('secret', $this->user->password));
}
 
public function testUpdateProfileWithNewPassword(): void
{
$this->putAsUser('api/me', [
'name' => 'Foo',
'email' => '[email protected]',
'new_password' => 'new-secret',
'current_password' => 'secret',
], $this->user)
->assertJsonStructure(['token']);
 
$this->user->refresh();
 
self::assertSame('Foo', $this->user->name);
self::assertSame('[email protected]', $this->user->email);
self::assertTrue(Hash::check('new-secret', $this->user->password));
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.