@@ -423,6 +423,86 @@ public function testCheckoutToUserOnAssetUpdate()
423423 $ this ->assertEquals ($ asset ->assigned_type , 'App\Models\User ' );
424424 }
425425
426+ public function testCheckoutToUserWithAssignedToAndAssignedType ()
427+ {
428+ $ asset = Asset::factory ()->create ();
429+ $ user = User::factory ()->editAssets ()->create ();
430+ $ assigned_user = User::factory ()->create ();
431+
432+ $ response = $ this ->actingAsForApi ($ user )
433+ ->patchJson (route ('api.assets.update ' , $ asset ->id ), [
434+ 'assigned_to ' => $ assigned_user ->id ,
435+ 'assigned_type ' => User::class
436+ ])
437+ ->assertOk ()
438+ ->assertStatusMessageIs ('success ' )
439+ ->json ();
440+
441+ $ asset ->refresh ();
442+ $ this ->assertEquals ($ assigned_user ->id , $ asset ->assigned_to );
443+ $ this ->assertEquals ($ asset ->assigned_type , 'App\Models\User ' );
444+ }
445+
446+ public function testCheckoutToUserWithAssignedToWithoutAssignedType ()
447+ {
448+ $ asset = Asset::factory ()->create ();
449+ $ user = User::factory ()->editAssets ()->create ();
450+ $ assigned_user = User::factory ()->create ();
451+
452+ $ response = $ this ->actingAsForApi ($ user )
453+ ->patchJson (route ('api.assets.update ' , $ asset ->id ), [
454+ 'assigned_to ' => $ assigned_user ->id ,
455+ // 'assigned_type' => User::class //deliberately omit assigned_type
456+ ])
457+ ->assertOk ()
458+ ->assertStatusMessageIs ('error ' );
459+
460+ $ asset ->refresh ();
461+ $ this ->assertNotEquals ($ assigned_user ->id , $ asset ->assigned_to );
462+ $ this ->assertNotEquals ($ asset ->assigned_type , 'App\Models\User ' );
463+ $ this ->assertNotNull ($ response ->json ('messages.assigned_type ' ));
464+ }
465+
466+ public function testCheckoutToUserWithAssignedToWithBadAssignedType ()
467+ {
468+ $ asset = Asset::factory ()->create ();
469+ $ user = User::factory ()->editAssets ()->create ();
470+ $ assigned_user = User::factory ()->create ();
471+
472+ $ response = $ this ->actingAsForApi ($ user )
473+ ->patchJson (route ('api.assets.update ' , $ asset ->id ), [
474+ 'assigned_to ' => $ assigned_user ->id ,
475+ 'assigned_type ' => 'more_deliberate_nonsense ' //deliberately bad assigned_type
476+ ])
477+ ->assertOk ()
478+ ->assertStatusMessageIs ('error ' );
479+
480+ $ asset ->refresh ();
481+ $ this ->assertNotEquals ($ assigned_user ->id , $ asset ->assigned_to );
482+ $ this ->assertNotEquals ($ asset ->assigned_type , 'App\Models\User ' );
483+ $ this ->assertNotNull ($ response ->json ('messages.assigned_type ' ));
484+ }
485+
486+ public function testCheckoutToUserWithoutAssignedToWithAssignedType ()
487+ {
488+ $ asset = Asset::factory ()->create ();
489+ $ user = User::factory ()->editAssets ()->create ();
490+ $ assigned_user = User::factory ()->create ();
491+
492+ $ response = $ this ->actingAsForApi ($ user )
493+ ->patchJson (route ('api.assets.update ' , $ asset ->id ), [
494+ //'assigned_to' => $assigned_user->id, // deliberately omit assigned_to
495+ 'assigned_type ' => User::class
496+ ])
497+ ->assertOk ()
498+ ->assertStatusMessageIs ('error ' );
499+
500+ $ asset ->refresh ();
501+ $ this ->assertNotEquals ($ assigned_user ->id , $ asset ->assigned_to );
502+ $ this ->assertNotEquals ($ asset ->assigned_type , 'App\Models\User ' );
503+ $ this ->assertNotNull ($ response ->json ('messages.assigned_to ' ));
504+ }
505+
426506 public function testCheckoutToDeletedUserFailsOnAssetUpdate ()
427507 {
428508 $ asset = Asset::factory ()->create ();
0 commit comments