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.

57 lines
2.2 KiB

2 years ago
  1. {!! $sol !!}
  2. namespace Tests\Feature\{{class_basename($model)}};
  3. use App\Models\{{class_basename($model)}};
  4. use Tests\Bootstrap;
  5. use App\Models\User;
  6. use Illuminate\Support\Arr;
  7. class {{class_basename($model)}}UpdateTest extends Bootstrap
  8. {
  9. public function test_{{lcfirst(class_basename($model))}}_update_success()
  10. {
  11. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.update'])
  12. ->loginAs(['{{$model->getTable()}}.update'])
  13. ->putJson(
  14. route("api.{{$model->getTable()}}.update", ${{lcfirst(class_basename($model))}} = $this->one({{class_basename($model)}}::class)),
  15. $update = $this->make({{class_basename($model)}}::class, withDependency: true)
  16. )
  17. ->assertOk();
  18. }
  19. /**
  20. * @testWith
  21. @foreach ($model->factory()->list() as $field)
  22. * ["{{$field}}"]
  23. @endforeach
  24. */
  25. public function test_{{lcfirst(class_basename($model))}}_update_unprocessable($field)
  26. {
  27. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.update'])
  28. ->loginAs(['{{$model->getTable()}}.update'])->putJson(
  29. route("api.{{$model->getTable()}}.update", ${{lcfirst(class_basename($model))}} = $this->one({{class_basename($model)}}::class)),
  30. $update = $this->make({{lcfirst(class_basename($model))}}::class, smash: $field, withDependency: true)
  31. )
  32. ->assertUnprocessable();
  33. }
  34. public function test_{{lcfirst(class_basename($model))}}_update_forbidden()
  35. {
  36. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.update'])
  37. ->loginAs(['wrong.permission'])
  38. ->putJson(
  39. route("api.{{$model->getTable()}}.update", ${{lcfirst(class_basename($model))}} = $this->one({{class_basename($model)}}::class)),
  40. []
  41. )
  42. ->assertForbidden();
  43. }
  44. public function test_{{lcfirst(class_basename($model))}}_update_not_found()
  45. {
  46. $this->loginAsUser(['{{$model->getTable()}}.update'])
  47. ->putJson(route("api.{{$model->getTable()}}.update", 0), [])
  48. ->assertNotFound();
  49. }
  50. }