test: add wechat integration test suite
Some checks failed
Build and Push Backend / docker (push) Has been cancelled
Some checks failed
Build and Push Backend / docker (push) Has been cancelled
- Add llm/wechat-subsystem-test-matrix.md and tests covering Wx controllers/services\n- Make ApiTestDataSeeder personnel group seeding idempotent for full-suite stability
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.starry.admin.api;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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;
|
||||
|
||||
import com.starry.admin.common.exception.CustomException;
|
||||
import com.starry.admin.modules.weichat.service.WxAccessTokenService;
|
||||
import com.starry.admin.modules.weichat.utils.WxFileUtils;
|
||||
import com.starry.admin.utils.SecurityUtils;
|
||||
import com.starry.common.redis.RedisCache;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
class WxCommonControllerAudioUploadApiTest extends AbstractApiTest {
|
||||
|
||||
@MockBean
|
||||
private com.starry.admin.common.oss.service.IOssFileService ossFileService;
|
||||
|
||||
@MockBean
|
||||
private WxAccessTokenService wxAccessTokenService;
|
||||
|
||||
@MockBean
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Test
|
||||
void audioUploadRejectsBlankMediaId__covers_COM_004() throws Exception {
|
||||
SecurityUtils.setTenantId("tenant-apitest");
|
||||
|
||||
mockMvc.perform(get("/wx/common/audio/upload")
|
||||
.header(USER_HEADER, DEFAULT_USER)
|
||||
.header(TENANT_HEADER, DEFAULT_TENANT)
|
||||
.param("mediaId", ""))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(500));
|
||||
}
|
||||
|
||||
@Test
|
||||
void audioUploadDownloadsConvertsAndUploadsMp3__covers_COM_005() throws Exception {
|
||||
SecurityUtils.setTenantId("tenant-apitest");
|
||||
when(wxAccessTokenService.getAccessToken()).thenReturn("access-token");
|
||||
when(ossFileService.upload(any(), eq("tenant-apitest"), anyString())).thenReturn("https://oss.example/audio.mp3");
|
||||
|
||||
try (MockedStatic<WxFileUtils> mocked = Mockito.mockStatic(WxFileUtils.class)) {
|
||||
mocked.when(() -> WxFileUtils.getTemporaryMaterial(eq("access-token"), eq("media-1")))
|
||||
.thenReturn(new ByteArrayInputStream("amr-bytes".getBytes()));
|
||||
mocked.when(() -> WxFileUtils.audioConvert2Mp3(any(File.class), any(File.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
File target = invocation.getArgument(1);
|
||||
Files.write(target.toPath(), "mp3-bytes".getBytes());
|
||||
return null;
|
||||
});
|
||||
|
||||
mockMvc.perform(get("/wx/common/audio/upload")
|
||||
.header(USER_HEADER, DEFAULT_USER)
|
||||
.header(TENANT_HEADER, DEFAULT_TENANT)
|
||||
.param("mediaId", "media-1")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(200))
|
||||
.andExpect(jsonPath("$.data").value("https://oss.example/audio.mp3"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user