test working
This commit is contained in:
parent
b59bf495e1
commit
8a99cc1391
3 changed files with 28 additions and 7 deletions
|
@ -12,10 +12,10 @@ use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
class CheckoutRequest extends Controller
|
class CheckoutRequest extends Controller
|
||||||
{
|
{
|
||||||
public function store(CheckoutRequestRequest $request, Asset $asset): JsonResponse
|
public function store(Asset $asset): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
CreateCheckoutRequest::run($asset, $request->validated()['user_id']);
|
CreateCheckoutRequest::run($asset, auth()->user());
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.requests.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.requests.success')));
|
||||||
} catch (AssetNotRequestable $e) {
|
} catch (AssetNotRequestable $e) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', 'Asset is not requestable'));
|
return response()->json(Helper::formatStandardApiResponse('error', 'Asset is not requestable'));
|
||||||
|
|
|
@ -347,12 +347,24 @@ class AssetFactory extends Factory
|
||||||
|
|
||||||
public function requestable()
|
public function requestable()
|
||||||
{
|
{
|
||||||
return $this->state(['requestable' => true]);
|
$id = Statuslabel::factory()->create([
|
||||||
|
'archived' => false,
|
||||||
|
'deployable' => true,
|
||||||
|
'pending' => true,
|
||||||
|
])->id;
|
||||||
|
//return $this->state(['requestable' => true]);
|
||||||
|
return $this->state(['status_id' => $id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nonrequestable()
|
public function nonrequestable()
|
||||||
{
|
{
|
||||||
return $this->state(['requestable' => false]);
|
$id = Statuslabel::factory()->create([
|
||||||
|
'archived' => true,
|
||||||
|
'deployable' => false,
|
||||||
|
'pending' => false,
|
||||||
|
])->id;
|
||||||
|
//return $this->state(['requestable' => false]);
|
||||||
|
return $this->state(['status_id' => $id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function noPurchaseOrEolDate()
|
public function noPurchaseOrEolDate()
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Checkouts\Api;
|
namespace Tests\Feature\Checkouts\Api;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use Notification;
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
use App\Events\CheckoutableCheckedOut;
|
use App\Events\CheckoutableCheckedOut;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
@ -23,11 +25,18 @@ class AssetCheckoutTest extends TestCase
|
||||||
|
|
||||||
public function testCheckoutRequest()
|
public function testCheckoutRequest()
|
||||||
{
|
{
|
||||||
$asset = Asset::factory()->create();
|
Notification::fake();
|
||||||
|
$requestable = Asset::factory()->requestable()->create();
|
||||||
|
$nonRequestable = Asset::factory()->nonrequestable()->create();
|
||||||
|
|
||||||
$this->actingAsForApi(User::factory()->create())
|
$this->actingAsForApi(User::factory()->create())
|
||||||
->post(route('api.assets.requests.store', $asset->id))
|
->post(route('api.assets.requests.store', $requestable->id))
|
||||||
->assertOk();
|
->assertStatusMessageIs('success');
|
||||||
|
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->post(route('api.assets.requests.store', $nonRequestable->id))
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCheckingOutAssetRequiresCorrectPermission()
|
public function testCheckingOutAssetRequiresCorrectPermission()
|
||||||
|
|
Loading…
Add table
Reference in a new issue