diff --git a/Modules/Clients/Feature/Modules/ClientsExportImportTest.php b/Modules/Clients/Feature/Modules/ClientsExportImportTest.php index 0dfdaa99d..fe8276180 100644 --- a/Modules/Clients/Feature/Modules/ClientsExportImportTest.php +++ b/Modules/Clients/Feature/Modules/ClientsExportImportTest.php @@ -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; @@ -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'], @@ -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'], @@ -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'], @@ -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'], @@ -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'], @@ -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'], diff --git a/Modules/Clients/Tests/Feature/ContactsTest.php b/Modules/Clients/Tests/Feature/ContactsTest.php index 1a5c07ba1..09b0b1c38 100644 --- a/Modules/Clients/Tests/Feature/ContactsTest.php +++ b/Modules/Clients/Tests/Feature/ContactsTest.php @@ -18,8 +18,6 @@ #[CoversClass(ListContacts::class)] class ContactsTest extends AbstractCompanyPanelTestCase { - protected User $user; - #region smoke #[Test] #[Group('smoke')] @@ -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 = [ @@ -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 = [ @@ -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); @@ -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 = [ @@ -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 = [ @@ -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 = [ diff --git a/Modules/Clients/Tests/Feature/CustomersTest.php b/Modules/Clients/Tests/Feature/CustomersTest.php index 3177a4092..cb747a908 100644 --- a/Modules/Clients/Tests/Feature/CustomersTest.php +++ b/Modules/Clients/Tests/Feature/CustomersTest.php @@ -20,8 +20,6 @@ #[CoversClass(ListRelations::class)] class CustomersTest extends AbstractCompanyPanelTestCase { - protected User $user; - #region smoke #[Test] #[Group('smoke')] @@ -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(); @@ -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 = [ @@ -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, ]); @@ -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, ]); diff --git a/Modules/Core/Filament/Admin/Resources/Numberings/Pages/EditNumbering.php b/Modules/Core/Filament/Admin/Resources/Numberings/Pages/EditNumbering.php index 43ef590bc..6861638be 100644 --- a/Modules/Core/Filament/Admin/Resources/Numberings/Pages/EditNumbering.php +++ b/Modules/Core/Filament/Admin/Resources/Numberings/Pages/EditNumbering.php @@ -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); } diff --git a/Modules/Core/Filament/Admin/Resources/Numberings/Schemas/NumberingForm.php b/Modules/Core/Filament/Admin/Resources/Numberings/Schemas/NumberingForm.php index 1f9828cbe..84c59eb67 100644 --- a/Modules/Core/Filament/Admin/Resources/Numberings/Schemas/NumberingForm.php +++ b/Modules/Core/Filament/Admin/Resources/Numberings/Schemas/NumberingForm.php @@ -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() diff --git a/Modules/Core/Filament/Company/Resources/Numberings/Schemas/NumberingForm.php b/Modules/Core/Filament/Company/Resources/Numberings/Schemas/NumberingForm.php index e271d7601..72308a0d4 100644 --- a/Modules/Core/Filament/Company/Resources/Numberings/Schemas/NumberingForm.php +++ b/Modules/Core/Filament/Company/Resources/Numberings/Schemas/NumberingForm.php @@ -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 diff --git a/Modules/Core/Models/Company.php b/Modules/Core/Models/Company.php index 2b4f1169d..b4159370c 100644 --- a/Modules/Core/Models/Company.php +++ b/Modules/Core/Models/Company.php @@ -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; @@ -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) { diff --git a/Modules/Core/Tests/AbstractCompanyPanelTestCase.php b/Modules/Core/Tests/AbstractCompanyPanelTestCase.php index dfef9d82e..d40f4a8a8 100644 --- a/Modules/Core/Tests/AbstractCompanyPanelTestCase.php +++ b/Modules/Core/Tests/AbstractCompanyPanelTestCase.php @@ -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. diff --git a/Modules/Expenses/Tests/Feature/ExpenseCategoriesTest.php b/Modules/Expenses/Tests/Feature/ExpenseCategoriesTest.php index a6f6c5bc3..946ef9144 100644 --- a/Modules/Expenses/Tests/Feature/ExpenseCategoriesTest.php +++ b/Modules/Expenses/Tests/Feature/ExpenseCategoriesTest.php @@ -18,8 +18,6 @@ #[CoversClass(ListExpenseCategories::class)] class ExpenseCategoriesTest extends AbstractCompanyPanelTestCase { - protected User $user; - # region smoke #[Test] #[Group('smoke')] @@ -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(); @@ -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 */ @@ -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 */ @@ -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) @@ -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 */ diff --git a/Modules/Expenses/Tests/Feature/ExpensesTest.php b/Modules/Expenses/Tests/Feature/ExpensesTest.php index 7a992054f..3b30075e1 100644 --- a/Modules/Expenses/Tests/Feature/ExpensesTest.php +++ b/Modules/Expenses/Tests/Feature/ExpensesTest.php @@ -28,8 +28,6 @@ #[CoversClass(ListExpenses::class)] class ExpensesTest extends AbstractCompanyPanelTestCase { - protected User $user; - # region smoke #[Test] #[Group('smoke')] @@ -40,8 +38,8 @@ class ExpensesTest extends AbstractCompanyPanelTestCase public function it_lists_expenses(): void { /* arrange */ - $category = ExpenseCategory::factory()->for($this->user->companies()->first())->create(); - $customer = Relation::factory()->for($this->user->companies()->first())->customer()->create(); + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); $payload = [ 'expense_amount' => 550.00, @@ -52,11 +50,11 @@ public function it_lists_expenses(): void 'expense_status' => ExpenseStatus::APPROVED, ]; - Expense::factory()->for($this->user->companies()->first())->create($payload); + Expense::factory()->for($this->company)->create($payload); /* act */ $component = Livewire::actingAs($this->user) - ->test(ListExpenses::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]); + ->test(ListExpenses::class, ['tenant' => Str::lower($this->company->search_code)]); /* assert */ $component->assertSuccessful(); @@ -71,13 +69,12 @@ public function it_lists_expenses(): void public function it_creates_an_expense_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $category = ExpenseCategory::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $category = ExpenseCategory::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -123,13 +120,12 @@ public function it_creates_an_expense_through_a_modal(): void public function it_fails_to_create_expense_through_a_modal_without_required_expense_number(): void { /* arrange */ - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -173,13 +169,12 @@ public function it_fails_to_create_expense_through_a_modal_without_required_expe public function it_fails_to_create_expense_through_a_modal_without_required_expensed_at(): void { /* arrange */ - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -223,13 +218,12 @@ public function it_fails_to_create_expense_through_a_modal_without_required_expe public function it_fails_to_create_expense_through_a_modal_without_required_amount(): void { /* arrange */ - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -273,13 +267,12 @@ public function it_fails_to_create_expense_through_a_modal_without_required_amou public function it_fails_to_create_expense_through_a_modal_without_required_category_id(): void { /* arrange */ - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -323,13 +316,12 @@ public function it_fails_to_create_expense_through_a_modal_without_required_cate public function it_fails_to_create_expense_through_a_modal_without_required_customer(): void { /* arrange */ - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -373,13 +365,12 @@ public function it_fails_to_create_expense_through_a_modal_without_required_cust public function it_fails_to_create_expense_through_a_modal_without_required_type(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $category = ExpenseCategory::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $category = ExpenseCategory::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -424,13 +415,12 @@ public function it_fails_to_create_expense_through_a_modal_without_required_type public function it_fails_to_create_expense_through_a_modal_without_required_status(): void { /* arrange */ - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -474,11 +464,10 @@ public function it_fails_to_create_expense_through_a_modal_without_required_stat public function it_updates_an_expense_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $category = ExpenseCategory::factory()->for($company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $category = ExpenseCategory::factory()->for($this->company)->create(); - $expense = Expense::factory()->for($this->user->companies()->first())->create([ + $expense = Expense::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'category_id' => $category->id, 'expense_type' => ExpenseType::FIXED->value, @@ -513,13 +502,12 @@ public function it_updates_an_expense_through_a_modal(): void public function it_creates_an_expense(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $category = ExpenseCategory::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $category = ExpenseCategory::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -561,13 +549,12 @@ public function it_creates_an_expense(): void #[Group('crud')] public function it_fails_to_create_without_required_expense_number(): void { - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -608,13 +595,12 @@ public function it_fails_to_create_without_required_expense_number(): void #[Group('crud')] public function it_fails_to_create_expense_without_required_expensed_at(): void { - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -655,13 +641,12 @@ public function it_fails_to_create_expense_without_required_expensed_at(): void #[Group('crud')] public function it_fails_to_create_expense_without_required_amount(): void { - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -702,13 +687,12 @@ public function it_fails_to_create_expense_without_required_amount(): void #[Group('crud')] public function it_fails_to_create_expense_without_required_category_id(): void { - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -749,13 +733,12 @@ public function it_fails_to_create_expense_without_required_category_id(): void #[Group('crud')] public function it_fails_to_create_expense_without_required_customer_id(): void { - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -796,13 +779,12 @@ public function it_fails_to_create_expense_without_required_customer_id(): void #[Group('crud')] public function it_fails_to_create_expense_without_required_expense_type(): void { - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -843,13 +825,12 @@ public function it_fails_to_create_expense_without_required_expense_type(): void #[Group('crud')] public function it_fails_to_create_expense_without_required_expense_status(): void { - $company = $this->user->companies()->first(); - $category = ExpenseCategory::factory()->for($company)->create(); - $customer = Relation::factory()->for($company)->customer()->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $category = ExpenseCategory::factory()->for($this->company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -891,11 +872,10 @@ public function it_fails_to_create_expense_without_required_expense_status(): vo public function it_updates_an_expense(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $category = ExpenseCategory::factory()->for($company)->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); + $category = ExpenseCategory::factory()->for($this->company)->create(); - $expense = Expense::factory()->for($this->user->companies()->first())->create([ + $expense = Expense::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'category_id' => $category->id, 'expense_type' => ExpenseType::FIXED->value, @@ -927,8 +907,7 @@ public function it_updates_an_expense(): void public function it_deletes_an_expense(): void { /* arrange */ - $company = $this->user->companies()->first(); - $expense = Expense::factory()->for($company)->create(); + $expense = Expense::factory()->for($this->company)->create(); /* act */ $component = Livewire::actingAs($this->user) @@ -947,7 +926,7 @@ public function it_fails_to_delete_expense_twice(): void $this->markTestIncomplete('record to deleteAction cannot be null'); /* arrange */ - $expense = Expense::factory()->for($this->user->companies()->first())->create(); + $expense = Expense::factory()->for($this->company)->create(); $expense->delete(); /* act */ diff --git a/Modules/Invoices/Tests/Feature/InvoicesTest.php b/Modules/Invoices/Tests/Feature/InvoicesTest.php index c2d9bd8bb..4be2b5b8d 100644 --- a/Modules/Invoices/Tests/Feature/InvoicesTest.php +++ b/Modules/Invoices/Tests/Feature/InvoicesTest.php @@ -27,8 +27,6 @@ #[CoversClass(ListInvoices::class)] class InvoicesTest extends AbstractCompanyPanelTestCase { - protected User $user; - # region smoke #[Test] #[Group('smoke')] @@ -38,14 +36,13 @@ class InvoicesTest extends AbstractCompanyPanelTestCase public function it_lists_invoices(): void { /* arrange */ - $company = $this->user->companies()->first(); $user = $this->user; - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -70,12 +67,12 @@ public function it_lists_invoices(): void ]; Invoice::factory() - ->for($company) + ->for($this->company) ->create($payload); /* act */ $component = Livewire::actingAs($this->user) - ->test(ListInvoices::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]); + ->test(ListInvoices::class, ['tenant' => Str::lower($this->company->search_code)]); /* assert */ $component->assertSuccessful(); @@ -88,13 +85,12 @@ public function it_lists_invoices(): void public function it_creates_an_invoice_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -136,13 +132,12 @@ public function it_creates_an_invoice_through_a_modal(): void public function it_fails_to_create_invoice_through_a_modal_without_required_invoice_number(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -182,13 +177,12 @@ public function it_fails_to_create_invoice_through_a_modal_without_required_invo public function it_fails_to_create_invoice_through_a_modal_without_required_invoice_status(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -226,13 +220,12 @@ public function it_fails_to_create_invoice_through_a_modal_without_required_invo public function it_fails_to_create_invoice_through_a_modal_without_required_customer(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -272,20 +265,19 @@ public function it_fails_to_create_invoice_through_a_modal_without_required_cust public function it_updates_an_invoice_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, 'tax_rate_2_id' => null, ]); - $invoice = Invoice::factory()->for($this->user->companies()->first())->create([ + $invoice = Invoice::factory()->for($this->company)->create([ 'invoice_number' => 'INV-987654', 'customer_id' => $customer->getKey(), 'numbering_id' => $documentGroup->getKey(), @@ -323,13 +315,12 @@ public function it_updates_an_invoice_through_a_modal(): void #[Group('crud')] public function it_creates_an_invoice_with_items(): void { - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -372,14 +363,13 @@ public function it_creates_an_invoice_with_items(): void public function it_fails_to_create_invoice_without_required_invoice_number(): void { /* arrange */ - $company = $this->user->companies()->first(); $user = $this->user; - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -417,14 +407,13 @@ public function it_fails_to_create_invoice_without_required_invoice_number(): vo public function it_fails_to_create_invoice_without_required_invoice_status(): void { /* arrange */ - $company = $this->user->companies()->first(); $user = $this->user; - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -460,14 +449,13 @@ public function it_fails_to_create_invoice_without_required_invoice_status(): vo public function it_fails_to_create_invoice_without_required_customer(): void { /* arrange */ - $company = $this->user->companies()->first(); $user = $this->user; - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -505,20 +493,19 @@ public function it_fails_to_create_invoice_without_required_customer(): void public function it_updates_an_invoice(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, 'tax_rate_2_id' => null, ]); - $invoice = Invoice::factory()->for($this->user->companies()->first())->create([ + $invoice = Invoice::factory()->for($this->company)->create([ 'invoice_number' => 'INV-987654', 'customer_id' => $customer->getKey(), 'numbering_id' => $documentGroup->getKey(), @@ -555,7 +542,7 @@ public function it_updates_invoice_and_updates_total(): void /* arrange */ - $invoice = Invoice::factory()->for($this->user->companies()->first())->create([ + $invoice = Invoice::factory()->for($this->company)->create([ 'subtotal' => 100, 'tax' => 20, 'discount' => 0, @@ -584,14 +571,13 @@ public function it_updates_invoice_and_updates_total(): void public function it_deletes_an_invoice(): void { /* arrange */ - $company = $this->user->companies()->first(); $user = $this->user; - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -616,7 +602,7 @@ public function it_deletes_an_invoice(): void ]; $invoice = Invoice::factory() - ->for($company) + ->for($this->company) ->create($payload); /* act */ @@ -641,14 +627,13 @@ public function it_fails_to_delete_paid_invoice(): void $this->markTestIncomplete('Still can delete paid invoice'); /* arrange */ - $company = $this->user->companies()->first(); $user = $this->user; - $customer = Relation::factory()->for($company)->customer()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->customer()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -673,7 +658,7 @@ public function it_fails_to_delete_paid_invoice(): void ]; $invoice = Invoice::factory() - ->for($company) + ->for($this->company) ->create($payload); $payment = Payment::factory()->for($this->company)->create([ @@ -698,7 +683,7 @@ public function it_fails_to_delete_invoice_that_was_already_deleted(): void $this->markTestIncomplete('record to deleteAction cannot be null'); /* arrange */ - $invoice = Invoice::factory()->for($this->user->companies()->first())->create(); + $invoice = Invoice::factory()->for($this->company)->create(); $invoice->delete(); /* act */ diff --git a/Modules/Payments/Tests/Feature/PaymentsTest.php b/Modules/Payments/Tests/Feature/PaymentsTest.php index ef780ee11..9d97de8b5 100644 --- a/Modules/Payments/Tests/Feature/PaymentsTest.php +++ b/Modules/Payments/Tests/Feature/PaymentsTest.php @@ -24,17 +24,14 @@ #[CoversClass(ListPayments::class)] class PaymentsTest extends AbstractCompanyPanelTestCase { - protected User $user; - # region smoke #[Test] #[Group('smoke')] public function it_lists_payments(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -47,11 +44,11 @@ public function it_lists_payments(): void 'paid_at' => '2024-11-01', ]; - Payment::factory()->for($company)->create($payload); + Payment::factory()->for($this->company)->create($payload); /* act */ $component = Livewire::actingAs($this->user) - ->test(ListPayments::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]); + ->test(ListPayments::class, ['tenant' => Str::lower($this->company->search_code)]); /*if (app()->runningUnitTests()) { dump($payload); @@ -80,9 +77,8 @@ public function it_lists_payments(): void public function it_creates_a_payment_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->customer()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->customer()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -132,12 +128,7 @@ public function it_creates_a_payment_through_a_modal(): void public function it_fails_to_create_payment_through_a_modal_without_required_invoice_id(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ - 'customer_id' => $customer->id, - 'user_id' => $this->user->id, - ]); + $customer = Relation::factory()->for($this->company)->create(); $payload = [ 'customer_id' => $customer->id, @@ -178,9 +169,8 @@ public function it_fails_to_create_payment_through_a_modal_without_required_invo public function it_fails_to_create_payment_through_a_modal_without_required_payment_method(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($this->user->companies()->first())->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -223,9 +213,8 @@ public function it_fails_to_create_payment_through_a_modal_without_required_paym public function it_fails_to_create_payment_through_a_modal_without_required_payment_status(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -272,9 +261,8 @@ public function it_fails_to_create_payment_through_a_modal_without_required_paym public function it_fails_to_create_payment_through_a_modal_without_required_paid_at(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -317,9 +305,8 @@ public function it_fails_to_create_payment_through_a_modal_without_required_paid public function it_fails_to_create_payment_through_a_modal_without_required_amount(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -349,15 +336,14 @@ public function it_fails_to_create_payment_through_a_modal_without_required_amou public function it_updates_a_payment_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->customer()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->customer()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); $payment = Payment::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->create([ 'invoice_id' => $invoice->id, 'customer_id' => $customer->id, @@ -405,9 +391,8 @@ public function it_updates_a_payment_through_a_modal(): void public function it_creates_a_payment(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->customer()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->customer()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -456,12 +441,7 @@ public function it_creates_a_payment(): void public function it_fails_to_create_payment_without_required_invoice_id(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ - 'customer_id' => $customer->id, - 'user_id' => $this->user->id, - ]); + $customer = Relation::factory()->for($this->company)->create(); $payload = [ 'customer_id' => $customer->id, @@ -501,9 +481,8 @@ public function it_fails_to_create_payment_without_required_invoice_id(): void public function it_fails_to_create_payment_without_required_payment_method(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -545,9 +524,8 @@ public function it_fails_to_create_payment_without_required_payment_method(): vo public function it_fails_to_create_payment_without_required_payment_status(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -593,9 +571,8 @@ public function it_fails_to_create_payment_without_required_payment_status(): vo public function it_fails_to_create_payment_without_required_paid_at(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -637,9 +614,8 @@ public function it_fails_to_create_payment_without_required_paid_at(): void public function it_fails_to_create_payment_without_required_amount(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); @@ -668,15 +644,14 @@ public function it_fails_to_create_payment_without_required_amount(): void public function it_updates_a_payment(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->customer()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->customer()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); $payment = Payment::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->create([ 'invoice_id' => $invoice->id, 'customer_id' => $customer->id, @@ -708,15 +683,14 @@ public function it_updates_a_payment(): void public function it_deletes_a_payment(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->customer()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->customer()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); $payment = Payment::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->for($invoice) ->create([ 'customer_id' => $customer->id, @@ -744,16 +718,15 @@ public function it_fails_to_delete_if_invoice_is_paid(): void $this->markTestIncomplete('Still can delete payment if invoice is paid'); /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->customer()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->customer()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, 'invoice_status' => InvoiceStatus::PAID->value, ]); $payment = Payment::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->for($invoice) ->create([ 'customer_id' => $customer->id, @@ -783,15 +756,14 @@ public function it_fails_to_delete_already_deleted_payment(): void $this->markTestIncomplete('record for delete action cannot be null'); /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->customer()->for($company)->create(); - $invoice = Invoice::factory()->for($company)->create([ + $customer = Relation::factory()->customer()->for($this->company)->create(); + $invoice = Invoice::factory()->for($this->company)->create([ 'customer_id' => $customer->id, 'user_id' => $this->user->id, ]); $payment = Payment::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->for($invoice) ->create([ 'customer_id' => $customer->id, diff --git a/Modules/Products/Tests/Feature/ProductCategoriesTest.php b/Modules/Products/Tests/Feature/ProductCategoriesTest.php index fd30b556b..7dc907ee6 100644 --- a/Modules/Products/Tests/Feature/ProductCategoriesTest.php +++ b/Modules/Products/Tests/Feature/ProductCategoriesTest.php @@ -31,12 +31,12 @@ public function it_lists_product_categories(): void ]; $record = ProductCategory::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->create($payload); /* act */ $component = Livewire::actingAs($this->user) - ->test(ListProductCategories::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]); + ->test(ListProductCategories::class, ['tenant' => Str::lower($this->company->search_code)]); /* assert */ $component->assertSuccessful() @@ -67,7 +67,7 @@ public function it_creates_a_product_category_through_a_modal(): void /* assert */ $component->assertSuccessful(); $this->assertDatabaseHas('product_categories', array_merge( - ['company_id' => $this->user->companies()->first()->id], + ['company_id' => $this->company->id], $payload )); } @@ -105,9 +105,8 @@ public function it_fails_to_create_product_category_through_a_modal_without_requ public function it_updates_a_product_category_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); $productCategory = ProductCategory::factory() - ->for($company) + ->for($this->company) ->create(['category_name' => 'Old Cat']); $payload = ['category_name' => 'Updated Category']; @@ -195,7 +194,7 @@ public function it_fails_to_create_product_category_without_required_category_na public function it_updates_a_product_category(): void { /* arrange */ - $record = ProductCategory::factory()->for($this->user->companies()->first())->create(['category_name' => 'Old Cat']); + $record = ProductCategory::factory()->for($this->company)->create(['category_name' => 'Old Cat']); $payload = ['category_name' => 'Updated Category']; /* act */ @@ -218,9 +217,8 @@ public function it_updates_a_product_category(): void public function it_deletes_a_product_category(): void { /* arrange */ - $company = $this->user->companies()->first(); $productCategory = ProductCategory::factory() - ->for($company) + ->for($this->company) ->create(['category_name' => 'Category to Delete']); /* act */ @@ -241,7 +239,7 @@ public function it_fails_to_delete_already_deleted_category(): void $this->markTestIncomplete('record to deleteAction cannot be null'); /* arrange */ - $productCategory = ProductCategory::factory()->for($this->user->companies()->first())->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); $productCategory->delete(); /* act */ diff --git a/Modules/Products/Tests/Feature/ProductUnitsTest.php b/Modules/Products/Tests/Feature/ProductUnitsTest.php index dc42a14db..befd84751 100644 --- a/Modules/Products/Tests/Feature/ProductUnitsTest.php +++ b/Modules/Products/Tests/Feature/ProductUnitsTest.php @@ -19,8 +19,6 @@ #[CoversClass(ProductUnitResource::class)] class ProductUnitsTest extends AbstractCompanyPanelTestCase { - protected User $user; - # region smoke #[Test] #[Group('smoke')] @@ -29,12 +27,12 @@ public function it_lists_product_units(): void /* arrange */ $payload = ['unit_name' => 'Box']; $record = ProductUnit::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->create($payload); /* act */ $component = Livewire::actingAs($this->user) - ->test(ListProductUnits::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]); + ->test(ListProductUnits::class, ['tenant' => Str::lower($this->company->search_code)]); /* assert */ $component->assertSuccessful() @@ -101,7 +99,7 @@ public function it_updates_a_product_unit_through_a_modal(): void { /* arrange */ $productUnit = ProductUnit::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->create(['unit_name' => 'Old Unit', 'unit_name_plrl' => 'kgs']); $payload = [ @@ -128,9 +126,9 @@ public function it_fails_to_update_product_unit_through_a_modal_without_required { $this->markTestIncomplete(); /* arrange */ - $record = ProductUnit::factory()->for($this->user->companies()->first())->create(['unit_name' => 'X']); + $record = ProductUnit::factory()->for($this->company)->create(['unit_name' => 'X']); - $tenant = Str::lower($this->user->companies()->first()->search_code); + $tenant = Str::lower($this->company->search_code); $payload = ['unit_name' => null]; /* act */ @@ -211,7 +209,7 @@ public function it_fails_to_create_product_unit_without_required_unit_name(): vo public function it_updates_a_product_unit(): void { /* arrange */ - $record = ProductUnit::factory()->for($this->user->companies()->first())->create(['unit_name' => 'Old Unit']); + $record = ProductUnit::factory()->for($this->company)->create(['unit_name' => 'Old Unit']); $payload = ['unit_name' => 'Updated Unit']; /* act */ @@ -235,7 +233,7 @@ public function it_deletes_a_product_unit(): void { /* arrange */ $productUnit = ProductUnit::factory() - ->for($this->user->companies()->first()) + ->for($this->company) ->create(); /* act */ @@ -256,7 +254,7 @@ public function it_fails_to_delete_product_unit_twice(): void $this->markTestIncomplete('record to deleteAction cannot be null'); /* arrange */ - $productUnit = ProductUnit::factory()->for($this->user->companies()->first())->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); $productUnit->delete(); /* act */ diff --git a/Modules/Products/Tests/Feature/ProductsTest.php b/Modules/Products/Tests/Feature/ProductsTest.php index 80340805f..9af619ca8 100644 --- a/Modules/Products/Tests/Feature/ProductsTest.php +++ b/Modules/Products/Tests/Feature/ProductsTest.php @@ -24,8 +24,6 @@ #[CoversClass(ProductResource::class)] class ProductsTest extends AbstractCompanyPanelTestCase { - protected User $user; - # region smoke #[Test] #[Group('smoke')] @@ -59,7 +57,7 @@ public function it_lists_products(): void /* act */ $component = Livewire::actingAs($this->user) - ->test(ListProducts::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]); + ->test(ListProducts::class, ['tenant' => Str::lower($this->company->search_code)]); /* assert */ $component diff --git a/Modules/Projects/Tests/Feature/ProjectsTest.php b/Modules/Projects/Tests/Feature/ProjectsTest.php index adc3f6d47..e495fb6a9 100644 --- a/Modules/Projects/Tests/Feature/ProjectsTest.php +++ b/Modules/Projects/Tests/Feature/ProjectsTest.php @@ -25,11 +25,10 @@ class ProjectsTest extends AbstractCompanyPanelTestCase public function it_lists_projects(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(['company_name' => 'Test Client']); + $customer = Relation::factory()->for($this->company)->create(['company_name' => 'Test Client']); $payload = [ - 'company_id' => $company->id, + 'company_id' => $this->company->id, 'customer_id' => $customer->id, 'project_status' => ProjectStatus::ACTIVE->value, 'project_name' => 'Test Project', @@ -38,11 +37,11 @@ public function it_lists_projects(): void 'description' => 'Test Description', ]; - $project = Project::factory()->for($company)->create($payload); + $project = Project::factory()->for($this->company)->create($payload); /* act */ $component = Livewire::actingAs($this->user) - ->test(ListProjects::class, ['tenant' => Str::lower($company->search_code)]); + ->test(ListProjects::class, ['tenant' => Str::lower($this->company->search_code)]); /* assert */ $component->assertSuccessful(); @@ -67,8 +66,7 @@ public function it_lists_projects(): void */ public function it_creates_a_project_through_a_modal(): void { - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(['company_name' => 'Test Client']); + $customer = Relation::factory()->for($this->company)->create(['company_name' => 'Test Client']); /* arrange */ $payload = [ @@ -91,7 +89,7 @@ public function it_creates_a_project_through_a_modal(): void /* assert */ $component->assertSuccessful(); $this->assertDatabaseHas('projects', array_merge( - ['company_id' => $company->id], + ['company_id' => $this->company->id], $payload )); } @@ -112,11 +110,10 @@ public function it_creates_a_project_through_a_modal(): void public function it_fails_to_create_project_through_a_modal_without_required_status(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->create(['company_name' => '::client_name::']); + $customer = Relation::factory()->for($this->company)->create(['company_name' => '::client_name::']); $payload = [ - 'company_id' => $company->id, + 'company_id' => $this->company->id, 'customer_id' => $customer->id, 'project_name' => 'Website Redesign', 'start_at' => '2025-05-01', @@ -152,9 +149,8 @@ public function it_fails_to_create_project_through_a_modal_without_required_stat */ public function it_fails_to_create_project_through_a_modal_without_required_project_name(): void { - $company = $this->user->companies()->first(); $customer = Relation::factory() - ->for($company, 'company') + ->for($this->company, 'company') ->create(['company_name' => '::client_name::']); $payload = [ @@ -223,9 +219,8 @@ public function it_fails_to_create_project_through_a_modal_without_required_star public function it_updates_a_project_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(['company_name' => 'Test Client']); - $project = Project::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(['company_name' => 'Test Client']); + $project = Project::factory()->for($this->company)->create([ 'project_name' => 'Old Project Name', 'customer_id' => $customer->id, 'project_status' => ProjectStatus::ACTIVE->value, @@ -270,8 +265,7 @@ public function it_updates_a_project_through_a_modal(): void */ public function it_creates_a_project(): void { - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(['company_name' => 'Test Client']); + $customer = Relation::factory()->for($this->company)->create(['company_name' => 'Test Client']); /* arrange */ $payload = [ @@ -312,13 +306,12 @@ public function it_creates_a_project(): void public function it_fails_to_create_project_without_required_status(): void { /* arrange */ - $company = $this->user->companies()->first(); $customer = Relation::factory() - ->for($company) + ->for($this->company) ->create(['company_name' => '::company_name::']); $payload = [ - 'company_id' => $company->id, + 'company_id' => $this->company->id, 'customer_id' => $customer->id, 'project_name' => 'Website Redesign', 'start_at' => '2025-05-01', @@ -355,11 +348,10 @@ public function it_fails_to_create_project_without_required_status(): void */ public function it_fails_to_create_project_without_required_project_name(): void { - $company = $this->user->companies()->first(); - $customer = Relation::factory()->create(['company_name' => '::company_name::']); + $customer = Relation::factory()->for($this->company)->create(['company_name' => '::company_name::']); $payload = [ - 'company_id' => $company->id, + 'company_id' => $this->company->id, 'customer_id' => $customer->id, 'project_status' => 'active', 'start_at' => '2025-05-01', @@ -459,9 +451,8 @@ public function it_updates_a_project(): void #[Group('crud')] public function it_deletes_a_project(): void { - $company = $this->user->companies()->first(); - $customer = Relation::factory()->for($company)->create(['company_name' => 'Test Client']); - $project = Project::factory()->for($company)->create([ + $customer = Relation::factory()->for($this->company)->create(['company_name' => 'Test Client']); + $project = Project::factory()->for($this->company)->create([ 'project_name' => 'Project to Delete', 'customer_id' => $customer->id, 'project_status' => ProjectStatus::ACTIVE->value, diff --git a/Modules/Projects/Tests/Feature/TasksTest.php b/Modules/Projects/Tests/Feature/TasksTest.php index 5bbfd32e6..bb9a1dc7d 100644 --- a/Modules/Projects/Tests/Feature/TasksTest.php +++ b/Modules/Projects/Tests/Feature/TasksTest.php @@ -28,11 +28,10 @@ class TasksTest extends AbstractCompanyPanelTestCase public function it_lists_tasks(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Customer::factory()->for($company)->create(['company_name' => '::customer_name::']); + $customer = Customer::factory()->for($this->company)->create(['company_name' => '::customer_name::']); $project = Project::factory() ->for($customer, 'customer') - ->for($company) + ->for($this->company) ->create([ 'project_name' => '::project_name::', ]); @@ -58,7 +57,7 @@ public function it_lists_tasks(): void /* act */ $component = Livewire::actingAs($this->user) - ->test(ListTasks::class, ['tenant' => Str::lower($this->user->companies()->first()->search_code)]); + ->test(ListTasks::class, ['tenant' => Str::lower($this->company->search_code)]); /* assert */ $component @@ -90,11 +89,10 @@ public function it_lists_tasks(): void public function it_creates_a_task_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Customer::factory()->for($company)->create(['company_name' => '::customer_name::']); + $customer = Customer::factory()->for($this->company)->create(['company_name' => '::customer_name::']); $project = Project::factory() ->for($customer, 'customer') - ->for($company) + ->for($this->company) ->create([ 'project_name' => '::project_name::', ]); @@ -149,11 +147,10 @@ public function it_creates_a_task_through_a_modal(): void public function it_fails_to_create_task_through_a_modal_without_required_task_name(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Customer::factory()->for($company)->create(['company_name' => '::customer_name::']); + $customer = Customer::factory()->for($this->company)->create(['company_name' => '::customer_name::']); $project = Project::factory() ->for($customer, 'customer') - ->for($company) + ->for($this->company) ->create([ 'project_name' => '::project_name::', ]); @@ -201,10 +198,9 @@ public function it_fails_to_create_task_through_a_modal_without_required_task_na public function it_fails_to_create_task_through_a_modal_without_required_project(): void { /* arrange */ - $company = $this->user->companies()->first(); $taxRate = TaxRate::factory() - ->for($company) + ->for($this->company) ->create(['name' => '::taxrate_name::']); $payload = [ @@ -248,11 +244,10 @@ public function it_fails_to_create_task_through_a_modal_without_required_project public function it_fails_to_create_task_through_a_modal_without_required_tax_rate(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Customer::factory()->for($company)->create(['company_name' => '::customer_name::']); + $customer = Customer::factory()->for($this->company)->create(['company_name' => '::customer_name::']); $project = Project::factory() ->for($customer, 'customer') - ->for($company) + ->for($this->company) ->create([ 'project_name' => '::project_name::', ]); @@ -301,11 +296,10 @@ public function it_fails_to_create_task_through_a_modal_without_required_tax_rat public function it_updates_a_task_through_a_modal(): void { /* arrange */ - $company = $this->user->companies()->first(); - $customer = Customer::factory()->for($company)->create(['company_name' => '::customer_name::']); + $customer = Customer::factory()->for($this->company)->create(['company_name' => '::customer_name::']); $project = Project::factory() ->for($customer, 'customer') - ->for($company) + ->for($this->company) ->create([ 'project_name' => '::project_name::', ]); @@ -470,14 +464,13 @@ public function it_fails_to_create_task_without_required_name(): void public function it_fails_to_create_task_without_required_project(): void { /* arrange */ - $company = $this->user->companies()->first(); $taxRate = TaxRate::factory() - ->for($company) + ->for($this->company) ->create(['name' => '::taxrate_name::']); $payload = [ - 'company_id' => $company->id, + 'company_id' => $this->company->id, // 'project_id' intentionally omitted 'tax_rate_id' => $taxRate->id, 'assigned_to' => $this->user->id, diff --git a/Modules/Quotes/Tests/Feature/QuotesTest.php b/Modules/Quotes/Tests/Feature/QuotesTest.php index ee79a71e7..3727e9069 100644 --- a/Modules/Quotes/Tests/Feature/QuotesTest.php +++ b/Modules/Quotes/Tests/Feature/QuotesTest.php @@ -27,8 +27,6 @@ #[CoversClass(ListQuotes::class)] class QuotesTest extends AbstractCompanyPanelTestCase { - protected User $user; - # region smoke #[Test] #[Group('smoke')] @@ -40,10 +38,10 @@ public function it_lists_quotes(): void /* arrange */ $company = $this->company; $user = $this->user; - $prospect = Relation::factory()->for($company)->prospect()->create(); + $prospect = Relation::factory()->for($this->company)->prospect()->create(); $quote = Quote::factory() - ->for($company) + ->for($this->company) ->create([ 'quote_number' => 'Q-0001', 'prospect_id' => $prospect->id, @@ -68,14 +66,13 @@ public function it_lists_quotes(): void #[Group('crud')] public function it_creates_a_quote_through_a_modal(): void { - $company = $this->user->companies()->first(); - $prospect = Relation::factory()->for($company)->prospect()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $prospect = Relation::factory()->for($this->company)->prospect()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -134,13 +131,12 @@ public function it_creates_a_quote_through_a_modal(): void public function it_fails_to_create_a_quote_through_a_modal_without_required_prospect(): void { /* arrange */ - $company = $this->user->companies()->first(); - $documentGroup = Numbering::factory()->for($company)->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -301,14 +297,13 @@ public function it_fails_to_create_quote_through_a_modal_without_required_quote_ $this->markTestIncomplete('revisit quote_item_subtotal'); /* arrange */ - $company = $this->user->companies()->first(); - $prospect = Relation::factory()->for($company)->prospect()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $prospect = Relation::factory()->for($this->company)->prospect()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -499,14 +494,13 @@ public function it_updates_a_quote_through_a_modal(): void */ public function it_creates_a_quote(): void { - $company = $this->user->companies()->first(); - $prospect = Relation::factory()->for($company)->prospect()->create(); - $documentGroup = Numbering::factory()->for($company)->create(); - - $taxRate = TaxRate::factory()->for($company)->create(); - $productCategory = ProductCategory::factory()->for($company)->create(); - $productUnit = ProductUnit::factory()->for($company)->create(); - $product = Product::factory()->for($company)->create([ + $prospect = Relation::factory()->for($this->company)->prospect()->create(); + $documentGroup = Numbering::factory()->for($this->company)->create(); + + $taxRate = TaxRate::factory()->for($this->company)->create(); + $productCategory = ProductCategory::factory()->for($this->company)->create(); + $productUnit = ProductUnit::factory()->for($this->company)->create(); + $product = Product::factory()->for($this->company)->create([ 'category_id' => $productCategory->id, 'unit_id' => $productUnit->id, 'tax_rate_id' => $taxRate->id, @@ -603,7 +597,7 @@ public function it_fails_to_create_quote_without_required_prospect(): void public function it_fails_to_create_quote_without_required_quote_number(): void { /* arrange */ - $prospect = Relation::factory()->for($this->user->companies()->first())->create(['relation_type' => 'prospect']); + $prospect = Relation::factory()->for($this->company)->create(['relation_type' => 'prospect']); $payload = [ 'prospect_id' => $prospect->id, @@ -640,7 +634,7 @@ public function it_fails_to_create_quote_without_required_quote_number(): void public function it_fails_to_create_quote_without_required_quote_status(): void { /* arrange */ - $prospect = Relation::factory()->for($this->user->companies()->first())->create(['relation_type' => 'prospect']); + $prospect = Relation::factory()->for($this->company)->create(['relation_type' => 'prospect']); $payload = [ 'prospect_id' => $prospect->id, @@ -679,7 +673,7 @@ public function it_fails_to_create_quote_without_required_quote_discount_percent $this->markTestIncomplete('quote_discount_percent missing, even though it is set'); /* arrange */ - $prospect = Relation::factory()->for($this->user->companies()->first())->create(['relation_type' => 'prospect']); + $prospect = Relation::factory()->for($this->company)->create(['relation_type' => 'prospect']); $payload = [ 'prospect_id' => $prospect->id, @@ -719,7 +713,7 @@ public function it_fails_to_create_quote_without_required_quote_item_subtotal(): $this->markTestIncomplete('revisit quote_item_subtotal'); /* arrange */ - $prospect = Relation::factory()->for($this->user->companies()->first())->create(['relation_type' => 'prospect']); + $prospect = Relation::factory()->for($this->company)->create(['relation_type' => 'prospect']); $payload = [ 'prospect_id' => $prospect->id, @@ -758,7 +752,7 @@ public function it_fails_to_create_quote_without_required_quote_tax_total(): voi $this->markTestIncomplete('revisit quote_tax_total'); /* arrange */ - $prospect = Relation::factory()->for($this->user->companies()->first())->create(['relation_type' => 'prospect']); + $prospect = Relation::factory()->for($this->company)->create(['relation_type' => 'prospect']); $payload = [ 'prospect_id' => $prospect->id, @@ -798,7 +792,7 @@ public function it_fails_to_create_quote_without_required_quote_total(): void $this->markTestIncomplete('revisit quote_total'); /* arrange */ - $prospect = Relation::factory()->for($this->user->companies()->first())->create(['relation_type' => 'prospect']); + $prospect = Relation::factory()->for($this->company)->create(['relation_type' => 'prospect']); $payload = [ 'prospect_id' => $prospect->id, @@ -827,10 +821,10 @@ public function it_deletes_a_quote(): void /* arrange */ $company = $this->company; $user = $this->user; - $prospect = Relation::factory()->for($company)->prospect()->create(); + $prospect = Relation::factory()->for($this->company)->prospect()->create(); $quote = Quote::factory() - ->for($company) + ->for($this->company) ->create([ 'quote_number' => 'Q-0001', 'prospect_id' => $prospect->id, @@ -857,10 +851,10 @@ public function it_fails_to_delete_approved_quote(): void /* arrange */ $company = $this->company; $user = $this->user; - $prospect = Relation::factory()->for($company)->prospect()->create(); + $prospect = Relation::factory()->for($this->company)->prospect()->create(); $quote = Quote::factory() - ->for($company) + ->for($this->company) ->create([ 'quote_number' => 'Q-0001', 'prospect_id' => $prospect->id, @@ -888,7 +882,7 @@ public function it_fails_to_delete_if_linked_paid_invoice(): void /* arrange */ $company = $this->company; $user = $this->user; - $customer = Relation::factory()->for($company)->customer()->create(); + $customer = Relation::factory()->for($this->company)->customer()->create(); $invoice = Invoice::factory() ->for($this->company) @@ -899,7 +893,7 @@ public function it_fails_to_delete_if_linked_paid_invoice(): void ]); $quote = Quote::factory() - ->for($company) + ->for($this->company) ->create([ 'quote_number' => 'Q-0001', 'prospect_id' => $customer->id, @@ -927,10 +921,10 @@ public function it_fails_to_delete_quote_that_was_already_deleted(): void /* arrange */ $company = $this->company; $user = $this->user; - $prospect = Relation::factory()->for($company)->prospect()->create(); + $prospect = Relation::factory()->for($this->company)->prospect()->create(); $quote = Quote::factory() - ->for($company) + ->for($this->company) ->create([ 'quote_number' => 'Q-0001', 'prospect_id' => $prospect->id, diff --git a/Modules/ReportBuilder/Tests/Feature/CreateReportTemplateTest.php b/Modules/ReportBuilder/Tests/Feature/CreateReportTemplateTest.php index c580dcb56..e894ee7c3 100644 --- a/Modules/ReportBuilder/Tests/Feature/CreateReportTemplateTest.php +++ b/Modules/ReportBuilder/Tests/Feature/CreateReportTemplateTest.php @@ -218,7 +218,7 @@ public function it_respects_company_tenancy(): void protected function createCompanyContext(): Company { - $company = Company::factory()->createOne(); + $company = Company::factory()->create(); $user = User::factory()->create(); $user->companies()->attach($company); session(['current_company_id' => $company->id]);