From 863c0a8b609d9c407bf7ed038bcb7db0e40dd4df Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 11:43:02 -0700 Subject: [PATCH 1/9] Fix import_type for accessory state --- database/factories/ImportFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/factories/ImportFactory.php b/database/factories/ImportFactory.php index 4fafc9621..830c87fa7 100644 --- a/database/factories/ImportFactory.php +++ b/database/factories/ImportFactory.php @@ -41,7 +41,7 @@ class ImportFactory extends Factory $fileBuilder = Importing\AccessoriesImportFileBuilder::new(); $attributes['name'] = "{$attributes['name']} Accessories"; - $attributes['import_type'] = 'Accessories'; + $attributes['import_type'] = 'accessory'; $attributes['header_row'] = $fileBuilder->toCsv()[0]; $attributes['first_row'] = $fileBuilder->firstRow(); From b5ffe54bd07bd6a14216e993142e9086fbdee9e7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 13:15:02 -0700 Subject: [PATCH 2/9] Swap assertEquals parameter order --- .../Importing/Api/ImportAccessoriesTest.php | 84 ++++---- .../Importing/Api/ImportAssetsTest.php | 188 +++++++++--------- .../Importing/Api/ImportComponentsTest.php | 62 +++--- .../Importing/Api/ImportConsumablesTest.php | 54 ++--- .../Importing/Api/ImportLicenseTest.php | 106 +++++----- .../Feature/Importing/Api/ImportUsersTest.php | 120 +++++------ 6 files changed, 307 insertions(+), 307 deletions(-) diff --git a/tests/Feature/Importing/Api/ImportAccessoriesTest.php b/tests/Feature/Importing/Api/ImportAccessoriesTest.php index cf7597c31..27a80c0dd 100644 --- a/tests/Feature/Importing/Api/ImportAccessoriesTest.php +++ b/tests/Feature/Importing/Api/ImportAccessoriesTest.php @@ -81,23 +81,23 @@ class ImportAccessoriesTest extends ImportDataTestCase ->where('item_id', $newAccessory->id) ->sole(); - $this->assertEquals($activityLog->action_type, 'create'); - $this->assertEquals($activityLog->action_source, 'importer'); - $this->assertEquals($activityLog->company_id, $newAccessory->company->id); + $this->assertEquals('create', $activityLog->action_type); + $this->assertEquals('importer', $activityLog->action_source); + $this->assertEquals($newAccessory->company->id, $activityLog->company_id); - $this->assertEquals($newAccessory->name, $row['itemName']); - $this->assertEquals($newAccessory->qty, $row['quantity']); - $this->assertEquals($newAccessory->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($newAccessory->purchase_cost, $row['purchaseCost']); - $this->assertEquals($newAccessory->order_number, $row['orderNumber']); - $this->assertEquals($newAccessory->notes, $row['notes']); - $this->assertEquals($newAccessory->category->name, $row['category']); - $this->assertEquals($newAccessory->category->category_type, 'accessory'); - $this->assertEquals($newAccessory->manufacturer->name, $row['manufacturerName']); - $this->assertEquals($newAccessory->supplier->name, $row['supplierName']); - $this->assertEquals($newAccessory->location->name, $row['location']); - $this->assertEquals($newAccessory->company->name, $row['companyName']); - $this->assertEquals($newAccessory->model_number, $row['modelNumber']); + $this->assertEquals($row['itemName'], $newAccessory->name); + $this->assertEquals($row['quantity'], $newAccessory->qty); + $this->assertEquals($row['purchaseDate'], $newAccessory->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $newAccessory->purchase_cost); + $this->assertEquals($row['orderNumber'], $newAccessory->order_number); + $this->assertEquals($row['notes'], $newAccessory->notes); + $this->assertEquals($row['category'], $newAccessory->category->name); + $this->assertEquals('accessory', $newAccessory->category->category_type); + $this->assertEquals($row['manufacturerName'], $newAccessory->manufacturer->name); + $this->assertEquals($row['supplierName'], $newAccessory->supplier->name); + $this->assertEquals($row['location'], $newAccessory->location->name); + $this->assertEquals($row['companyName'], $newAccessory->company->name); + $this->assertEquals($row['modelNumber'], $newAccessory->model_number); $this->assertFalse($newAccessory->requestable); $this->assertNull($newAccessory->min_amt); $this->assertNull($newAccessory->user_id); @@ -131,7 +131,7 @@ class ImportAccessoriesTest extends ImportDataTestCase ->where('name', $importFileBuilder->firstRow()['itemName']) ->sole(['purchase_date']); - $this->assertEquals($accessory->purchase_date->toDateString(), '2022-10-10'); + $this->assertEquals('2022-10-10', $accessory->purchase_date->toDateString()); } #[Test] @@ -165,7 +165,7 @@ class ImportAccessoriesTest extends ImportDataTestCase ->get(['name']); $this->assertCount(1, $probablyNewAccessories); - $this->assertEquals($probablyNewAccessories->first()->name, $accessory->name); + $this->assertEquals($accessory->name, $probablyNewAccessories->first()->name); } #[Test] @@ -292,23 +292,23 @@ class ImportAccessoriesTest extends ImportDataTestCase 'location_id', 'model_number', 'updated_at' ]; - $this->assertEquals($updatedAccessory->name, $row['itemName']); + $this->assertEquals($row['itemName'], $updatedAccessory->name); $this->assertEquals($row['companyName'], $updatedAccessory->company->name); - $this->assertEquals($updatedAccessory->qty, $row['quantity']); - $this->assertEquals($updatedAccessory->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($updatedAccessory->purchase_cost, $row['purchaseCost']); - $this->assertEquals($updatedAccessory->order_number, $row['orderNumber']); - $this->assertEquals($updatedAccessory->notes, $row['notes']); - $this->assertEquals($updatedAccessory->category->name, $row['category']); - $this->assertEquals($updatedAccessory->category->category_type, 'accessory'); - $this->assertEquals($updatedAccessory->manufacturer->name, $row['manufacturerName']); - $this->assertEquals($updatedAccessory->supplier->name, $row['supplierName']); - $this->assertEquals($updatedAccessory->location->name, $row['location']); - $this->assertEquals($updatedAccessory->model_number, $row['modelNumber']); + $this->assertEquals($row['quantity'], $updatedAccessory->qty); + $this->assertEquals($row['purchaseDate'], $updatedAccessory->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $updatedAccessory->purchase_cost); + $this->assertEquals($row['orderNumber'], $updatedAccessory->order_number); + $this->assertEquals($row['notes'], $updatedAccessory->notes); + $this->assertEquals($row['category'], $updatedAccessory->category->name); + $this->assertEquals('accessory', $updatedAccessory->category->category_type); + $this->assertEquals($row['manufacturerName'], $updatedAccessory->manufacturer->name); + $this->assertEquals($row['supplierName'], $updatedAccessory->supplier->name); + $this->assertEquals($row['location'], $updatedAccessory->location->name); + $this->assertEquals($row['modelNumber'], $updatedAccessory->model_number); $this->assertEquals( - Arr::except($updatedAccessory->attributesToArray(), $updatedAttributes), Arr::except($accessory->attributesToArray(), $updatedAttributes), + Arr::except($updatedAccessory->attributesToArray(), $updatedAttributes), ); } @@ -362,7 +362,7 @@ class ImportAccessoriesTest extends ImportDataTestCase $updatedAccessory = clone $accessory; $updatedAccessory->refresh(); - $this->assertEquals($updatedAccessory->toArray(), $accessory->toArray()); + $this->assertEquals($accessory->toArray(), $updatedAccessory->toArray()); } #[Test] @@ -412,15 +412,15 @@ class ImportAccessoriesTest extends ImportDataTestCase ->where('name', $row['modelNumber']) ->sole(); - $this->assertEquals($newAccessory->name, $row['modelNumber']); - $this->assertEquals($newAccessory->model_number, $row['itemName']); - $this->assertEquals($newAccessory->qty, $row['quantity']); - $this->assertEquals($newAccessory->purchase_date->toDateString(), $row['notes']); - $this->assertEquals($newAccessory->purchase_cost, $row['location']); - $this->assertEquals($newAccessory->order_number, $row['companyName']); - $this->assertEquals($newAccessory->notes, $row['purchaseDate']); - $this->assertEquals($newAccessory->category->name, $row['manufacturerName']); - $this->assertEquals($newAccessory->manufacturer->name, $row['category']); - $this->assertEquals($newAccessory->location->name, $row['purchaseCost']); + $this->assertEquals($row['modelNumber'], $newAccessory->name); + $this->assertEquals($row['itemName'], $newAccessory->model_number); + $this->assertEquals($row['quantity'], $newAccessory->qty); + $this->assertEquals($row['notes'], $newAccessory->purchase_date->toDateString()); + $this->assertEquals($row['location'], $newAccessory->purchase_cost); + $this->assertEquals($row['companyName'], $newAccessory->order_number); + $this->assertEquals($row['purchaseDate'], $newAccessory->notes); + $this->assertEquals($row['manufacturerName'], $newAccessory->category->name); + $this->assertEquals($row['category'], $newAccessory->manufacturer->name); + $this->assertEquals($row['purchaseCost'], $newAccessory->location->name); } } diff --git a/tests/Feature/Importing/Api/ImportAssetsTest.php b/tests/Feature/Importing/Api/ImportAssetsTest.php index b7c6298d3..d4b6ac52e 100644 --- a/tests/Feature/Importing/Api/ImportAssetsTest.php +++ b/tests/Feature/Importing/Api/ImportAssetsTest.php @@ -89,60 +89,60 @@ class ImportAssetsTest extends ImportDataTestCase $this->assertCount(2, $activityLogs); - $this->assertEquals($activityLogs[0]->action_type, 'checkout'); - $this->assertEquals($activityLogs[0]->item_type, Asset::class); - $this->assertEquals($activityLogs[0]->target_id, $assignee->id); - $this->assertEquals($activityLogs[0]->target_type, User::class); - $this->assertEquals($activityLogs[0]->note, 'Checkout from CSV Importer'); + $this->assertEquals('checkout', $activityLogs[0]->action_type); + $this->assertEquals(Asset::class, $activityLogs[0]->item_type); + $this->assertEquals($assignee->id, $activityLogs[0]->target_id); + $this->assertEquals(User::class, $activityLogs[0]->target_type); + $this->assertEquals('Checkout from CSV Importer', $activityLogs[0]->note); - $this->assertEquals($activityLogs[1]->action_type, 'create'); + $this->assertEquals('create', $activityLogs[1]->action_type); $this->assertNull($activityLogs[1]->target_id); - $this->assertEquals($activityLogs[1]->item_type, Asset::class); + $this->assertEquals(Asset::class, $activityLogs[1]->item_type); $this->assertNull($activityLogs[1]->note); $this->assertNull($activityLogs[1]->target_type); - $this->assertEquals("{$assignee->first_name} {$assignee->last_name}", $row['assigneeFullName']); - $this->assertEquals($assignee->email, $row['assigneeEmail']); - $this->assertEquals($assignee->username, $row['assigneeUsername']); + $this->assertEquals($row['assigneeFullName'], "{$assignee->first_name} {$assignee->last_name}"); + $this->assertEquals($row['assigneeEmail'], $assignee->email); + $this->assertEquals($row['assigneeUsername'], $assignee->username); - $this->assertEquals($newAsset->model->category->name, $row['category']); - $this->assertEquals($newAsset->model->manufacturer->name, $row['manufacturerName']); - $this->assertEquals($newAsset->name, $row['itemName']); - $this->assertEquals($newAsset->asset_tag, $row['tag']); - $this->assertEquals($newAsset->model->name, $row['model']); - $this->assertEquals($newAsset->model->model_number, $row['modelNumber']); - $this->assertEquals($newAsset->purchase_date->toDateString(), $row['purchaseDate']); + $this->assertEquals($row['category'], $newAsset->model->category->name); + $this->assertEquals($row['manufacturerName'], $newAsset->model->manufacturer->name); + $this->assertEquals($row['itemName'], $newAsset->name); + $this->assertEquals($row['tag'], $newAsset->asset_tag); + $this->assertEquals($row['model'], $newAsset->model->name); + $this->assertEquals($row['modelNumber'], $newAsset->model->model_number); + $this->assertEquals($row['purchaseDate'], $newAsset->purchase_date->toDateString()); $this->assertNull($newAsset->asset_eol_date); $this->assertEquals(0, $newAsset->eol_explicit); $this->assertEquals($newAsset->location_id, $newAsset->rtd_location_id); - $this->assertEquals($newAsset->purchase_cost, $row['purchaseCost']); + $this->assertEquals($row['purchaseCost'], $newAsset->purchase_cost); $this->assertNull($newAsset->order_number); - $this->assertEquals($newAsset->image, ''); + $this->assertEquals('', $newAsset->image); $this->assertNull($newAsset->user_id); - $this->assertEquals($newAsset->physical, 1); - $this->assertEquals($newAsset->assetStatus->name, $row['status']); - $this->assertEquals($newAsset->archived, 0); - $this->assertEquals($newAsset->warranty_months, $row['warrantyInMonths']); + $this->assertEquals(1, $newAsset->physical); + $this->assertEquals($row['status'], $newAsset->assetStatus->name); + $this->assertEquals(0, $newAsset->archived); + $this->assertEquals($row['warrantyInMonths'], $newAsset->warranty_months); $this->assertNull($newAsset->deprecate); - $this->assertEquals($newAsset->supplier->name, $row['supplierName']); - $this->assertEquals($newAsset->requestable, 0); - $this->assertEquals($newAsset->defaultLoc->name, $row['location']); - $this->assertEquals($newAsset->accepted, null); - $this->assertEquals(Carbon::parse($newAsset->last_checkout)->toDateString(), now()->toDateString()); - $this->assertEquals($newAsset->last_checkin, 0); - $this->assertEquals($newAsset->expected_checkin, 0); - $this->assertEquals($newAsset->company->name, $row['companyName']); - $this->assertEquals($newAsset->assigned_type, User::class); + $this->assertEquals($row['supplierName'], $newAsset->supplier->name); + $this->assertEquals(0, $newAsset->requestable); + $this->assertEquals($row['location'], $newAsset->defaultLoc->name); + $this->assertEquals(null, $newAsset->accepted); + $this->assertEquals(now()->toDateString(), Carbon::parse($newAsset->last_checkout)->toDateString()); + $this->assertEquals(0, $newAsset->last_checkin); + $this->assertEquals(0, $newAsset->expected_checkin); + $this->assertEquals($row['companyName'], $newAsset->company->name); + $this->assertEquals(User::class, $newAsset->assigned_type); $this->assertNull($newAsset->last_audit_date); $this->assertNull($newAsset->next_audit_date); - $this->assertEquals($newAsset->location->name, $row['location']); - $this->assertEquals($newAsset->checkin_counter, 0); - $this->assertEquals($newAsset->checkout_counter, 1); - $this->assertEquals($newAsset->requests_counter, 0); - $this->assertEquals($newAsset->byod, 0); + $this->assertEquals($row['location'], $newAsset->location->name); + $this->assertEquals(0, $newAsset->checkin_counter); + $this->assertEquals(1, $newAsset->checkout_counter); + $this->assertEquals(0, $newAsset->requests_counter); + $this->assertEquals(0, $newAsset->byod); //Notes is never read. - //$this->assertEquals($asset->notes, $row['notes']); + // $this->assertEquals($row['notes'], $newAsset->notes); Notification::assertSentTo($assignee, CheckoutAssetNotification::class); } @@ -309,7 +309,7 @@ class ImportAssetsTest extends ImportDataTestCase ->where('serial', $importFileBuilder->firstRow()['serialNumber']) ->sole(); - $this->assertEquals($newAsset->assetStatus->name, 'Ready to Deploy'); + $this->assertEquals('Ready to Deploy', $newAsset->assetStatus->name); $this->assertNull($newAsset->purchase_date); $this->assertNull($newAsset->purchase_cost); } @@ -331,8 +331,8 @@ class ImportAssetsTest extends ImportDataTestCase ->where('serial', $importFileBuilder->firstRow()['serialNumber']) ->sole(); - $this->assertEquals($newAsset->warranty_months, 3); - $this->assertEquals($newAsset->purchase_date->toDateString(), '2022-10-10'); + $this->assertEquals(3, $newAsset->warranty_months); + $this->assertEquals('2022-10-10', $newAsset->purchase_date->toDateString()); } #[Test] @@ -406,33 +406,33 @@ class ImportAssetsTest extends ImportDataTestCase 'last_checkout', 'requestable', 'updated_at', 'checkout_counter', 'assigned_type' ]; - $this->assertEquals("{$assignee->first_name} {$assignee->last_name}", $row['assigneeFullName']); - $this->assertEquals($assignee->email, $row['assigneeEmail']); - $this->assertEquals($assignee->username, $row['assigneeUsername']); + $this->assertEquals($row['assigneeFullName'], "{$assignee->first_name} {$assignee->last_name}"); + $this->assertEquals($row['assigneeEmail'], $assignee->email); + $this->assertEquals($row['assigneeUsername'], $assignee->username); - $this->assertEquals($updatedAsset->model->category->name, $row['category']); - $this->assertEquals($updatedAsset->model->manufacturer->name, $row['manufacturerName']); - $this->assertEquals($updatedAsset->name, $row['itemName']); - $this->assertEquals($updatedAsset->asset_tag, $row['tag']); - $this->assertEquals($updatedAsset->model->name, $row['model']); - $this->assertEquals($updatedAsset->model->model_number, $row['modelNumber']); - $this->assertEquals($updatedAsset->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($updatedAsset->purchase_cost, $row['purchaseCost']); - $this->assertEquals($updatedAsset->assetStatus->name, $row['status']); - $this->assertEquals($updatedAsset->warranty_months, $row['warrantyInMonths']); - $this->assertEquals($updatedAsset->supplier->name, $row['supplierName']); - $this->assertEquals($updatedAsset->defaultLoc->name, $row['location']); - $this->assertEquals($updatedAsset->company->name, $row['companyName']); - $this->assertEquals($updatedAsset->location->name, $row['location']); - $this->assertEquals($updatedAsset->checkout_counter, 1); - $this->assertEquals($updatedAsset->assigned_type, user::class); + $this->assertEquals($row['category'], $updatedAsset->model->category->name); + $this->assertEquals($row['manufacturerName'], $updatedAsset->model->manufacturer->name); + $this->assertEquals($row['itemName'], $updatedAsset->name); + $this->assertEquals($row['tag'], $updatedAsset->asset_tag); + $this->assertEquals($row['model'], $updatedAsset->model->name); + $this->assertEquals($row['modelNumber'], $updatedAsset->model->model_number); + $this->assertEquals($row['purchaseDate'], $updatedAsset->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $updatedAsset->purchase_cost); + $this->assertEquals($row['status'], $updatedAsset->assetStatus->name); + $this->assertEquals($row['warrantyInMonths'], $updatedAsset->warranty_months); + $this->assertEquals($row['supplierName'], $updatedAsset->supplier->name); + $this->assertEquals($row['location'], $updatedAsset->defaultLoc->name); + $this->assertEquals($row['companyName'], $updatedAsset->company->name); + $this->assertEquals($row['location'], $updatedAsset->location->name); + $this->assertEquals(1, $updatedAsset->checkout_counter); + $this->assertEquals(user::class, $updatedAsset->assigned_type); //RequestAble is always updated regardless of initial value. - //$this->assertEquals($updatedAsset->requestable, $asset->requestable); + // $this->assertEquals($asset->requestable, $updatedAsset->requestable); $this->assertEquals( - Arr::except($updatedAsset->attributesToArray(), $updatedAttributes), Arr::except($asset->attributesToArray(), $updatedAttributes), + Arr::except($updatedAsset->attributesToArray(), $updatedAttributes), ); } @@ -497,45 +497,45 @@ class ImportAssetsTest extends ImportDataTestCase $assignee = User::query()->find($asset->assigned_to, ['id', 'first_name', 'last_name', 'email', 'username']); - $this->assertEquals("{$assignee->first_name} {$assignee->last_name}", $row['warrantyInMonths']); - $this->assertEquals($assignee->email, $row['tag']); - $this->assertEquals($assignee->username, $row['location']); + $this->assertEquals($row['warrantyInMonths'], "{$assignee->first_name} {$assignee->last_name}"); + $this->assertEquals($row['tag'], $assignee->email); + $this->assertEquals($row['location'], $assignee->username); - $this->assertEquals($asset->model->category->name, $row['modelNumber']); - $this->assertEquals($asset->model->manufacturer->name, $row['assigneeEmail']); - $this->assertEquals($asset->name, $row['model']); - $this->assertEquals($asset->asset_tag, $row['serialNumber']); - $this->assertEquals($asset->model->name, $row['purchaseCost']); - $this->assertEquals($asset->model->model_number, $row['itemName']); - $this->assertEquals($asset->purchase_date->toDateString(), $row['supplierName']); - $this->assertEquals($asset->purchase_cost, $row['companyName']); - $this->assertEquals($asset->assetStatus->name, $row['manufacturerName']); - $this->assertEquals($asset->warranty_months, $row['status']); - $this->assertEquals($asset->supplier->name, $row['assigneeFullName']); - $this->assertEquals($asset->defaultLoc->name, $row['category']); - $this->assertEquals($asset->company->name, $row['purchaseDate']); - $this->assertEquals($asset->location->name, $row['category']); - $this->assertEquals($asset->notes, $row['notes']); + $this->assertEquals($row['modelNumber'], $asset->model->category->name); + $this->assertEquals($row['assigneeEmail'], $asset->model->manufacturer->name); + $this->assertEquals($row['model'], $asset->name); + $this->assertEquals($row['serialNumber'], $asset->asset_tag); + $this->assertEquals($row['purchaseCost'], $asset->model->name); + $this->assertEquals($row['itemName'], $asset->model->model_number); + $this->assertEquals($row['supplierName'], $asset->purchase_date->toDateString()); + $this->assertEquals($row['companyName'], $asset->purchase_cost); + $this->assertEquals($row['manufacturerName'], $asset->assetStatus->name); + $this->assertEquals($row['status'], $asset->warranty_months); + $this->assertEquals($row['assigneeFullName'], $asset->supplier->name); + $this->assertEquals($row['category'], $asset->defaultLoc->name); + $this->assertEquals($row['purchaseDate'], $asset->company->name); + $this->assertEquals($row['category'], $asset->location->name); + $this->assertEquals($row['notes'], $asset->notes); $this->assertNull($asset->asset_eol_date); $this->assertEquals(0, $asset->eol_explicit); $this->assertNull($asset->order_number); - $this->assertEquals($asset->image, ''); + $this->assertEquals('', $asset->image); $this->assertNull($asset->user_id); - $this->assertEquals($asset->physical, 1); - $this->assertEquals($asset->archived, 0); + $this->assertEquals(1, $asset->physical); + $this->assertEquals(0, $asset->archived); $this->assertNull($asset->deprecate); - $this->assertEquals($asset->requestable, 0); - $this->assertEquals($asset->accepted, null); - $this->assertEquals(Carbon::parse($asset->last_checkout)->toDateString(), now()->toDateString()); - $this->assertEquals($asset->last_checkin, 0); - $this->assertEquals($asset->expected_checkin, 0); - $this->assertEquals($asset->assigned_type, User::class); + $this->assertEquals(0, $asset->requestable); + $this->assertEquals(null, $asset->accepted); + $this->assertEquals(now()->toDateString(), Carbon::parse($asset->last_checkout)->toDateString()); + $this->assertEquals(0, $asset->last_checkin); + $this->assertEquals(0, $asset->expected_checkin); + $this->assertEquals(User::class, $asset->assigned_type); $this->assertNull($asset->last_audit_date); $this->assertNull($asset->next_audit_date); - $this->assertEquals($asset->checkin_counter, 0); - $this->assertEquals($asset->checkout_counter, 1); - $this->assertEquals($asset->requests_counter, 0); - $this->assertEquals($asset->byod, 0); + $this->assertEquals(0, $asset->checkin_counter); + $this->assertEquals(1, $asset->checkout_counter); + $this->assertEquals(0, $asset->requests_counter); + $this->assertEquals(0, $asset->byod); } #[Test] @@ -565,7 +565,7 @@ class ImportAssetsTest extends ImportDataTestCase $newAsset = Asset::query()->where('serial', $importFileBuilder->firstRow()['serialNumber'])->sole(); - $this->assertEquals($newAsset->getAttribute($customField->db_column), $macAddress); + $this->assertEquals($macAddress, $newAsset->getAttribute($customField->db_column)); } #[Test] diff --git a/tests/Feature/Importing/Api/ImportComponentsTest.php b/tests/Feature/Importing/Api/ImportComponentsTest.php index 56c40ba46..1a68fbf1c 100644 --- a/tests/Feature/Importing/Api/ImportComponentsTest.php +++ b/tests/Feature/Importing/Api/ImportComponentsTest.php @@ -79,21 +79,21 @@ class ImportComponentsTest extends ImportDataTestCase ->where('item_id', $newComponent->id) ->sole(); - $this->assertEquals($activityLog->action_type, 'create'); - $this->assertEquals($activityLog->action_source, 'importer'); - $this->assertEquals($activityLog->company_id, $newComponent->company->id); + $this->assertEquals('create', $activityLog->action_type); + $this->assertEquals('importer', $activityLog->action_source); + $this->assertEquals($newComponent->company->id, $activityLog->company_id); - $this->assertEquals($newComponent->name, $row['itemName']); - $this->assertEquals($newComponent->company->name, $row['companyName']); - $this->assertEquals($newComponent->category->name, $row['category']); - $this->assertEquals($newComponent->location->name, $row['location']); + $this->assertEquals($row['itemName'], $newComponent->name); + $this->assertEquals($row['companyName'], $newComponent->company->name); + $this->assertEquals($row['category'], $newComponent->category->name); + $this->assertEquals($row['location'], $newComponent->location->name); $this->assertNull($newComponent->supplier_id); - $this->assertEquals($newComponent->qty, $row['quantity']); - $this->assertEquals($newComponent->order_number, $row['orderNumber']); - $this->assertEquals($newComponent->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($newComponent->purchase_cost, $row['purchaseCost']); + $this->assertEquals($row['quantity'], $newComponent->qty); + $this->assertEquals($row['orderNumber'], $newComponent->order_number); + $this->assertEquals($row['purchaseDate'], $newComponent->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $newComponent->purchase_cost); $this->assertNull($newComponent->min_amt); - $this->assertEquals($newComponent->serial, $row['serialNumber']); + $this->assertEquals($row['serialNumber'], $newComponent->serial); $this->assertNull($newComponent->image); $this->assertNull($newComponent->notes); } @@ -239,18 +239,18 @@ class ImportComponentsTest extends ImportDataTestCase ->where('serial', $row['serialNumber']) ->sole(); - $this->assertEquals($updatedComponent->name, $row['itemName']); - $this->assertEquals($updatedComponent->category->name, $row['category']); - $this->assertEquals($updatedComponent->location->name, $row['location']); - $this->assertEquals($updatedComponent->supplier_id, $component->supplier_id); - $this->assertEquals($updatedComponent->qty, $row['quantity']); - $this->assertEquals($updatedComponent->order_number, $row['orderNumber']); - $this->assertEquals($updatedComponent->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($updatedComponent->purchase_cost, $row['purchaseCost']); - $this->assertEquals($updatedComponent->min_amt, $component->min_amt); - $this->assertEquals($updatedComponent->serial, $row['serialNumber']); - $this->assertEquals($updatedComponent->image, $component->image); - $this->assertEquals($updatedComponent->notes, $component->notes); + $this->assertEquals($row['itemName'], $updatedComponent->name); + $this->assertEquals($row['category'], $updatedComponent->category->name); + $this->assertEquals($row['location'], $updatedComponent->location->name); + $this->assertEquals($component->supplier_id, $updatedComponent->supplier_id); + $this->assertEquals($row['quantity'], $updatedComponent->qty); + $this->assertEquals($row['orderNumber'], $updatedComponent->order_number); + $this->assertEquals($row['purchaseDate'], $updatedComponent->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $updatedComponent->purchase_cost); + $this->assertEquals($component->min_amt, $updatedComponent->min_amt); + $this->assertEquals($row['serialNumber'], $updatedComponent->serial); + $this->assertEquals($component->image, $updatedComponent->image); + $this->assertEquals($component->notes, $updatedComponent->notes); } #[Test] @@ -294,14 +294,14 @@ class ImportComponentsTest extends ImportDataTestCase ->where('serial', $importFileBuilder->firstRow()['category']) ->sole(); - $this->assertEquals($newComponent->name, $row['quantity']); - $this->assertEquals($newComponent->category->name, $row['purchaseCost']); - $this->assertEquals($newComponent->location->name, $row['serialNumber']); + $this->assertEquals($row['quantity'], $newComponent->name); + $this->assertEquals($row['purchaseCost'], $newComponent->category->name); + $this->assertEquals($row['serialNumber'], $newComponent->location->name); $this->assertNull($newComponent->supplier_id); - $this->assertEquals($newComponent->qty, $row['companyName']); - $this->assertEquals($newComponent->order_number, $row['orderNumber']); - $this->assertEquals($newComponent->purchase_date->toDateString(), $row['itemName']); - $this->assertEquals($newComponent->purchase_cost, $row['location']); + $this->assertEquals($row['companyName'], $newComponent->qty); + $this->assertEquals($row['orderNumber'], $newComponent->order_number); + $this->assertEquals($row['itemName'], $newComponent->purchase_date->toDateString()); + $this->assertEquals($row['location'], $newComponent->purchase_cost); $this->assertNull($newComponent->min_amt); $this->assertNull($newComponent->image); $this->assertNull($newComponent->notes); diff --git a/tests/Feature/Importing/Api/ImportConsumablesTest.php b/tests/Feature/Importing/Api/ImportConsumablesTest.php index 7591ee971..3962dea5d 100644 --- a/tests/Feature/Importing/Api/ImportConsumablesTest.php +++ b/tests/Feature/Importing/Api/ImportConsumablesTest.php @@ -79,22 +79,22 @@ class ImportConsumablesTest extends ImportDataTestCase ->where('item_id', $newConsumable->id) ->sole(); - $this->assertEquals($activityLog->action_type, 'create'); - $this->assertEquals($activityLog->action_source, 'importer'); - $this->assertEquals($activityLog->company_id, $newConsumable->company->id); + $this->assertEquals('create', $activityLog->action_type); + $this->assertEquals('importer', $activityLog->action_source); + $this->assertEquals($newConsumable->company->id, $activityLog->company_id); - $this->assertEquals($newConsumable->name, $row['itemName']); - $this->assertEquals($newConsumable->category->name, $row['category']); - $this->assertEquals($newConsumable->location->name, $row['location']); - $this->assertEquals($newConsumable->company->name, $row['companyName']); + $this->assertEquals($row['itemName'], $newConsumable->name); + $this->assertEquals($row['category'], $newConsumable->category->name); + $this->assertEquals($row['location'], $newConsumable->location->name); + $this->assertEquals($row['companyName'], $newConsumable->company->name); $this->assertNull($newConsumable->supplier_id); $this->assertFalse($newConsumable->requestable); $this->assertNull($newConsumable->image); - $this->assertEquals($newConsumable->order_number, $row['orderNumber']); - $this->assertEquals($newConsumable->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($newConsumable->purchase_cost, $row['purchaseCost']); + $this->assertEquals($row['orderNumber'], $newConsumable->order_number); + $this->assertEquals($row['purchaseDate'], $newConsumable->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $newConsumable->purchase_cost); $this->assertNull($newConsumable->min_amt); - $this->assertEquals($newConsumable->model_number, ''); + $this->assertEquals('', $newConsumable->model_number); $this->assertNull($newConsumable->item_number); $this->assertNull($newConsumable->manufacturer_id); $this->assertNull($newConsumable->notes); @@ -229,13 +229,13 @@ class ImportConsumablesTest extends ImportDataTestCase ->where('name', $importFileBuilder->firstRow()['itemName']) ->sole(); - $this->assertEquals($updatedConsumable->name, $row['itemName']); - $this->assertEquals($updatedConsumable->category->name, $row['category']); - $this->assertEquals($updatedConsumable->location->name, $row['location']); - $this->assertEquals($updatedConsumable->company->name, $row['companyName']); - $this->assertEquals($updatedConsumable->order_number, $row['orderNumber']); - $this->assertEquals($updatedConsumable->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($updatedConsumable->purchase_cost, $row['purchaseCost']); + $this->assertEquals($row['itemName'], $updatedConsumable->name); + $this->assertEquals($row['category'], $updatedConsumable->category->name); + $this->assertEquals($row['location'], $updatedConsumable->location->name); + $this->assertEquals($row['companyName'], $updatedConsumable->company->name); + $this->assertEquals($row['orderNumber'], $updatedConsumable->order_number); + $this->assertEquals($row['purchaseDate'], $updatedConsumable->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $updatedConsumable->purchase_cost); $this->assertEquals($consumable->supplier_id, $updatedConsumable->supplier_id); $this->assertEquals($consumable->requestable, $updatedConsumable->requestable); @@ -289,19 +289,19 @@ class ImportConsumablesTest extends ImportDataTestCase ->where('name', $importFileBuilder->firstRow()['quantity']) ->sole(); - $this->assertEquals($newConsumable->category->name, $row['supplier']); - $this->assertEquals($newConsumable->location->name, $row['purchaseCost']); - $this->assertEquals($newConsumable->company->name, $row['purchaseDate']); - $this->assertEquals($newConsumable->qty, $row['companyName']); - $this->assertEquals($newConsumable->name, $row['quantity']); + $this->assertEquals($row['supplier'], $newConsumable->category->name); + $this->assertEquals($row['purchaseCost'], $newConsumable->location->name); + $this->assertEquals($row['purchaseDate'], $newConsumable->company->name); + $this->assertEquals($row['companyName'], $newConsumable->qty); + $this->assertEquals($row['quantity'], $newConsumable->name); $this->assertNull($newConsumable->supplier_id); $this->assertFalse($newConsumable->requestable); $this->assertNull($newConsumable->image); - $this->assertEquals($newConsumable->order_number, $row['orderNumber']); - $this->assertEquals($newConsumable->purchase_date->toDateString(), $row['itemName']); - $this->assertEquals($newConsumable->purchase_cost, $row['location']); + $this->assertEquals($row['orderNumber'], $newConsumable->order_number); + $this->assertEquals($row['itemName'], $newConsumable->purchase_date->toDateString()); + $this->assertEquals($row['location'], $newConsumable->purchase_cost); $this->assertNull($newConsumable->min_amt); - $this->assertEquals($newConsumable->model_number, ''); + $this->assertEquals('', $newConsumable->model_number); $this->assertNull($newConsumable->item_number); $this->assertNull($newConsumable->manufacturer_id); $this->assertNull($newConsumable->notes); diff --git a/tests/Feature/Importing/Api/ImportLicenseTest.php b/tests/Feature/Importing/Api/ImportLicenseTest.php index a5147d55a..11865236f 100644 --- a/tests/Feature/Importing/Api/ImportLicenseTest.php +++ b/tests/Feature/Importing/Api/ImportLicenseTest.php @@ -79,22 +79,22 @@ class ImportLicenseTest extends ImportDataTestCase $this->assertCount(2, $activityLogs); - $this->assertEquals($newLicense->name, $row['licenseName']); - $this->assertEquals($newLicense->serial, $row['serialNumber']); - $this->assertEquals($newLicense->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($newLicense->purchase_cost, $row['purchaseCost']); - $this->assertEquals($newLicense->order_number, $row['orderNumber']); - $this->assertEquals($newLicense->seats, $row['seats']); - $this->assertEquals($newLicense->notes, $row['notes']); - $this->assertEquals($newLicense->license_name, $row['licensedToName']); - $this->assertEquals($newLicense->license_email, $row['licensedToEmail']); - $this->assertEquals($newLicense->supplier->name, $row['supplierName']); - $this->assertEquals($newLicense->company->name, $row['companyName']); - $this->assertEquals($newLicense->category->name, $row['category']); - $this->assertEquals($newLicense->expiration_date->toDateString(), $row['expirationDate']); - $this->assertEquals($newLicense->maintained, $row['isMaintained'] === 'TRUE'); - $this->assertEquals($newLicense->reassignable, $row['isReassignAble'] === 'TRUE'); - $this->assertEquals($newLicense->purchase_order, ''); + $this->assertEquals($row['licenseName'], $newLicense->name); + $this->assertEquals($row['serialNumber'], $newLicense->serial); + $this->assertEquals($row['purchaseDate'], $newLicense->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $newLicense->purchase_cost); + $this->assertEquals($row['orderNumber'], $newLicense->order_number); + $this->assertEquals($row['seats'], $newLicense->seats); + $this->assertEquals($row['notes'], $newLicense->notes); + $this->assertEquals($row['licensedToName'], $newLicense->license_name); + $this->assertEquals($row['licensedToEmail'], $newLicense->license_email); + $this->assertEquals($row['supplierName'], $newLicense->supplier->name); + $this->assertEquals($row['companyName'], $newLicense->company->name); + $this->assertEquals($row['category'], $newLicense->category->name); + $this->assertEquals($row['expirationDate'], $newLicense->expiration_date->toDateString()); + $this->assertEquals($row['isMaintained'] === 'TRUE', $newLicense->maintained); + $this->assertEquals($row['isReassignAble'] === 'TRUE', $newLicense->reassignable); + $this->assertEquals('', $newLicense->purchase_order); $this->assertNull($newLicense->depreciation_id); $this->assertNull($newLicense->termination_date); $this->assertNull($newLicense->deprecate); @@ -155,7 +155,7 @@ class ImportLicenseTest extends ImportDataTestCase ->where('serial', $importFileBuilder->firstRow()['serialNumber']) ->sole(); - $this->assertEquals($newLicense->expiration_date->toDateString(), '2022-10-10'); + $this->assertEquals('2022-10-10', $newLicense->expiration_date->toDateString()); } #[Test] @@ -259,26 +259,26 @@ class ImportLicenseTest extends ImportDataTestCase ->where('serial', $row['serialNumber']) ->sole(); - $this->assertEquals($updatedLicense->name, $row['licenseName']); - $this->assertEquals($updatedLicense->serial, $row['serialNumber']); - $this->assertEquals($updatedLicense->purchase_date->toDateString(), $row['purchaseDate']); - $this->assertEquals($updatedLicense->purchase_cost, $row['purchaseCost']); - $this->assertEquals($updatedLicense->order_number, $row['orderNumber']); - $this->assertEquals($updatedLicense->seats, $row['seats']); - $this->assertEquals($updatedLicense->notes, $row['notes']); - $this->assertEquals($updatedLicense->license_name, $row['licensedToName']); - $this->assertEquals($updatedLicense->license_email, $row['licensedToEmail']); - $this->assertEquals($updatedLicense->supplier->name, $row['supplierName']); - $this->assertEquals($updatedLicense->company->name, $row['companyName']); - $this->assertEquals($updatedLicense->category->name, $row['category']); - $this->assertEquals($updatedLicense->expiration_date->toDateString(), $row['expirationDate']); - $this->assertEquals($updatedLicense->maintained, $row['isMaintained'] === 'TRUE'); - $this->assertEquals($updatedLicense->reassignable, $row['isReassignAble'] === 'TRUE'); - $this->assertEquals($updatedLicense->purchase_order, $license->purchase_order); - $this->assertEquals($updatedLicense->depreciation_id, $license->depreciation_id); - $this->assertEquals($updatedLicense->termination_date, $license->termination_date); - $this->assertEquals($updatedLicense->deprecate, $license->deprecate); - $this->assertEquals($updatedLicense->min_amt, $license->min_amt); + $this->assertEquals($row['licenseName'], $updatedLicense->name); + $this->assertEquals($row['serialNumber'], $updatedLicense->serial); + $this->assertEquals($row['purchaseDate'], $updatedLicense->purchase_date->toDateString()); + $this->assertEquals($row['purchaseCost'], $updatedLicense->purchase_cost); + $this->assertEquals($row['orderNumber'], $updatedLicense->order_number); + $this->assertEquals($row['seats'], $updatedLicense->seats); + $this->assertEquals($row['notes'], $updatedLicense->notes); + $this->assertEquals($row['licensedToName'], $updatedLicense->license_name); + $this->assertEquals($row['licensedToEmail'], $updatedLicense->license_email); + $this->assertEquals($row['supplierName'], $updatedLicense->supplier->name); + $this->assertEquals($row['companyName'], $updatedLicense->company->name); + $this->assertEquals($row['category'], $updatedLicense->category->name); + $this->assertEquals($row['expirationDate'], $updatedLicense->expiration_date->toDateString()); + $this->assertEquals($row['isMaintained'] === 'TRUE', $updatedLicense->maintained); + $this->assertEquals($row['isReassignAble'] === 'TRUE', $updatedLicense->reassignable); + $this->assertEquals($license->purchase_order, $updatedLicense->purchase_order); + $this->assertEquals($license->depreciation_id, $updatedLicense->depreciation_id); + $this->assertEquals($license->termination_date, $updatedLicense->termination_date); + $this->assertEquals($license->deprecate, $updatedLicense->deprecate); + $this->assertEquals($license->min_amt, $updatedLicense->min_amt); } #[Test] @@ -336,22 +336,22 @@ class ImportLicenseTest extends ImportDataTestCase ->where('serial', $row['companyName']) ->sole(); - $this->assertEquals($newLicense->name, $row['licenseName']); - $this->assertEquals($newLicense->serial, $row['companyName']); - $this->assertEquals($newLicense->purchase_date->toDateString(), $row['isMaintained']); - $this->assertEquals($newLicense->purchase_cost, $row['isReassignAble']); - $this->assertEquals($newLicense->order_number, $row['licensedToName']); - $this->assertEquals($newLicense->seats, $row['expirationDate']); - $this->assertEquals($newLicense->notes, $row['licensedToEmail']); - $this->assertEquals($newLicense->license_name, $row['seats']); - $this->assertEquals($newLicense->license_email, $row['serialNumber']); - $this->assertEquals($newLicense->supplier->name, $row['category']); - $this->assertEquals($newLicense->company->name, $row['notes']); - $this->assertEquals($newLicense->category->name, $row['manufacturerName']); - $this->assertEquals($newLicense->expiration_date->toDateString(), $row['orderNumber']); - $this->assertEquals($newLicense->maintained, $row['purchaseCost'] === 'TRUE'); - $this->assertEquals($newLicense->reassignable, $row['purchaseDate'] === 'TRUE'); - $this->assertEquals($newLicense->purchase_order, ''); + $this->assertEquals($row['licenseName'], $newLicense->name); + $this->assertEquals($row['companyName'], $newLicense->serial); + $this->assertEquals($row['isMaintained'], $newLicense->purchase_date->toDateString()); + $this->assertEquals($row['isReassignAble'], $newLicense->purchase_cost); + $this->assertEquals($row['licensedToName'], $newLicense->order_number); + $this->assertEquals($row['expirationDate'], $newLicense->seats); + $this->assertEquals($row['licensedToEmail'], $newLicense->notes); + $this->assertEquals($row['seats'], $newLicense->license_name); + $this->assertEquals($row['serialNumber'], $newLicense->license_email); + $this->assertEquals($row['category'], $newLicense->supplier->name); + $this->assertEquals($row['notes'], $newLicense->company->name); + $this->assertEquals($row['manufacturerName'], $newLicense->category->name); + $this->assertEquals($row['orderNumber'], $newLicense->expiration_date->toDateString()); + $this->assertEquals($row['purchaseCost'] === 'TRUE', $newLicense->maintained); + $this->assertEquals($row['purchaseDate'] === 'TRUE', $newLicense->reassignable); + $this->assertEquals('', $newLicense->purchase_order); $this->assertNull($newLicense->depreciation_id); $this->assertNull($newLicense->termination_date); $this->assertNull($newLicense->deprecate); diff --git a/tests/Feature/Importing/Api/ImportUsersTest.php b/tests/Feature/Importing/Api/ImportUsersTest.php index 4415da3f1..6ac0070a1 100644 --- a/tests/Feature/Importing/Api/ImportUsersTest.php +++ b/tests/Feature/Importing/Api/ImportUsersTest.php @@ -78,21 +78,21 @@ class ImportUsersTest extends ImportDataTestCase Notification::assertNothingSent(); - $this->assertEquals($newUser->email, $row['email']); - $this->assertEquals($newUser->first_name, $row['firstName']); - $this->assertEquals($newUser->last_name, $row['lastName']); - $this->assertEquals($newUser->employee_num, $row['employeeNumber']); - $this->assertEquals($newUser->company->name, $row['companyName']); - $this->assertEquals($newUser->location->name, $row['location']); - $this->assertEquals($newUser->phone, $row['phoneNumber']); - $this->assertEquals($newUser->jobtitle, $row['position']); + $this->assertEquals($row['email'], $newUser->email); + $this->assertEquals($row['firstName'], $newUser->first_name); + $this->assertEquals($row['lastName'], $newUser->last_name); + $this->assertEquals($row['employeeNumber'], $newUser->employee_num); + $this->assertEquals($row['companyName'], $newUser->company->name); + $this->assertEquals($row['location'], $newUser->location->name); + $this->assertEquals($row['phoneNumber'], $newUser->phone); + $this->assertEquals($row['position'], $newUser->jobtitle); $this->assertTrue(Hash::isHashed($newUser->password)); - $this->assertEquals($newUser->website, ''); - $this->assertEquals($newUser->country, ''); - $this->assertEquals($newUser->address, ''); - $this->assertEquals($newUser->city, ''); - $this->assertEquals($newUser->state, ''); - $this->assertEquals($newUser->zip, ''); + $this->assertEquals('', $newUser->website); + $this->assertEquals('', $newUser->country); + $this->assertEquals('', $newUser->address); + $this->assertEquals('', $newUser->city); + $this->assertEquals('', $newUser->state); + $this->assertEquals('', $newUser->zip); $this->assertNull($newUser->permissions); $this->assertNull($newUser->avatar); $this->assertNull($newUser->notes); @@ -100,15 +100,15 @@ class ImportUsersTest extends ImportDataTestCase $this->assertNull($newUser->department_id); $this->assertNull($newUser->two_factor_secret); $this->assertNull($newUser->idap_import); - $this->assertEquals($newUser->locale, 'en-US'); - $this->assertEquals($newUser->show_in_list, 1); - $this->assertEquals($newUser->two_factor_enrolled, 0); - $this->assertEquals($newUser->two_factor_optin, 0); - $this->assertEquals($newUser->remote, 0); - $this->assertEquals($newUser->autoassign_licenses, 0); - $this->assertEquals($newUser->vip, 0); - $this->assertEquals($newUser->enable_sounds, 0); - $this->assertEquals($newUser->enable_confetti, 0); + $this->assertEquals('en-US', $newUser->locale); + $this->assertEquals(1, $newUser->show_in_list); + $this->assertEquals(0, $newUser->two_factor_enrolled); + $this->assertEquals(0, $newUser->two_factor_optin); + $this->assertEquals(0, $newUser->remote); + $this->assertEquals(0, $newUser->autoassign_licenses); + $this->assertEquals(0, $newUser->vip); + $this->assertEquals(0, $newUser->enable_sounds); + $this->assertEquals(0, $newUser->enable_confetti); $this->assertNull($newUser->created_by); $this->assertNull($newUser->start_date); $this->assertNull($newUser->end_date); @@ -118,7 +118,7 @@ class ImportUsersTest extends ImportDataTestCase $this->assertNull($newUser->last_login); $this->assertNull($newUser->persist_code); $this->assertNull($newUser->reset_password_code); - $this->assertEquals($newUser->activated, 0); + $this->assertEquals(0, $newUser->activated); } #[Test] @@ -169,7 +169,7 @@ class ImportUsersTest extends ImportDataTestCase $generatedUsername = User::generateFormattedNameFromFullName("{$row['firstName']} {$row['lastName']}")['username']; - $this->assertEquals($newUser->username, $generatedUsername); + $this->assertEquals($generatedUsername, $newUser->username); } #[Test] @@ -186,8 +186,8 @@ class ImportUsersTest extends ImportDataTestCase $userLocation = Location::query()->where('name', $importFileBuilder->firstRow()['location'])->sole(['id']); $this->assertEquals( - $assetsAssignedToUser->refresh()->location_id, - $userLocation->id + $userLocation->id, + $assetsAssignedToUser->refresh()->location_id ); } @@ -238,19 +238,19 @@ class ImportUsersTest extends ImportDataTestCase 'location_id', 'company_id', 'updated_at', 'phone', 'jobtitle' ]; - $this->assertEquals($updatedUser->email, $row['email']); - $this->assertEquals($updatedUser->first_name, $row['firstName']); - $this->assertEquals($updatedUser->last_name, $row['lastName']); - $this->assertEquals($updatedUser->employee_num, $row['employeeNumber']); - $this->assertEquals($updatedUser->company->name, $row['companyName']); - $this->assertEquals($updatedUser->location->name, $row['location']); - $this->assertEquals($updatedUser->phone, $row['phoneNumber']); - $this->assertEquals($updatedUser->jobtitle, $row['position']); + $this->assertEquals($row['email'], $updatedUser->email); + $this->assertEquals($row['firstName'], $updatedUser->first_name); + $this->assertEquals($row['lastName'], $updatedUser->last_name); + $this->assertEquals($row['employeeNumber'], $updatedUser->employee_num); + $this->assertEquals($row['companyName'], $updatedUser->company->name); + $this->assertEquals($row['location'], $updatedUser->location->name); + $this->assertEquals($row['phoneNumber'], $updatedUser->phone); + $this->assertEquals($row['position'], $updatedUser->jobtitle); $this->assertTrue(Hash::isHashed($updatedUser->password)); $this->assertEquals( - Arr::except($updatedUser->attributesToArray(), $updatedAttributes), Arr::except($user->attributesToArray(), $updatedAttributes), + Arr::except($updatedUser->attributesToArray(), $updatedAttributes), ); } @@ -295,21 +295,21 @@ class ImportUsersTest extends ImportDataTestCase ->where('username', $row['companyName']) ->sole(); - $this->assertEquals($newUser->email, $row['position']); - $this->assertEquals($newUser->first_name, $row['location']); - $this->assertEquals($newUser->last_name, $row['lastName']); - $this->assertEquals($newUser->jobtitle, $row['email']); - $this->assertEquals($newUser->employee_num, $row['phoneNumber']); - $this->assertEquals($newUser->company->name, $row['username']); - $this->assertEquals($newUser->location->name, $row['firstName']); - $this->assertEquals($newUser->phone, $row['employeeNumber']); + $this->assertEquals($row['position'], $newUser->email); + $this->assertEquals($row['location'], $newUser->first_name); + $this->assertEquals($row['lastName'], $newUser->last_name); + $this->assertEquals($row['email'], $newUser->jobtitle); + $this->assertEquals($row['phoneNumber'], $newUser->employee_num); + $this->assertEquals($row['username'], $newUser->company->name); + $this->assertEquals($row['firstName'], $newUser->location->name); + $this->assertEquals($row['employeeNumber'], $newUser->phone); $this->assertTrue(Hash::isHashed($newUser->password)); - $this->assertEquals($newUser->website, ''); - $this->assertEquals($newUser->country, ''); - $this->assertEquals($newUser->address, ''); - $this->assertEquals($newUser->city, ''); - $this->assertEquals($newUser->state, ''); - $this->assertEquals($newUser->zip, ''); + $this->assertEquals('', $newUser->website); + $this->assertEquals('', $newUser->country); + $this->assertEquals('', $newUser->address); + $this->assertEquals('', $newUser->city); + $this->assertEquals('', $newUser->state); + $this->assertEquals('', $newUser->zip); $this->assertNull($newUser->permissions); $this->assertNull($newUser->avatar); $this->assertNull($newUser->notes); @@ -317,15 +317,15 @@ class ImportUsersTest extends ImportDataTestCase $this->assertNull($newUser->department_id); $this->assertNull($newUser->two_factor_secret); $this->assertNull($newUser->idap_import); - $this->assertEquals($newUser->locale, 'en-US'); - $this->assertEquals($newUser->show_in_list, 1); - $this->assertEquals($newUser->two_factor_enrolled, 0); - $this->assertEquals($newUser->two_factor_optin, 0); - $this->assertEquals($newUser->remote, 0); - $this->assertEquals($newUser->autoassign_licenses, 0); - $this->assertEquals($newUser->vip, 0); - $this->assertEquals($newUser->enable_sounds, 0); - $this->assertEquals($newUser->enable_confetti, 0); + $this->assertEquals('en-US', $newUser->locale); + $this->assertEquals(1, $newUser->show_in_list); + $this->assertEquals(0, $newUser->two_factor_enrolled); + $this->assertEquals(0, $newUser->two_factor_optin); + $this->assertEquals(0, $newUser->remote); + $this->assertEquals(0, $newUser->autoassign_licenses); + $this->assertEquals(0, $newUser->vip); + $this->assertEquals(0, $newUser->enable_sounds); + $this->assertEquals(0, $newUser->enable_confetti); $this->assertNull($newUser->created_by); $this->assertNull($newUser->start_date); $this->assertNull($newUser->end_date); @@ -335,6 +335,6 @@ class ImportUsersTest extends ImportDataTestCase $this->assertNull($newUser->last_login); $this->assertNull($newUser->persist_code); $this->assertNull($newUser->reset_password_code); - $this->assertEquals($newUser->activated, 0); + $this->assertEquals(0, $newUser->activated); } } From bde05d6ed9840d6e712e0f4a785f9c9166f352fd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 13:15:49 -0700 Subject: [PATCH 3/9] Use new() instead of times() --- database/factories/ImportFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/factories/ImportFactory.php b/database/factories/ImportFactory.php index 830c87fa7..0b0f79aa4 100644 --- a/database/factories/ImportFactory.php +++ b/database/factories/ImportFactory.php @@ -76,7 +76,7 @@ class ImportFactory extends Factory public function component() { return $this->state(function (array $attributes) { - $fileBuilder = Importing\ComponentsImportFileBuilder::times(); + $fileBuilder = Importing\ComponentsImportFileBuilder::new(); $attributes['name'] = "{$attributes['name']} Components"; $attributes['import_type'] = 'component'; From 983a25aa5f9004e05f27713fbef6e8f9302bb772 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 13:39:54 -0700 Subject: [PATCH 4/9] Simplify permission tests --- .../Feature/Importing/Api/ImportAccessoriesTest.php | 13 +++++-------- tests/Feature/Importing/Api/ImportAssetsTest.php | 12 ++++-------- .../Feature/Importing/Api/ImportComponentsTest.php | 13 +++++-------- .../Feature/Importing/Api/ImportConsumablesTest.php | 13 +++++-------- tests/Feature/Importing/Api/ImportLicenseTest.php | 13 +++++-------- tests/Feature/Importing/Api/ImportUsersTest.php | 12 ++++-------- 6 files changed, 28 insertions(+), 48 deletions(-) diff --git a/tests/Feature/Importing/Api/ImportAccessoriesTest.php b/tests/Feature/Importing/Api/ImportAccessoriesTest.php index 27a80c0dd..b4285775f 100644 --- a/tests/Feature/Importing/Api/ImportAccessoriesTest.php +++ b/tests/Feature/Importing/Api/ImportAccessoriesTest.php @@ -5,6 +5,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Accessory; use App\Models\Actionlog; use App\Models\Company; +use App\Models\User; use Database\Factories\AccessoryFactory; use Database\Factories\CompanyFactory; use Illuminate\Support\Str; @@ -15,9 +16,10 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Arr; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; +use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\AccessoriesImportFileBuilder as ImportFileBuilder; -class ImportAccessoriesTest extends ImportDataTestCase +class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissionsRequirement { use WithFaker; @@ -31,14 +33,9 @@ class ImportAccessoriesTest extends ImportDataTestCase } #[Test] - #[DataProvider('permissionsTestData')] - public function onlyUserWithPermissionCanImportAccessories(array|string $permissions): void + public function testRequiresPermission() { - $permissions = collect((array) $permissions) - ->map(fn (string $permission) => [$permission => '1']) - ->toJson(); - - $this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions])); + $this->actingAsForApi(User::factory()->create()); $this->importFileResponse(['import' => 44])->assertForbidden(); } diff --git a/tests/Feature/Importing/Api/ImportAssetsTest.php b/tests/Feature/Importing/Api/ImportAssetsTest.php index d4b6ac52e..70e61b41d 100644 --- a/tests/Feature/Importing/Api/ImportAssetsTest.php +++ b/tests/Feature/Importing/Api/ImportAssetsTest.php @@ -19,9 +19,10 @@ use Illuminate\Support\Arr; use Illuminate\Support\Facades\Notification; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; +use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\AssetsImportFileBuilder as ImportFileBuilder; -class ImportAssetsTest extends ImportDataTestCase +class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsRequirement { use WithFaker; @@ -35,14 +36,9 @@ class ImportAssetsTest extends ImportDataTestCase } #[Test] - #[DataProvider('permissionsTestData')] - public function onlyUserWithPermissionCanImportAssets(array|string $permissions): void + public function testRequiresPermission() { - $permissions = collect((array) $permissions) - ->map(fn (string $permission) => [$permission => '1']) - ->toJson(); - - $this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions])); + $this->actingAsForApi(User::factory()->create()); $this->importFileResponse(['import' => 44])->assertForbidden(); } diff --git a/tests/Feature/Importing/Api/ImportComponentsTest.php b/tests/Feature/Importing/Api/ImportComponentsTest.php index 1a68fbf1c..c8a1209cf 100644 --- a/tests/Feature/Importing/Api/ImportComponentsTest.php +++ b/tests/Feature/Importing/Api/ImportComponentsTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Actionlog as ActionLog; use App\Models\Component; +use App\Models\User; use Database\Factories\ComponentFactory; use Illuminate\Support\Str; use Database\Factories\UserFactory; @@ -13,9 +14,10 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Notification; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; +use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\ComponentsImportFileBuilder as ImportFileBuilder; -class ImportComponentsTest extends ImportDataTestCase +class ImportComponentsTest extends ImportDataTestCase implements TestsPermissionsRequirement { use WithFaker; @@ -29,14 +31,9 @@ class ImportComponentsTest extends ImportDataTestCase } #[Test] - #[DataProvider('permissionsTestData')] - public function onlyUserWithPermissionCanImportComponents(array|string $permissions): void + public function testRequiresPermission() { - $permissions = collect((array) $permissions) - ->map(fn (string $permission) => [$permission => '1']) - ->toJson(); - - $this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions])); + $this->actingAsForApi(User::factory()->create()); $this->importFileResponse(['import' => 44])->assertForbidden(); } diff --git a/tests/Feature/Importing/Api/ImportConsumablesTest.php b/tests/Feature/Importing/Api/ImportConsumablesTest.php index 3962dea5d..7647946dd 100644 --- a/tests/Feature/Importing/Api/ImportConsumablesTest.php +++ b/tests/Feature/Importing/Api/ImportConsumablesTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Actionlog as ActivityLog; use App\Models\Consumable; +use App\Models\User; use Database\Factories\ConsumableFactory; use Illuminate\Support\Str; use Database\Factories\UserFactory; @@ -13,9 +14,10 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Notification; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; +use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\ConsumablesImportFileBuilder as ImportFileBuilder; -class ImportConsumablesTest extends ImportDataTestCase +class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissionsRequirement { use WithFaker; @@ -29,14 +31,9 @@ class ImportConsumablesTest extends ImportDataTestCase } #[Test] - #[DataProvider('permissionsTestData')] - public function onlyUserWithPermissionCanImportConsumables(array|string $permissions): void + public function testRequiresPermission() { - $permissions = collect((array) $permissions) - ->map(fn (string $permission) => [$permission => '1']) - ->toJson(); - - $this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions])); + $this->actingAsForApi(User::factory()->create()); $this->importFileResponse(['import' => 44])->assertForbidden(); } diff --git a/tests/Feature/Importing/Api/ImportLicenseTest.php b/tests/Feature/Importing/Api/ImportLicenseTest.php index 11865236f..0d9e3e2a5 100644 --- a/tests/Feature/Importing/Api/ImportLicenseTest.php +++ b/tests/Feature/Importing/Api/ImportLicenseTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Actionlog as ActivityLog; use App\Models\License; +use App\Models\User; use Illuminate\Support\Str; use Database\Factories\UserFactory; use Database\Factories\ImportFactory; @@ -12,9 +13,10 @@ use PHPUnit\Framework\Attributes\Test; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; +use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\LicensesImportFileBuilder as ImportFileBuilder; -class ImportLicenseTest extends ImportDataTestCase +class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRequirement { use WithFaker; @@ -28,14 +30,9 @@ class ImportLicenseTest extends ImportDataTestCase } #[Test] - #[DataProvider('permissionsTestData')] - public function onlyUserWithPermissionCanImportLicenses(array|string $permissions): void + public function testRequiresPermission() { - $permissions = collect((array) $permissions) - ->map(fn (string $permission) => [$permission => '1']) - ->toJson(); - - $this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions])); + $this->actingAsForApi(User::factory()->create()); $this->importFileResponse(['import' => 44])->assertForbidden(); } diff --git a/tests/Feature/Importing/Api/ImportUsersTest.php b/tests/Feature/Importing/Api/ImportUsersTest.php index 6ac0070a1..f506c0ac2 100644 --- a/tests/Feature/Importing/Api/ImportUsersTest.php +++ b/tests/Feature/Importing/Api/ImportUsersTest.php @@ -15,9 +15,10 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Notification; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; +use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\UsersImportFileBuilder as ImportFileBuilder; -class ImportUsersTest extends ImportDataTestCase +class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequirement { use WithFaker; @@ -31,14 +32,9 @@ class ImportUsersTest extends ImportDataTestCase } #[Test] - #[DataProvider('permissionsTestData')] - public function onlyUserWithPermissionCanImportUsers(array|string $permissions): void + public function testRequiresPermission() { - $permissions = collect((array) $permissions) - ->map(fn (string $permission) => [$permission => '1']) - ->toJson(); - - $this->actingAsForApi(UserFactory::new()->create(['permissions' => $permissions])); + $this->actingAsForApi(User::factory()->create()); $this->importFileResponse(['import' => 44])->assertForbidden(); } From 88d549e7c5ee8fd385d897be557dbbac60a66f73 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 13:40:37 -0700 Subject: [PATCH 5/9] Remove unused data provider method --- .../Importing/Api/ImportDataTestCase.php | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/tests/Feature/Importing/Api/ImportDataTestCase.php b/tests/Feature/Importing/Api/ImportDataTestCase.php index ac39fab67..546b6c0f3 100644 --- a/tests/Feature/Importing/Api/ImportDataTestCase.php +++ b/tests/Feature/Importing/Api/ImportDataTestCase.php @@ -11,26 +11,4 @@ abstract class ImportDataTestCase extends TestCase { return $this->postJson(route('api.imports.importFile', $parameters), $parameters); } - - /** - * @todo Add more permissions. - */ - public static function permissionsTestData(): array - { - return [ - '`admin`' => ['admin'], - '`reports.view`' => ['reports.view'], - 'only `assets` permission' => [ - 'assets.view', - 'assets.create', - 'assets.edit', - 'assets.delete', - 'assets.checkout', - 'assets.checkin', - 'assets.audit', - 'assets.view.requestable', - 'assets.view.encrypted_custom_fields' - ] - ]; - } } From e21305377549886099d21b67f49d2abbccc42d91 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 13:59:58 -0700 Subject: [PATCH 6/9] Swap factory syntax --- app/Models/Import.php | 3 + .../Importing/Api/ImportAccessoriesTest.php | 69 +++++++++-------- .../Importing/Api/ImportAssetsTest.php | 77 ++++++++++--------- .../Importing/Api/ImportComponentsTest.php | 45 +++++------ .../Importing/Api/ImportConsumablesTest.php | 45 +++++------ .../Importing/Api/ImportLicenseTest.php | 49 ++++++------ .../Feature/Importing/Api/ImportUsersTest.php | 46 +++++------ 7 files changed, 172 insertions(+), 162 deletions(-) diff --git a/app/Models/Import.php b/app/Models/Import.php index 81728c8a5..052612a19 100644 --- a/app/Models/Import.php +++ b/app/Models/Import.php @@ -2,10 +2,13 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Import extends Model { + use HasFactory; + protected $casts = [ 'header_row' => 'array', 'first_row' => 'array', diff --git a/tests/Feature/Importing/Api/ImportAccessoriesTest.php b/tests/Feature/Importing/Api/ImportAccessoriesTest.php index b4285775f..e4ad8b3be 100644 --- a/tests/Feature/Importing/Api/ImportAccessoriesTest.php +++ b/tests/Feature/Importing/Api/ImportAccessoriesTest.php @@ -5,6 +5,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Accessory; use App\Models\Actionlog; use App\Models\Company; +use App\Models\Import; use App\Models\User; use Database\Factories\AccessoryFactory; use Database\Factories\CompanyFactory; @@ -43,9 +44,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio #[Test] public function userWithImportAccessoryPermissionCanImportAccessories(): void { - $this->actingAsForApi(UserFactory::new()->canImport()->create()); + $this->actingAsForApi(User::factory()->canImport()->create()); - $import = ImportFactory::new()->accessory()->create(); + $import = Import::factory()->accessory()->create(); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -55,9 +56,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio { $importFileBuilder = ImportFileBuilder::new(); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertOk() ->assertExactJson([ @@ -108,9 +109,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio $importFileBuilder = new ImportFileBuilder([$row]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -119,9 +120,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio public function willFormatDate(): void { $importFileBuilder = ImportFileBuilder::new(['purchaseDate' => '2022/10/10']); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $accessory = Accessory::query() @@ -135,9 +136,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio public function willNotCreateNewCategoryWhenCategoryExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['category' => Str::random()]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAccessories = Accessory::query() @@ -150,11 +151,11 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio #[Test] public function willNotCreateNewAccessoryWhenAccessoryWithNameExists(): void { - $accessory = AccessoryFactory::new()->create(['name' => Str::random()]); + $accessory = Accessory::factory()->create(['name' => Str::random()]); $importFileBuilder = ImportFileBuilder::times(2)->replace(['itemName' => $accessory->name]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $probablyNewAccessories = Accessory::query() @@ -169,9 +170,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio public function willNotCreateNewCompanyWhenCompanyAlreadyExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['companyName' => Str::random()]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAccessories = Accessory::query() @@ -185,9 +186,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio public function willNotCreateNewLocationWhenLocationAlreadyExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['location' => Str::random()]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAccessories = Accessory::query() @@ -201,9 +202,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio public function willNotCreateNewManufacturerWhenManufacturerAlreadyExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['manufacturerName' => $this->faker->company]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAccessories = Accessory::query() @@ -217,9 +218,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio public function willNotCreateNewSupplierWhenSupplierAlreadyExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['supplierName' => $this->faker->company]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAccessories = Accessory::query() @@ -233,9 +234,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio public function whenColumnsAreMissingInImportFile(): void { $importFileBuilder = ImportFileBuilder::new()->forget(['minimumAmount', 'purchaseCost', 'purchaseDate']); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAccessory = Accessory::query() @@ -251,9 +252,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio public function whenRequiredColumnsAreMissingInImportFile(): void { $importFileBuilder = ImportFileBuilder::new()->forget(['itemName', 'quantity', 'category']); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertInternalServerError() ->assertExactJson([ @@ -274,12 +275,12 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio #[Test] public function updateAccessoryFromImport(): void { - $accessory = AccessoryFactory::new()->create(['name' => Str::random()])->refresh(); + $accessory = Accessory::factory()->create(['name' => Str::random()])->refresh(); $importFileBuilder = ImportFileBuilder::new(['itemName' => $accessory->name]); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id, 'import-update' => true])->assertOk(); $updatedAccessory = Accessory::query()->find($accessory->id); @@ -312,7 +313,7 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio #[Test] public function whenImportFileContainsEmptyValues(): void { - $accessory = AccessoryFactory::new()->create(['name' => Str::random()]); + $accessory = Accessory::factory()->create(['name' => Str::random()]); $accessory->refresh(); $importFileBuilder = ImportFileBuilder::new([ @@ -332,9 +333,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio 'modelNumber' => '' ]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertInternalServerError() ->assertExactJson([ @@ -352,7 +353,7 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio $importFileBuilder->replace(['itemName' => $accessory->name]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->importFileResponse(['import' => $import->id, 'import-update' => true])->assertOk(); @@ -382,9 +383,9 @@ class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissio ]; $importFileBuilder = new ImportFileBuilder([$row]); - $import = ImportFactory::new()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->accessory()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse([ 'import' => $import->id, 'column-mappings' => [ diff --git a/tests/Feature/Importing/Api/ImportAssetsTest.php b/tests/Feature/Importing/Api/ImportAssetsTest.php index 70e61b41d..27fc72316 100644 --- a/tests/Feature/Importing/Api/ImportAssetsTest.php +++ b/tests/Feature/Importing/Api/ImportAssetsTest.php @@ -5,6 +5,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Actionlog as ActionLog; use App\Models\Asset; use App\Models\CustomField; +use App\Models\Import; use App\Models\User; use App\Notifications\CheckoutAssetNotification; use Carbon\Carbon; @@ -46,9 +47,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq #[Test] public function userWithImportAssetsPermissionCanImportAssets(): void { - $this->actingAsForApi(UserFactory::new()->canImport()->create()); + $this->actingAsForApi(User::factory()->canImport()->create()); - $import = ImportFactory::new()->asset()->create(); + $import = Import::factory()->asset()->create(); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -60,9 +61,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq $importFileBuilder = ImportFileBuilder::new(); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertOk() ->assertExactJson([ @@ -151,9 +152,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq $importFileBuilder = new ImportFileBuilder([$row]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -161,11 +162,11 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq #[Test] public function willNotCreateNewAssetWhenAssetWithSameTagAlreadyExists(): void { - $asset = AssetFactory::new()->create(['asset_tag' => $this->faker->uuid]); + $asset = Asset::factory()->create(['asset_tag' => $this->faker->uuid]); $importFileBuilder = ImportFileBuilder::times(4)->replace(['tag' => $asset->asset_tag]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertInternalServerError() ->assertExactJson([ @@ -191,9 +192,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq public function willNotCreateNewCompanyWhenCompanyExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['companyName' => Str::random()]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAssets = Asset::query() @@ -207,9 +208,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq public function willNotCreateNewLocationWhenLocationExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['location' => Str::random()]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAssets = Asset::query() @@ -223,9 +224,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq public function willNotCreateNewSupplierWhenSupplierExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['supplierName' => $this->faker->company]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAssets = Asset::query() @@ -239,9 +240,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq public function willNotCreateNewManufacturerWhenManufacturerExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['manufacturerName' => $this->faker->company]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAssets = Asset::query() @@ -256,9 +257,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq public function willNotCreateCategoryWhenCategoryExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['category' => $this->faker->company]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAssets = Asset::query() @@ -273,9 +274,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq public function willNotCreateNewAssetModelWhenAssetModelExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['model' => Str::random()]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAssets = Asset::query() @@ -295,9 +296,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq 'status' ]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAsset = Asset::query() @@ -318,9 +319,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq 'purchaseDate' => '2022/10/10' ]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAsset = Asset::query() @@ -339,9 +340,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq ->replace(['model' => '']); $rows = $importFileBuilder->all(); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertInternalServerError() ->assertJson([ @@ -381,12 +382,12 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq #[Test] public function updateAssetFromImport(): void { - $asset = AssetFactory::new()->create()->refresh(); + $asset = Asset::factory()->create()->refresh(); $importFileBuilder = ImportFileBuilder::times(1)->replace(['tag' => $asset->asset_tag]); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id, 'import-update' => true])->assertOk(); $updatedAsset = Asset::query() @@ -458,9 +459,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq ]; $importFileBuilder = new ImportFileBuilder([$row]); - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse([ 'import' => $import->id, @@ -546,7 +547,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq $customField = CustomField::query()->where('name', 'Mac Address')->firstOrNew(); if (!$customField->exists) { - $customField = CustomFieldFactory::new()->macAddress()->create(['db_column' => '_snipeit_mac_address_1']); + $customField = CustomField::factory()->macAddress()->create(['db_column' => '_snipeit_mac_address_1']); } if ($customField->field_encrypted) { @@ -554,9 +555,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq $customField->save(); } - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newAsset = Asset::query()->where('serial', $importFileBuilder->firstRow()['serialNumber'])->sole(); @@ -576,7 +577,7 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq $customField = CustomField::query()->where('name', 'Mac Address')->firstOrNew(); if (!$customField->exists) { - $customField = CustomFieldFactory::new()->macAddress()->create(); + $customField = CustomField::factory()->macAddress()->create(); } if (!$customField->field_encrypted) { @@ -584,9 +585,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq $customField->save(); } - $import = ImportFactory::new()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->asset()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $asset = Asset::query()->where('serial', $importFileBuilder->firstRow()['serialNumber'])->sole(); diff --git a/tests/Feature/Importing/Api/ImportComponentsTest.php b/tests/Feature/Importing/Api/ImportComponentsTest.php index c8a1209cf..0eca70ae4 100644 --- a/tests/Feature/Importing/Api/ImportComponentsTest.php +++ b/tests/Feature/Importing/Api/ImportComponentsTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Actionlog as ActionLog; use App\Models\Component; +use App\Models\Import; use App\Models\User; use Database\Factories\ComponentFactory; use Illuminate\Support\Str; @@ -41,9 +42,9 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission #[Test] public function userWithImportAssetsPermissionCanImportComponents(): void { - $this->actingAsForApi(UserFactory::new()->canImport()->create()); + $this->actingAsForApi(User::factory()->canImport()->create()); - $import = ImportFactory::new()->component()->create(); + $import = Import::factory()->component()->create(); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -55,9 +56,9 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission $importFileBuilder = ImportFileBuilder::new(); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertOk() ->assertExactJson([ @@ -103,9 +104,9 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission $importFileBuilder = new ImportFileBuilder([$row]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -113,16 +114,16 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission #[Test] public function willNotCreateNewComponentWhenComponentWithNameAndSerialNumberExists(): void { - $component = ComponentFactory::new()->create(); + $component = Component::factory()->create(); $importFileBuilder = ImportFileBuilder::times(4)->replace([ 'itemName' => $component->name, 'serialNumber' => $component->serial ]); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $probablyNewComponents = Component::query() @@ -138,9 +139,9 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission public function willNotCreateNewCompanyWhenCompanyExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['companyName' => Str::random()]); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newComponents = Component::query() @@ -154,9 +155,9 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission public function willNotCreateNewLocationWhenLocationExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['location' => Str::random()]); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newComponents = Component::query() @@ -170,9 +171,9 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission public function willNotCreateNewCategoryWhenCategoryExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['category' => $this->faker->company]); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newComponents = Component::query() @@ -190,9 +191,9 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission ->forget(['quantity']); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertInternalServerError() @@ -219,16 +220,16 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission #[Test] public function updateComponentFromImport(): void { - $component = ComponentFactory::new()->create(); + $component = Component::factory()->create(); $importFileBuilder = ImportFileBuilder::new([ 'itemName' => $component->name, 'serialNumber' => $component->serial ]); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id, 'import-update' => true])->assertOk(); $updatedComponent = Component::query() @@ -267,9 +268,9 @@ class ImportComponentsTest extends ImportDataTestCase implements TestsPermission ]; $importFileBuilder = new ImportFileBuilder([$row]); - $import = ImportFactory::new()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->component()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse([ 'import' => $import->id, diff --git a/tests/Feature/Importing/Api/ImportConsumablesTest.php b/tests/Feature/Importing/Api/ImportConsumablesTest.php index 7647946dd..4b338629a 100644 --- a/tests/Feature/Importing/Api/ImportConsumablesTest.php +++ b/tests/Feature/Importing/Api/ImportConsumablesTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Actionlog as ActivityLog; use App\Models\Consumable; +use App\Models\Import; use App\Models\User; use Database\Factories\ConsumableFactory; use Illuminate\Support\Str; @@ -41,9 +42,9 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio #[Test] public function userWithImportAssetsPermissionCanImportConsumables(): void { - $this->actingAsForApi(UserFactory::new()->canImport()->create()); + $this->actingAsForApi(User::factory()->canImport()->create()); - $import = ImportFactory::new()->consumable()->create(); + $import = Import::factory()->consumable()->create(); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -55,9 +56,9 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio $importFileBuilder = ImportFileBuilder::new(); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertOk() ->assertExactJson([ @@ -105,9 +106,9 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio $importFileBuilder = new ImportFileBuilder([$row]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -115,11 +116,11 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio #[Test] public function willNotCreateNewConsumableWhenConsumableNameAlreadyExist(): void { - $consumable = ConsumableFactory::new()->create(['name' => Str::random()]); + $consumable = Consumable::factory()->create(['name' => Str::random()]); $importFileBuilder = ImportFileBuilder::new(['itemName' => $consumable->name]); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $probablyNewConsumables = Consumable::query() @@ -134,9 +135,9 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio public function willNotCreateNewCompanyWhenCompanyExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['companyName' => Str::random()]); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newConsumables = Consumable::query() @@ -150,9 +151,9 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio public function willNotCreateNewLocationWhenLocationExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['location' => Str::random()]); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newConsumables = Consumable::query() @@ -166,9 +167,9 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio public function willNotCreateNewCategoryWhenCategoryExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['category' => Str::random()]); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newConsumables = Consumable::query() @@ -184,9 +185,9 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio $importFileBuilder = ImportFileBuilder::new(['category' => ''])->forget(['quantity', 'name']); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertInternalServerError() @@ -212,13 +213,13 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio #[Test] public function updateConsumableFromImport(): void { - $consumable = ConsumableFactory::new()->create(['name' => Str::random()]); + $consumable = Consumable::factory()->create(['name' => Str::random()]); $importFileBuilder = ImportFileBuilder::new(['itemName' => $consumable->name]); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id, 'import-update' => true])->assertOk(); $updatedConsumable = Consumable::query() @@ -262,9 +263,9 @@ class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissio $importFileBuilder = new ImportFileBuilder([$row]); - $import = ImportFactory::new()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->consumable()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse([ 'import' => $import->id, diff --git a/tests/Feature/Importing/Api/ImportLicenseTest.php b/tests/Feature/Importing/Api/ImportLicenseTest.php index 0d9e3e2a5..99f770c28 100644 --- a/tests/Feature/Importing/Api/ImportLicenseTest.php +++ b/tests/Feature/Importing/Api/ImportLicenseTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature\Importing\Api; use App\Models\Actionlog as ActivityLog; +use App\Models\Import; use App\Models\License; use App\Models\User; use Illuminate\Support\Str; @@ -40,9 +41,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe #[Test] public function userWithImportAssetsPermissionCanImportLicenses(): void { - $this->actingAsForApi(UserFactory::new()->canImport()->create()); + $this->actingAsForApi(User::factory()->canImport()->create()); - $import = ImportFactory::new()->license()->create(); + $import = Import::factory()->license()->create(); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -52,9 +53,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe { $importFileBuilder = ImportFileBuilder::new(); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertOk() ->assertExactJson([ @@ -106,9 +107,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe $importFileBuilder = new ImportFileBuilder([$row]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -116,16 +117,16 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe #[Test] public function willNotCreateNewLicenseWhenNameAndSerialNumberAlreadyExist(): void { - $license = LicenseFactory::new()->create(); + $license = License::factory()->create(); $importFileBuilder = ImportFileBuilder::times(4)->replace([ 'itemName' => $license->name, 'serialNumber' => $license->serial ]); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $probablyNewLicenses = License::query() @@ -143,9 +144,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe 'expirationDate' => '2022/10/10' ]); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newLicense = License::query() @@ -159,9 +160,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe public function willNotCreateNewCompanyWhenCompanyExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['companyName' => Str::random()]); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newLicenses = License::query() @@ -175,9 +176,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe public function willNotCreateNewManufacturerWhenManufacturerExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['manufacturerName' => Str::random()]); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newLicenses = License::query() @@ -191,9 +192,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe public function willNotCreateNewCategoryWhenCategoryExists(): void { $importFileBuilder = ImportFileBuilder::times(4)->replace(['category' => $this->faker->company]); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newLicenses = License::query() @@ -211,9 +212,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe ->forget(['seats']); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertInternalServerError() @@ -239,16 +240,16 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe #[Test] public function updateLicenseFromImport(): void { - $license = LicenseFactory::new()->create(); + $license = License::factory()->create(); $importFileBuilder = ImportFileBuilder::new([ 'licenseName' => $license->name, 'serialNumber' => $license->serial ]); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id, 'import-update' => true])->assertOk(); $updatedLicense = License::query() @@ -302,9 +303,9 @@ class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRe ]; $importFileBuilder = new ImportFileBuilder([$row]); - $import = ImportFactory::new()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->license()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse([ 'import' => $import->id, diff --git a/tests/Feature/Importing/Api/ImportUsersTest.php b/tests/Feature/Importing/Api/ImportUsersTest.php index f506c0ac2..6de759090 100644 --- a/tests/Feature/Importing/Api/ImportUsersTest.php +++ b/tests/Feature/Importing/Api/ImportUsersTest.php @@ -2,6 +2,8 @@ namespace Tests\Feature\Importing\Api; +use App\Models\Asset; +use App\Models\Import; use App\Models\Location; use App\Models\User; use Database\Factories\AssetFactory; @@ -42,9 +44,9 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ #[Test] public function userWithImportAssetsPermissionCanImportUsers(): void { - $this->actingAsForApi(UserFactory::new()->canImport()->create()); + $this->actingAsForApi(User::factory()->canImport()->create()); - $import = ImportFactory::new()->users()->create(); + $import = Import::factory()->users()->create(); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -56,9 +58,9 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ $importFileBuilder = ImportFileBuilder::new(); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id, 'send-welcome' => 1]) ->assertOk() ->assertExactJson([ @@ -125,9 +127,9 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ $importFileBuilder = new ImportFileBuilder([$row]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); - $import = ImportFactory::new()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); $this->importFileResponse(['import' => $import->id])->assertOk(); } @@ -135,11 +137,11 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ #[Test] public function willNotCreateNewUserWhenUserWithUserNameAlreadyExist(): void { - $user = UserFactory::new()->create(['username' => Str::random()]); + $user = User::factory()->create(['username' => Str::random()]); $importFileBuilder = ImportFileBuilder::times(4)->replace(['username' => $user->username]); - $import = ImportFactory::new()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $probablyNewUsers = User::query() @@ -154,9 +156,9 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ { $importFileBuilder = ImportFileBuilder::new()->forget('username'); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id])->assertOk(); $newUser = User::query() @@ -171,12 +173,12 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ #[Test] public function willUpdateLocationOfAllAssetsAssignedToUser(): void { - $user = UserFactory::new()->create(['username' => Str::random()]); - $assetsAssignedToUser = AssetFactory::new()->create(['assigned_to' => $user->id, 'assigned_type' => User::class]); + $user = User::factory()->create(['username' => Str::random()]); + $assetsAssignedToUser = Asset::factory()->create(['assigned_to' => $user->id, 'assigned_type' => User::class]); $importFileBuilder = ImportFileBuilder::new(['username' => $user->username]); - $import = ImportFactory::new()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id, 'import-update' => true])->assertOk(); $userLocation = Location::query()->where('name', $importFileBuilder->firstRow()['location'])->sole(['id']); @@ -191,9 +193,9 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ public function whenRequiredColumnsAreMissingInImportFile(): void { $importFileBuilder = ImportFileBuilder::new(['firstName' => ''])->forget(['username']); - $import = ImportFactory::new()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id]) ->assertInternalServerError() @@ -219,13 +221,13 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ #[Test] public function updateUserFromImport(): void { - $user = UserFactory::new()->create(['username' => Str::random()])->refresh(); + $user = User::factory()->create(['username' => Str::random()])->refresh(); $importFileBuilder = ImportFileBuilder::new(['username' => $user->username]); $row = $importFileBuilder->firstRow(); - $import = ImportFactory::new()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse(['import' => $import->id, 'import-update' => true])->assertOk(); $updatedUser = User::query()->with(['company', 'location'])->find($user->id); @@ -267,9 +269,9 @@ class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequ ]; $importFileBuilder = new ImportFileBuilder([$row]); - $import = ImportFactory::new()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); + $import = Import::factory()->users()->create(['file_path' => $importFileBuilder->saveToImportsDirectory()]); - $this->actingAsForApi(UserFactory::new()->superuser()->create()); + $this->actingAsForApi(User::factory()->superuser()->create()); $this->importFileResponse([ 'import' => $import->id, From 063ea1892b3fecdd52ad8cd353c39038a8087de7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 15:02:03 -0700 Subject: [PATCH 7/9] Add trait to clean up files after test runs --- .../Importing/Api/ImportAccessoriesTest.php | 2 ++ .../Importing/Api/ImportAssetsTest.php | 2 ++ .../Importing/Api/ImportComponentsTest.php | 2 ++ .../Importing/Api/ImportConsumablesTest.php | 2 ++ .../Importing/Api/ImportLicenseTest.php | 2 ++ .../Feature/Importing/Api/ImportUsersTest.php | 3 +++ .../Support/Importing/CleansUpImportFiles.php | 20 +++++++++++++++++++ 7 files changed, 33 insertions(+) create mode 100644 tests/Support/Importing/CleansUpImportFiles.php diff --git a/tests/Feature/Importing/Api/ImportAccessoriesTest.php b/tests/Feature/Importing/Api/ImportAccessoriesTest.php index e4ad8b3be..91f72fe74 100644 --- a/tests/Feature/Importing/Api/ImportAccessoriesTest.php +++ b/tests/Feature/Importing/Api/ImportAccessoriesTest.php @@ -19,9 +19,11 @@ use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\AccessoriesImportFileBuilder as ImportFileBuilder; +use Tests\Support\Importing\CleansUpImportFiles; class ImportAccessoriesTest extends ImportDataTestCase implements TestsPermissionsRequirement { + use CleansUpImportFiles; use WithFaker; protected function importFileResponse(array $parameters = []): TestResponse diff --git a/tests/Feature/Importing/Api/ImportAssetsTest.php b/tests/Feature/Importing/Api/ImportAssetsTest.php index 27fc72316..50c31d6d9 100644 --- a/tests/Feature/Importing/Api/ImportAssetsTest.php +++ b/tests/Feature/Importing/Api/ImportAssetsTest.php @@ -22,9 +22,11 @@ use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\AssetsImportFileBuilder as ImportFileBuilder; +use Tests\Support\Importing\CleansUpImportFiles; class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsRequirement { + use CleansUpImportFiles; use WithFaker; protected function importFileResponse(array $parameters = []): TestResponse diff --git a/tests/Feature/Importing/Api/ImportComponentsTest.php b/tests/Feature/Importing/Api/ImportComponentsTest.php index 0eca70ae4..20f0e803d 100644 --- a/tests/Feature/Importing/Api/ImportComponentsTest.php +++ b/tests/Feature/Importing/Api/ImportComponentsTest.php @@ -16,10 +16,12 @@ use Illuminate\Support\Facades\Notification; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; use Tests\Concerns\TestsPermissionsRequirement; +use Tests\Support\Importing\CleansUpImportFiles; use Tests\Support\Importing\ComponentsImportFileBuilder as ImportFileBuilder; class ImportComponentsTest extends ImportDataTestCase implements TestsPermissionsRequirement { + use CleansUpImportFiles; use WithFaker; protected function importFileResponse(array $parameters = []): TestResponse diff --git a/tests/Feature/Importing/Api/ImportConsumablesTest.php b/tests/Feature/Importing/Api/ImportConsumablesTest.php index 4b338629a..d48486d19 100644 --- a/tests/Feature/Importing/Api/ImportConsumablesTest.php +++ b/tests/Feature/Importing/Api/ImportConsumablesTest.php @@ -16,10 +16,12 @@ use Illuminate\Support\Facades\Notification; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; use Tests\Concerns\TestsPermissionsRequirement; +use Tests\Support\Importing\CleansUpImportFiles; use Tests\Support\Importing\ConsumablesImportFileBuilder as ImportFileBuilder; class ImportConsumablesTest extends ImportDataTestCase implements TestsPermissionsRequirement { + use CleansUpImportFiles; use WithFaker; protected function importFileResponse(array $parameters = []): TestResponse diff --git a/tests/Feature/Importing/Api/ImportLicenseTest.php b/tests/Feature/Importing/Api/ImportLicenseTest.php index 99f770c28..fb4b9b932 100644 --- a/tests/Feature/Importing/Api/ImportLicenseTest.php +++ b/tests/Feature/Importing/Api/ImportLicenseTest.php @@ -15,10 +15,12 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; use Tests\Concerns\TestsPermissionsRequirement; +use Tests\Support\Importing\CleansUpImportFiles; use Tests\Support\Importing\LicensesImportFileBuilder as ImportFileBuilder; class ImportLicenseTest extends ImportDataTestCase implements TestsPermissionsRequirement { + use CleansUpImportFiles; use WithFaker; protected function importFileResponse(array $parameters = []): TestResponse diff --git a/tests/Feature/Importing/Api/ImportUsersTest.php b/tests/Feature/Importing/Api/ImportUsersTest.php index 6de759090..eb624e560 100644 --- a/tests/Feature/Importing/Api/ImportUsersTest.php +++ b/tests/Feature/Importing/Api/ImportUsersTest.php @@ -7,6 +7,7 @@ use App\Models\Import; use App\Models\Location; use App\Models\User; use Database\Factories\AssetFactory; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Database\Factories\UserFactory; use Database\Factories\ImportFactory; @@ -18,10 +19,12 @@ use Illuminate\Support\Facades\Notification; use Illuminate\Testing\TestResponse; use PHPUnit\Framework\Attributes\DataProvider; use Tests\Concerns\TestsPermissionsRequirement; +use Tests\Support\Importing\CleansUpImportFiles; use Tests\Support\Importing\UsersImportFileBuilder as ImportFileBuilder; class ImportUsersTest extends ImportDataTestCase implements TestsPermissionsRequirement { + use CleansUpImportFiles; use WithFaker; protected function importFileResponse(array $parameters = []): TestResponse diff --git a/tests/Support/Importing/CleansUpImportFiles.php b/tests/Support/Importing/CleansUpImportFiles.php new file mode 100644 index 000000000..8e0cbc310 --- /dev/null +++ b/tests/Support/Importing/CleansUpImportFiles.php @@ -0,0 +1,20 @@ +beforeApplicationDestroyed(function () use ($import) { + Storage::delete('private_uploads/imports/' . $import->file_path); + }); + }); + } +} From dfdd85abb17422380499d20fe4596a759ff56e4c Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 15:14:07 -0700 Subject: [PATCH 8/9] Remove unused imports --- tests/Feature/Importing/Api/ImportAccessoriesTest.php | 6 ------ tests/Feature/Importing/Api/ImportAssetsTest.php | 9 ++------- tests/Feature/Importing/Api/ImportComponentsTest.php | 8 ++------ tests/Feature/Importing/Api/ImportConsumablesTest.php | 8 ++------ tests/Feature/Importing/Api/ImportDataTestCase.php | 2 +- tests/Feature/Importing/Api/ImportLicenseTest.php | 8 ++------ tests/Feature/Importing/Api/ImportUsersTest.php | 9 ++------- 7 files changed, 11 insertions(+), 39 deletions(-) diff --git a/tests/Feature/Importing/Api/ImportAccessoriesTest.php b/tests/Feature/Importing/Api/ImportAccessoriesTest.php index 91f72fe74..aac9dabb1 100644 --- a/tests/Feature/Importing/Api/ImportAccessoriesTest.php +++ b/tests/Feature/Importing/Api/ImportAccessoriesTest.php @@ -4,19 +4,13 @@ namespace Tests\Feature\Importing\Api; use App\Models\Accessory; use App\Models\Actionlog; -use App\Models\Company; use App\Models\Import; use App\Models\User; -use Database\Factories\AccessoryFactory; -use Database\Factories\CompanyFactory; use Illuminate\Support\Str; -use Database\Factories\UserFactory; -use Database\Factories\ImportFactory; use PHPUnit\Framework\Attributes\Test; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Arr; use Illuminate\Testing\TestResponse; -use PHPUnit\Framework\Attributes\DataProvider; use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\AccessoriesImportFileBuilder as ImportFileBuilder; use Tests\Support\Importing\CleansUpImportFiles; diff --git a/tests/Feature/Importing/Api/ImportAssetsTest.php b/tests/Feature/Importing/Api/ImportAssetsTest.php index 50c31d6d9..e001add38 100644 --- a/tests/Feature/Importing/Api/ImportAssetsTest.php +++ b/tests/Feature/Importing/Api/ImportAssetsTest.php @@ -9,17 +9,12 @@ use App\Models\Import; use App\Models\User; use App\Notifications\CheckoutAssetNotification; use Carbon\Carbon; -use Database\Factories\AssetFactory; -use Database\Factories\CustomFieldFactory; -use Illuminate\Support\Str; -use Database\Factories\UserFactory; -use Database\Factories\ImportFactory; -use PHPUnit\Framework\Attributes\Test; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Str; use Illuminate\Testing\TestResponse; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\AssetsImportFileBuilder as ImportFileBuilder; use Tests\Support\Importing\CleansUpImportFiles; diff --git a/tests/Feature/Importing/Api/ImportComponentsTest.php b/tests/Feature/Importing/Api/ImportComponentsTest.php index 20f0e803d..376b5b32e 100644 --- a/tests/Feature/Importing/Api/ImportComponentsTest.php +++ b/tests/Feature/Importing/Api/ImportComponentsTest.php @@ -6,15 +6,11 @@ use App\Models\Actionlog as ActionLog; use App\Models\Component; use App\Models\Import; use App\Models\User; -use Database\Factories\ComponentFactory; -use Illuminate\Support\Str; -use Database\Factories\UserFactory; -use Database\Factories\ImportFactory; -use PHPUnit\Framework\Attributes\Test; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Str; use Illuminate\Testing\TestResponse; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\CleansUpImportFiles; use Tests\Support\Importing\ComponentsImportFileBuilder as ImportFileBuilder; diff --git a/tests/Feature/Importing/Api/ImportConsumablesTest.php b/tests/Feature/Importing/Api/ImportConsumablesTest.php index d48486d19..81bfdf4bf 100644 --- a/tests/Feature/Importing/Api/ImportConsumablesTest.php +++ b/tests/Feature/Importing/Api/ImportConsumablesTest.php @@ -6,15 +6,11 @@ use App\Models\Actionlog as ActivityLog; use App\Models\Consumable; use App\Models\Import; use App\Models\User; -use Database\Factories\ConsumableFactory; -use Illuminate\Support\Str; -use Database\Factories\UserFactory; -use Database\Factories\ImportFactory; -use PHPUnit\Framework\Attributes\Test; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Str; use Illuminate\Testing\TestResponse; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\CleansUpImportFiles; use Tests\Support\Importing\ConsumablesImportFileBuilder as ImportFileBuilder; diff --git a/tests/Feature/Importing/Api/ImportDataTestCase.php b/tests/Feature/Importing/Api/ImportDataTestCase.php index 546b6c0f3..eaa2a8f03 100644 --- a/tests/Feature/Importing/Api/ImportDataTestCase.php +++ b/tests/Feature/Importing/Api/ImportDataTestCase.php @@ -2,8 +2,8 @@ namespace Tests\Feature\Importing\Api; -use Tests\TestCase; use Illuminate\Testing\TestResponse; +use Tests\TestCase; abstract class ImportDataTestCase extends TestCase { diff --git a/tests/Feature/Importing/Api/ImportLicenseTest.php b/tests/Feature/Importing/Api/ImportLicenseTest.php index fb4b9b932..0cd5fe447 100644 --- a/tests/Feature/Importing/Api/ImportLicenseTest.php +++ b/tests/Feature/Importing/Api/ImportLicenseTest.php @@ -6,14 +6,10 @@ use App\Models\Actionlog as ActivityLog; use App\Models\Import; use App\Models\License; use App\Models\User; -use Illuminate\Support\Str; -use Database\Factories\UserFactory; -use Database\Factories\ImportFactory; -use Database\Factories\LicenseFactory; -use PHPUnit\Framework\Attributes\Test; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Support\Str; use Illuminate\Testing\TestResponse; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\CleansUpImportFiles; use Tests\Support\Importing\LicensesImportFileBuilder as ImportFileBuilder; diff --git a/tests/Feature/Importing/Api/ImportUsersTest.php b/tests/Feature/Importing/Api/ImportUsersTest.php index eb624e560..f8c0b7c74 100644 --- a/tests/Feature/Importing/Api/ImportUsersTest.php +++ b/tests/Feature/Importing/Api/ImportUsersTest.php @@ -6,18 +6,13 @@ use App\Models\Asset; use App\Models\Import; use App\Models\Location; use App\Models\User; -use Database\Factories\AssetFactory; -use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Str; -use Database\Factories\UserFactory; -use Database\Factories\ImportFactory; -use PHPUnit\Framework\Attributes\Test; use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Notification; +use Illuminate\Support\Str; use Illuminate\Testing\TestResponse; -use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Tests\Concerns\TestsPermissionsRequirement; use Tests\Support\Importing\CleansUpImportFiles; use Tests\Support\Importing\UsersImportFileBuilder as ImportFileBuilder; From 8035326675e9a479c030687dc5a8079fd43e34f5 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 3 Oct 2024 16:53:19 -0700 Subject: [PATCH 9/9] Add test --- .../Feature/Importing/Api/GeneralImportTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/Feature/Importing/Api/GeneralImportTest.php diff --git a/tests/Feature/Importing/Api/GeneralImportTest.php b/tests/Feature/Importing/Api/GeneralImportTest.php new file mode 100644 index 000000000..5c38dab7f --- /dev/null +++ b/tests/Feature/Importing/Api/GeneralImportTest.php @@ -0,0 +1,16 @@ +actingAsForApi(User::factory()->canImport()->create()); + + $this->importFileResponse(['import' => 9999, 'import-type' => 'accessory']) + ->assertStatusMessageIs('import-errors'); + } +}