Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Modules/Clients/Database/Factories/RelationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}" : '');
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions Modules/Clients/Tests/Feature/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Modules/Core/Database/Factories/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
3 changes: 1 addition & 2 deletions Modules/Core/Database/Factories/EmailTemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions Modules/Invoices/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Invoices",
"alias": "invoices",
"description": "",
"keywords": [],
"priority": 0,
"providers": [
"Modules\\Invoices\\Providers\\InvoicesServiceProvider"
],
"files": []
}
83 changes: 0 additions & 83 deletions Modules/Projects/Tests/Feature/ProjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
* {
Expand Down Expand Up @@ -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')]
/**
Expand Down
Loading