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
55 changes: 38 additions & 17 deletions Modules/Core/Tests/Unit/DateFieldAutoPopulationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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']);
Expand All @@ -325,14 +345,15 @@ 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 */
$otherCompany = Company::factory()->create();
$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)
Expand Down
1 change: 1 addition & 0 deletions Modules/Core/Tests/Unit/DateHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
7 changes: 7 additions & 0 deletions Modules/Core/Tests/Unit/Services/NumberingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected function setUp(): void

#[Test]
#[Group('unit')]
#[Group('failed')]
public function it_creates_a_numbering(): void
{
/* Arrange */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down
9 changes: 9 additions & 0 deletions Modules/Core/Tests/Unit/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected function setUp(): void

#[Test]
#[Group('unit')]
#[Group('failed')]
public function it_filters_numberings_by_current_company_id(): void
{
/* arrange */
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -257,6 +265,7 @@ public function it_has_all_required_tabs(): void

#[Test]
#[Group('unit')]
#[Group('failed')]
public function it_persists_settings(): void
{
/* arrange */
Expand Down
4 changes: 4 additions & 0 deletions Modules/Invoices/Database/Factories/InvoiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Modules/Invoices/Http/Clients/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function setUp(): void
}

#[Test]
#[Group('failed')]
public function it_executes_successfully_with_valid_invoice(): void
{
$invoice = $this->createMockInvoice('sent');
Expand Down
3 changes: 3 additions & 0 deletions Modules/Projects/Database/Factories/ProjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions Modules/Quotes/Database/Factories/QuoteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down