mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 22:21:09 +08:00
Merge branch 'main' into codex/fix-test-case-for-complexflowintegrationtest
This commit is contained in:
@@ -47,7 +47,7 @@ class NotificationControllerTest {
|
||||
.principal(new UsernamePasswordAuthenticationToken("alice","p")))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$[0].id").value(1))
|
||||
.andExpect(jsonPath("$[0].postId").value(2));
|
||||
.andExpect(jsonPath("$[0].post.id").value(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -81,7 +81,7 @@ class UserControllerTest {
|
||||
User u = new User();
|
||||
u.setId(2L);
|
||||
u.setUsername("bob");
|
||||
Mockito.when(userService.findByUsername("bob")).thenReturn(Optional.of(u));
|
||||
Mockito.when(userService.findByIdentifier("bob")).thenReturn(Optional.of(u));
|
||||
|
||||
mockMvc.perform(get("/api/users/bob"))
|
||||
.andExpect(status().isOk())
|
||||
@@ -100,6 +100,7 @@ class UserControllerTest {
|
||||
post.setCreatedAt(java.time.LocalDateTime.now());
|
||||
post.setCategory(cat);
|
||||
post.setAuthor(user);
|
||||
Mockito.when(userService.findByIdentifier("bob")).thenReturn(Optional.of(user));
|
||||
Mockito.when(postService.getRecentPostsByUser("bob", 10)).thenReturn(java.util.List.of(post));
|
||||
|
||||
mockMvc.perform(get("/api/users/bob/posts"))
|
||||
@@ -119,6 +120,7 @@ class UserControllerTest {
|
||||
comment.setCreatedAt(java.time.LocalDateTime.now());
|
||||
comment.setAuthor(user);
|
||||
comment.setPost(post);
|
||||
Mockito.when(userService.findByIdentifier("bob")).thenReturn(Optional.of(user));
|
||||
Mockito.when(commentService.getRecentCommentsByUser("bob", 50)).thenReturn(java.util.List.of(comment));
|
||||
|
||||
mockMvc.perform(get("/api/users/bob/replies"))
|
||||
@@ -147,7 +149,7 @@ class UserControllerTest {
|
||||
comment.setAuthor(user);
|
||||
comment.setPost(post);
|
||||
|
||||
Mockito.when(userService.findByUsername("bob")).thenReturn(Optional.of(user));
|
||||
Mockito.when(userService.findByIdentifier("bob")).thenReturn(Optional.of(user));
|
||||
Mockito.when(postService.getRecentPostsByUser("bob", 10)).thenReturn(java.util.List.of(post));
|
||||
Mockito.when(commentService.getRecentCommentsByUser("bob", 50)).thenReturn(java.util.List.of(comment));
|
||||
|
||||
|
||||
@@ -36,8 +36,10 @@ class PublishModeIntegrationTest {
|
||||
rest.postForEntity("/api/auth/register", new HttpEntity<>(
|
||||
Map.of("username", username, "email", email, "password", "pass123"), h), Map.class);
|
||||
User u = users.findByUsername(username).orElseThrow();
|
||||
rest.postForEntity("/api/auth/verify", new HttpEntity<>(
|
||||
Map.of("username", username, "code", u.getVerificationCode()), h), Map.class);
|
||||
if (u.getVerificationCode() != null) {
|
||||
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<>(
|
||||
Map.of("username", username, "password", "pass123"), h), Map.class);
|
||||
return (String) resp.getBody().get("token");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.openisle.service;
|
||||
|
||||
import com.openisle.model.PasswordStrength;
|
||||
import com.openisle.exception.FieldException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -11,7 +12,7 @@ class PasswordValidatorTest {
|
||||
void lowStrengthRequiresSixChars() {
|
||||
PasswordValidator validator = new PasswordValidator(PasswordStrength.LOW);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("12345"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("12345"));
|
||||
assertDoesNotThrow(() -> validator.validate("123456"));
|
||||
}
|
||||
|
||||
@@ -19,9 +20,9 @@ class PasswordValidatorTest {
|
||||
void mediumStrengthRules() {
|
||||
PasswordValidator validator = new PasswordValidator(PasswordStrength.MEDIUM);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("abc123"));
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("abcdefgh"));
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("12345678"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("abc123"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("abcdefgh"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("12345678"));
|
||||
assertDoesNotThrow(() -> validator.validate("abcd1234"));
|
||||
}
|
||||
|
||||
@@ -29,11 +30,11 @@ class PasswordValidatorTest {
|
||||
void highStrengthRules() {
|
||||
PasswordValidator validator = new PasswordValidator(PasswordStrength.HIGH);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("Abc123$"));
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("abcd1234$xyz"));
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("ABCD1234$XYZ"));
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("AbcdABCDabcd"));
|
||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("Abcd1234abcd"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("Abc123$"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("abcd1234$xyz"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("ABCD1234$XYZ"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("AbcdABCDabcd"));
|
||||
assertThrows(FieldException.class, () -> validator.validate("Abcd1234abcd"));
|
||||
assertDoesNotThrow(() -> validator.validate("Abcd1234$xyz"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user