20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:57:50 +01:00
parent 854ce02bf6
commit 4d6b4930b2
128 changed files with 18247 additions and 2093 deletions

View file

@ -0,0 +1,81 @@
<?php
use App\Models\Hub;
use App\Models\Partner;
use App\Models\Product;
use App\Models\User;
test('partner belongs to hub', function () {
$hub = Hub::factory()->create();
$partner = Partner::factory()->create(['hub_id' => $hub->id]);
expect($partner->hub->id)->toBe($hub->id);
});
test('partner has many users', function () {
$partner = Partner::factory()->create();
User::factory()->count(3)->create(['partner_id' => $partner->id]);
expect($partner->users)->toHaveCount(3);
});
test('partner has many products', function () {
$partner = Partner::factory()->create();
Product::factory()->count(2)->create(['partner_id' => $partner->id]);
expect($partner->products)->toHaveCount(2);
});
test('partner can have parent partner (broker)', function () {
$broker = Partner::factory()->estateAgent()->create();
$customer = Partner::factory()->create(['parent_partner_id' => $broker->id]);
expect($customer->parentPartner->id)->toBe($broker->id);
expect($customer->broker()->first()->id)->toBe($broker->id);
});
test('partner can have child partners (customers)', function () {
$broker = Partner::factory()->estateAgent()->create();
Partner::factory()->count(2)->create(['parent_partner_id' => $broker->id]);
expect($broker->childPartners)->toHaveCount(2);
expect($broker->customers)->toHaveCount(2);
});
test('partner factory has retailer state', function () {
$partner = Partner::factory()->retailer()->create();
expect($partner->type->value)->toBe('Retailer');
});
test('partner factory has manufacturer state', function () {
$partner = Partner::factory()->manufacturer()->create();
expect($partner->type->value)->toBe('Manufacturer');
});
test('partner factory has estateAgent state', function () {
$partner = Partner::factory()->estateAgent()->create();
expect($partner->type->value)->toBe('Estate-Agent');
});
test('partner casts opening_hours to array', function () {
$hours = ['mon' => '09:00-18:00', 'tue' => '09:00-18:00'];
$partner = Partner::factory()->create(['opening_hours' => $hours]);
$partner->refresh();
expect($partner->opening_hours)->toBeArray();
expect($partner->opening_hours['mon'])->toBe('09:00-18:00');
});
test('partner casts specialties to array', function () {
$specialties = ['Küchen', 'Wohnzimmer', 'Schlafzimmer'];
$partner = Partner::factory()->create(['specialties' => $specialties]);
$partner->refresh();
expect($partner->specialties)->toBeArray();
expect($partner->specialties)->toHaveCount(3);
});

View file

@ -0,0 +1,172 @@
<?php
use App\Enums\PriceType;
use App\Enums\ProductStatus;
use App\Enums\ProductType;
use App\Models\Brand;
use App\Models\Category;
use App\Models\Collection;
use App\Models\Hub;
use App\Models\Media;
use App\Models\Partner;
use App\Models\Product;
use App\Models\Tag;
test('product can be created with factory', function () {
$product = Product::factory()->create();
expect($product)->toBeInstanceOf(Product::class);
expect($product->id)->toBeInt();
expect($product->name)->toBeString();
expect($product->slug)->toBeString();
});
test('product casts product_type to enum', function () {
$product = Product::factory()->create(['product_type' => 'local_stock']);
expect($product->product_type)->toBe(ProductType::LocalStock);
});
test('product casts status to enum', function () {
$product = Product::factory()->create(['status' => 'draft']);
expect($product->status)->toBe(ProductStatus::Draft);
});
test('product casts price_type to enum', function () {
$product = Product::factory()->create(['price_type' => 'from_price']);
expect($product->price_type)->toBe(PriceType::FromPrice);
});
test('product belongs to partner', function () {
$partner = Partner::factory()->create();
$product = Product::factory()->create(['partner_id' => $partner->id]);
expect($product->partner->id)->toBe($partner->id);
});
test('product belongs to hub', function () {
$hub = Hub::factory()->create();
$product = Product::factory()->create(['hub_id' => $hub->id]);
expect($product->hub->id)->toBe($hub->id);
});
test('product belongs to brand', function () {
$partner = Partner::factory()->manufacturer()->create();
$brand = Brand::factory()->create(['partner_id' => $partner->id]);
$product = Product::factory()->create(['brand_id' => $brand->id]);
expect($product->brand->id)->toBe($brand->id);
});
test('product belongs to collection', function () {
$collection = Collection::create(['name' => 'Test Kollektion', 'slug' => 'test-kollektion']);
$product = Product::factory()->create(['collection_id' => $collection->id]);
expect($product->collection->id)->toBe($collection->id);
});
test('product can have categories', function () {
$product = Product::factory()->create();
$category = Category::create(['name' => 'Sofas', 'slug' => 'sofas']);
$product->categories()->attach($category);
expect($product->categories)->toHaveCount(1);
expect($product->categories->first()->name)->toBe('Sofas');
});
test('product can have tags', function () {
$product = Product::factory()->create();
$tag = Tag::create(['name' => 'Neu', 'slug' => 'neu']);
$product->tags()->attach($tag);
expect($product->tags)->toHaveCount(1);
expect($product->tags->first()->name)->toBe('Neu');
});
test('product can have media', function () {
$product = Product::factory()->create();
$media = Media::factory()->create([
'model_type' => Product::class,
'model_id' => $product->id,
]);
expect($product->media)->toHaveCount(1);
expect($product->media->first()->file_path)->toBe($media->file_path);
});
test('product scope active filters correctly', function () {
Product::factory()->create(['status' => ProductStatus::Active]);
Product::factory()->create(['status' => ProductStatus::Draft]);
Product::factory()->create(['status' => ProductStatus::Archived]);
expect(Product::active()->count())->toBe(1);
});
test('product scope curated filters correctly', function () {
Product::factory()->create(['is_curated' => true]);
Product::factory()->create(['is_curated' => false]);
expect(Product::curated()->count())->toBe(1);
});
test('product scope localStock filters correctly', function () {
Product::factory()->localStock()->create();
Product::factory()->smartOrder()->create();
expect(Product::localStock()->count())->toBe(1);
expect(Product::smartOrder()->count())->toBe(1);
});
test('product scope inHub filters correctly', function () {
$hub = Hub::factory()->create();
$otherHub = Hub::factory()->create();
Product::factory()->create(['hub_id' => $hub->id]);
Product::factory()->create(['hub_id' => $otherHub->id]);
expect(Product::inHub($hub->id)->count())->toBe(1);
});
test('product scope available combines active curated and available', function () {
Product::factory()->create([
'status' => ProductStatus::Active,
'is_curated' => true,
'is_available' => true,
]);
Product::factory()->create([
'status' => ProductStatus::Active,
'is_curated' => false,
'is_available' => true,
]);
Product::factory()->create([
'status' => ProductStatus::Draft,
'is_curated' => true,
'is_available' => true,
]);
expect(Product::available()->count())->toBe(1);
});
test('product factory has localStock state', function () {
$product = Product::factory()->localStock()->create();
expect($product->product_type)->toBe(ProductType::LocalStock);
});
test('product factory has smartOrder state', function () {
$product = Product::factory()->smartOrder()->create();
expect($product->product_type)->toBe(ProductType::SmartOrder);
});
test('product factory has active state', function () {
$product = Product::factory()->active()->create();
expect($product->status)->toBe(ProductStatus::Active);
expect($product->is_curated)->toBeTrue();
});

View file

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
use App\Models\Partner;
use App\Models\Product;
use App\Models\ProductWoodOrigin;
test('product wood origin can be created with factory', function () {
$partner = Partner::factory()->create();
$product = Product::factory()->create(['partner_id' => $partner->id]);
$origin = ProductWoodOrigin::factory()->create(['product_id' => $product->id]);
expect($origin)->toBeInstanceOf(ProductWoodOrigin::class);
expect($origin->wood_species)->not->toBeEmpty();
expect($origin->origin_country)->toHaveLength(2);
});
test('product wood origin belongs to product', function () {
$partner = Partner::factory()->create();
$product = Product::factory()->create(['partner_id' => $partner->id]);
$origin = ProductWoodOrigin::factory()->create(['product_id' => $product->id]);
expect($origin->product)->toBeInstanceOf(Product::class);
expect($origin->product->id)->toBe($product->id);
});
test('product has many wood origins', function () {
$partner = Partner::factory()->create();
$product = Product::factory()->create(['partner_id' => $partner->id]);
ProductWoodOrigin::factory()->count(3)->create(['product_id' => $product->id]);
expect($product->woodOrigins)->toHaveCount(3);
});
test('deleting product cascades to wood origins', function () {
$partner = Partner::factory()->create();
$product = Product::factory()->create(['partner_id' => $partner->id]);
ProductWoodOrigin::factory()->count(2)->create(['product_id' => $product->id]);
expect(ProductWoodOrigin::where('product_id', $product->id)->count())->toBe(2);
$product->delete();
expect(ProductWoodOrigin::where('product_id', $product->id)->count())->toBe(0);
});

View file

@ -0,0 +1,53 @@
<?php
use App\Models\Setting;
test('setting can store and retrieve a string value', function () {
Setting::create([
'group' => 'test',
'key' => 'string_val',
'value' => 'hello',
'type' => 'string',
]);
expect(Setting::getValue('test', 'string_val'))->toBe('hello');
});
test('setting can store and retrieve an integer value', function () {
Setting::create([
'group' => 'test',
'key' => 'int_val',
'value' => '42',
'type' => 'integer',
]);
expect(Setting::getValue('test', 'int_val'))->toBe(42);
});
test('setting can store and retrieve a boolean value', function () {
Setting::create([
'group' => 'test',
'key' => 'bool_val',
'value' => 'true',
'type' => 'boolean',
]);
expect(Setting::getValue('test', 'bool_val'))->toBeTrue();
});
test('setting returns default when key does not exist', function () {
expect(Setting::getValue('nonexistent', 'key', 'default'))->toBe('default');
});
test('setting can update value', function () {
Setting::create([
'group' => 'test',
'key' => 'update_val',
'value' => 'old',
'type' => 'string',
]);
Setting::setValue('test', 'update_val', 'new');
expect(Setting::getValue('test', 'update_val'))->toBe('new');
});

View file

@ -0,0 +1,39 @@
<?php
use App\Enums\UserOrigin;
use App\Models\Hub;
use App\Models\Partner;
use App\Models\User;
test('user can have a hub', function () {
$hub = Hub::factory()->create();
$user = User::factory()->create(['hub_id' => $hub->id]);
expect($user->hub->id)->toBe($hub->id);
});
test('user can have an origin', function () {
$user = User::factory()->create(['origin' => 'style2own']);
expect($user->origin)->toBe(UserOrigin::Style2Own);
});
test('user origin casts stileigentum correctly', function () {
$user = User::factory()->create(['origin' => 'stileigentum']);
expect($user->origin)->toBe(UserOrigin::StilEigentum);
expect($user->origin->tonality())->toBe('sie');
});
test('user origin can be null', function () {
$user = User::factory()->create(['origin' => null]);
expect($user->origin)->toBeNull();
});
test('user belongs to partner', function () {
$partner = Partner::factory()->create();
$user = User::factory()->create(['partner_id' => $partner->id]);
expect($user->partner->id)->toBe($partner->id);
});