File manager - Edit - /var/www/html/homologBancodetalentos/tests/Feature/TalentBank/ApiCompatibilityMatrixTest.php
Back
<?php namespace Tests\Feature\TalentBank; use App\Models\TalentBank\Candidate; use App\Models\TalentBank\Company; use App\Models\TalentBank\ContractType; use App\Models\TalentBank\Ethnicity; use App\Models\TalentBank\ExpertiseLevel; use App\Models\TalentBank\Gender; use App\Models\TalentBank\JobListing; use App\Models\TalentBank\Modality; use App\Models\TalentBank\Neighbourhood; use App\Models\TalentBank\Occupation; use App\Models\TalentBank\SalaryRange; use App\Models\TalentBank\Workload; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\DB; use Tests\TestCase; class ApiCompatibilityMatrixTest extends TestCase { use DatabaseTransactions; protected function setUp(): void { parent::setUp(); config([ 'talent_bank.bypass_auth' => true, ]); } public function test_legacy_auth_session_compat_endpoint_returns_sso_payload(): void { $response = $this->getJson('/api/session'); $response->assertOk(); $response->assertJsonStructure([ 'data' => [ 'document', 'name', 'email', 'permissions' => [ 'siati', ], ], ]); } public function test_candidate_session_contract_minimum_fields_are_available(): void { $this->createCandidateFixture(); $response = $this->getJson('/api/talent-bank/candidate/session'); $response->assertOk(); $response->assertJsonStructure([ 'data' => [ 'candidate' => [ 'id', 'cpf', 'name', 'email', ], ], 'message', ]); } public function test_company_session_contract_minimum_fields_are_available(): void { $this->createCompanyFixture(); $response = $this->getJson('/api/talent-bank/company/session'); $response->assertOk(); $response->assertJsonStructure([ 'data' => [ 'company' => [ 'id', 'cnpj', 'corporate_name', 'trading_name', 'email', ], ], 'message', ]); } public function test_jobs_list_and_show_keep_legacy_public_contract_shape(): void { $job = $this->createJobFixture(); $listResponse = $this->getJson('/api/talent-bank/job'); $listResponse->assertOk(); $listResponse->assertJsonStructure([ 'data' => [ 'data' => [ '*' => [ 'id', 'descripton', 'is_hiring', ], ], ], 'message', ]); $showResponse = $this->getJson('/api/talent-bank/job/'.$job->id); $showResponse->assertOk(); $showResponse->assertJsonStructure([ 'data' => [ 'job' => [ 'id', 'descripton', 'is_hiring', ], ], 'message', ]); } public function test_application_endpoints_keep_store_and_delete_contract(): void { $this->createCandidateFixture(); $job = $this->createJobFixture(); $applyResponse = $this->postJson('/api/talent-bank/job/'.$job->id.'/application'); $applyResponse->assertOk(); $applyResponse->assertJsonStructure(['message']); $this->assertSame(1, (int) DB::table('job_listing_candidate')->where('job_listing_id', $job->id)->count()); $this->assertDatabaseHas('job_listing_candidate', [ 'job_listing_id' => $job->id, ]); $deleteResponse = $this->deleteJson('/api/talent-bank/job/'.$job->id.'/application'); $deleteResponse->assertOk(); $deleteResponse->assertJsonStructure(['message']); $this->assertSame(0, (int) DB::table('job_listing_candidate')->where('job_listing_id', $job->id)->count()); } public function test_application_post_is_idempotent_for_duplicate_candidates(): void { $this->createCandidateFixture(); $job = $this->createJobFixture(); $first = $this->postJson('/api/talent-bank/job/'.$job->id.'/application'); $second = $this->postJson('/api/talent-bank/job/'.$job->id.'/application'); $first->assertOk()->assertJsonStructure(['message']); $second->assertOk()->assertJsonStructure(['message']); $this->assertSame(1, (int) DB::table('job_listing_candidate')->where('job_listing_id', $job->id)->count()); } public function test_report_dashboard_and_contact_contracts_have_expected_minimum_shape(): void { $this->createCandidateFixture(); $this->createJobFixture(); $reportResponse = $this->getJson('/api/talent-bank/report/candidate?paginate=0'); $reportResponse->assertOk(); $reportResponse->assertJsonStructure([ 'data' => [ 'list', 'counters' => [ 'total', ], ], 'message', ]); $dashboardResponse = $this->getJson('/api/talent-bank/dashboard'); $dashboardResponse->assertOk(); $dashboardResponse->assertJsonStructure([ 'data' => [ 'candidates', 'jobs', 'companies', 'companies_active', ], 'message', ]); $dashjobsResponse = $this->getJson('/api/talent-bank/dashjobs'); $dashjobsResponse->assertOk(); $dashjobsResponse->assertJsonStructure([ 'data' => [ 'open', 'closed', 'applications', ], 'message', ]); $contactResponse = $this->postJson('/api/talent-bank/contact', []); $contactResponse->assertStatus(422); $contactResponse->assertJsonStructure([ 'data' => [ 'email', 'name', 'phone', 'subject', 'message', ], 'message', ]); $contactOk = $this->postJson('/api/talent-bank/contact', [ 'email' => 'contato+'.uniqid().'@example.com', 'name' => 'Contato BT', 'phone' => '24999999999', 'subject' => 'Teste contrato', 'message' => 'Mensagem valida para contato', ]); $contactOk->assertOk()->assertJsonStructure([ 'data', 'message', ]); } private function createCandidateFixture(): Candidate { $neighbourhood = Neighbourhood::query()->create([ 'name' => 'Centro Compat '.uniqid(), ]); $occupation = Occupation::query()->create([ 'name' => 'Desenvolvedor Compat '.uniqid(), ]); $gender = Gender::query()->create([ 'name' => 'Outro', ]); $ethnicity = Ethnicity::query()->create([ 'name' => 'Branco', ]); return Candidate::query()->create([ 'cpf' => (string) random_int(10000000000, 99999999999), 'name' => 'Candidato Compat', 'email' => 'candidate+'.uniqid().'@example.com', 'neighbourhood_id' => $neighbourhood->id, 'occupation_id' => $occupation->id, 'gender_id' => $gender->id, 'ethnicity_id' => $ethnicity->id, 'active' => true, ]); } private function createCompanyFixture(): Company { $neighbourhood = Neighbourhood::query()->create([ 'name' => 'Bairro Empresa '.uniqid(), ]); return Company::query()->create([ 'cnpj' => (string) random_int(10000000000000, 99999999999999), 'corporate_name' => 'Empresa Compat LTDA', 'trading_name' => 'Empresa Compat', 'email' => 'company+'.uniqid().'@example.com', 'neighbourhood_id' => $neighbourhood->id, 'active' => true, ]); } private function createJobFixture(): JobListing { $company = $this->createCompanyFixture(); $occupation = Occupation::query()->create(['name' => 'Ocupacao '.uniqid()]); $salaryRange = SalaryRange::query()->create(['name' => 'A combinar '.uniqid()]); $contractType = ContractType::query()->create(['name' => 'CLT '.uniqid()]); $neighbourhood = Neighbourhood::query()->create(['name' => 'Bairro Vaga '.uniqid()]); $expertiseLevel = ExpertiseLevel::query()->create(['name' => 'Pleno '.uniqid()]); $modality = Modality::query()->create(['name' => 'Presencial '.uniqid()]); $workload = Workload::query()->create(['name' => '40h '.uniqid()]); return JobListing::query()->create([ 'company_id' => $company->id, 'occupation_id' => $occupation->id, 'salary_range_id' => $salaryRange->id, 'contract_type_id' => $contractType->id, 'neighbourhood_id' => $neighbourhood->id, 'expertise_level_id' => $expertiseLevel->id, 'modality_id' => $modality->id, 'workload_id' => $workload->id, 'spots_total' => 3, 'spots_filled' => 0, 'description' => 'Descricao compatibilidade', 'requirements_mandatory' => 'PHP, Laravel', 'requirements_optional' => 'Docker', 'benefits' => 'VT/VR', 'misc_info' => 'Informacoes adicionais', 'hide_company' => false, 'is_hiring' => true, ]); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings