Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
1949e1e1e9
4 changed files with 188 additions and 5 deletions
|
@ -351,11 +351,6 @@ class AssetsController extends Controller
|
||||||
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on asset update with '.$status->getStatuslabelType().' status', date('Y-m-d H:i:s'), $originalValues));
|
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), 'Checkin on asset update with '.$status->getStatuslabelType().' status', date('Y-m-d H:i:s'), $originalValues));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($asset->assigned_to == '') {
|
|
||||||
$asset->location_id = $request->input('rtd_location_id', null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($request->filled('image_delete')) {
|
if ($request->filled('image_delete')) {
|
||||||
try {
|
try {
|
||||||
unlink(public_path().'/uploads/assets/'.$asset->image);
|
unlink(public_path().'/uploads/assets/'.$asset->image);
|
||||||
|
|
|
@ -65,6 +65,7 @@ class LogListener
|
||||||
$logaction->filename = $event->acceptance->stored_eula_file;
|
$logaction->filename = $event->acceptance->stored_eula_file;
|
||||||
$logaction->note = $event->acceptance->note;
|
$logaction->note = $event->acceptance->note;
|
||||||
$logaction->action_type = 'accepted';
|
$logaction->action_type = 'accepted';
|
||||||
|
$logaction->action_date = $event->acceptance->accepted_at;
|
||||||
|
|
||||||
// TODO: log the actual license seat that was checked out
|
// TODO: log the actual license seat that was checked out
|
||||||
if ($event->acceptance->checkoutable instanceof LicenseSeat) {
|
if ($event->acceptance->checkoutable instanceof LicenseSeat) {
|
||||||
|
@ -82,6 +83,7 @@ class LogListener
|
||||||
$logaction->accept_signature = $event->acceptance->signature_filename;
|
$logaction->accept_signature = $event->acceptance->signature_filename;
|
||||||
$logaction->note = $event->acceptance->note;
|
$logaction->note = $event->acceptance->note;
|
||||||
$logaction->action_type = 'declined';
|
$logaction->action_type = 'declined';
|
||||||
|
$logaction->action_date = $event->acceptance->declined_at;
|
||||||
|
|
||||||
// TODO: log the actual license seat that was checked out
|
// TODO: log the actual license seat that was checked out
|
||||||
if ($event->acceptance->checkoutable instanceof LicenseSeat) {
|
if ($event->acceptance->checkoutable instanceof LicenseSeat) {
|
||||||
|
|
|
@ -102,4 +102,27 @@ class EditAssetTest extends TestCase
|
||||||
}, 1);
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCurrentLocationIsNotUpdatedOnEdit()
|
||||||
|
{
|
||||||
|
$defaultLocation = Location::factory()->create();
|
||||||
|
$currentLocation = Location::factory()->create();
|
||||||
|
$asset = Asset::factory()->create([
|
||||||
|
'location_id' => $currentLocation->id,
|
||||||
|
'rtd_location_id' => $defaultLocation->id
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->viewAssets()->editAssets()->create())
|
||||||
|
->put(route('hardware.update', $asset), [
|
||||||
|
'redirect_option' => 'item',
|
||||||
|
'name' => 'New name',
|
||||||
|
'asset_tags' => 'New Asset Tag',
|
||||||
|
'status_id' => $asset->status_id,
|
||||||
|
'model_id' => $asset->model_id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$asset->refresh();
|
||||||
|
$this->assertEquals('New name', $asset->name);
|
||||||
|
$this->assertEquals($currentLocation->id, $asset->location_id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
163
tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php
Normal file
163
tests/Feature/CheckoutAcceptances/Ui/AssetAcceptanceTest.php
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\CheckoutAcceptances\Ui;
|
||||||
|
|
||||||
|
use App\Events\CheckoutAccepted;
|
||||||
|
use App\Models\Actionlog;
|
||||||
|
use App\Models\Asset;
|
||||||
|
use App\Models\CheckoutAcceptance;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AssetAcceptanceTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testAssetCheckoutAcceptPageRenders()
|
||||||
|
{
|
||||||
|
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
||||||
|
|
||||||
|
$this->actingAs($checkoutAcceptance->assignedTo)
|
||||||
|
->get(route('account.accept.item', $checkoutAcceptance))
|
||||||
|
->assertViewIs('account.accept.create');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotAcceptAssetAlreadyAccepted()
|
||||||
|
{
|
||||||
|
Event::fake([CheckoutAccepted::class]);
|
||||||
|
|
||||||
|
$checkoutAcceptance = CheckoutAcceptance::factory()->accepted()->create();
|
||||||
|
|
||||||
|
$this->assertFalse($checkoutAcceptance->isPending());
|
||||||
|
|
||||||
|
$this->actingAs($checkoutAcceptance->assignedTo)
|
||||||
|
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||||
|
'asset_acceptance' => 'accepted',
|
||||||
|
'note' => 'my note',
|
||||||
|
])
|
||||||
|
->assertRedirectToRoute('account.accept')
|
||||||
|
->assertSessionHas('error');
|
||||||
|
|
||||||
|
Event::assertNotDispatched(CheckoutAccepted::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCannotAcceptAssetForAnotherUser()
|
||||||
|
{
|
||||||
|
Event::fake([CheckoutAccepted::class]);
|
||||||
|
|
||||||
|
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
||||||
|
|
||||||
|
$this->assertTrue($checkoutAcceptance->isPending());
|
||||||
|
|
||||||
|
$anotherUser = User::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAs($anotherUser)
|
||||||
|
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||||
|
'asset_acceptance' => 'accepted',
|
||||||
|
'note' => 'my note',
|
||||||
|
])
|
||||||
|
->assertRedirectToRoute('account.accept')
|
||||||
|
->assertSessionHas('error');
|
||||||
|
|
||||||
|
$this->assertTrue($checkoutAcceptance->fresh()->isPending());
|
||||||
|
|
||||||
|
Event::assertNotDispatched(CheckoutAccepted::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUserCanAcceptAsset()
|
||||||
|
{
|
||||||
|
Event::fake([CheckoutAccepted::class]);
|
||||||
|
|
||||||
|
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
||||||
|
|
||||||
|
$this->assertTrue($checkoutAcceptance->isPending());
|
||||||
|
|
||||||
|
$this->actingAs($checkoutAcceptance->assignedTo)
|
||||||
|
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||||
|
'asset_acceptance' => 'accepted',
|
||||||
|
'note' => 'my note',
|
||||||
|
])
|
||||||
|
->assertRedirectToRoute('account.accept')
|
||||||
|
->assertSessionHas('success');
|
||||||
|
|
||||||
|
$checkoutAcceptance->refresh();
|
||||||
|
|
||||||
|
$this->assertFalse($checkoutAcceptance->isPending());
|
||||||
|
$this->assertNotNull($checkoutAcceptance->accepted_at);
|
||||||
|
$this->assertNull($checkoutAcceptance->declined_at);
|
||||||
|
|
||||||
|
Event::assertDispatched(CheckoutAccepted::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUserCanDeclineAsset()
|
||||||
|
{
|
||||||
|
Event::fake([CheckoutAccepted::class]);
|
||||||
|
|
||||||
|
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
||||||
|
|
||||||
|
$this->assertTrue($checkoutAcceptance->isPending());
|
||||||
|
|
||||||
|
$this->actingAs($checkoutAcceptance->assignedTo)
|
||||||
|
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||||
|
'asset_acceptance' => 'declined',
|
||||||
|
'note' => 'my note',
|
||||||
|
])
|
||||||
|
->assertRedirectToRoute('account.accept')
|
||||||
|
->assertSessionHas('success');
|
||||||
|
|
||||||
|
$checkoutAcceptance->refresh();
|
||||||
|
|
||||||
|
$this->assertFalse($checkoutAcceptance->isPending());
|
||||||
|
$this->assertNull($checkoutAcceptance->accepted_at);
|
||||||
|
$this->assertNotNull($checkoutAcceptance->declined_at);
|
||||||
|
|
||||||
|
Event::assertNotDispatched(CheckoutAccepted::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testActionLoggedWhenAcceptingAsset()
|
||||||
|
{
|
||||||
|
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
||||||
|
|
||||||
|
$this->actingAs($checkoutAcceptance->assignedTo)
|
||||||
|
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||||
|
'asset_acceptance' => 'accepted',
|
||||||
|
'note' => 'my note',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue(Actionlog::query()
|
||||||
|
->where([
|
||||||
|
'action_type' => 'accepted',
|
||||||
|
'target_id' => $checkoutAcceptance->assignedTo->id,
|
||||||
|
'target_type' => User::class,
|
||||||
|
'note' => 'my note',
|
||||||
|
'item_type' => Asset::class,
|
||||||
|
'item_id' => $checkoutAcceptance->checkoutable->id,
|
||||||
|
])
|
||||||
|
->whereNotNull('action_date')
|
||||||
|
->exists()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testActionLoggedWhenDecliningAsset()
|
||||||
|
{
|
||||||
|
$checkoutAcceptance = CheckoutAcceptance::factory()->pending()->create();
|
||||||
|
|
||||||
|
$this->actingAs($checkoutAcceptance->assignedTo)
|
||||||
|
->post(route('account.store-acceptance', $checkoutAcceptance), [
|
||||||
|
'asset_acceptance' => 'declined',
|
||||||
|
'note' => 'my note',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue(Actionlog::query()
|
||||||
|
->where([
|
||||||
|
'action_type' => 'declined',
|
||||||
|
'target_id' => $checkoutAcceptance->assignedTo->id,
|
||||||
|
'target_type' => User::class,
|
||||||
|
'note' => 'my note',
|
||||||
|
'item_type' => Asset::class,
|
||||||
|
'item_id' => $checkoutAcceptance->checkoutable->id,
|
||||||
|
])
|
||||||
|
->whereNotNull('action_date')
|
||||||
|
->exists()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue