diff --git a/Modules/Clients/Database/Factories/RelationFactory.php b/Modules/Clients/Database/Factories/RelationFactory.php index a92622aec..304523c3a 100644 --- a/Modules/Clients/Database/Factories/RelationFactory.php +++ b/Modules/Clients/Database/Factories/RelationFactory.php @@ -21,9 +21,6 @@ class RelationFactory extends AbstractFactory public function definition(): array { $companyId = $this->resolveCompanyId(); - if ( ! $companyId) { - $companyId = \Modules\Core\Models\Company::factory()->create()->id; - } $companyName = $this->faker->company; $suffix = $this->faker->optional(0.7)->companySuffix(); $tradingName = $companyName . ($suffix ? " {$suffix}" : ''); @@ -36,7 +33,7 @@ public function definition(): array ]); return [ - 'company_id' => $companyId, + 'company_id' => $companyId ?? \Modules\Core\Models\Company::factory(), 'primary_contact_id' => null, // Set to null or a valid Contact ID if needed 'relation_type' => $relationType, 'relation_status' => $this->faker->randomElement(RelationStatus::cases())->value, diff --git a/Modules/Clients/Tests/Feature/CustomersTest.php b/Modules/Clients/Tests/Feature/CustomersTest.php index 79ee2d130..d7a6ce1ea 100644 --- a/Modules/Clients/Tests/Feature/CustomersTest.php +++ b/Modules/Clients/Tests/Feature/CustomersTest.php @@ -455,6 +455,7 @@ public function it_only_lists_customers_for_the_current_tenant(): void $component->assertSeeText('Visible Customer'); $this->assertDatabaseHas('relations', ['id' => $customerB->id]); $component->assertDontSeeText('Hidden Customer'); + } # endregion # region spicy diff --git a/Modules/Core/Database/Factories/AbstractFactory.php b/Modules/Core/Database/Factories/AbstractFactory.php index 348fab1fd..b2c38e52c 100644 --- a/Modules/Core/Database/Factories/AbstractFactory.php +++ b/Modules/Core/Database/Factories/AbstractFactory.php @@ -23,11 +23,13 @@ protected function resolveCompany(array $attributes = []): ?Company protected function resolveForeignKey($relatedClass, $companyId = null) { - if (app()->runningUnitTests()) { + if (app()->runningUnitTests() && $companyId !== null) { return $relatedClass::query()->where('company_id', $companyId) ->inRandomOrder() ->first()?->id ?? $relatedClass::factory(); } + + return $relatedClass::factory(); } } diff --git a/Modules/Core/Database/Factories/EmailTemplateFactory.php b/Modules/Core/Database/Factories/EmailTemplateFactory.php index 9133859be..678c2e572 100644 --- a/Modules/Core/Database/Factories/EmailTemplateFactory.php +++ b/Modules/Core/Database/Factories/EmailTemplateFactory.php @@ -13,10 +13,9 @@ class EmailTemplateFactory extends AbstractFactory public function definition(): array { $companyId = $this->resolveCompanyId(); - $company = $this->resolveCompany(); return [ - 'company_id' => $company->id, + 'company_id' => $companyId ?? Company::factory(), 'title' => $this->faker->sentence(), 'type' => $this->faker->randomElement(EmailTemplateType::cases())->value, 'subject' => $this->faker->word, diff --git a/Modules/Invoices/Tests/Unit/Peppol/FormatHandlers/FormatHandlersTest.php b/Modules/Invoices/Tests/Unit/Peppol/FormatHandlers/FormatHandlersTest.php index c30460337..9e2268efa 100644 --- a/Modules/Invoices/Tests/Unit/Peppol/FormatHandlers/FormatHandlersTest.php +++ b/Modules/Invoices/Tests/Unit/Peppol/FormatHandlers/FormatHandlersTest.php @@ -41,7 +41,7 @@ public function it_returns_correct_format($handlerClass, $expectedFormat): void #[Test] #[Group('still_failing')] #[DataProvider('handlerProvider')] - public function it_returns_correct_mime_type($handlerClass): void + public function it_returns_correct_mime_type($handlerClass, $format = null): void { $handler = new $handlerClass(); $mimeType = $handler->getMimeType(); @@ -52,7 +52,7 @@ public function it_returns_correct_mime_type($handlerClass): void #[Test] #[Group('still_failing')] #[DataProvider('handlerProvider')] - public function it_returns_correct_file_extension($handlerClass): void + public function it_returns_correct_file_extension($handlerClass, $format = null): void { $handler = new $handlerClass(); $extension = $handler->getFileExtension(); @@ -63,7 +63,7 @@ public function it_returns_correct_file_extension($handlerClass): void #[Test] #[Group('still_failing')] #[DataProvider('handlerProvider')] - public function it_transforms_invoice_correctly($handlerClass): void + public function it_transforms_invoice_correctly($handlerClass, $format = null): void { $handler = new $handlerClass(); $invoice = $this->createMockInvoice(); @@ -77,7 +77,7 @@ public function it_transforms_invoice_correctly($handlerClass): void #[Test] #[Group('still_failing')] #[DataProvider('handlerProvider')] - public function it_validates_basic_invoice_fields($handlerClass): void + public function it_validates_basic_invoice_fields($handlerClass, $format = null): void { $handler = new $handlerClass(); $invoice = $this->createMockInvoice(); @@ -91,7 +91,7 @@ public function it_validates_basic_invoice_fields($handlerClass): void #[Test] #[Group('still_failing')] #[DataProvider('handlerProvider')] - public function it_validates_missing_customer($handlerClass): void + public function it_validates_missing_customer($handlerClass, $format = null): void { $handler = new $handlerClass(); $invoice = new Invoice(); @@ -112,7 +112,7 @@ public function it_validates_missing_customer($handlerClass): void #[Test] #[Group('still_failing')] #[DataProvider('handlerProvider')] - public function it_validates_missing_invoice_number($handlerClass): void + public function it_validates_missing_invoice_number($handlerClass, $format = null): void { $handler = new $handlerClass(); $invoice = $this->createMockInvoice(); @@ -127,7 +127,7 @@ public function it_validates_missing_invoice_number($handlerClass): void #[Test] #[Group('still_failing')] #[DataProvider('handlerProvider')] - public function it_validates_missing_items($handlerClass): void + public function it_validates_missing_items($handlerClass, $format = null): void { $handler = new $handlerClass(); $invoice = $this->createMockInvoice(); @@ -142,7 +142,7 @@ public function it_validates_missing_items($handlerClass): void #[Test] #[Group('still_failing')] #[DataProvider('handlerProvider')] - public function it_generates_xml($handlerClass): void + public function it_generates_xml($handlerClass, $format = null): void { $handler = new $handlerClass(); $invoice = $this->createMockInvoice(); diff --git a/Modules/Invoices/module.json b/Modules/Invoices/module.json new file mode 100644 index 000000000..73538dece --- /dev/null +++ b/Modules/Invoices/module.json @@ -0,0 +1,11 @@ +{ + "name": "Invoices", + "alias": "invoices", + "description": "", + "keywords": [], + "priority": 0, + "providers": [ + "Modules\\Invoices\\Providers\\InvoicesServiceProvider" + ], + "files": [] +} diff --git a/Modules/Projects/Tests/Feature/ProjectsTest.php b/Modules/Projects/Tests/Feature/ProjectsTest.php index e3190d3c1..863e832bd 100644 --- a/Modules/Projects/Tests/Feature/ProjectsTest.php +++ b/Modules/Projects/Tests/Feature/ProjectsTest.php @@ -396,51 +396,6 @@ public function it_fails_to_create_project_without_required_project_name(): void $this->assertDatabaseMissing('projects', $payload); } - #[Test] - #[Group('crud')] - /** - * @payload missing: project_name - * { - * "company_id": 1, - * "customer_id": 2, - * "project_status": "active", - * "project_name": "Website Redesign", - * "start_at": "2025-05-01", - * "end_at": "2025-06-01", - * "description": "Redesigning the corporate website" - * } - */ - public function it_fails_to_create_project_without_required_project_name(): void - { - $this->markTestIncomplete(); - - $company = $this->user->companies()->first(); - $customer = Relation::factory()->create(['client_name' => '::client_name::']); - - /* arrange */ - $payload = [ - 'company_id' => $company->id, - 'customer_id' => 2, - 'project_status' => 'active', - 'start_at' => '2025-05-01', - 'end_at' => '2025-06-01', - 'description' => 'Redesigning the corporate website', - ]; - - $component = Livewire::actingAs($this->user) - ->test(CreateProject::class) - ->fillForm($payload) - ->call('create'); - - $component - ->assertHasFormErrors(['project_name' => 'required']); - - $this->assertDatabaseMissing('projects', [ - 'customer_id' => $customer->id, - 'project_name' => 'Website Redesign', - ]); - } - /** * @payload missing: starts_at * { @@ -471,44 +426,6 @@ public function it_fails_to_create_project_without_required_starts_at(): void $component->assertHasFormErrors(['starts_at']); } - #[Test] - #[Group('crud')] - /** - * @payload - * { - * "project_name": "Updated Project Name" - * } - */ - public function it_updates_a_project(): void - { - $this->markTestIncomplete(); - - /* arrange */ - - $this->markTestSkipped('Not implemented yet'); - // $this->authenticate(); - $client = Relation::factory()->create(['client_name' => '::client_name::']); - - $project = Project::factory()->create([ - 'client_id' => $client->client_id, - 'project_name' => '::project_name::', - ]); - - $updatedData = [ - 'project_name' => '::updated_project_name::', - ]; - - /* act */ - $component = Livewire::actingAs($this->user)->test(EditProject::class, ['record' => $project->project_id])->set('data.project_name', $updatedData['project_name'])->call('save'); - - /* assert */ - $component->assertSuccessful()->assertHasNoErrors(); - - $this->assertDatabaseHas('projects', array_merge($updatedData, [ - 'project_id' => $project->project_id, - ])); - } - #[Test] #[Group('crud')] /**