added it_create_new_user_with_avatar test

This commit is contained in:
Peter Papp
2021-03-04 17:47:26 +01:00
parent 2782dc879b
commit 5844e66b7f
2 changed files with 57 additions and 23 deletions

View File

@@ -8,8 +8,10 @@ use App\Models\User;
use App\Notifications\ResetPassword;
use DB;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Http\UploadedFile;
use Notification;
use Laravel\Sanctum\Sanctum;
use Storage;
use Tests\TestCase;
class AdminTest extends TestCase
@@ -121,7 +123,6 @@ class AdminTest extends TestCase
]);
}
/**
* @test
*/
@@ -267,4 +268,41 @@ class AdminTest extends TestCase
$this->assertTrue(User::find($user->id)->role === 'admin');
}
/**
* @test
*/
public function it_create_new_user_with_avatar()
{
Storage::fake('local');
$admin = User::factory(User::class)
->create(['role' => 'admin']);
Sanctum::actingAs($admin);
$avatar = UploadedFile::fake()
->image('fake-image.jpg');
$this->postJson("/api/admin/users/create", [
'name' => 'John Doe',
'role' => 'user',
'email' => 'john@doe.com',
'password' => 'VerySecretPassword',
'storage_capacity' => 15,
'password_confirmation' => 'VerySecretPassword',
'avatar' => $avatar,
])->assertStatus(201);
$this->assertDatabaseHas('users', [
'email' => 'john@doe.com'
]);
$this->assertDatabaseHas('user_settings', [
'name' => 'John Doe'
]);
Storage::disk('local')
->assertExists(User::whereEmail('john@doe.com')->first()->settings->getRawOriginal('avatar'));
}
}