mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-16 09:00:47 +08:00
Merge pull request #38 from nagisa77/codex/define-captchaservice-bean
Fix captcha dependency in tests
This commit is contained in:
@@ -4,6 +4,7 @@ import com.openisle.model.User;
|
|||||||
import com.openisle.service.EmailSender;
|
import com.openisle.service.EmailSender;
|
||||||
import com.openisle.service.JwtService;
|
import com.openisle.service.JwtService;
|
||||||
import com.openisle.service.UserService;
|
import com.openisle.service.UserService;
|
||||||
|
import com.openisle.service.CaptchaService;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -34,6 +35,8 @@ class AuthControllerTest {
|
|||||||
private JwtService jwtService;
|
private JwtService jwtService;
|
||||||
@MockBean
|
@MockBean
|
||||||
private EmailSender emailService;
|
private EmailSender emailService;
|
||||||
|
@MockBean
|
||||||
|
private CaptchaService captchaService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void registerSendsEmail() throws Exception {
|
void registerSendsEmail() throws Exception {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.openisle.model.Comment;
|
|||||||
import com.openisle.model.Post;
|
import com.openisle.model.Post;
|
||||||
import com.openisle.model.User;
|
import com.openisle.model.User;
|
||||||
import com.openisle.service.CommentService;
|
import com.openisle.service.CommentService;
|
||||||
|
import com.openisle.service.CaptchaService;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -30,6 +31,8 @@ class CommentControllerTest {
|
|||||||
|
|
||||||
@MockBean
|
@MockBean
|
||||||
private CommentService commentService;
|
private CommentService commentService;
|
||||||
|
@MockBean
|
||||||
|
private CaptchaService captchaService;
|
||||||
|
|
||||||
private Comment createComment(Long id, String content, String authorName) {
|
private Comment createComment(Long id, String content, String authorName) {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.openisle.model.Category;
|
|||||||
import com.openisle.service.PostService;
|
import com.openisle.service.PostService;
|
||||||
import com.openisle.service.CommentService;
|
import com.openisle.service.CommentService;
|
||||||
import com.openisle.service.ReactionService;
|
import com.openisle.service.ReactionService;
|
||||||
|
import com.openisle.service.CaptchaService;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -37,6 +38,8 @@ class PostControllerTest {
|
|||||||
private CommentService commentService;
|
private CommentService commentService;
|
||||||
@MockBean
|
@MockBean
|
||||||
private ReactionService reactionService;
|
private ReactionService reactionService;
|
||||||
|
@MockBean
|
||||||
|
private CaptchaService captchaService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createAndGetPost() throws Exception {
|
void createAndGetPost() throws Exception {
|
||||||
|
|||||||
@@ -35,8 +35,10 @@ class ComplexFlowIntegrationTest {
|
|||||||
rest.postForEntity("/api/auth/register", new HttpEntity<>(
|
rest.postForEntity("/api/auth/register", new HttpEntity<>(
|
||||||
Map.of("username", username, "email", email, "password", "pass123"), h), Map.class);
|
Map.of("username", username, "email", email, "password", "pass123"), h), Map.class);
|
||||||
User u = users.findByUsername(username).orElseThrow();
|
User u = users.findByUsername(username).orElseThrow();
|
||||||
rest.postForEntity("/api/auth/verify", new HttpEntity<>(
|
if (u.getVerificationCode() != null) {
|
||||||
Map.of("username", username, "code", u.getVerificationCode()), h), Map.class);
|
rest.postForEntity("/api/auth/verify", new HttpEntity<>(
|
||||||
|
Map.of("username", username, "code", u.getVerificationCode()), h), Map.class);
|
||||||
|
}
|
||||||
ResponseEntity<Map> resp = rest.postForEntity("/api/auth/login", new HttpEntity<>(
|
ResponseEntity<Map> resp = rest.postForEntity("/api/auth/login", new HttpEntity<>(
|
||||||
Map.of("username", username, "password", "pass123"), h), Map.class);
|
Map.of("username", username, "password", "pass123"), h), Map.class);
|
||||||
return (String) resp.getBody().get("token");
|
return (String) resp.getBody().get("token");
|
||||||
|
|||||||
@@ -31,8 +31,10 @@ class SearchIntegrationTest {
|
|||||||
rest.postForEntity("/api/auth/register", new HttpEntity<>(
|
rest.postForEntity("/api/auth/register", new HttpEntity<>(
|
||||||
Map.of("username", username, "email", email, "password", "pass123"), h), Map.class);
|
Map.of("username", username, "email", email, "password", "pass123"), h), Map.class);
|
||||||
User u = users.findByUsername(username).orElseThrow();
|
User u = users.findByUsername(username).orElseThrow();
|
||||||
rest.postForEntity("/api/auth/verify", new HttpEntity<>(
|
if (u.getVerificationCode() != null) {
|
||||||
Map.of("username", username, "code", u.getVerificationCode()), h), Map.class);
|
rest.postForEntity("/api/auth/verify", new HttpEntity<>(
|
||||||
|
Map.of("username", username, "code", u.getVerificationCode()), h), Map.class);
|
||||||
|
}
|
||||||
ResponseEntity<Map> resp = rest.postForEntity("/api/auth/login", new HttpEntity<>(
|
ResponseEntity<Map> resp = rest.postForEntity("/api/auth/login", new HttpEntity<>(
|
||||||
Map.of("username", username, "password", "pass123"), h), Map.class);
|
Map.of("username", username, "password", "pass123"), h), Map.class);
|
||||||
return (String) resp.getBody().get("token");
|
return (String) resp.getBody().get("token");
|
||||||
|
|||||||
Reference in New Issue
Block a user