Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrección de tests #194

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions backend/tests/auth_student_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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")

}
2 changes: 1 addition & 1 deletion backend/tests/carrera_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/company_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
37 changes: 23 additions & 14 deletions backend/tests/functional_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"backend/configs"
"bytes"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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{})

}
54 changes: 29 additions & 25 deletions backend/tests/offer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"backend/configs"
"bytes"
"encoding/json"
"fmt"
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 *************")

}