You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

  1. <?php
  2. namespace Tests\Feature\Collection;
  3. use App\Models\Collection;
  4. use Tests\Bootstrap;
  5. use App\Models\User;
  6. use Illuminate\Support\Arr;
  7. class CollectionUpdateTest extends Bootstrap
  8. {
  9. public function test_collection_update_success()
  10. {
  11. $this->modelWithPolicy('collections', ['permission:collections.update'])
  12. ->loginAs(['collections.update'])
  13. ->putJson(
  14. route("api.collections.update", $collection = $this->one(Collection::class)),
  15. $update = $this->make(Collection::class, withDependency: true)
  16. )
  17. ->assertOk();
  18. }
  19. /**
  20. * @testWith
  21. * ["name:gt"]
  22. */
  23. public function test_collection_update_unprocessable($field)
  24. {
  25. $this->modelWithPolicy('collections', ['permission:collections.update'])
  26. ->loginAs(['collections.update'])->putJson(
  27. route("api.collections.update", $collection = $this->one(Collection::class)),
  28. $update = $this->make(collection::class, smash: $field, withDependency: true)
  29. )
  30. ->assertUnprocessable();
  31. }
  32. public function test_collection_update_forbidden()
  33. {
  34. $this->modelWithPolicy('collections', ['permission:collections.update'])
  35. ->loginAs(['wrong.permission'])
  36. ->putJson(
  37. route("api.collections.update", $collection = $this->one(Collection::class)),
  38. []
  39. )
  40. ->assertForbidden();
  41. }
  42. public function test_collection_update_not_found()
  43. {
  44. $this->loginAsUser(['collections.update'])
  45. ->putJson(route("api.collections.update", 0), [])
  46. ->assertNotFound();
  47. }
  48. }