feat: 完成情绪博物馆项目重构和功能增强 - 新增日记评论和帖子功能 - 重构前端架构,优化用户体验 - 完善WebSocket通信机制 - 更新项目文档和部署配置

This commit is contained in:
2025-07-27 10:05:59 +08:00
parent 6903ac1c0d
commit cc886cd4d5
126 changed files with 21179 additions and 15734 deletions
@@ -0,0 +1,100 @@
package com.emotion.controller;
import com.emotion.service.AuthService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* AuthController 测试类
*
* @author emotion-museum
* @date 2025-07-26
*/
@WebMvcTest(AuthController.class)
public class AuthControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private AuthService authService;
@Test
public void testCheckAccountExists() throws Exception {
// 模拟账户存在的情况
when(authService.existsByAccount("existingUser")).thenReturn(true);
mockMvc.perform(get("/auth/check-account")
.param("account", "existingUser"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data").value(true));
}
@Test
public void testCheckAccountNotExists() throws Exception {
// 模拟账户不存在的情况
when(authService.existsByAccount("nonExistingUser")).thenReturn(false);
mockMvc.perform(get("/auth/check-account")
.param("account", "nonExistingUser"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data").value(false));
}
@Test
public void testCheckEmailExists() throws Exception {
// 模拟邮箱存在的情况
when(authService.existsByEmail("existing@example.com")).thenReturn(true);
mockMvc.perform(get("/auth/check-email")
.param("email", "existing@example.com"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data").value(true));
}
@Test
public void testCheckEmailNotExists() throws Exception {
// 模拟邮箱不存在的情况
when(authService.existsByEmail("nonexisting@example.com")).thenReturn(false);
mockMvc.perform(get("/auth/check-email")
.param("email", "nonexisting@example.com"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data").value(false));
}
@Test
public void testCheckPhoneExists() throws Exception {
// 模拟手机号存在的情况
when(authService.existsByPhone("13800138000")).thenReturn(true);
mockMvc.perform(get("/auth/check-phone")
.param("phone", "13800138000"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data").value(true));
}
@Test
public void testCheckPhoneNotExists() throws Exception {
// 模拟手机号不存在的情况
when(authService.existsByPhone("13900139000")).thenReturn(false);
mockMvc.perform(get("/auth/check-phone")
.param("phone", "13900139000"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data").value(false));
}
}