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
|
||||
{
|
||||
public function store(CheckoutRequestRequest $request, Asset $asset): JsonResponse
|
||||
public function store(Asset $asset): JsonResponse
|
||||
{
|
||||
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')));
|
||||
} catch (AssetNotRequestable $e) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', 'Asset is not requestable'));
|
||||
|
|
|
@ -347,12 +347,24 @@ class AssetFactory extends Factory
|
|||
|
||||
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()
|
||||
{
|
||||
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()
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Tests\Feature\Checkouts\Api;
|
||||
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Notification;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use App\Events\CheckoutableCheckedOut;
|
||||
use App\Models\Asset;
|
||||
|
@ -23,11 +25,18 @@ class AssetCheckoutTest extends TestCase
|
|||
|
||||
public function testCheckoutRequest()
|
||||
{
|
||||
$asset = Asset::factory()->create();
|
||||
Notification::fake();
|
||||
$requestable = Asset::factory()->requestable()->create();
|
||||
$nonRequestable = Asset::factory()->nonrequestable()->create();
|
||||
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->post(route('api.assets.requests.store', $asset->id))
|
||||
->assertOk();
|
||||
->post(route('api.assets.requests.store', $requestable->id))
|
||||
->assertStatusMessageIs('success');
|
||||
|
||||
$this->actingAsForApi(User::factory()->create())
|
||||
->post(route('api.assets.requests.store', $nonRequestable->id))
|
||||
->assertStatusMessageIs('error');
|
||||
|
||||
}
|
||||
|
||||
public function testCheckingOutAssetRequiresCorrectPermission()
|
||||
|
|
Loading…
Add table
Reference in a new issue