diff --git a/app/FileManagerFile.php b/app/Models/FileManagerFile.php similarity index 100% rename from app/FileManagerFile.php rename to app/Models/FileManagerFile.php diff --git a/app/FileManagerFolder.php b/app/Models/FileManagerFolder.php similarity index 100% rename from app/FileManagerFolder.php rename to app/Models/FileManagerFolder.php diff --git a/app/Invoice.php b/app/Models/Invoice.php similarity index 100% rename from app/Invoice.php rename to app/Models/Invoice.php diff --git a/app/Page.php b/app/Models/Page.php similarity index 100% rename from app/Page.php rename to app/Models/Page.php diff --git a/app/PaymentGateway.php b/app/Models/PaymentGateway.php similarity index 100% rename from app/PaymentGateway.php rename to app/Models/PaymentGateway.php diff --git a/app/Setting.php b/app/Models/Setting.php similarity index 100% rename from app/Setting.php rename to app/Models/Setting.php diff --git a/app/Share.php b/app/Models/Share.php similarity index 100% rename from app/Share.php rename to app/Models/Share.php diff --git a/app/Traffic.php b/app/Models/Traffic.php similarity index 100% rename from app/Traffic.php rename to app/Models/Traffic.php diff --git a/app/User.php b/app/Models/User.php similarity index 65% rename from app/User.php rename to app/Models/User.php index 07d9e34f..1d1ceb76 100644 --- a/app/User.php +++ b/app/Models/User.php @@ -6,79 +6,19 @@ use App\Notifications\ResetPassword; use App\Notifications\ResetUserPasswordNotification; use ByteUnits\Metric; use Carbon\Carbon; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Str; use Laravel\Cashier\Billable; use Laravel\Passport\HasApiTokens; use Kyslik\ColumnSortable\Sortable; use Rinvex\Subscriptions\Traits\HasSubscriptions; -/** - * App\User - * - * @property int $id - * @property string $name - * @property string $email - * @property \Illuminate\Support\Carbon|null $email_verified_at - * @property string $password - * @property \Illuminate\Contracts\Routing\UrlGenerator|string $avatar - * @property string|null $remember_token - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Client[] $clients - * @property-read int|null $clients_count - * @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFolder[] $favourites - * @property-read int|null $favourites_count - * @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFile[] $files - * @property-read int|null $files_count - * @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFile[] $files_with_trashed - * @property-read int|null $files_with_trashed_count - * @property-read mixed $used_capacity - * @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFile[] $latest_uploads - * @property-read int|null $latest_uploads_count - * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications - * @property-read int|null $notifications_count - * @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Passport\Token[] $tokens - * @property-read int|null $tokens_count - * @method static \Illuminate\Database\Eloquent\Builder|\App\User newModelQuery() - * @method static \Illuminate\Database\Eloquent\Builder|\App\User newQuery() - * @method static \Illuminate\Database\Eloquent\Builder|\App\User query() - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereAvatar($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmail($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmailVerifiedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereName($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value) - * @mixin \Eloquent - * @property string $role - * @property string|null $stripe_id - * @property string|null $card_brand - * @property string|null $card_last_four - * @property string|null $trial_ends_at - * @property-read \Illuminate\Database\Eloquent\Collection|\App\FileManagerFolder[] $favourite_folders - * @property-read int|null $favourite_folders_count - * @property-read mixed $folder_tree - * @property-read mixed $storage - * @property-read \Illuminate\Database\Eloquent\Collection|\App\Invoice[] $invoices - * @property-read int|null $invoices_count - * @property-read int|null $payment_cards_count - * @property-read \App\UserSettings|null $settings - * @property-read \Illuminate\Database\Eloquent\Collection|\Laravel\Cashier\Subscription[] $subscriptions - * @property-read int|null $subscriptions_count - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCardBrand($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCardLastFour($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRole($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereStripeId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTrialEndsAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|User sortable($defaultParameters = null) - */ class User extends Authenticatable { - use HasApiTokens, Notifiable, Billable, Sortable; + use Notifiable, Billable, Sortable, HasFactory, \Laravel\Sanctum\HasApiTokens; protected $guarded = ['id', 'role']; @@ -126,6 +66,10 @@ class User extends Authenticatable 'storage_capacity', ]; + public $incrementing = false; + + protected $keyType = 'string'; + /** * Get tax rate id for user * @@ -345,4 +289,16 @@ class User extends Authenticatable { return $this->hasOne(UserSettings::class); } + + /** + * Generate uuid + */ + protected static function boot() + { + parent::boot(); + + static::creating(function ($model) { + $model->id = (string)Str::uuid(); + }); + } } diff --git a/app/UserSettings.php b/app/Models/UserSettings.php similarity index 100% rename from app/UserSettings.php rename to app/Models/UserSettings.php diff --git a/app/Zip.php b/app/Models/Zip.php similarity index 100% rename from app/Zip.php rename to app/Models/Zip.php diff --git a/composer.json b/composer.json index 43be456e..a06b66b8 100644 --- a/composer.json +++ b/composer.json @@ -32,10 +32,10 @@ "require-dev": { "barryvdh/laravel-ide-helper": "^2.7", "facade/ignition": "^2.3.6", - "fzaninotto/faker": "^1.4", - "mockery/mockery": "^1.0", + "fzaninotto/faker": "^1.9.1", + "mockery/mockery": "^1.3.1", "nunomaduro/collision": "^5.0", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.5.2" }, "config": { "optimize-autoloader": true, diff --git a/composer.lock b/composer.lock index d6cf42ac..009e5dac 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "31b80dcbc3703ef7b5654f9afe18d13e", + "content-hash": "9f04ec7084949f2d0a1c343da44c30cd", "packages": [ { "name": "asm89/stack-cors", diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php new file mode 100644 index 00000000..f7845b36 --- /dev/null +++ b/database/factories/UserFactory.php @@ -0,0 +1,61 @@ + $this->faker->randomElement(['user', 'admin']), + 'name' => $this->faker->name(), + 'email' => $this->faker->unique()->safeEmail, + 'email_verified_at' => now(), + 'password' => Hash::make('secret'), + 'remember_token' => Str::random(10), + 'created_at' => $this->faker->dateTimeBetween($startDate = '-36 months', $endDate = 'now', $timezone = null), + ]; + } + + /** + * Configure the model factory. + * + * @return $this + */ + public function configure() + { + return $this->afterCreating(function (User $user) { + $user + ->settings() + ->create([ + 'storage_capacity' => $this->faker->randomNumber(1), + 'name' => $this->faker->name, + 'address' => $this->faker->address, + 'state' => $this->faker->state, + 'city' => $this->faker->city, + 'postal_code' => $this->faker->postcode, + 'country' => $this->faker->randomElement(['SK', 'CZ', 'DE', 'FR']), + 'phone_number' => $this->faker->phoneNumber, + 'timezone' => $this->faker->randomElement(['+1.0', '+2.0', '+3.0']), + ]); + }); + } +} diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php index aca59428..f9d1cd79 100644 --- a/tests/Feature/UserTest.php +++ b/tests/Feature/UserTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature; +use App\User; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; @@ -12,14 +13,20 @@ class UserTest extends TestCase use DatabaseMigrations; /** - * A basic feature test example. - * - * @return void + * @test */ - public function test_example() + public function it_generate_and_store_user() { - $response = $this->get('/'); + $user = User::factory(User::class) + ->create(['role' => 'user']); - $response->assertStatus(200); + $this->assertDatabaseHas('users', [ + 'id' => $user->id, + 'role' => 'user', + ]); + + $this->assertDatabaseHas('user_settings', [ + 'user_id' => $user->id, + ]); } }