mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 05:04:07 -08:00
Swap factory syntax
This commit is contained in:
parent
88d549e7c5
commit
e213053775
|
@ -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',
|
||||
|
|
|
@ -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' => [
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue