hasSettings() ->create(['role' => 'user']); $this->assertDatabaseHas('users', [ 'id' => $user->id, 'role' => 'user', ]); $this->assertDatabaseHas('user_settings', [ 'user_id' => $user->id, ]); Storage::disk('local') ->assertExists('files/' . User::first()->id); } /** * todo: finish test */ public function it_test_user_timezone() { $user = User::factory() ->create(['role' => 'user']); Folder::factory(Folder::class) ->create([ 'user_id' => $user->id, 'created_at' => now(), ]); $user->settings()->update([ 'timezone' => '2.0', ]); $this ->actingAs($user) ->getJson('/api/browse/folders/undefined') ->assertJsonFragment([ 'created_at' => '01. January. 2021 at 02:00', ]); } /** * @test */ public function it_change_user_password_in_profile_settings() { $user = User::factory() ->hasSettings() ->create(); $this ->actingAs($user) ->postJson('/api/user/password', [ 'current_password' => 'secret', 'password' => 'VerySecretPassword', 'password_confirmation' => 'VerySecretPassword', ])->assertStatus(204); // TODO: login s novym heslom } /** * @test */ public function it_update_user_settings() { $user = User::factory() ->hasSettings() ->create(); $this ->actingAs($user) ->patchJson('/api/user/settings', [ 'name' => 'address', 'value' => 'Jantar', ])->assertStatus(204); $this->assertDatabaseHas('user_settings', [ 'address' => 'Jantar', ]); } /** * @test */ public function it_update_user_avatar() { $user = User::factory() ->hasSettings() ->create(); $avatar = UploadedFile::fake() ->image('fake-image.jpg'); $this ->actingAs($user) ->patchJson('/api/user/settings', [ 'avatar' => $avatar, ])->assertStatus(204); collect(config('vuefilemanager.avatar_sizes')) ->each( fn ($size) => Storage::disk('local') ->assertExists("avatars/{$size['name']}-{$user->settings->getRawOriginal('avatar')}") ); } /** * @test */ public function it_get_user_data() { $user = User::factory() ->hasSettings() ->create(); $this ->actingAs($user) ->getJson('/api/user') ->assertStatus(200) ->assertExactJson([ 'data' => [ 'id' => (string) $user->id, 'type' => 'user', 'attributes' => [ 'avatar' => [ 'md' => 'http://localhost/assets/images/default-avatar.png', 'sm' => 'http://localhost/assets/images/default-avatar.png', 'xs' => 'http://localhost/assets/images/default-avatar.png', ], 'email' => $user->email, 'role' => $user->role, 'socialite_account' => false, 'two_factor_authentication' => false, 'folders' => [], 'storage' => [ 'used' => 0, 'used_formatted' => '0%', 'capacity' => '1', 'capacity_formatted' => '1GB', ], 'created_at' => format_date($user->created_at, '%d. %b. %Y'), 'updated_at' => format_date($user->updated_at, '%d. %B. %Y'), ], 'meta' => [ 'restrictions' => [ 'canCreateFolder' => true, 'canCreateTeamFolder' => true, 'canDownload' => true, 'canInviteTeamMembers' => true, 'canUpload' => true, ], ], 'relationships' => [ 'creditCards' => [ 'data' => [], ], 'settings' => [ 'data' => [ 'id' => (string) $user->id, 'type' => 'settings', 'attributes' => [ 'avatar' => $user->settings->avatar, 'name' => $user->settings->name, 'address' => $user->settings->address, 'state' => $user->settings->state, 'city' => $user->settings->city, 'postal_code' => $user->settings->postal_code, 'country' => $user->settings->country, 'phone_number' => $user->settings->phone_number, 'timezone' => $user->settings->timezone, ], ], ], 'favourites' => [ 'data' => [], ], ], ], ]); } /** * @test */ public function it_verify_user_email() { $user = User::factory() ->create([ 'email_verified_at' => null, ]); $verificationUrl = URL::temporarySignedRoute( 'verification.verify', now()->addMinutes(60), ['id' => $user->id, 'hash' => sha1($user->email)] ); $this ->getJson($verificationUrl) ->assertRedirect('successfully-verified'); $this->assertNotNull(User::find($user->id)->get('email_verified_at')); } /** * @test */ public function it_resend_user_verify_email() { $user = User::factory() ->create([ 'email_verified_at' => null, ]); $this->postJson('/api/user/email/verify/resend', [ 'email' => $user->email, ]) ->assertStatus(204); Notification::assertTimesSent(1, VerifyEmail::class); } }