mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
tests 'n stuff
This commit is contained in:
parent
3e97f0274c
commit
9f815996c7
|
@ -46,8 +46,6 @@ class StoreAssetAction
|
||||||
$assigned_user = null,
|
$assigned_user = null,
|
||||||
$assigned_asset = null,
|
$assigned_asset = null,
|
||||||
$assigned_location = null,
|
$assigned_location = null,
|
||||||
$custom_fields = null,
|
|
||||||
|
|
||||||
$last_audit_date = null,
|
$last_audit_date = null,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,9 +14,13 @@ use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Watson\Validating\ValidationException;
|
||||||
|
|
||||||
class UpdateAssetAction
|
class UpdateAssetAction
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
public static function run(
|
public static function run(
|
||||||
Asset $asset,
|
Asset $asset,
|
||||||
ImageUploadRequest $request, //very much would like this to go away
|
ImageUploadRequest $request, //very much would like this to go away
|
||||||
|
@ -111,7 +115,11 @@ class UpdateAssetAction
|
||||||
|
|
||||||
$asset->serial = $serial;
|
$asset->serial = $serial;
|
||||||
|
|
||||||
$asset->name = $name;
|
if ($request->filled('null_name')) {
|
||||||
|
$asset->name = null;
|
||||||
|
} else {
|
||||||
|
$asset->name = $name ?? $asset->name;
|
||||||
|
}
|
||||||
$asset->company_id = Company::getIdForCurrentUser($company_id);
|
$asset->company_id = Company::getIdForCurrentUser($company_id);
|
||||||
$asset->model_id = $model_id ?? $asset->model_id;
|
$asset->model_id = $model_id ?? $asset->model_id;
|
||||||
$asset->order_number = $order_number ?? $asset->order_number;
|
$asset->order_number = $order_number ?? $asset->order_number;
|
||||||
|
@ -127,10 +135,12 @@ class UpdateAssetAction
|
||||||
// FIXME: No idea why this is returning a Builder error on db_column_name.
|
// FIXME: No idea why this is returning a Builder error on db_column_name.
|
||||||
// Need to investigate and fix. Using static method for now.
|
// Need to investigate and fix. Using static method for now.
|
||||||
|
|
||||||
$model = AssetModel::find($request->get('model_id'));
|
$model = $asset->model;
|
||||||
if (($model) && ($model->fieldset)) {
|
if (($model) && ($model->fieldset)) {
|
||||||
|
dump($model->fieldset->fields);
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
|
|
||||||
|
|
||||||
if ($field->field_encrypted == '1') {
|
if ($field->field_encrypted == '1') {
|
||||||
if (Gate::allows('assets.view.encrypted_custom_fields')) {
|
if (Gate::allows('assets.view.encrypted_custom_fields')) {
|
||||||
if (is_array($request->input($field->db_column))) {
|
if (is_array($request->input($field->db_column))) {
|
||||||
|
|
|
@ -652,7 +652,7 @@ class AssetsController extends Controller
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$updatedAsset = UpdateAssetAction::run($asset, $request, ...$request->validated());
|
$updatedAsset = UpdateAssetAction::run($asset, $request, ...$request->validated());
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', trans('admin/hardware/message.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success')));
|
||||||
} catch (CheckoutNotAllowed $e) {
|
} catch (CheckoutNotAllowed $e) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $e->getMessage()), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, $e->getMessage()), 200);
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
|
@ -680,7 +680,7 @@ class AssetsController extends Controller
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.delete.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.delete.success')));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
report($e);
|
report($e);
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'something went wrong: '));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.something_went_wrong')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,7 @@ class AssetsController extends Controller
|
||||||
$asset = StoreAssetAction::run(
|
$asset = StoreAssetAction::run(
|
||||||
model_id: $request->validated('model_id'),
|
model_id: $request->validated('model_id'),
|
||||||
status_id: $request->validated('status_id'),
|
status_id: $request->validated('status_id'),
|
||||||
|
request: $request,
|
||||||
name: $request->validated('name'),
|
name: $request->validated('name'),
|
||||||
serial: $request->has('serials') ? $serials[$key] : null,
|
serial: $request->has('serials') ? $serials[$key] : null,
|
||||||
company_id: $request->validated('company_id'),
|
company_id: $request->validated('company_id'),
|
||||||
|
@ -140,8 +141,6 @@ class AssetsController extends Controller
|
||||||
assigned_user: $request->validated('assigned_user'),
|
assigned_user: $request->validated('assigned_user'),
|
||||||
assigned_asset: $request->validated('assigned_asset'),
|
assigned_asset: $request->validated('assigned_asset'),
|
||||||
assigned_location: $request->validated('assigned_location'),
|
assigned_location: $request->validated('assigned_location'),
|
||||||
custom_fields: $custom_fields,
|
|
||||||
request: $request, //this is just for the handleImages method... would love to figure out a different way of doing this
|
|
||||||
last_audit_date: $request->validated('last_audit_date'),
|
last_audit_date: $request->validated('last_audit_date'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +152,6 @@ class AssetsController extends Controller
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.create.error'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.create.error'));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
report($e);
|
report($e);
|
||||||
dd($e);
|
|
||||||
return redirect()->back()->with('error', 'something bad');
|
return redirect()->back()->with('error', 'something bad');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +281,7 @@ class AssetsController extends Controller
|
||||||
* @param int $assetId
|
* @param int $assetId
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
*/
|
*/
|
||||||
public function destroy(Asset $asset): RedirectResponse
|
public function destroy(Asset $asset, $request): RedirectResponse
|
||||||
{
|
{
|
||||||
$this->authorize('delete', $asset);
|
$this->authorize('delete', $asset);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Assets;
|
namespace App\Http\Controllers\Assets;
|
||||||
|
|
||||||
|
use App\Actions\Assets\StoreAssetAction;
|
||||||
use App\Actions\Assets\UpdateAssetAction;
|
use App\Actions\Assets\UpdateAssetAction;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Http\Controllers\CheckInOutRequest;
|
use App\Http\Controllers\CheckInOutRequest;
|
||||||
|
|
|
@ -80,6 +80,7 @@ class UpdateAssetTest extends TestCase
|
||||||
->assertStatusMessageIs('success')
|
->assertStatusMessageIs('success')
|
||||||
->json();
|
->json();
|
||||||
|
|
||||||
|
dd($response);
|
||||||
$updatedAsset = Asset::find($response['payload']['id']);
|
$updatedAsset = Asset::find($response['payload']['id']);
|
||||||
|
|
||||||
$this->assertEquals('2024-06-02', $updatedAsset->asset_eol_date);
|
$this->assertEquals('2024-06-02', $updatedAsset->asset_eol_date);
|
||||||
|
|
|
@ -7,6 +7,7 @@ use App\Models\Category;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
|
use Watson\Validating\ValidationException;
|
||||||
|
|
||||||
class AssetTest extends TestCase
|
class AssetTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -31,7 +32,8 @@ class AssetTest extends TestCase
|
||||||
$b = Asset::factory()->make(['asset_tag' => Asset::autoincrement_asset() ]);
|
$b = Asset::factory()->make(['asset_tag' => Asset::autoincrement_asset() ]);
|
||||||
|
|
||||||
$this->assertTrue($a->save());
|
$this->assertTrue($a->save());
|
||||||
$this->assertFalse($b->save());
|
$this->expectException(ValidationException::class);
|
||||||
|
$b->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAutoIncrementDouble()
|
public function testAutoIncrementDouble()
|
||||||
|
@ -181,7 +183,7 @@ class AssetTest extends TestCase
|
||||||
]
|
]
|
||||||
)->id,
|
)->id,
|
||||||
'warranty_months' => 24,
|
'warranty_months' => 24,
|
||||||
'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)
|
'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)->format("Y-m-d")
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ class DepreciationTest extends TestCase
|
||||||
->create(
|
->create(
|
||||||
[
|
[
|
||||||
'category_id' => Category::factory()->assetLaptopCategory()->create(),
|
'category_id' => Category::factory()->assetLaptopCategory()->create(),
|
||||||
'purchase_date' => now()->subDecade(),
|
'purchase_date' => now()->subDecade()->format("Y-m-d"),
|
||||||
'purchase_cost' => 4000,
|
'purchase_cost' => 4000,
|
||||||
]);
|
]);
|
||||||
$asset->model->update([
|
$asset->model->update([
|
||||||
|
@ -63,7 +63,7 @@ class DepreciationTest extends TestCase
|
||||||
->create(
|
->create(
|
||||||
[
|
[
|
||||||
'category_id' => Category::factory()->assetLaptopCategory()->create(),
|
'category_id' => Category::factory()->assetLaptopCategory()->create(),
|
||||||
'purchase_date' => now()->subDecade(),
|
'purchase_date' => now()->subDecade()->format("Y-m-d"),
|
||||||
'purchase_cost' => 4000,
|
'purchase_cost' => 4000,
|
||||||
]);
|
]);
|
||||||
$asset->model->update([
|
$asset->model->update([
|
||||||
|
|
Loading…
Reference in a new issue