Commit f116e1bf by Rubén Ramírez

fix: [DTOBibliotecaPersonal]: Corregida errata

parent 4da14105
package com.ujaen.tfg.mangaffinity.rest.DTO;
import com.ujaen.tfg.mangaffinity.entidades.BibliotecaPersonal;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor
public class DTOBibliotecaPersonal {
private Long id;
private Long usuarioId;
......
......@@ -4,9 +4,7 @@ import com.ujaen.tfg.mangaffinity.MangAffinityApplication;
import com.ujaen.tfg.mangaffinity.config.JpaTestConfig;
import com.ujaen.tfg.mangaffinity.entidades.BibliotecaPersonal;
import com.ujaen.tfg.mangaffinity.entidades.Usuario;
import com.ujaen.tfg.mangaffinity.rest.DTO.DTOLoginRespuesta;
import com.ujaen.tfg.mangaffinity.rest.DTO.DTOUsuario;
import com.ujaen.tfg.mangaffinity.rest.DTO.Mapper;
import com.ujaen.tfg.mangaffinity.rest.DTO.*;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -17,6 +15,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.*;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
......@@ -56,6 +55,8 @@ public class TestUsuariosController {
@Autowired
TestRestTemplate restTemplateUsuarios;
@Autowired
private JdbcTemplate jdbcTemplate;
@PostConstruct
......@@ -192,7 +193,6 @@ public class TestUsuariosController {
assertThat(authResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
String token = "Bearer " + authResponse.getBody().getToken();
ResponseEntity<Long> respuestaUsuarioId = restTemplate.exchange(
"/usuarios/email/{email}", HttpMethod.GET, null, Long.class, "usuario@example.com"
);
......@@ -200,21 +200,28 @@ public class TestUsuariosController {
Long usuarioId = respuestaUsuarioId.getBody();
assertThat(usuarioId).isNotNull();
// Verifico que la biblioteca personal se creó en la base de datos
boolean bibliotecaExiste = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM biblioteca_personal WHERE usuario_id = ?",
Integer.class, usuarioId
) > 0;
assertThat(bibliotecaExiste).isTrue();
// Obtengo la biblioteca personal del usuario
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", token);
HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
ResponseEntity<BibliotecaPersonal> respuestaBiblioteca = restTemplate.exchange(
"/usuarios/{usuarioId}/biblioteca", HttpMethod.GET, requestEntity, BibliotecaPersonal.class, usuarioId
ResponseEntity<DTOBibliotecaPersonal> respuestaBiblioteca = restTemplate.exchange(
"/usuarios/{usuarioId}/biblioteca", HttpMethod.GET, requestEntity, DTOBibliotecaPersonal.class, usuarioId
);
// Verifico la respuesta
assertThat(respuestaBiblioteca.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(respuestaBiblioteca.getBody().getUsuario().getId()).isEqualTo(usuarioId);
assertThat(respuestaBiblioteca.getBody()).isNotNull();
assertThat(respuestaBiblioteca.getBody().getUsuarioId()).isEqualTo(usuarioId);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment