File manager - Edit - /var/www/html/spdc/api/tests/Feature/ScaleTest.php
Back
<?php namespace Tests\Feature; use Tests\BaseTest; use App\Models\Form; use App\Models\Field; use App\Models\Scale; use App\Enums\ScaleType; use App\Models\ScaleTeam; use App\Models\Department; use App\Models\ScaleFunction; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\DB; use App\Enums\OccurrencyScriptureType; use AluisioPires\LaravelBaseTest\BaseTestTransactions; class ScaleTest extends BaseTest { public function test_index() { // deleting existing scales Scale::query()->delete(); // creating two scales Scale::factory(2)->create(); $response = $this->authRequest( 'get', route('scale.index'), JsonResponse::HTTP_OK ); $response->assertJsonCount(2, 'data.data'); dump($response->json()); } public function test_store_warning() { // deleting existing scales Scale::query()->delete(); $deparment = Department::factory()->create(); $scaleData = Scale::factory()->state(['department_id' => $deparment->id])->make()->toArray(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents(5, $scaleData['department_id'])->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $agenda = []; $users = []; foreach ($scaleFunctions as $scaleFunction) { $users = [...$users, ...DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray()]; } $days = 31; for ($i = 1; $i <= $days; $i++) { $calendar[] = [ 'user_id' => $users[array_rand($users)], 'day' => $i ]; } // dd($deparment->toArray(), $scaleData); // creating a text scale $response = $this->authRequest( 'post', route('scale.storeWarning'), JsonResponse::HTTP_CREATED, [ ...$scaleData, 'calendar' => $calendar ] ); dump($response->json()); } public function test_store_warning_with_function() { // deleting existing scales Scale::query()->delete(); $deparment = Department::factory()->create(); $scaleData = Scale::factory()->state(['department_id' => $deparment->id])->make()->toArray(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents(5, $scaleData['department_id'])->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $agenda = []; $users = []; foreach ($scaleFunctions as $scaleFunction) { $users = [...$users, ...DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray()]; } $days = 31; for ($i = 1; $i <= $days; $i++) { $calendar[] = [ 'user_id' => $users[array_rand($users)], 'day' => $i, 'scale_function_id' => $scaleFunctions->random()->id ]; } // dd($deparment->toArray(), $scaleData); // creating a text scale $response = $this->authRequest( 'post', route('scale.storeWarning'), JsonResponse::HTTP_CREATED, [ ...$scaleData, 'calendar' => $calendar ] ); dump($response->json()); } public function test_store_scale_team_without_previous_scale() { // deleting existing scales Scale::query()->delete(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents()->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...Scale::factory()->make()->toArray(), 'members' => $members ] ); // dump($response->json()); } public function test_store_scale_team_with_previous_scale() { // deleting existing scales /** * creating first scale */ Scale::query()->delete(); $scaleData = Scale::factory()->make()->toArray(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents(5, $scaleData['department_id'])->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...$scaleData, 'members' => $members ] ); /** * creating second scale */ $secondScaleData = $scaleData; $secondScaleData['month'] = $scaleData['month'] === 12 ? 1 : $scaleData['month'] + 1; $secondScaleData['year'] = $scaleData['year'] === 12 ? $scaleData['year'] + 1 : $scaleData['year']; // dd($scaleData, $secondScaleData); $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...$secondScaleData, 'members' => $members ] ); // dump($response->json()); } public function test_store_scale_individual_without_previous_scale() { // deleting existing scales Scale::query()->delete(); $deparment = Department::factory()->state(['scale_type' => ScaleType::INDIVIDUAL->value])->create(); $scaleData = Scale::factory()->state(['department_id' => $deparment->id])->make()->toArray(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents(5, $scaleData['department_id'])->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // dd($deparment->toArray(), $scaleData); // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...$scaleData, 'members' => $members ] ); // dump($response->json()); } public function test_store_scale_individual_with_previous_scale() { // deleting existing scales Scale::query()->delete(); $deparment = Department::factory()->state(['scale_type' => ScaleType::INDIVIDUAL->value])->create(); $scaleData = Scale::factory()->state(['department_id' => $deparment->id])->make()->toArray(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents(5, $scaleData['department_id'])->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // creating first scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...$scaleData, 'members' => $members ] ); // creating second scale $secondScaleData = $scaleData; $secondScaleData['month'] = $scaleData['month'] === 12 ? 1 : $scaleData['month'] + 1; $secondScaleData['year'] = $scaleData['year'] === 12 ? $scaleData['year'] + 1 : $scaleData['year']; $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...$secondScaleData, 'members' => $members ] ); // dump($response->json()); } public function test_finish_scale_team() { // deleting existing scales Scale::query()->delete(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents()->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...Scale::factory()->make()->toArray(), 'members' => $members ] ); $scale = Scale::findOrFail($response['data']['id']); $response = $this->authRequest( 'post', route('scale.finish', $scale), JsonResponse::HTTP_OK ); // dump($response->json()); } public function test_suggest_warning_scale() { // deleting existing scales Scale::query()->delete(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents()->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...Scale::factory()->make()->toArray(), 'members' => $members ] ); $scale = Scale::findOrFail($response['data']['id']); $response = $this->authRequest( 'get', route('scale.suggestWarningScale', $scale), JsonResponse::HTTP_OK ); // dump($response->json()); } // public function test_store() // { // // deleting existing scales // Scale::query()->delete(); // // creating a text scale // $response = $this->authRequest( // 'post', // route('scale.store'), // JsonResponse::HTTP_CREATED, // Scale::factory()->make()->toArray() // ); // // dump($response->json()); // } // /** // * // * canot have two scales from the same month of the same year with the same type // */ // public function test_store_with_duplicated_entries() // { // // deleting existing scales // Scale::query()->delete(); // $scale = Scale::factory()->create(); // // creating a text scale // $response = $this->authRequest( // 'post', // route('scale.store'), // JsonResponse::HTTP_BAD_REQUEST, // $scale->toArray() // ); // // dump($response->json()); // } public function test_show() { // deleting existing scales Scale::query()->delete(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents()->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...Scale::factory()->make()->toArray(), 'members' => $members ] ); $scaleId = $response['data']['id']; //creating a text scale $response = $this->authRequest( 'get', route('scale.show', $scaleId) ); dump($response->json()); } public function test_update_team() { // deleting existing scales Scale::query()->delete(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents()->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...Scale::factory()->make()->toArray(), 'members' => $members ] ); // dump($response->json()); $scaleId = $response['data']['id']; $request = $response['data']; // dd($request['department']); $response = $this->authRequest( 'put', route('scale.update', $scaleId), JsonResponse::HTTP_OK, $request ); // dump($response->json()['data']['department']); } public function test_update_individual() { // deleting existing scales Scale::query()->delete(); $deparment = Department::factory()->state(['scale_type' => ScaleType::INDIVIDUAL->value])->create(); $scaleData = Scale::factory()->state(['department_id' => $deparment->id])->make()->toArray(); $scaleFunctions = ScaleFunction::factory(5)->withInternalAgents(5, $scaleData['department_id'])->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } // dd($deparment->toArray(), $scaleData); // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...$scaleData, 'members' => $members ] ); $scaleId = $response['data']['id']; $request = $response['data']; // dd($request['department']); $response = $this->authRequest( 'put', route('scale.update', $scaleId), JsonResponse::HTTP_OK, $request ); // dump($response->json()['data']['department']); } public function test_destroy_many() { // deleting existing fields Scale::query()->delete(); $scales = Scale::factory(5)->create(); // creating a text field $response = $this->authRequest( 'post', route('scale.destroyMany'), JsonResponse::HTTP_NO_CONTENT, [ 'scales' => $scales->pluck('id')->toArray() ] ); } public function test_my_agenda() { // deleting existing scales $scaleFunctions = ScaleFunction::factory(5)->withInternalAgentsAndCurrentUser()->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } $scaleData = Scale::factory()->make()->toArray(); $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...$scaleData, 'members' => $members ] ); $scale = Scale::findOrFail($response['data']['id']); // finishe scale $response = $this->authRequest( 'post', route('scale.finish', $scale), JsonResponse::HTTP_OK ); // suggest warning scale $scaleFunctions = ScaleFunction::factory(5)->withInternalAgentsAndCurrentUser()->create(); // $scaleFunctions = ScaleFunction::factory(5)->withFakeInternalAgents()->create(); $teams = ScaleTeam::factory(5)->create(); $members = []; foreach ($scaleFunctions as $scaleFunction) { $users = DB::table('internal_agent_scale_function') ->where('scale_function_id', $scaleFunction->id) ->get()->pluck('user_id') ->toArray(); foreach ($teams as $key => $scaleTeam) { if (isset($users[$key])) { $members[] = [ 'user_id' => $users[$key], 'scale_function_id' => $scaleFunction->id, 'scale_team_id' => $scaleTeam->id ]; } } } $warningScaleData = Scale::factory()->state([ 'month' => $scaleData['month'], 'year' => $scaleData['year'] ])->make()->toArray(); // creating a text scale $response = $this->authRequest( 'post', route('scale.store'), JsonResponse::HTTP_CREATED, [ ...$warningScaleData, 'members' => $members ] ); $scale = Scale::findOrFail($response['data']['id']); $response = $this->authRequest( 'get', route('scale.suggestWarningScale', $scale), JsonResponse::HTTP_OK ); $scale = Scale::findOrFail($response['data']['id']); // finishe scale $response = $this->authRequest( 'post', route('scale.finish', $scale), JsonResponse::HTTP_OK ); $response = $this->authRequest( 'get', route('scale.myAgenda', [ 'month' => $scaleData['month'], 'year' => $scaleData['year'] ]) ); dump($response->json()); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.17 |
proxy
|
phpinfo
|
Settings