mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
adds @snipe's rules for undeleted assigned targets
This commit is contained in:
parent
cdb1140f10
commit
8ce577db37
|
@ -114,6 +114,9 @@ class Asset extends Depreciable
|
|||
'notes' => ['nullable', 'string', 'max:65535'],
|
||||
'assigned_to' => ['nullable', 'integer'],
|
||||
'requestable' => ['nullable', 'boolean'],
|
||||
'assigned_user' => ['nullable', 'exists:users,id,deleted_at,NULL'],
|
||||
'assigned_location' => ['nullable', 'exists:locations,id,deleted_at,NULL'],
|
||||
'assigned_asset' => ['nullable', 'exists:assets,id,deleted_at,NULL']
|
||||
];
|
||||
|
||||
|
||||
|
|
|
@ -25,4 +25,9 @@ class LocationFactory extends Factory
|
|||
'image' => rand(1, 9).'.jpg',
|
||||
];
|
||||
}
|
||||
|
||||
public function deleted(): self
|
||||
{
|
||||
return $this->state(['deleted_at' => $this->faker->dateTime()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -299,4 +299,9 @@ class UserFactory extends Factory
|
|||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function deleted(): self
|
||||
{
|
||||
return $this->state(['deleted_at' => $this->faker->dateTime()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -306,4 +306,121 @@ class AssetUpdateTest extends TestCase
|
|||
$asset->refresh();
|
||||
$this->assertEquals("encrypted value should not change", Crypt::decrypt($asset->{$field->db_column_name()}));
|
||||
}
|
||||
|
||||
public function testCheckoutToUserOnAssetUpdate()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
$user = User::factory()->editAssets()->create();
|
||||
$assigned_user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAsForApi($user)
|
||||
->patchJson(route('api.assets.update', $asset->id), [
|
||||
'assigned_user' => $assigned_user->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->json();
|
||||
|
||||
$asset->refresh();
|
||||
$this->assertEquals($assigned_user->id, $asset->assigned_to);
|
||||
$this->assertEquals($asset->assigned_type, 'App\Models\User');
|
||||
}
|
||||
|
||||
public function testCheckoutToDeletedUserFailsOnAssetUpdate()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
$user = User::factory()->editAssets()->create();
|
||||
$assigned_user = User::factory()->deleted()->create();
|
||||
|
||||
$this->actingAsForApi($user)
|
||||
->patchJson(route('api.assets.update', $asset->id), [
|
||||
'assigned_user' => $assigned_user->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
|
||||
$asset->refresh();
|
||||
$this->assertNull($asset->assigned_to);
|
||||
$this->assertNull($asset->assigned_type);
|
||||
}
|
||||
|
||||
public function testCheckoutToLocationOnAssetUpdate()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
$user = User::factory()->editAssets()->create();
|
||||
$assigned_location = Location::factory()->create();
|
||||
|
||||
$this->actingAsForApi($user)
|
||||
->patchJson(route('api.assets.update', $asset->id), [
|
||||
'assigned_location' => $assigned_location->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->json();
|
||||
|
||||
$asset->refresh();
|
||||
$this->assertEquals($assigned_location->id, $asset->assigned_to);
|
||||
$this->assertEquals($asset->assigned_type, 'App\Models\Location');
|
||||
|
||||
}
|
||||
|
||||
public function testCheckoutToDeletedLocationFailsOnAssetUpdate()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
$user = User::factory()->editAssets()->create();
|
||||
$assigned_location = Location::factory()->deleted()->create();
|
||||
|
||||
$this->actingAsForApi($user)
|
||||
->patchJson(route('api.assets.update', $asset->id), [
|
||||
'assigned_location' => $assigned_location->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
|
||||
$asset->refresh();
|
||||
$this->assertNull($asset->assigned_to);
|
||||
$this->assertNull($asset->assigned_type);
|
||||
}
|
||||
|
||||
public function testCheckoutAssetOnAssetUpdate()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
$user = User::factory()->editAssets()->create();
|
||||
$assigned_asset = Asset::factory()->create();
|
||||
|
||||
$this->actingAsForApi($user)
|
||||
->patchJson(route('api.assets.update', $asset->id), [
|
||||
'assigned_asset' => $assigned_asset->id,
|
||||
'checkout_to_type' => 'user',
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('success')
|
||||
->json();
|
||||
|
||||
$asset->refresh();
|
||||
$this->assertEquals($assigned_asset->id, $asset->assigned_to);
|
||||
$this->assertEquals($asset->assigned_type, 'App\Models\Asset');
|
||||
|
||||
}
|
||||
|
||||
public function testCheckoutToDeletedAssetFailsOnAssetUpdate()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
$user = User::factory()->editAssets()->create();
|
||||
$assigned_asset = Asset::factory()->deleted()->create();
|
||||
|
||||
$this->actingAsForApi($user)
|
||||
->patchJson(route('api.assets.update', $asset->id), [
|
||||
'assigned_asset' => $assigned_asset->id,
|
||||
])
|
||||
->assertOk()
|
||||
->assertStatusMessageIs('error')
|
||||
->json();
|
||||
|
||||
$asset->refresh();
|
||||
$this->assertNull($asset->assigned_to);
|
||||
$this->assertNull($asset->assigned_type);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue