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.

42 lines
1.6 KiB

2 years ago
  1. {!! $sol !!}
  2. namespace Tests\Feature\{{class_basename($model)}};
  3. use App\Models\{{class_basename($model)}};
  4. use App\Documents\UserDocument;
  5. use Tests\Bootstrap;
  6. use Illuminate\Support\Arr;
  7. class {{class_basename($model)}}StoreTest extends Bootstrap
  8. {
  9. public function test_{{lcfirst(class_basename($model))}}_store_success()
  10. {
  11. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.store'])
  12. ->loginAs(['{{$model->getTable()}}.store'])
  13. ->postJson(route('api.{{$model->getTable()}}.store'), ${{lcfirst(class_basename($model))}} = $this->make({{class_basename($model)}}::class))
  14. ->assertCreated();
  15. }
  16. /**
  17. * @testWith
  18. @foreach ($model->factory()->list() as $field)
  19. * ["{{$field}}"]
  20. @endforeach
  21. */
  22. public function test_{{lcfirst(class_basename($model))}}_store_unprocessable($field)
  23. {
  24. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.store'])
  25. ->loginAsAdmin()
  26. ->postJson(route("api.{{$model->getTable()}}.store"), ${{lcfirst(class_basename($model))}} = $this->make({{lcfirst(class_basename($model))}}::class, smash: $field, withDependency: true))
  27. ->assertUnprocessable();
  28. }
  29. public function test_{{lcfirst(class_basename($model))}}_store_forbidden()
  30. {
  31. $this->modelWithPolicy('{{$model->getTable()}}', ['permission:{{$model->getTable()}}.store'])
  32. ->loginAs(['wrong.permission'])
  33. ->postJson(route("api.{{$model->getTable()}}.store"), [])
  34. ->assertForbidden();
  35. }
  36. }