File manager - Edit - /var/www/html/spdc/api/tests/Feature/ScaleFunctionTest.php
Back
<?php namespace Tests\Feature; use Tests\BaseTest; use App\Models\Form; use App\Models\Field; use App\Models\ExternalAgent; use App\Models\ScaleFunction; use App\Enums\ScaleFunctionType; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\DB; use App\Enums\OccurrencyScriptureType; use AluisioPires\LaravelBaseTest\BaseTestTransactions; class ScaleFunctionTest extends BaseTest { public function test_index() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); // creating two scaleFunctions ScaleFunction::factory(2)->create(); $response = $this->authRequest( 'get', route('scale-function.index'), JsonResponse::HTTP_OK ); // $response->assertJsonCount(2, 'data.data'); dump($response->json()); } public function test_index_with_filter_type() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); // creating two scaleFunctions ScaleFunction::factory(2)->state(['type' => ScaleFunctionType::INTERNO->value])->create(); ScaleFunction::factory(3)->state(['type' => ScaleFunctionType::EXTERNO->value])->create(); $response = $this->authRequest( 'get', route('scale-function.index', [ 'type' => ScaleFunctionType::INTERNO->value ]), JsonResponse::HTTP_OK ); $response = $this->authRequest( 'get', route('scale-function.index', [ 'type' => ScaleFunctionType::EXTERNO->value ]), JsonResponse::HTTP_OK ); } public function test_index_with_filter_type_and_enable() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); // creating two scaleFunctions ScaleFunction::factory(2)->state(['type' => ScaleFunctionType::INTERNO->value])->create(); ScaleFunction::factory(3)->state(['type' => ScaleFunctionType::EXTERNO->value])->create(); $response = $this->authRequest( 'get', route('scale-function.index', [ 'type' => ScaleFunctionType::INTERNO->value, 'enable' => 1 ]), JsonResponse::HTTP_OK ); dump($response->json()); $response = $this->authRequest( 'get', route('scale-function.index', [ 'type' => ScaleFunctionType::EXTERNO->value ]), JsonResponse::HTTP_OK ); } public function test_store() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); // creating a text scale-function $response = $this->authRequest( 'post', route('scale-function.store'), JsonResponse::HTTP_CREATED, ScaleFunction::factory()->make()->toArray() ); // dump($response->json()); } public function test_store_with_valid_external_agents() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); // creating a text scale-function $response = $this->authRequest( 'post', route('scale-function.store'), JsonResponse::HTTP_CREATED, ScaleFunction::factory()->requestWithExternalAgents()->make()->toArray() ); // dump($response->json()); } public function test_store_with_invalid_external_agents() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); // creating a text scale-function $response = $this->authRequest( 'post', route('scale-function.store'), JsonResponse::HTTP_UNPROCESSABLE_ENTITY, ScaleFunction::factory()->requestWithExternalAgents() ->state(['external_agents' => ['sadsadh', 'sadojsadj']]) ->make() ->toArray() ); // dump($response->json()); } public function test_store_with_valid_internal_agents() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); // creating a text scale-function $response = $this->authRequest( 'post', route('scale-function.store'), JsonResponse::HTTP_CREATED, ScaleFunction::factory()->requestWithInternalAgents()->make()->toArray() ); // dump($response->json()); } public function test_store_with_invalid_internal_agents() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); // creating a text scale-function $response = $this->authRequest( 'post', route('scale-function.store'), JsonResponse::HTTP_UNPROCESSABLE_ENTITY, ScaleFunction::factory()->requestWithInternalAgents()->state([ 'external_agents' =>['849572394', 'sadjaskd'] ])->make()->toArray() ); // dump($response->json()); } public function test_show() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); $scaleFunction = ScaleFunction::factory()->create(); // creating a text scale-function $response = $this->authRequest( 'get', route('scale-function.show', $scaleFunction) ); // dump($response->json()); } public function test_update() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); $scaleFunction = ScaleFunction::factory()->create(); $response = $this->authRequest( 'put', route('scale-function.update', $scaleFunction), JsonResponse::HTTP_OK, ScaleFunction::factory()->make()->toArray() ); // dump($response->json()); } public function test_update_with_valid_external_agents() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); $scaleFunction = ScaleFunction::factory()->withExternalAgents()->create(); $externalAgents = $scaleFunction->externalAgents->pluck('id')->toArray(); array_pop($externalAgents); $newExternalAgent = ExternalAgent::factory()->create(); $response = $this->authRequest( 'put', route('scale-function.update', $scaleFunction), JsonResponse::HTTP_OK, [ ...$scaleFunction->toArray(), 'external_agents' => [ ...$externalAgents, $newExternalAgent->id ] ] ); // dump($response->json()); } public function test_update_with_valid_internal_agents() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); $scaleFunction = ScaleFunction::factory()->withInternalAgents()->create(); $internalAgents = DB::table('internal_agent_scale_function')->select('user_id')->where('scale_function_id', $scaleFunction->id)->get()->pluck('user_id')->toArray(); // new user $url = env('AUTH_SERVICE_URL') . '/api/user?like=app_id,' . env('CLIENT_APP_KEY'); $usersResponse = authServiceClient('get', $url, null, [ 'Authorization' => 'Bearer ' . authLogin()['access_token'] ]); $users = getItemsByKey($usersResponse->json()['data']['data'], 'id'); $newUser = array_pop($users); // dump($newUser, $internalAgents); $response = $this->authRequest( 'put', route('scale-function.update', $scaleFunction), JsonResponse::HTTP_OK, [ ...$scaleFunction->toArray(), 'internal_agents' => [ ...$internalAgents, $newUser ] ] ); // dump($response->json()); } public function test_disable() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); $scaleFunctions = ScaleFunction::factory(3)->create(); // creating a text scale-function $response = $this->authRequest( 'post', route('scale-function.disable'), JsonResponse::HTTP_NO_CONTENT, [ 'scale_functions' => $scaleFunctions->pluck('id')->toArray() ] ); // dump(ScaleFunction::all()->toArray()); } public function test_enable() { // deleting existing scaleFunctions ScaleFunction::query()->delete(); $scaleFunctions = ScaleFunction::factory(3)->state(['enable' => 0])->create(); // creating a text scale-function $response = $this->authRequest( 'post', route('scale-function.enable'), JsonResponse::HTTP_NO_CONTENT, [ 'scale_functions' => $scaleFunctions->pluck('id')->toArray() ] ); // dump(ScaleFunction::all()->toArray()); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.16 |
proxy
|
phpinfo
|
Settings