diff --git a/backend/tests/auth_student_test.go b/backend/tests/auth_student_test.go index 4ca2caa8..fdd39a4a 100644 --- a/backend/tests/auth_student_test.go +++ b/backend/tests/auth_student_test.go @@ -39,13 +39,11 @@ func CORS() gin.HandlerFunc { } } -func TestLogin(t *testing.T) { +func TestLogin(t *testing.T) { // no es necesario eliminar usuarios. router := setupRouter() w := httptest.NewRecorder() - // usuario: mor21246@uvg - // contraseña: mora - jsonData := `{"usuario": "prueba@prueba", "contra": "prueba"}` + jsonData := `{"usuario": "empresa@prueba.com", "contra": "empresaprueba"}` body := bytes.NewBufferString(jsonData) @@ -63,7 +61,7 @@ func TestNewStudent(t *testing.T) { w := httptest.NewRecorder() - jsonData := `{"dpi": "101010101010", "nombre": "Juan", "apellido": "Perez", "nacimiento": "19/05/2002", "correo": "juan@prueba.com", "telefono": "55555555", "carrera": 1, "semestre": 4, "contra": "12345678", "CV": "", "foto": "", "universidad": "Universidad del Valle de Guatemala"}` + jsonData := `{"dpi": "101010101010", "nombre": "Estudiante", "apellido": "Prueba", "nacimiento": "01/01/2001", "correo": "estudiante@prueba.com", "telefono": "12345678", "carrera": 1, "semestre": 4, "contra": "estudianteprueba", "CV": "", "foto": "", "universidad": "Universidad del Valle de Guatemala"}` body := bytes.NewBufferString(jsonData) @@ -81,7 +79,7 @@ func TestUpdateStudent(t *testing.T) { router := setupRouter() w := httptest.NewRecorder() - jsonData := `{"usuario": "prueba@prueba", "contra": "prueba"}` // Solo para obtener el token + jsonData := `{"usuario": "estudiante@prueba.com", "contra": "estudianteprueba"}` // Solo para obtener el token body := bytes.NewBufferString(jsonData) req := httptest.NewRequest("POST", "/api/login", body) @@ -107,7 +105,7 @@ func TestUpdateStudent(t *testing.T) { // Paso 3: Usar el token para hacer la actualización del estudiante w = httptest.NewRecorder() - jsonData = `{"dpi": "101010101010", "nombre": "Juan", "apellido": "Perez", "nacimiento": "19/05/2002", "correo": "juan@prueba.com", "telefono": "666666", "carrera": 1, "semestre": 4, "contra": "12345678", "CV": "", "foto": "", "universidad": "Universidad del Valle de Guatemala"}` + jsonData = `{"dpi": "101010101010", "nombre": "ESTUDIANTE", "apellido": "PRUEBA", "nacimiento": "02/02/2002", "correo": "estudiante@prueba.com", "telefono": "87654321", "carrera": 1, "semestre": 4, "contra": "estudianteprueba", "CV": "", "foto": "", "universidad": "Universidad del Valle de Guatemala"}` body = bytes.NewBufferString(jsonData) req = httptest.NewRequest("PUT", "/api/students/update", body) @@ -118,4 +116,5 @@ func TestUpdateStudent(t *testing.T) { fmt.Println(w.Body.String()) assert.Equal(t, http.StatusOK, w.Code, "Status code is not 200 on update student") + } diff --git a/backend/tests/carrera_test.go b/backend/tests/carrera_test.go index c25191a2..bf438a85 100644 --- a/backend/tests/carrera_test.go +++ b/backend/tests/carrera_test.go @@ -17,7 +17,7 @@ func TestGetCarreras(t *testing.T) { w := httptest.NewRecorder() // login needed to get token - jsonData := `{"usuario": "prueba@prueba", "contra": "prueba"}` + jsonData := `{"usuario": "estudiante@prueba.com", "contra": "estudianteprueba"}` body := bytes.NewBufferString(jsonData) req := httptest.NewRequest("POST", "/api/login", body) router.ServeHTTP(w, req) diff --git a/backend/tests/company_test.go b/backend/tests/company_test.go index ccf10a62..53dec57d 100644 --- a/backend/tests/company_test.go +++ b/backend/tests/company_test.go @@ -15,7 +15,7 @@ func TestUpdateCompany(t *testing.T) { w := httptest.NewRecorder() // Login needed to get token - jsonDataPrev := `{"usuario": "reclutamiento@sarita.com", "contra": "sarita"}` + jsonDataPrev := `{"usuario": "empresa@prueba.com", "contra": "empresaprueba"}` bodyPrev := bytes.NewBufferString(jsonDataPrev) reqPrev := httptest.NewRequest("POST", "/api/login", bodyPrev) router.ServeHTTP(w, reqPrev) @@ -32,7 +32,7 @@ func TestUpdateCompany(t *testing.T) { err := json.Unmarshal(w.Body.Bytes(), &loginResponse) assert.NoError(t, err, "Error unmarshalling login response") - jsonData := `{"nombre": "Sarita SA", "detalles": "Dummy 2", "correo": "reclutamiento@sarita.com", "telefono": "22227314", "contra": "sarita"}` + jsonData := `{"nombre": "Empresa de Prueba", "detalles": "Detalles de Prueba", "correo": "empresa@prueba.com", "telefono": "12345678", "contra": "empresaprueba"}` body := bytes.NewBufferString(jsonData) req := httptest.NewRequest("PUT", "/api/companies/update", body) req.Header.Set("Authorization", "Bearer "+loginResponse.Data.Token) diff --git a/backend/tests/functional_test.go b/backend/tests/functional_test.go index 826f93c0..c1c6a0e1 100644 --- a/backend/tests/functional_test.go +++ b/backend/tests/functional_test.go @@ -1,6 +1,7 @@ package tests import ( + "backend/configs" "bytes" "encoding/json" "fmt" @@ -42,7 +43,7 @@ func TestCaseOne(t *testing.T) { w := httptest.NewRecorder() // Paso 1: Iniciar sesión - jsonLogin := `{"usuario": "alb21004@uvg.edu.gt", "contra": "mark"}` + jsonLogin := `{"usuario": "estudiante@prueba.com", "contra": "estudianteprueba"}` body := bytes.NewBufferString(jsonLogin) req := httptest.NewRequest("POST", "/api/login", body) @@ -101,7 +102,7 @@ func TestCaseOne(t *testing.T) { w = httptest.NewRecorder() // id_oferta, id_estudiante, estado - jsonPostulation := `{"id_oferta": ` + id_offer_S + `, "id_estudiante": "alb21004@uvg.edu.gt", "estado": "Enviada"}` + jsonPostulation := `{"id_oferta": ` + id_offer_S + `, "id_estudiante": "estudiante@prueba.com", "estado": "Enviada"}` body = bytes.NewBufferString(jsonPostulation) req = httptest.NewRequest("POST", "/api/postulations/", body) @@ -116,7 +117,7 @@ func TestCaseOne(t *testing.T) { } -func TestCaseTwo(t *testing.T) { +func TestCaseTwo(t *testing.T) { // ESTEE /* Una empresa quiere "postear" una oferta laboral. pasos: @@ -127,7 +128,7 @@ func TestCaseTwo(t *testing.T) { w := httptest.NewRecorder() // Paso 1: Iniciar sesión - jsonLogin := `{"usuario": "prueba@prueba", "contra": "prueba"}` + jsonLogin := `{"usuario": "empresa@prueba.com", "contra": "empresaprueba"}` body := bytes.NewBufferString(jsonLogin) req := httptest.NewRequest("POST", "/api/login", body) router.ServeHTTP(w, req) @@ -150,7 +151,7 @@ func TestCaseTwo(t *testing.T) { w = httptest.NewRecorder() // crear el body. - jsonOffer := `{"id_empresa": "prueba@prueba", "puesto": "FrontEnd Developer", "descripcion": "UX/UI Desing with JS", "requisitos": "Experiencia con JavaScript y Typescript", "salario":100.00, "id_carreras":["1", "2", "3"]}` + jsonOffer := `{"id_empresa": "empresa@prueba.com", "puesto": "Puesto de Prueba TC2", "descripcion": "Descripcion de Prueba", "requisitos": "Experiencia de Prueba", "salario":100.00, "id_carreras":["1", "2", "3"]}` body2 := bytes.NewBufferString(jsonOffer) req = httptest.NewRequest("POST", "/api/offers/", body2) @@ -162,6 +163,11 @@ func TestCaseTwo(t *testing.T) { assert.True(t, w.Code == http.StatusOK || w.Code == http.StatusConflict, w.Code, "El usuario puede añadir una oferta laboral") assert.Equal(t, http.StatusOK, w.Code, "El usuario puede añadir una oferta laboral") + // eliminar con un query la oferta que se acaba de crear. + + //configs.DB.Where("puesto = 'Puesto de Prueba TC2'").Delete(&Offer{}) + //configs.DB.Raw("DELETE FROM oferta WHERE puesto = 'Puesto de Prueba TC2'").Scan(&Offer{}) + } func TestCaseThree(t *testing.T) { @@ -173,7 +179,7 @@ func TestCaseThree(t *testing.T) { w := httptest.NewRecorder() // Paso 1: Iniciar sesión - jsonLogin := `{"usuario": "mor21146@uvg.edu.gt", "contra": "mora"}` + jsonLogin := `{"usuario": "estudiante@prueba.com", "contra": "estudianteprueba"}` body := bytes.NewBufferString(jsonLogin) req := httptest.NewRequest("POST", "/api/login", body) router.ServeHTTP(w, req) @@ -199,18 +205,18 @@ func TestCaseThree(t *testing.T) { // Paso 3: Modificar los campos que se deseen // crear el body. - jsonUpdate := `{"dpi" : "3239183600512", - "nombre" : "Diego", - "apellido" : "Morales", - "nacimiento" : "2002-10-24", - "correo" : "mor21146@uvg.edu.gt", - "telefono" : "55447788", + jsonUpdate := `{"dpi" : "101010101010", + "nombre" : "Estudiante Actualizado", + "apellido" : "Prueba", + "nacimiento" : "2002-02-02", + "correo" : "estudiante@prueba.com", + "telefono" : "12345678", "carrera" : 1, "semestre" : 4, "cv" : "", "foto" : "", - "contra" : "mora", - "universidad" : "UVG"}` + "contra" : "estudianteprueba", + "universidad" : "Universidad Del Valle de Guatemala"}` body2 := bytes.NewBufferString(jsonUpdate) // Paso 4: Guardar los cambios req = httptest.NewRequest("PUT", "/api/students/update", body2) @@ -222,4 +228,7 @@ func TestCaseThree(t *testing.T) { fmt.Println(w.Body.String()) assert.True(t, w.Code == http.StatusOK || w.Code == http.StatusConflict, w.Code, "El usuario puede editar su perfil") + configs.DB.Raw("DELETE FROM oferta WHERE puesto = 'Puesto de Prueba TC2'").Scan(&Offer{}) + configs.DB.Raw("DELETE FROM postulacion WHERE id_estudiante = 'estudiante@prueba.com'").Scan(&Postulations{}) + } diff --git a/backend/tests/offer_test.go b/backend/tests/offer_test.go index bb92477d..3025d975 100644 --- a/backend/tests/offer_test.go +++ b/backend/tests/offer_test.go @@ -1,6 +1,7 @@ package tests import ( + "backend/configs" "bytes" "encoding/json" "fmt" @@ -10,16 +11,14 @@ import ( "testing" ) -func TestGetOffer(t *testing.T) { - // api/offers/all - // Get a specific offer. +func TestNewOffer(t *testing.T) { + // api/offers/ + // Create a new offer. - // setting up router router := setupRouter() w := httptest.NewRecorder() - // Login needed to get token - jsonData := `{"usuario": "reclutamiento@sarita.com", "contra": "sarita"}` + jsonData := `{"usuario": "empresa@prueba.com", "contra": "empresaprueba"}` body := bytes.NewBufferString(jsonData) req := httptest.NewRequest("POST", "/api/login", body) router.ServeHTTP(w, req) @@ -36,27 +35,33 @@ func TestGetOffer(t *testing.T) { err := json.Unmarshal(w.Body.Bytes(), &loginResponse) assert.NoError(t, err, "Error unmarshalling login response") - jsonData2 := `{"id_oferta":"7"}` + jsonData2 := `{"id_empresa":"empresa@prueba.com", "puesto":"puesto prueba JSJSJS", "descripcion":"descripcion prueba", "requisitos":"requisitos prueba", "salario":1000.00, "id_carreras":["1", "2", "3"]}` body2 := bytes.NewBufferString(jsonData2) - req2 := httptest.NewRequest("POST", "/api/offers/all", body2) + req2 := httptest.NewRequest("POST", "/api/offers/", body2) req2.Header.Set("Authorization", "Bearer "+loginResponse.Data.Token) + router.ServeHTTP(w, req2) - fmt.Println("************* TEST GET OFFER *************") + fmt.Println("************* Creating a new Offer *************") fmt.Println(w.Body.String()) assert.Equal(t, http.StatusOK, w.Code, "Status code is not 200 on new offer") fmt.Println("************* Testing Results END *************") + + // eliminar la oferta que acabo de hacer. + configs.DB.Raw("DELETE FROM oferta WHERE puesto = 'puesto prueba JSJSJS'").Scan(&loginResponse) + } -func TestCompanyOffers(t *testing.T) { - // api/offers/company - // All the offers a company has made. +func TestGetOffer(t *testing.T) { + // api/offers/all + // Get a specific offer. + // setting up router router := setupRouter() w := httptest.NewRecorder() // Login needed to get token - jsonData := `{"usuario": "reclutamiento@sarita.com", "contra": "sarita"}` + jsonData := `{"usuario": "empresa@prueba.com", "contra": "empresaprueba"}` body := bytes.NewBufferString(jsonData) req := httptest.NewRequest("POST", "/api/login", body) router.ServeHTTP(w, req) @@ -73,26 +78,27 @@ func TestCompanyOffers(t *testing.T) { err := json.Unmarshal(w.Body.Bytes(), &loginResponse) assert.NoError(t, err, "Error unmarshalling login response") - jsonData2 := `{"id_empresa": "reclutamiento@sarita.com"}` + jsonData2 := `{"id_oferta":"330"}` body2 := bytes.NewBufferString(jsonData2) - req2 := httptest.NewRequest("POST", "/api/offers/company", body2) + req2 := httptest.NewRequest("POST", "/api/offers/all", body2) req2.Header.Set("Authorization", "Bearer "+loginResponse.Data.Token) router.ServeHTTP(w, req2) - fmt.Println("************* Test All the Offers of a company *************") + fmt.Println("************* TEST GET OFFER *************") fmt.Println(w.Body.String()) assert.Equal(t, http.StatusOK, w.Code, "Status code is not 200 on new offer") fmt.Println("************* Testing Results END *************") } -func TestNewOffer(t *testing.T) { - // api/offers/ - // Create a new offer. +func TestCompanyOffers(t *testing.T) { + // api/offers/company + // All the offers a company has made. router := setupRouter() w := httptest.NewRecorder() - jsonData := `{"usuario": "reclutamiento@sarita.com", "contra": "sarita"}` + // Login needed to get token + jsonData := `{"usuario": "empresa@prueba.com", "contra": "empresaprueba"}` body := bytes.NewBufferString(jsonData) req := httptest.NewRequest("POST", "/api/login", body) router.ServeHTTP(w, req) @@ -109,16 +115,14 @@ func TestNewOffer(t *testing.T) { err := json.Unmarshal(w.Body.Bytes(), &loginResponse) assert.NoError(t, err, "Error unmarshalling login response") - jsonData2 := `{"id_empresa":"reclutamiento@sarita.com", "puesto":"puesto dummy", "descripcion":"descripcion dummy", "requisitos":"requisitos dummy", "salario":1000.00, "id_carreras":["1", "2", "3"]}` + jsonData2 := `{"id_empresa": "reclutamiento@sarita.com"}` body2 := bytes.NewBufferString(jsonData2) - req2 := httptest.NewRequest("POST", "/api/offers/", body2) + req2 := httptest.NewRequest("POST", "/api/offers/company", body2) req2.Header.Set("Authorization", "Bearer "+loginResponse.Data.Token) - router.ServeHTTP(w, req2) - fmt.Println("************* Creating a new Offer *************") + fmt.Println("************* Test All the Offers of a company *************") fmt.Println(w.Body.String()) assert.Equal(t, http.StatusOK, w.Code, "Status code is not 200 on new offer") fmt.Println("************* Testing Results END *************") - }