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
26 changes: 13 additions & 13 deletions Modules/Clients/Feature/Modules/ClientsExportImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Modules\Clients\Filament\Company\Resources\Clients\Pages\ListClients;
use Modules\Clients\Models\Client;
use Modules\Clients\Filament\Company\Resources\Relations\Pages\ListRelations;
use Modules\Clients\Models\Relation;
use Modules\Core\Tests\AbstractCompanyPanelTestCase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
Expand All @@ -25,11 +25,11 @@ public function it_dispatches_csv_export_job_v2(): void
/* Arrange */
Queue::fake();
Storage::fake('local');
$clients = Client::factory()->for($this->company)->count(3)->create();
$relations = Relation::factory()->for($this->company)->count(3)->create();

/* Act */
Livewire::actingAs($this->user)
->test(ListClients::class)
->test(ListRelations::class)
->callAction('exportCsvV2', data: [
'columnMap' => [
'company_name' => ['isEnabled' => true, 'label' => 'Company Name'],
Expand All @@ -52,11 +52,11 @@ public function it_dispatches_excel_export_job_v2(): void
/* Arrange */
Queue::fake();
Storage::fake('local');
$clients = Client::factory()->for($this->company)->count(3)->create();
$relations = Relation::factory()->for($this->company)->count(3)->create();

/* Act */
Livewire::actingAs($this->user)
->test(ListClients::class)
->test(ListRelations::class)
->callAction('exportExcelV2', data: [
'columnMap' => [
'company_name' => ['isEnabled' => true, 'label' => 'Company Name'],
Expand All @@ -83,7 +83,7 @@ public function it_exports_with_no_records(): void

/* Act */
Livewire::actingAs($this->user)
->test(ListClients::class)
->test(ListRelations::class)
->callAction('exportExcelV2', data: [
'columnMap' => [
'company_name' => ['isEnabled' => true, 'label' => 'Company Name'],
Expand All @@ -105,13 +105,13 @@ public function it_exports_with_special_characters(): void
/* Arrange */
Queue::fake();
Storage::fake('local');
$client = Client::factory()->for($this->company)->create([
$relation = Relation::factory()->for($this->company)->create([
'company_name' => 'ÜClient, "Test"',
]);

/* Act */
Livewire::actingAs($this->user)
->test(ListClients::class)
->test(ListRelations::class)
->callAction('exportExcelV2', data: [
'columnMap' => [
'company_name' => ['isEnabled' => true, 'label' => 'Company Name'],
Expand All @@ -133,11 +133,11 @@ public function it_dispatches_csv_export_job_v1(): void
/* Arrange */
Queue::fake();
Storage::fake('local');
$clients = Client::factory()->for($this->company)->count(3)->create();
$relations = Relation::factory()->for($this->company)->count(3)->create();

/* Act */
Livewire::actingAs($this->user)
->test(ListClients::class)
->test(ListRelations::class)
->callAction('exportCsvV1', data: [
'columnMap' => [
'company_name' => ['isEnabled' => true, 'label' => 'Company Name'],
Expand All @@ -159,11 +159,11 @@ public function it_dispatches_excel_export_job_v1(): void
/* Arrange */
Queue::fake();
Storage::fake('local');
$clients = Client::factory()->for($this->company)->count(3)->create();
$relations = Relation::factory()->for($this->company)->count(3)->create();

/* Act */
Livewire::actingAs($this->user)
->test(ListClients::class)
->test(ListRelations::class)
->callAction('exportExcelV1', data: [
'columnMap' => [
'company_name' => ['isEnabled' => true, 'label' => 'Company Name'],
Expand Down
14 changes: 6 additions & 8 deletions Modules/Clients/Tests/Feature/ContactsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#[CoversClass(ListContacts::class)]
class ContactsTest extends AbstractCompanyPanelTestCase
{
protected User $user;

#region smoke
#[Test]
#[Group('smoke')]
Expand Down Expand Up @@ -134,7 +132,7 @@ public function it_fails_through_a_modal_without_required_first_name(): void
{
/* arrange */
$relation = Relation::factory()
->for($this->user->companies()->first(), 'company')
->for($this->company, 'company')
->create();

$payload = [
Expand Down Expand Up @@ -165,7 +163,7 @@ public function it_fails_through_a_modal_without_required_last_name(): void
{
/* arrange */
$relation = Relation::factory()
->for($this->user->companies()->first(), 'company')
->for($this->company, 'company')
->create();

$payload = [
Expand Down Expand Up @@ -205,7 +203,7 @@ public function it_updates_a_contact_through_a_modal(): void
];

$contact = Contact::factory()
->for($this->user->companies()->first())
->for($this->company)
->for($relation)
->create($payload);

Expand Down Expand Up @@ -237,7 +235,7 @@ public function it_creates_a_contact(): void
{
/* arrange */
$relation = Relation::factory()
->for($this->user->companies()->first(), 'company')
->for($this->company, 'company')
->create();

$payload = [
Expand Down Expand Up @@ -289,7 +287,7 @@ public function it_fails_to_create_without_required_first_name(): void
{
/* arrange */
$relation = Relation::factory()
->for($this->user->companies()->first(), 'company')
->for($this->company, 'company')
->create();

$payload = [
Expand All @@ -314,7 +312,7 @@ public function it_fails_to_create_without_required_last_name(): void
{
/* arrange */
$relation = Relation::factory()
->for($this->user->companies()->first(), 'company')
->for($this->company, 'company')
->create();

$payload = [
Expand Down
12 changes: 5 additions & 7 deletions Modules/Clients/Tests/Feature/CustomersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#[CoversClass(ListRelations::class)]
class CustomersTest extends AbstractCompanyPanelTestCase
{
protected User $user;

#region smoke
#[Test]
#[Group('smoke')]
Expand All @@ -40,11 +38,11 @@ public function it_lists_customers(): void
'registered_at' => Carbon::parse('2025-01-01')->toDateString(),
];

$customer = Relation::factory()->for($this->user->companies()->first())->create($payload);
$customer = Relation::factory()->for($this->company)->create($payload);

/* act */
$component = Livewire::actingAs($this->user)
->test(ListRelations::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]);
->test(ListRelations::class, ['tenant' => Str::lower($this->company->search_code)]);

/* assert */
$component->assertSuccessful();
Expand Down Expand Up @@ -223,7 +221,7 @@ public function it_updates_a_customer_through_a_modal(): void
];

$customer = Relation::factory()
->for($this->user->companies()->first())
->for($this->company)
->create($original);

$updatedData = [
Expand Down Expand Up @@ -377,7 +375,7 @@ public function it_deletes_a_customer(): void
$this->markTestIncomplete('foreign key contact');

/* arrange */
$customer = Relation::factory()->for($this->user->companies()->first())->create([
$customer = Relation::factory()->for($this->company)->create([
'company_name' => 'Delete Me',
'relation_type' => RelationType::CUSTOMER,
]);
Expand All @@ -398,7 +396,7 @@ public function it_fails_to_delete_customer_when_contact_attached(): void
$this->markTestIncomplete();

/* arrange */
$customer = Relation::factory()->for($this->user->companies()->first())->create([
$customer = Relation::factory()->for($this->company)->create([
'company_name' => 'Delete Me',
'relation_type' => RelationType::CUSTOMER,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function getHeaderActions(): array
/**
* @throws Throwable
*/
protected function handleRecordUpdate(Numbering|Model $record, array $data): mixed
protected function handleRecordUpdate(Numbering|Model $record, array $data): Numbering
{
return app(NumberingService::class)->updateNumbering($record, $data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static function configure(Schema $schema): Schema
Select::make('type')
->label(trans('ip.numbering_type'))
->options(array_combine(
array_map(fn ($case) => $case->value, NumberingType::cases()),
array_map(fn ($case) => $case->label(), NumberingType::cases())
array_map(fn (NumberingType $case): string => $case->value, NumberingType::cases()),
array_map(fn (NumberingType $case): string => $case->label(), NumberingType::cases())
))
->required()
->reactive()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static function configure(Schema $schema): Schema
Select::make('type')
->label(trans('ip.numbering_type'))
->options(array_combine(
array_map(fn ($case) => $case->value, NumberingType::cases()),
array_map(fn ($case) => $case->label(), NumberingType::cases())
array_map(fn (NumberingType $case): string => $case->value, NumberingType::cases()),
array_map(fn (NumberingType $case): string => $case->label(), NumberingType::cases())
))
->required()
->disabled() // Company users cannot change type
Expand Down
3 changes: 2 additions & 1 deletion Modules/Core/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Filament\Models\Contracts\HasCurrentTenantLabel;
use Filament\Models\Contracts\HasName;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -89,7 +90,7 @@ class Company extends Model implements HasName, HasCurrentTenantLabel
| Relationships
|--------------------------------------------------------------------------
*/
public function customerAdmins(): BelongsToMany
public function customerAdmins(): Builder
{
return $this->users()
->whereHas('roles', function ($query) {
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Tests/AbstractCompanyPanelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function setUp(): void
'slug' => 'invoiceplane-corporation',
])->create();

$this->company = Company::query()->where('search_code', 'IVPLV2')->first();
$this->company = Company::query()->where('search_code', 'IVPLV2')->firstOrFail();

/*
* quietly set tenant so it won't wine about user not being set yet.
Expand Down
14 changes: 6 additions & 8 deletions Modules/Expenses/Tests/Feature/ExpenseCategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#[CoversClass(ListExpenseCategories::class)]
class ExpenseCategoriesTest extends AbstractCompanyPanelTestCase
{
protected User $user;

# region smoke
#[Test]
#[Group('smoke')]
Expand All @@ -35,12 +33,12 @@ public function it_lists_expense_categories(): void
];

$record = ExpenseCategory::factory()
->for($this->user->companies()->first())
->for($this->company)
->create($payload);

/* act */
$component = Livewire::actingAs($this->user)
->test(ListExpenseCategories::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]);
->test(ListExpenseCategories::class, ['tenant' => Str::lower($this->company->search_code)]);

/* assert */
$component->assertSuccessful();
Expand Down Expand Up @@ -109,7 +107,7 @@ public function it_fails_to_create_category_through_a_modal_without_required_cat
public function it_updates_an_expense_category_through_a_modal(): void
{
/* arrange */
$record = ExpenseCategory::factory()->for($this->user->companies()->first())->create(['category_name' => 'Original']);
$record = ExpenseCategory::factory()->for($this->company)->create(['category_name' => 'Original']);
$payload = ['category_name' => 'Updated Name'];

/* act */
Expand Down Expand Up @@ -187,7 +185,7 @@ public function it_fails_to_create_category_without_required_category_name(): vo
public function it_updates_an_expense_category(): void
{
/* arrange */
$record = ExpenseCategory::factory()->for($this->user->companies()->first())->create(['category_name' => 'Original']);
$record = ExpenseCategory::factory()->for($this->company)->create(['category_name' => 'Original']);
$payload = ['category_name' => 'Updated Name'];

/* act */
Expand All @@ -210,7 +208,7 @@ public function it_updates_an_expense_category(): void
public function it_deletes_an_expense_category(): void
{
/* arrange */
$expenseCategory = ExpenseCategory::factory()->for($this->user->companies()->first())->create();
$expenseCategory = ExpenseCategory::factory()->for($this->company)->create();

/* act */
$component = Livewire::actingAs($this->user)
Expand All @@ -229,7 +227,7 @@ public function it_fails_to_delete_already_deleted_category(): void
$this->markTestIncomplete('record to deleteAction cannot be null');

/* arrange */
$expenseCategory = ExpenseCategory::factory()->for($this->user->companies()->first())->create();
$expenseCategory = ExpenseCategory::factory()->for($this->company)->create();
$expenseCategory->delete();

/* act */
Expand Down
Loading