fix: restore miniapp public startup flows
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@ public class ActivityController {
|
||||
@GetMapping
|
||||
public ApiResponse<?> getActivities(
|
||||
@AuthenticationPrincipal UserPrincipal principal) {
|
||||
String userId = principal.id();
|
||||
String userId = principal == null ? null : principal.id();
|
||||
return ApiResponse.ok(activityService.getActivities(userId));
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ public class SecurityConfig {
|
||||
.requestMatchers("/auth/wechat/login", "/auth/refresh", "/auth/operator/login").permitAll()
|
||||
.requestMatchers("/health/**").permitAll()
|
||||
.requestMatchers("/version").permitAll()
|
||||
.requestMatchers("/app/config").permitAll()
|
||||
.requestMatchers("/activities").permitAll()
|
||||
.requestMatchers("/auth/**").authenticated()
|
||||
// 操作台接口需要认证
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.danyang.match.platform.security;
|
||||
|
||||
import com.danyang.match.platform.activity.service.ActivityService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
class PublicMiniappApiTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private ActivityService activityService;
|
||||
|
||||
@Test
|
||||
void appConfigIsAvailableWithoutLogin() throws Exception {
|
||||
mockMvc.perform(get("/api/v1/app/config").contextPath("/api/v1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.success").value(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void activityListIsAvailableWithoutLogin() throws Exception {
|
||||
when(activityService.getActivities(null)).thenReturn(List.of());
|
||||
|
||||
mockMvc.perform(get("/api/v1/activities").contextPath("/api/v1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.success").value(true));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user