File manager - Edit - /var/www/html/spdc/api/tests/Feature/OccurrencyTest.php
Back
<?php namespace Tests\Feature; use Tests\BaseTest; use App\Models\Form; use App\Models\Field; use App\Models\Category; use App\Models\Occurrency; use App\Models\CategoryOption; use App\Models\OccurrencyType; use App\Enums\OccurrencySection; use Illuminate\Http\JsonResponse; use Illuminate\Http\UploadedFile; use AluisioPires\LaravelBaseTest\BaseTestTransactions; class OccurrencyTest extends BaseTest { public function test_index() { // deleting existing occurrencys Occurrency::query()->delete(); // creating two occurrencys Occurrency::factory(2)->create(); $response = $this->authRequest( 'get', route('occurrency.index'), JsonResponse::HTTP_OK ); $response->assertJsonCount(2, 'data.data'); } public function test_index_with_filters() { // deleting existing occurrencys Occurrency::query()->delete(); // creating two occurrencys $occurrencies = Occurrency::factory(2)->create(); $response = $this->authRequest( 'get', route('occurrency.index', [ 'code' => $occurrencies[0]->code ]), JsonResponse::HTTP_OK ); $response = $this->authRequest( 'get', route('occurrency.index', [ 'created_at_start' => '2023-09-04 00:00:00', 'created_at_end' => '2023-09-04 23:59:59', ]), JsonResponse::HTTP_OK ); $response = $this->authRequest( 'get', route('occurrency.index', [ 'neighborhood' => $occurrencies[0]->address->neighborhood, 'created_at_end' => '2023-09-04 23:59:59', ]), JsonResponse::HTTP_OK ); $response = $this->authRequest( 'get', route('occurrency.index', [ 'code' => 'ofjskldfjds' ]), JsonResponse::HTTP_OK ); $categoryOption = CategoryOption::factory()->create(); $occurrencies = Occurrency::factory(2)->state([ 'category_option_id' => $categoryOption->id ])->create(); $occurrencyTypes = OccurrencyType::factory(2)->create(); foreach($occurrencies as $occurrency) { $occurrency->occurrencyTypes()->attach($occurrencyTypes->pluck('id')->toArray()); } $response = $this->authRequest( 'get', route('occurrency.index', [ 'neighborhood' => $occurrencies[0]->category_option_id, 'category' => $categoryOption->id, 'occurrency_type' => $occurrencyTypes[0]->id ]), JsonResponse::HTTP_OK ); $occurrencies[0]->movements()->create([ 'user_id' => 'alsdksad', 'section' => OccurrencySection::EXECUÇÃO->value ]); sleep(1); $occurrencies[0]->movements()->create([ 'user_id' => 'alsdksad', 'section' => OccurrencySection::VISTORIA->value ]); $occurrencies[1]->movements()->create([ 'user_id' => 'alsdksad', 'section' => OccurrencySection::VISTORIA->value ]); sleep(1); $occurrencies[1]->movements()->create([ 'user_id' => 'alsdksad', 'section' => OccurrencySection::EXECUÇÃO->value ]); $response = $this->authRequest( 'get', route('occurrency.index', [ 'current_section' => 'VISTORIA,EXECUÇÃO', ]), JsonResponse::HTTP_OK ); dump($response->json()); } public function test_store() { // deleting existing occurrencys Occurrency::query()->delete(); // creating a text occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->request()->make()->toArray() ); } public function test_store_with_occurrency_types() { // deleting existing occurrencys Occurrency::query()->delete(); // creating a text occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->requestWithOccurrencyTypes()->make()->toArray() ); } public function test_store_with_field_validation() { // deleting existing occurrencys Occurrency::query()->delete(); // creating a text occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->requestWithFieldsValidations()->make()->toArray() ); } public function test_store_with_invalid_field_value() { // deleting existing occurrencys Occurrency::query()->delete(); // creating a text occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_UNPROCESSABLE_ENTITY, Occurrency::factory()->requestWithFieldsValidationsToFail()->make()->toArray() ); } public function test_store_with_system_fields() { // deleting existing occurrencys Occurrency::query()->delete(); // creating a text occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->requestWithSystemFields()->make()->toArray() ); } public function test_show() { // deleting existing occurrencys Occurrency::query()->delete(); // creating an occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->request()->make()->toArray() ); $occurrency = Occurrency::findOrfail($response['data']['id']); // showing an occurrency $response = $this->authRequest( 'get', route('occurrency.show', $occurrency) ); $response->assertSeeText('forms'); $response->assertSeeText('fields'); // dump($response->json()); } public function test_show_with_section_query_filter() { // deleting existing occurrencys Occurrency::query()->delete(); // creating an occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->request()->make()->toArray() ); $occurrency = Occurrency::findOrfail($response['data']['id']); // showing an occurrency $response = $this->authRequest( 'get', route('occurrency.show', [$occurrency, 'section' => 'vistoria']) ); $response->assertSeeText('forms'); $response->assertSeeText('fields'); // dump($response->json(), 'somente vistoria'); $response = $this->authRequest( 'get', route('occurrency.show', [$occurrency]) ); // dump($response->json(), 'todos'); } public function test_update_inspection() { // deleting existing occurrencys Occurrency::query()->delete(); $occurrency = Occurrency::factory()->create(); // creating an occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->request()->make()->toArray() ); $storeResponse = $response->json(); $occurrency = Occurrency::findOrfail($response['data']['id']); $occurencyRequest = [ 'current_section' => 'VISTORIA', 'category_id' => $occurrency->original_category_id, 'address' => [ ...$occurrency->address->toArray(), 'neighborhood' => fake()->word ], 'forms' => [] ]; foreach($occurrency->forms as $formKey => $fo) { $occurencyRequest['forms'][$formKey]['id'] = $fo['id']; foreach($fo->fields as $fieldKey => $fi) { $occurencyRequest['forms'][$formKey]['fields'][$fieldKey]['id'] = $fi['id']; $occurencyRequest['forms'][$formKey]['fields'][$fieldKey]['value'] = fake()->text; } } // updating a occurrency $response = $this->authRequest( 'put', route('occurrency.update', $occurrency), JsonResponse::HTTP_OK, $occurencyRequest ); $updateResponse = $response->json(); $response->assertSeeText('forms'); $response->assertSeeText('fields'); $this->assertJsonStringNotEqualsJsonString(json_encode($storeResponse), json_encode($updateResponse)); } public function test_update_execution() { // deleting existing occurrencys Occurrency::query()->delete(); $occurrency = Occurrency::factory()->create(); // creating an occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->request()->make()->toArray() ); $storeResponse = $response->json(); $occurrency = Occurrency::findOrfail($response['data']['id']); $occurencyRequest = [ 'files_paths' => [], 'images_paths' => [], 'current_section' => 'EXECUÇÃO', 'category_id' => $occurrency->original_category_id, 'address' => [ ...$occurrency->address->toArray(), 'neighborhood' => fake()->word ], 'forms' => [] ]; foreach($occurrency->forms as $formKey => $fo) { $occurencyRequest['forms'][$formKey]['id'] = $fo['id']; foreach($fo->fields as $fieldKey => $fi) { $occurencyRequest['forms'][$formKey]['fields'][$fieldKey]['id'] = $fi['id']; $occurencyRequest['forms'][$formKey]['fields'][$fieldKey]['value'] = fake()->text; } } // updating a occurrency $response = $this->authRequest( 'put', route('occurrency.update', $occurrency), JsonResponse::HTTP_OK, $occurencyRequest ); $updateResponse = $response->json(); $response->assertSeeText('forms'); $response->assertSeeText('fields'); $this->assertJsonStringNotEqualsJsonString(json_encode($storeResponse), json_encode($updateResponse)); } public function test_destroy() { // deleting existing occurrencys Occurrency::query()->delete(); // creating an occurrency $response = $this->authRequest( 'post', route('occurrency.store'), JsonResponse::HTTP_CREATED, Occurrency::factory()->request()->make()->toArray() ); $occurrency = Occurrency::findOrfail($response['data']['id']); // creating a text occurrency $response = $this->authRequest( 'delete', route('occurrency.destroy', $occurrency), JsonResponse::HTTP_NO_CONTENT ); } public function test_destroy_many() { // deleting existing occurrencys Occurrency::query()->delete(); $occurrencys = Occurrency::factory(3)->create(); // creating a text occurrency $response = $this->authRequest( 'post', route('occurrency.destroyMany'), JsonResponse::HTTP_NO_CONTENT, [ 'occurrencies' => $occurrencys->pluck('id')->toArray() ] ); } public function test_move() { // deleting existing occurrencys Occurrency::query()->delete(); $occurrency = Occurrency::factory()->create(); // creating a text occurrency $response = $this->authRequest( 'post', route('occurrency.move', $occurrency), JsonResponse::HTTP_NO_CONTENT, [ 'section' => 'EXECUÇÃO' ] ); dump($response->json()); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.13 |
proxy
|
phpinfo
|
Settings