This commit completes the PR #53 integration by optimizing the test suite: Performance Improvements: - Migrated 25 test files from RefreshDatabase to DatabaseTransactions - Tests now run in 12.69s parallel (previously 30s+) - Increased PostgreSQL max_locks_per_transaction to 256 for parallel testing Test Infrastructure Changes: - Disabled broadcasting in tests (set to null) to avoid Reverb connectivity issues - Reverted 5 integration tests to RefreshDatabase (CheckoutFlowTest + 4 Service tests) that require full schema recreation due to complex fixtures PR #53 Integration Fixes: - Added Product.inStock() scope for inventory queries - Fixed ProductFactory to create InventoryItem records instead of using removed columns - Added Department.products() relationship - Fixed FulfillmentWorkOrderController view variables - Fixed orders migration location_id foreign key constraint - Created seller-layout component wrapper All 146 tests now pass with optimal performance.
52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Models;
|
|
|
|
use App\Models\Business;
|
|
use App\Models\Department;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Tests\TestCase;
|
|
|
|
class DepartmentUserTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_user_can_be_assigned_to_departments(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$business = Business::factory()->create();
|
|
$dept1 = Department::factory()->create(['business_id' => $business->id]);
|
|
$dept2 = Department::factory()->create(['business_id' => $business->id]);
|
|
|
|
$user->departments()->attach([$dept1->id, $dept2->id]);
|
|
|
|
$this->assertCount(2, $user->departments);
|
|
$this->assertTrue($user->departments->contains($dept1));
|
|
$this->assertTrue($user->departments->contains($dept2));
|
|
}
|
|
|
|
public function test_department_has_many_users(): void
|
|
{
|
|
$department = Department::factory()->create();
|
|
$user1 = User::factory()->create();
|
|
$user2 = User::factory()->create();
|
|
|
|
$department->users()->attach([$user1->id, $user2->id]);
|
|
|
|
$this->assertCount(2, $department->users);
|
|
$this->assertTrue($department->users->contains($user1));
|
|
}
|
|
|
|
public function test_cannot_assign_same_user_to_department_twice(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$department = Department::factory()->create();
|
|
|
|
$department->users()->attach($user->id);
|
|
|
|
$this->expectException(\Illuminate\Database\QueryException::class);
|
|
$department->users()->attach($user->id);
|
|
}
|
|
}
|