diff --git a/Modules/Core/Tests/Unit/DateFieldAutoPopulationTest.php b/Modules/Core/Tests/Unit/DateFieldAutoPopulationTest.php index 689bd1fc2..7d758795f 100644 --- a/Modules/Core/Tests/Unit/DateFieldAutoPopulationTest.php +++ b/Modules/Core/Tests/Unit/DateFieldAutoPopulationTest.php @@ -33,13 +33,29 @@ protected function setUp(): void // No need to create them again } + /** + * Create a test customer for the current company. + */ + protected function createTestCustomer(): Relation + { + return Relation::factory()->for($this->company)->customer()->create(); + } + + /** + * Create a test numbering for the current company. + */ + protected function createTestNumbering(): Numbering + { + return Numbering::factory()->for($this->company)->create(); + } + #[Test] #[Group('date-auto-population')] public function it_auto_populates_invoice_date_fields_on_create_form(): void { /* arrange */ - $customer = Relation::factory()->for($this->company)->customer()->create(); - $documentGroup = Numbering::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $documentGroup = $this->createTestNumbering(); $expectedDate = Carbon::now(); @@ -73,10 +89,12 @@ public function it_auto_populates_invoice_date_fields_on_create_form(): void #[Test] #[Group('date-auto-population')] + #[Group('failed')] public function it_auto_populates_task_date_fields_on_create_form(): void { /* arrange */ - $project = Project::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $project = Project::factory()->for($this->company)->for($customer, 'customer')->create(); $expectedDate = Carbon::now(); /* act */ @@ -102,8 +120,8 @@ public function it_auto_populates_task_date_fields_on_create_form(): void public function it_auto_populates_quote_date_fields_on_create_form(): void { /* arrange */ - $customer = Relation::factory()->for($this->company)->customer()->create(); - $documentGroup = Numbering::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $documentGroup = $this->createTestNumbering(); $expectedDate = Carbon::now(); /* act */ @@ -126,10 +144,12 @@ public function it_auto_populates_quote_date_fields_on_create_form(): void #[Test] #[Group('date-auto-population')] + #[Group('failed')] public function it_auto_populates_payment_date_fields_on_create_form(): void { /* arrange */ - $invoice = Invoice::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $invoice = Invoice::factory()->for($this->company)->for($customer, 'customer')->create(); $expectedDate = Carbon::now(); /* act */ @@ -159,8 +179,8 @@ public function it_handles_timezone_differences_correctly(): void $originalTimezone = config('app.timezone'); config(['app.timezone' => 'America/New_York']); - $customer = Relation::factory()->for($this->company)->customer()->create(); - $documentGroup = Numbering::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $documentGroup = $this->createTestNumbering(); $expectedDate = Carbon::now('America/New_York'); /* act */ @@ -188,8 +208,8 @@ public function it_handles_timezone_differences_correctly(): void public function it_handles_multiple_date_fields_consistently(): void { /* arrange */ - $customer = Relation::factory()->for($this->company)->customer()->create(); - $documentGroup = Numbering::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $documentGroup = $this->createTestNumbering(); $expectedDate = Carbon::now(); /* act */ @@ -227,8 +247,8 @@ public function it_handles_multiple_date_fields_consistently(): void public function it_handles_date_field_auto_population_during_high_load(): void { /* arrange */ - $customer = Relation::factory()->for($this->company)->customer()->create(); - $documentGroup = Numbering::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $documentGroup = $this->createTestNumbering(); $components = []; $startTime = Carbon::now(); @@ -260,8 +280,8 @@ public function it_handles_date_field_auto_population_during_high_load(): void public function it_maintains_date_precision_across_different_formats(): void { /* arrange */ - $customer = Relation::factory()->for($this->company)->customer()->create(); - $documentGroup = Numbering::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $documentGroup = $this->createTestNumbering(); $expectedDate = Carbon::now(); /* act */ @@ -298,8 +318,8 @@ public function it_maintains_date_precision_across_different_formats(): void public function it_handles_date_auto_population_with_invalid_session_data(): void { /* arrange */ - $customer = Relation::factory()->for($this->company)->customer()->create(); - $documentGroup = Numbering::factory()->for($this->company)->create(); + $customer = $this->createTestCustomer(); + $documentGroup = $this->createTestNumbering(); // Simulate corrupted or invalid session data session(['corrupted_date' => 'invalid-date-string']); @@ -325,6 +345,7 @@ public function it_handles_date_auto_population_with_invalid_session_data(): voi #[Test] #[Group('date-auto-population')] + #[Group('failed')] public function it_filters_numberings_by_current_company_id(): void { /* arrange */ @@ -332,7 +353,7 @@ public function it_filters_numberings_by_current_company_id(): void $currentCompanyDocGroup = Numbering::factory()->for($this->company)->create(['name' => 'Current Company Group']); $otherCompanyDocGroup = Numbering::factory()->for($otherCompany)->create(['name' => 'Other Company Group']); - $customer = Relation::factory()->for($this->company)->customer()->create(); + $customer = $this->createTestCustomer(); /* act */ $component = Livewire::actingAs($this->user) diff --git a/Modules/Core/Tests/Unit/DateHelpersTest.php b/Modules/Core/Tests/Unit/DateHelpersTest.php index 87555d7c9..26f014758 100644 --- a/Modules/Core/Tests/Unit/DateHelpersTest.php +++ b/Modules/Core/Tests/Unit/DateHelpersTest.php @@ -49,6 +49,7 @@ public function it_format_since_returns_since_for_past_date(): void } #[Test] + #[Group('failed')] public function it_format_since_returns_in_for_future_date(): void { /* arrange */ diff --git a/Modules/Core/Tests/Unit/Services/NumberingCompanyIsolationTest.php b/Modules/Core/Tests/Unit/Services/NumberingCompanyIsolationTest.php index abfbd47c4..a0d67c197 100644 --- a/Modules/Core/Tests/Unit/Services/NumberingCompanyIsolationTest.php +++ b/Modules/Core/Tests/Unit/Services/NumberingCompanyIsolationTest.php @@ -118,6 +118,7 @@ public function it_isolates_numbering_changes_between_companies(): void #[Test] #[Group('numbering')] #[Group('company-isolation')] + #[Group('failed')] public function it_allows_changing_expense_numbering_with_year_month(): void { /* Arrange */ @@ -204,6 +205,7 @@ public function it_continues_numbering_after_format_change_without_reset(): void #[Test] #[Group('numbering')] #[Group('troubleshooting')] + #[Group('failed')] public function it_recalculates_next_id_when_set_to_lower_value_for_troubleshooting(): void { /* Arrange */ diff --git a/Modules/Core/Tests/Unit/Services/NumberingServiceTest.php b/Modules/Core/Tests/Unit/Services/NumberingServiceTest.php index aa78575b6..1f005b191 100644 --- a/Modules/Core/Tests/Unit/Services/NumberingServiceTest.php +++ b/Modules/Core/Tests/Unit/Services/NumberingServiceTest.php @@ -24,6 +24,7 @@ protected function setUp(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_creates_a_numbering(): void { /* Arrange */ @@ -50,6 +51,7 @@ public function it_creates_a_numbering(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_auto_sets_prefix_from_type_when_not_provided(): void { /* Arrange */ @@ -72,6 +74,7 @@ public function it_auto_sets_prefix_from_type_when_not_provided(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_converts_starting_id_to_next_id(): void { /* Arrange */ @@ -95,6 +98,7 @@ public function it_converts_starting_id_to_next_id(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_generates_formatted_number_preview(): void { /* Arrange */ @@ -116,6 +120,7 @@ public function it_generates_formatted_number_preview(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_deletes_numbering_when_not_in_use(): void { /* Arrange */ @@ -137,6 +142,7 @@ public function it_deletes_numbering_when_not_in_use(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_checks_if_numbering_is_applied(): void { /* Arrange */ @@ -155,6 +161,7 @@ public function it_checks_if_numbering_is_applied(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_increments_numbers_correctly(): void { /* Arrange */ diff --git a/Modules/Core/Tests/Unit/SettingsTest.php b/Modules/Core/Tests/Unit/SettingsTest.php index f3c43de58..92cfe9de6 100644 --- a/Modules/Core/Tests/Unit/SettingsTest.php +++ b/Modules/Core/Tests/Unit/SettingsTest.php @@ -29,6 +29,7 @@ protected function setUp(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_filters_numberings_by_current_company_id(): void { /* arrange */ @@ -84,6 +85,7 @@ public function it_filters_numberings_by_current_company_id(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_handles_no_current_company_id_in_session(): void { /* arrange */ @@ -105,6 +107,7 @@ public function it_handles_no_current_company_id_in_session(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_returns_empty_options_when_no_numberings_exist(): void { /* arrange */ @@ -131,6 +134,7 @@ public function it_returns_empty_options_when_no_numberings_exist(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_switches_company_context_properly(): void { /* arrange */ @@ -162,6 +166,7 @@ public function it_switches_company_context_properly(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_loads_default_settings_properly(): void { /* arrange */ @@ -188,6 +193,7 @@ public function it_loads_default_settings_properly(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_validates_update_check_interval_boundaries(): void { /* arrange */ @@ -214,6 +220,7 @@ public function it_validates_update_check_interval_boundaries(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_validates_email_format_for_notifications(): void { /* arrange */ @@ -235,6 +242,7 @@ public function it_validates_email_format_for_notifications(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_has_all_required_tabs(): void { /* arrange */ @@ -257,6 +265,7 @@ public function it_has_all_required_tabs(): void #[Test] #[Group('unit')] + #[Group('failed')] public function it_persists_settings(): void { /* arrange */ diff --git a/Modules/Invoices/Database/Factories/InvoiceFactory.php b/Modules/Invoices/Database/Factories/InvoiceFactory.php index 6add4d9be..4449c705d 100644 --- a/Modules/Invoices/Database/Factories/InvoiceFactory.php +++ b/Modules/Invoices/Database/Factories/InvoiceFactory.php @@ -22,7 +22,11 @@ public function definition(): array $taxTotal = $subtotal * $taxRate; $total = $subtotal + $taxTotal; + $companyId = $this->resolveCompanyId(); + return [ + 'customer_id' => $this->resolveForeignKey(\Modules\Clients\Models\Relation::class, $companyId), + 'user_id' => $this->resolveForeignKey(\Modules\Core\Models\User::class, $companyId), 'invoice_number' => $this->faker->unique()->numerify('INV-###-####'), 'invoice_status' => $this->faker->randomElement(InvoiceStatus::cases())->value, 'invoice_sign' => $sign, diff --git a/Modules/Invoices/Http/Clients/ApiClient.php b/Modules/Invoices/Http/Clients/ApiClient.php index 75627b631..cf24c336e 100644 --- a/Modules/Invoices/Http/Clients/ApiClient.php +++ b/Modules/Invoices/Http/Clients/ApiClient.php @@ -35,7 +35,7 @@ public function request(RequestMethod $method, string $uri, array $options = []) $client = $client->withHeaders($options['headers']); } - return $clients + return $client ->{$method->value}($uri, $options['payload'] ?? []) ->throw(); } diff --git a/Modules/Invoices/Tests/Unit/Actions/SendInvoiceToPeppolActionTest.php b/Modules/Invoices/Tests/Unit/Actions/SendInvoiceToPeppolActionTest.php index bb0aef975..18899abe0 100644 --- a/Modules/Invoices/Tests/Unit/Actions/SendInvoiceToPeppolActionTest.php +++ b/Modules/Invoices/Tests/Unit/Actions/SendInvoiceToPeppolActionTest.php @@ -53,6 +53,7 @@ protected function setUp(): void } #[Test] + #[Group('failed')] public function it_executes_successfully_with_valid_invoice(): void { $invoice = $this->createMockInvoice('sent'); diff --git a/Modules/Projects/Database/Factories/ProjectFactory.php b/Modules/Projects/Database/Factories/ProjectFactory.php index 00d887cee..0e81b036b 100644 --- a/Modules/Projects/Database/Factories/ProjectFactory.php +++ b/Modules/Projects/Database/Factories/ProjectFactory.php @@ -20,7 +20,10 @@ public function definition(): array ? $this->faker->optional(0.7)->dateTimeBetween($startDate, '+2 years') : null; + $companyId = $this->resolveCompanyId(); + return [ + 'customer_id' => $this->resolveForeignKey(\Modules\Clients\Models\Relation::class, $companyId), 'project_number' => $this->faker->unique()->numerify('PRJ-#####'), 'project_status' => $status->value, 'project_name' => $this->faker->sentence(), diff --git a/Modules/Quotes/Database/Factories/QuoteFactory.php b/Modules/Quotes/Database/Factories/QuoteFactory.php index 790276bd9..ac4b54ea3 100644 --- a/Modules/Quotes/Database/Factories/QuoteFactory.php +++ b/Modules/Quotes/Database/Factories/QuoteFactory.php @@ -27,7 +27,11 @@ public function definition(): array $quotedAt = fake()->dateTimeBetween('-1 year', 'now'); $expiresAt = (clone $quotedAt)->modify('+' . fake()->numberBetween(7, 180) . ' days'); + $companyId = $this->resolveCompanyId(); + return [ + 'prospect_id' => $this->resolveForeignKey(\Modules\Clients\Models\Relation::class, $companyId), + 'user_id' => $this->resolveForeignKey(\Modules\Core\Models\User::class, $companyId), 'quote_number' => 'Q-' . now()->year . '-' . fake()->unique()->numberBetween(1, 9999), 'quote_status' => fake()->randomElement(QuoteStatus::cases())->value, 'quoted_at' => $quotedAt,