koel/tests/Feature/ProfileTest.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2016-05-30 05:50:59 +00:00
<?php
2017-02-14 06:53:02 +00:00
namespace Tests\Feature;
2016-05-30 05:50:59 +00:00
use App\Models\User;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Hash;
2016-05-30 05:50:59 +00:00
2017-08-05 16:56:11 +00:00
class ProfileTest extends TestCase
2016-05-30 05:50:59 +00:00
{
2022-07-06 16:08:55 +00:00
private User $user;
2018-08-22 19:46:36 +00:00
2019-07-22 07:03:23 +00:00
public function setUp(): void
2018-08-22 19:46:36 +00:00
{
parent::setUp();
$this->user = User::factory()->create(['password' => Hash::make('secret')]);
2018-08-22 19:46:36 +00:00
}
public function testUpdateProfileRequiresCurrentPassword(): void
2016-05-30 05:50:59 +00:00
{
2022-07-27 08:49:33 +00:00
$this->putAs('api/me', [
'name' => 'Foo',
'email' => 'bar@baz.com',
], $this->user)
->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
}
2018-08-22 19:46:36 +00:00
public function testUpdateProfileWithoutNewPassword(): void
{
2022-07-27 08:49:33 +00:00
$this->putAs('api/me', [
'name' => 'Foo',
'email' => 'bar@baz.com',
'current_password' => 'secret',
], $this->user);
2018-08-22 19:46:36 +00:00
$this->user->refresh();
2016-05-30 05:50:59 +00:00
self::assertSame('Foo', $this->user->name);
self::assertSame('bar@baz.com', $this->user->email);
self::assertTrue(Hash::check('secret', $this->user->password));
2016-05-30 05:50:59 +00:00
}
2018-08-22 19:46:36 +00:00
public function testUpdateProfileWithNewPassword(): void
2018-08-22 19:46:36 +00:00
{
2022-07-27 08:49:33 +00:00
$this->putAs('api/me', [
2018-08-22 19:46:36 +00:00
'name' => 'Foo',
'email' => 'bar@baz.com',
'new_password' => 'new-secret',
'current_password' => 'secret',
], $this->user)
2022-07-06 16:08:55 +00:00
->assertHeader('Authorization', $this->user->refresh()->api_token);
self::assertSame('Foo', $this->user->name);
self::assertSame('bar@baz.com', $this->user->email);
self::assertTrue(Hash::check('new-secret', $this->user->password));
2018-08-22 19:46:36 +00:00
}
2016-05-30 05:50:59 +00:00
}