diff --git a/.github/workflows/pull_request_phpunit_tests.yml b/.github/workflows/pull_request_phpunit_tests.yml index 85c94050..91df59db 100644 --- a/.github/workflows/pull_request_phpunit_tests.yml +++ b/.github/workflows/pull_request_phpunit_tests.yml @@ -34,6 +34,7 @@ jobs: - name: Configurar .env para pruebas run: | + echo "APP_KEY=" >> .env echo "APP_ENV=testing" >> .env echo "DB_CONNECTION=mysql" >> .env echo "DB_HOST=127.0.0.1" >> .env diff --git a/app/Annotations/OpenApi/controllersAnnotations/studentBootcampDetailAnnotations/AnnotationsStudentBootcampDetail.php b/app/Annotations/OpenApi/controllersAnnotations/studentBootcampDetailAnnotations/AnnotationsStudentBootcampDetail.php new file mode 100644 index 00000000..ced81d5d --- /dev/null +++ b/app/Annotations/OpenApi/controllersAnnotations/studentBootcampDetailAnnotations/AnnotationsStudentBootcampDetail.php @@ -0,0 +1,62 @@ +firstOrFail(); + + $bootcamp_detail = [ + + 'bootcamp' => [ + [ + 'bootcamp_id' => '1', + 'bootcamp_name' => 'php Fullstack Developer', + 'bootcamp_end_date' => ['November 2023'], + ], + ] + ]; + + return response()->json($bootcamp_detail); + } +} diff --git a/routes/api/v1.php b/routes/api/v1.php index f0897ed8..d4b709ed 100644 --- a/routes/api/v1.php +++ b/routes/api/v1.php @@ -6,6 +6,7 @@ use App\Http\Controllers\api\StudentController; use App\Http\Controllers\api\StudentListController; use App\Http\Controllers\api\StudentProjectsDetailController; +use App\Http\Controllers\api\StudentBootcampDetailController; use App\Http\Controllers\api\StudentDetailController; use App\Http\Controllers\api\TagController; use App\Http\Controllers\api\SpecializationListController; @@ -36,7 +37,8 @@ Route::get('/recruiters', [RecruiterController::class, 'index'])->name('recruiter.list'); Route::get('/recruiters/{id}', [RecruiterController::class, 'show'])->name('recruiter.show'); - +// Student bootcamp detail Endpoint +Route::get('/students/{id}/bootcamp', StudentBootcampDetailController::class)->name('bootcamp.list'); // Specialization List Endpoint Route::get('/specialization/list', SpecializationListController::class)->name('roles.list'); diff --git a/storage/api-docs/api-docs.json b/storage/api-docs/api-docs.json index c4b47169..39f081e8 100644 --- a/storage/api-docs/api-docs.json +++ b/storage/api-docs/api-docs.json @@ -1563,6 +1563,63 @@ } } }, + "/api/v1/students/{uuid}/bootcamp": { + "get": { + "tags": [ + "Bootcamp" + ], + "summary": "Get a detailed list of a student bootcamp", + "description": "Returns detail for a specific student bootcamp. (Note: This endpoint returns hardcoded bootcamp details)", + "operationId": "getStudentBootcamp", + "parameters": [ + { + "name": "uuid", + "in": "path", + "description": "Student UUID", + "required": true, + "schema": { + "type": "string", + "format": "uuid" + } + } + ], + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "properties": { + "bootcamp_id": { + "description": "Bootcamp ID", + "type": "string" + }, + "bootcamp_name": { + "description": "Bootcamp Name", + "type": "string" + }, + "bootcamp_end_date": { + "description": "Bootcamp end date", + "type": "array", + "items": { + "type": "string" + } + } + }, + "type": "object" + } + } + } + } + }, + "404": { + "description": "Student not found" + } + } + } + }, "/api/v1/students/{uuid}/projects": { "get": { "tags": [ diff --git a/tests/Feature/AdminControllerTest.php b/tests/Feature/AdminControllerTest.php deleted file mode 100644 index d6d475ff..00000000 --- a/tests/Feature/AdminControllerTest.php +++ /dev/null @@ -1,377 +0,0 @@ -exists()) { - Role::create(['name' => 'admin']); - } - } - - public function test_create_admin_with_valid_data() - { - $this->verifyOrCreateRole(); - - $userData = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '53671299V', - 'email' => 'john@example.com', - 'password' => 'password123', - ]; - - $response = $this->post('/api/v1/admins', $userData); - $response->assertHeader('Content-Type', 'application/json'); - - $response->assertStatus(201); - - $this->assertDatabaseHas('users', [ - 'name' => $userData['name'], - 'surname' => $userData['surname'], - 'dni' => $userData['dni'], - 'email' => $userData['email'], - ]); - - $this->assertDatabaseHas('admins', [ - 'user_id' => User::where('email', $userData['email'])->first()->id, - ]); - - $user = User::where('email', $userData['email'])->first(); - $this->assertTrue($user->hasRole('admin')); - - $response->assertJson([ - 'message' => __('Registre realitzat amb èxit.'), - ]); - $response->assertHeader('Content-Type', 'application/json'); - - } - - public function test_can_create_admin_with_bad_name() - { - $this->verifyOrCreateRole(); - - $userData = [ - 'name' => 'J@hn', - 'surname' => 'Doe', - 'dni' => '53671299V', - 'email' => 'john@example.com', - 'password' => 'password123', - ]; - - $response = $this->post('/api/v1/admins', $userData); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422)->assertJsonStructure([ - 'errors' => [ - 'name', - ], - ]) - ->assertJson([ - 'errors' => [ - 'name' => [ - 'El format de nom és invàlid.', - ], - ], - ]); - - } - - public function test_can_create_admin_with_bad_surname() - { - $this->verifyOrCreateRole(); - - $userData = [ - 'name' => 'John', - 'surname' => 'Doe67', - 'dni' => '53671299V', - 'email' => 'john@example.com', - 'password' => 'password123', - ]; - - $response = $this->post('/api/v1/admins', $userData); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422)->assertJsonStructure([ - 'errors' => [ - 'surname', - ], - ]) - ->assertJson([ - 'errors' => [ - 'surname' => [ - 'El format de cognom és invàlid.', - ], - ], - ]); - - } - - public function test_can_create_admin_with_bad_dni() - { - $this->verifyOrCreateRole(); - - $userData = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '53671299x', - 'email' => 'john@example.com', - 'password' => 'password123', - ]; - - $response = $this->post('/api/v1/admins', $userData); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422)->assertJsonStructure([ - 'errors' => [ - 'dni', - ], - ]) - ->assertJson([ - 'errors' => [ - 'dni' => [ - 'No és un Dni vàlid', - ], - ], - ]); - - } - - public function test_can_create_admin_with_bad_email() - { - $this->verifyOrCreateRole(); - - $userData = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '53671299V', - 'email' => 'johnexample.com', - 'password' => 'password123', - ]; - - $response = $this->post('/api/v1/admins', $userData); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422)->assertJsonStructure([ - 'errors' => [ - 'email', - ], - ]) - ->assertJson([ - 'errors' => [ - 'email' => [ - 'Adreça electrònica no és un e-mail vàlid', - ], - ], - ]); - - } - - public function test_can_create_admin_with_bad_password() - { - $this->verifyOrCreateRole(); - - $userData = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '53671299V', - 'email' => 'john@example.com', - 'password' => 'passwor', - ]; - - $response = $this->post('/api/v1/admins', $userData); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(422)->assertJsonStructure([ - 'errors' => [ - 'password', - ], - ]) - ->assertJson([ - 'errors' => [ - 'password' => [ - 'Contrasenya ha de contenir almenys 8 caràcters.', - ], - ], - ]); - - } - - public function test_it_returns_a_list_of_admins() - { - $this->verifyOrCreateRole(); - - $user = User::factory()->create(); - $admin = Admin::create(['user_id' => $user->id]); - $user->assignRole('admin'); - - $this->actingAs($user, 'api'); - - $response = $this->get('/api/v1/admins'); - - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - - $response->assertJsonStructure([ - 'data' => [ - '*' => [ - 'id', - 'name', - 'surname', - 'email', - ], - ], - ]); - } - - public function test_can_Show_specific_admin() - { - - $this->verifyOrCreateRole(); - - $user = User::factory()->create(); - $user->assignRole('admin'); - - $this->actingAs($user, 'api'); - - $admin = Admin::create(['user_id' => $user->id]); - - $response = $this->get("/api/v1/admins/{$admin->id}"); - - $response->assertStatus(200); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'id', 'name', 'surname', 'email', - ], - ]); - } - - public function test_can_show_specific_admin_invalid_data() - { - - $this->verifyOrCreateRole(); - - $user = User::factory()->create(); - $user->assignRole('admin'); - - $this->actingAs($user, 'api'); - - $admin = Admin::create(['user_id' => $user->id]); - $user2 = User::factory()->create(); - $admin2 = Admin::create(['user_id' => $user2->id]); - - $response = $this->get("/api/v1/admins/{$admin2->id}"); - - $response->assertStatus(401); - $response->assertJson([ - 'message' => 'No tens permisos per veure aquest usuari.', - ]); - - $response->assertHeader('Content-Type', 'application/json'); - - } - - public function test_update_specify_admin() - { - $this->verifyOrCreateRole(); - - $user = User::factory()->create(); - - $user->assignRole('admin'); - - $this->actingAs($user, 'api'); - - $admin = Admin::create(['user_id' => $user->id]); - - $response = $this->put("/api/v1/admins/{$admin->id}", [ - 'name' => 'Nuevo Nombre', - 'surname' => 'Nuevo Apellido', - 'email' => 'nuevo@example.com', - ]); - - $response->assertHeader('Content-Type', 'application/json'); - - $response->assertStatus(200); - - } - - public function test_can_update_invalid_user() - { - $this->verifyOrCreateRole(); - - $user = User::factory()->create(); - - $user->assignRole('admin'); - - $this->actingAs($user, 'api'); - - $admin = Admin::create(['user_id' => $user->id]); - - $user2 = User::factory()->create(); - $admin2 = Admin::create(['user_id' => $user2->id]); - - $response = $this->put("/api/v1/admins/{$admin2->id}", [ - 'name' => 'Nuevo Nombre', - 'surname' => 'Nuevo Apellido', - 'email' => 'nuevo@example.com', - ]); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson(['message' => 'No tens permís per modificar aquest usuari']); - - $response->assertStatus(401); - } - - public function test_can_destroy_destroy() - { - $this->verifyOrCreateRole(); - $user = User::factory()->create(); - $user->assignRole('admin'); - $this->actingAs($user, 'api'); - - $admin = Admin::create(['user_id' => $user->id]); - - $response = $this->delete("/api/v1/admins/{$admin->id}"); - - $response->assertHeader('Content-Type', 'application/json'); - - $response->assertStatus(200); - - $this->assertDatabaseMissing('admins', [ - 'id' => $admin->id, - ]); - - $this->assertDatabaseMissing('users', [ - 'id' => $user->id, - ]); - - $response->assertJson([ - 'message' => 'La seva compte ha estat eliminada amb èxit', - ]); - } - - public function test_can_destroy_dont_have_permissions() - { - $this->verifyOrCreateRole(); - - $user = User::factory()->create(); - $user->assignRole('admin'); - - $this->actingAs($user, 'api'); - $admin = Admin::create(['user_id' => $user->id]); - - $user2 = User::factory()->create(); - $admin2 = Admin::create(['user_id' => $user2->id]); - - $response = $this->delete("/api/v1/admins/{$admin2->id}"); - $response->assertStatus(401); - $response->assertHeader('Content-Type', 'application/json'); - - $response->assertJson([ - 'message' => 'No tens permís per eliminar aquest usuari', - ]); - } -} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index d0060c5c..00000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } */ -} diff --git a/tests/Feature/Recruiter/RecruiterDeleteTest.php b/tests/Feature/Recruiter/RecruiterDeleteTest.php deleted file mode 100644 index 9455bd47..00000000 --- a/tests/Feature/Recruiter/RecruiterDeleteTest.php +++ /dev/null @@ -1,70 +0,0 @@ -exists()) { - Role::create(['name' => 'recruiter']); - } - } - - public function test_delete_specifc_recruiter() - { - - $this->verifyOrCreateRole(); - - $user = User::factory()->create([ - - ]); - $user->assignRole('recruiter'); - $recruiter = $user->recruiter()->create([ - 'company' => 'Apple', - 'sector' => 'TIC', - - ]); - - $this->actingAs($user, 'api'); - - $response = $this->deleteJson(route('recruiter.delete', ['id' => $recruiter->id])); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson(['message' => "T'has donat de baixa com a reclutador d'It Profiles."]); - $response->assertStatus(200); - - } - - public function test_cannot_delete_specifc_recruiter() - { - - $this->verifyOrCreateRole(); - - $user = User::factory()->create([ - - ]); - $user->assignRole('recruiter'); - $user->recruiter()->create([ - 'company' => 'Apple', - 'sector' => 'TIC', - - ]); - - $fakeId = 9; - - $this->actingAs($user, 'api'); - - $response = $this->deleteJson(route('recruiter.delete', ['id' => $fakeId])); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson(['message' => 'Usuari no autenticat']); - $response->assertStatus(401); - - } -} diff --git a/tests/Feature/Recruiter/RecruiterListTest.php b/tests/Feature/Recruiter/RecruiterListTest.php deleted file mode 100644 index ec9b5f97..00000000 --- a/tests/Feature/Recruiter/RecruiterListTest.php +++ /dev/null @@ -1,40 +0,0 @@ -create(); - $user->recruiter()->create([ - 'company' => fake()->name(), - 'sector' => 'TIC', - ]); - $user->assignRole('recruiter'); - - $response = $this->getJson(route('recruiter.list')); - - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - - $response->assertJsonStructure([ - 'data' => [ - '*' => [ - 'id', - 'name', - 'surname', - 'company', - 'sector', - ], - ], - ]); - } -} diff --git a/tests/Feature/Recruiter/RecruiterRegisterTest.php b/tests/Feature/Recruiter/RecruiterRegisterTest.php deleted file mode 100644 index 6d4e4d92..00000000 --- a/tests/Feature/Recruiter/RecruiterRegisterTest.php +++ /dev/null @@ -1,107 +0,0 @@ -artisan('passport:install'); - } - - public function verifyOrCreateRole() - { - - if (! Role::where('name', 'recruiter')->exists()) { - Role::create(['name' => 'recruier']); - - } - - } - - public function test_create_recruiter_with_valid_data() - { - $this->verifyOrCreateRole(); - - $userData = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '33461332N', - 'email' => fake()->email(), - 'password' => 'password123', - 'company' => 'Apple', - 'sector' => 'Telefonia', - ]; - - $response = $this->postJson(route('recruiter.create'), $userData); - $response->assertHeader('Content-Type', 'application/json'); - - $response->assertStatus(201); - $response->assertCreated(); - - $this->assertDatabaseHas('users', [ - 'name' => $userData['name'], - 'surname' => $userData['surname'], - 'dni' => $userData['dni'], - 'email' => $userData['email'], - ]); - - $this->assertDatabaseHas('recruiters', [ - 'user_id' => User::where('email', $userData['email'])->first()->id, - 'company' => $userData['company'], - 'sector' => $userData['sector'], - ]); - - $user = User::where('email', $userData['email'])->first(); - $this->assertTrue($user->hasRole('recruiter')); - - $response->assertJson([ - 'message' => __('Registre realitzat amb èxit.'), - ]); - - } - - public function test_cant_create_recruiter_with_bad_email() - { - - $userData = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '28829324C', - 'email' => 'prueba123', - 'password' => 'password123', - 'company' => 'Apple', - 'sector' => 'Telefonia', - ]; - $response = $this->postJson(route('recruiter.create'), $userData); - $response->assertHeader('Content-Type', 'application/json')->assertStatus(422)->assertJson([ - 'errors' => [ - 'email' => [ - 'Adreça electrònica no és un e-mail vàlid', - ], - ], - ]); - - } - - public static function generateNie(): string - { - $prefixes = ['X', 'Y', 'Z']; - $randomPrefix = $prefixes[array_rand($prefixes)]; - $numbers = str_pad(mt_rand(1, 99999999), 7, '0', STR_PAD_LEFT); - $letters = 'TRWAGMYFPDXBNJZSQVHLCKE'; - - $checkDigit = $letters[($randomPrefix . $numbers) % 23]; - - return $randomPrefix . $numbers . $checkDigit; - } -} diff --git a/tests/Feature/Recruiter/RecruiterShowTest.php b/tests/Feature/Recruiter/RecruiterShowTest.php deleted file mode 100644 index 81892243..00000000 --- a/tests/Feature/Recruiter/RecruiterShowTest.php +++ /dev/null @@ -1,44 +0,0 @@ -create(); - $recruiter = $user->recruiter()->create([ - 'company' => 'Apple', - 'sector' => 'TIC', - ]); - $this->actingAs($user, 'api'); - $response = $this->getJson(route('recruiter.show', ['id' => $recruiter->id])); - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonStructure([ - 'data' => [ - 'name', 'surname', 'company', 'sector', - ], - ]); - - } - - public function test_search_recruiter_not_found() - { - $response = $this->getJson(route('recruiter.show', ['id' => 34567])); - - $response->assertStatus(404); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson([ - 'message' => 'Usuari no trobat.', - - ]); - } -} diff --git a/tests/Feature/Recruiter/RecruiterUpdateTest.php b/tests/Feature/Recruiter/RecruiterUpdateTest.php deleted file mode 100644 index 07ed7562..00000000 --- a/tests/Feature/Recruiter/RecruiterUpdateTest.php +++ /dev/null @@ -1,102 +0,0 @@ -artisan('passport:install'); - } - - public function verifyOrCreateRole() - { - if (! Role::where('name', 'recruiter')->exists()) { - Role::create(['name' => 'recruiter']); - - } - } - - public function test_update_specific_recruiter() - { - $this->verifyOrCreateRole(); - $user = User::factory()->create([ - - ]); - $user->assignRole('recruiter'); - $user->recruiter()->create([ - 'company' => 'Apple', - 'sector' => 'TIC', - - ]); - $data = ['name' => 'Nuevo nombre', - 'surname' => 'Nuevo apellido', - 'email' => fake()->email(), - 'company' => 'prueba update', - 'sector' => 'TOC', ]; - $this->actingAs($user, 'api'); - $idRecruiter = $user->recruiter->id; - - $response = $this->put(route('recruiter.update', [$idRecruiter]), $data); - - $user = $user->fresh(); - $user->recruiter->fresh(); - $this->assertEquals(ucfirst($user->name), $data['name']); - $this->assertEquals(ucfirst($user->surname), $data['surname']); - $this->assertEquals(ucfirst($user->recruiter->company), ucfirst($data['company'])); - $this->assertEquals(ucfirst($user->recruiter->sector), $data['sector']); - - $response->assertJson([ - 'data' => [ - 'name' => ucwords($user->name), - 'surname' => ucwords($user->surname), - 'company' => ucwords($user->recruiter->company), - 'sector' => ucwords($user->recruiter->sector)], - ]); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertStatus(200); - - } - - public function test_attempting_to_update_another_recruiter() - { - $this->verifyOrCreateRole(); - $user = User::factory()->create([ - - ]); - $user->assignRole('recruiter'); - $user->recruiter()->create([ - 'company' => 'Apple', - 'sector' => 'TIC', - - ]); - $fakeID = fake()->numberBetween(); - - $data = ['name' => 'Nuevo nombre', - 'surname' => 'Nuevo Apellido', - 'email' => fake()->email(), - 'company' => 'prueba update', - 'sector' => 'TOC', ]; - $this->actingAs($user, 'api'); - $response = $this->put(route('recruiter.update', [$fakeID]), $data); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson([ - 'message' => 'Usuari no autenticat', - ]); - - $response->assertUnauthorized(); - - $response->assertStatus(401); - } -} diff --git a/tests/Feature/Student/StudentDeleteTest.php b/tests/Feature/Student/StudentDeleteTest.php deleted file mode 100644 index 589b82b5..00000000 --- a/tests/Feature/Student/StudentDeleteTest.php +++ /dev/null @@ -1,105 +0,0 @@ -artisan('passport:install'); - } - - public function verifyOrCreateRolesAndPermissions() - { - if (! Role::where('name', 'student')->exists()) { - $student = Role::create(['name' => 'student']); - } - - if (! Permission::where('name', 'delete.student')->exists()) { - $deleteStudent = Permission::create(['name' => 'delete.student']); - } - - } - - /** @test */ - public function a_student_can_get_unregistered(): void - { - $this->verifyOrCreateRolesAndPermissions(); - - $user = User::create([ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '64955736X', - 'email' => $email = fake()->email(), - 'password' => bcrypt($password = 'password'), - ]); - - $user->student()->create([ - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - ]); - - $user->assignRole('student'); - - $response = $this->post('api/v1/login', [ - 'email' => $email, - 'password' => $password, - ]); - - $this->assertAuthenticatedAs($user); - - $this->actingAs($user, 'api'); - - $response = $this->withHeaders(['Accept' => 'application/json'])->delete('api/v1/students/' . $user->student->id); - - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - /* - $this->assertCount(0, User::all()); */ - $this->assertCount(0, Student::all()); - - } - - /** @test */ - public function a_student_cannot_get_unregistered_by_another_student(): void - { - $this->verifyOrCreateRolesAndPermissions(); - - $user = User::create([ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '43312254B', - 'email' => $email = fake()->email(), - 'password' => bcrypt($password = 'password'), - ]); - - $user->student()->create([ - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - ]); - - $user->assignRole('student'); - - $response = $this->post('api/v1/login', [ - 'email' => $email, - 'password' => $password, - ]); - - $this->assertAuthenticatedAs($user); - - $this->actingAs($user, 'api'); - - $response = $this->withHeaders(['Accept' => 'application/json'])->delete('api/v1/students/25'); - - $response->status(401); - - } -} diff --git a/tests/Feature/Student/StudentListTest.php b/tests/Feature/Student/StudentListTest.php deleted file mode 100644 index 9f7879c6..00000000 --- a/tests/Feature/Student/StudentListTest.php +++ /dev/null @@ -1,41 +0,0 @@ -artisan('passport:install'); - $this->artisan('migrate:fresh --seed'); - } - - /** - * @test - * @group OpenEndpoints - */ - public function test_student_list_controller() - { - $response = $this->getJson(route('profiles.home')); - - $response->assertStatus(200); - - $response->assertJsonStructure([ - '*' => [ - 'fullname', - 'subtitle', - 'photo', - 'tags' => [ - '*' => [ - 'id', - 'name' - ], - ], - ], - ]); - } -} diff --git a/tests/Feature/Student/StudentRegisterTest.php b/tests/Feature/Student/StudentRegisterTest.php deleted file mode 100644 index 391c2e36..00000000 --- a/tests/Feature/Student/StudentRegisterTest.php +++ /dev/null @@ -1,208 +0,0 @@ -artisan('passport:install'); - } - - public function verifyOrCreateRole() - { - if (! Role::where('name', 'student')->exists()) { - Role::create(['name' => 'student']); - } - } - - /** @test */ - public function a_student_can_register_with_valid_data(): void - { - $this->verifyOrCreateRole(); - - $data = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '79569967H', - 'email' => fake()->email(), - 'password' => 'password123', - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - //end_date - ]; - - $response = $this->post('/api/v1/students', $data); - - $this->assertDatabaseHas('users', [ - 'name' => $data['name'], - 'surname' => $data['surname'], - 'dni' => $data['dni'], - 'email' => $data['email'], - ]); - - $this->assertDatabaseHas('students', [ - 'subtitle' => $data['subtitle'], - 'bootcamp' => $data['bootcamp'], - 'user_id' => User::where('email', $data['email'])->first()->id, - ]); - - $user = User::where('email', $data['email'])->first(); - - $this->assertTrue($user->hasRole('student')); - - $response->assertStatus(201); - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJson(['message' => __('Registre realitzat amb èxit.')], 201); - } - - /** @test */ - public function a_student_can_not_register_with_null_fields(): void - { - $this->verifyOrCreateRole(); - - $data = [ - 'name' => null, - 'surname' => null, - 'dni' => null, - 'email' => null, - 'password' => null, - 'subtitle' => null, - 'bootcamp' => null, - //end_date - ]; - - $response = $this->post('/api/v1/students', $data); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonValidationErrors([ - 'name', 'surname', 'dni', 'email', 'password', 'subtitle', 'bootcamp', - ]); - } - - /** @test */ - public function a_student_can_not_register_if_name_or_surname_contains_numbers(): void - { - $this->verifyOrCreateRole(); - - $data = [ - 'name' => 'John23', - 'surname' => 'Doe23', - 'dni' => '48022981Q', - 'email' => fake()->email(), - 'password' => 'password123', - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - //end_date - ]; - - $response = $this->post('/api/v1/students', $data); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonValidationErrors([ - 'name', 'surname', - ]); - } - - /** @test */ - public function a_student_can_not_register_if_name_or_surname_is_email(): void - { - $this->verifyOrCreateRole(); - - $data = [ - 'name' => 'john@example.com', - 'surname' => 'john@example.com', - 'dni' => '00768001P', - 'email' => fake()->email(), - 'password' => 'password123', - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - //end_date - ]; - - $response = $this->post('/api/v1/students', $data); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonValidationErrors([ - 'name', 'surname', - ]); - } - - /** @test */ - public function a_student_can_not_register_with_invalid_mail(): void - { - $this->verifyOrCreateRole(); - - $data = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '18469917C', - 'email' => 'fvdfvfd', - 'password' => 'password123', - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - //end_date - ]; - - $response = $this->post('/api/v1/students', $data); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonValidationErrors([ - 'email', - ]); - } - - /** @test */ - public function a_student_can_not_register_with_invalid_bootcamp(): void - { - $this->verifyOrCreateRole(); - - $data = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '79331328G', - 'email' => fake()->email(), - 'password' => 'password123', - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP', - //end_date - ]; - - $response = $this->post('/api/v1/students', $data); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonValidationErrors([ - 'bootcamp', - ]); - } - - /** @test */ - public function a_student_can_not_register_if_dni_is_invalid(): void - { - $this->verifyOrCreateRole(); - - $data = [ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '53671299Z', - 'email' => fake()->email(), - 'password' => 'password123', - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - //end_date - ]; - - $response = $this->post('/api/v1/students', $data); - - $response->assertHeader('Content-Type', 'application/json'); - $response->assertJsonValidationErrors([ - 'dni', - ]); - } -} diff --git a/tests/Feature/Student/StudentShowTest.php b/tests/Feature/Student/StudentShowTest.php deleted file mode 100644 index 4fbec6be..00000000 --- a/tests/Feature/Student/StudentShowTest.php +++ /dev/null @@ -1,50 +0,0 @@ -artisan('passport:install'); - } - - public function verifyOrCreateRole() - { - if (! Role::where('name', 'student')->exists()) { - Role::create(['name' => 'student']); - } - } - - /** @test */ - public function a_student_info_can_be_retrieved(): void - { - $this->verifyOrCreateRole(); - - $user = User::create([ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '71858753Z', - 'email' => fake()->email(), - 'password' => 'password123', - ]); - - $user->student()->create([ - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - ]); - - $user->assignRole('student'); - - $response = $this->get('api/v1/students/' . $user->student->id); - - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - } -} diff --git a/tests/Feature/Student/StudentUpdateTest.php b/tests/Feature/Student/StudentUpdateTest.php deleted file mode 100644 index 9527e5b9..00000000 --- a/tests/Feature/Student/StudentUpdateTest.php +++ /dev/null @@ -1,131 +0,0 @@ -artisan('passport:install'); - } - - public function verifyOrCreateRolesAndPermissions() - { - if (! Role::where('name', 'student')->exists()) { - $student = Role::create(['name' => 'student']); - } - - if (! Permission::where('name', 'update.student')->exists()) { - $updateStudent = Permission::create(['name' => 'update.student']); - } - - } - - /** @test */ - public function student_data_can_be_updated_by_himself(): void - { - $this->verifyOrCreateRolesAndPermissions(); - - $user = User::create([ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '52089182R', - 'email' => fake()->email(), - 'password' => bcrypt($password = 'password'), - ]); - - $user->student()->create([ - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - ]); - - $user->assignRole('student'); - $this->actingAs($user, 'api'); - $response = $this->post('api/v1/login', [ - 'email' => fake()->email(), - 'password' => $password, - ]); - - $this->assertAuthenticatedAs($user); - - $data = [ - 'name' => 'Johnny', - 'surname' => 'Doe', - 'email' => 'johnny@example.com', - 'subtitle' => 'Enginyer Informàtic i Programador', - 'bootcamp' => 'PHP Developer', - 'about' => 'Lorem ipsum dolor sit amet.', - 'cv' => 'New Curriculum', - 'linkedin' => 'http://www.linkedin.com/johnnydoe', - 'github' => 'http://www.github.com/johnnydoe', - ]; - - $response = $this->withHeaders(['Accept' => 'application/json'])->put('api/v1/students/' . $user->student->id, $data); - - $user = $user->fresh(); - $student = $user->student->fresh(); - - $response->assertStatus(200); - $response->assertHeader('Content-Type', 'application/json'); - - $this->assertEquals($user->name, Str::lower($data['name'])); - $this->assertEquals($user->email, Str::lower($data['email'])); - $this->assertEquals($student->cv, $data['cv']); - } - - /** @test */ - public function student_data_cannot_be_updated_by_another_student(): void - { - $this->verifyOrCreateRolesAndPermissions(); - - $user = User::create([ - 'name' => 'John', - 'surname' => 'Doe', - 'dni' => '74542265R', - 'email' => fake()->email(), - 'password' => bcrypt($password = 'password'), - ]); - - $user->student()->create([ - 'subtitle' => 'Enginyer Informàtic i Programador.', - 'bootcamp' => 'PHP Developer', - ]); - - $user->assignRole('student'); - - $response = $this->post('api/v1/login', [ - 'email' => fake()->email(), - 'password' => $password, - ]); - - $this->actingAs($user, 'api'); - - $data = [ - 'name' => 'Johnny', - 'surname' => 'Doe', - 'email' => fake()->email(), - 'subtitle' => 'Enginyer Informàtic i Programador', - 'bootcamp' => 'PHP Developer', - 'about' => 'Lorem ipsum dolor sit amet.', - 'cv' => 'New Curriculum', - 'linkedin' => 'http://www.linkedin.com/johnnydoe', - 'github' => 'http://www.github.com/johnnydoe', - ]; - - $response = $this->withHeaders(['Accept' => 'application/json'])->put('api/v1/students/50', $data); - - $user = $user->fresh(); - $student = $user->student->fresh(); - - $response->assertStatus(401); - - } -}