test(apitest): add e2e seed endpoints and coverage

This commit is contained in:
irving
2026-01-17 00:49:54 -05:00
parent e2300fc7d0
commit 6a3b4fef1f
7 changed files with 1228 additions and 10 deletions

View File

@@ -0,0 +1,51 @@
package com.starry.admin.api;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
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.apitest.ApiTestDataSeeder;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.context.TestPropertySource;
@TestPropertySource(properties = "test.auth.secret=apitest-secret")
class WxOauthE2eSeedOrderApiTest extends AbstractApiTest {
private static final String TEST_AUTH_HEADER = "X-Test-Auth";
private static final String TEST_AUTH_SECRET = "apitest-secret";
@Test
void seedOrderRejectsWithoutSecretHeader() throws Exception {
mockMvc.perform(post("/wx/oauth2/e2e/seed/order")
.header(USER_HEADER, DEFAULT_USER)
.header(TENANT_HEADER, DEFAULT_TENANT)
.header("User-Agent", "apitest")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(403));
}
@Test
void seedOrderReturnsFixtureWhenSecretHeaderValid() throws Exception {
mockMvc.perform(post("/wx/oauth2/e2e/seed/order")
.header(USER_HEADER, DEFAULT_USER)
.header(TENANT_HEADER, DEFAULT_TENANT)
.header("User-Agent", "apitest")
.header(TEST_AUTH_HEADER, TEST_AUTH_SECRET)
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.code").value(200))
.andExpect(jsonPath("$.data.tenantKey").value(ApiTestDataSeeder.DEFAULT_TENANT_KEY))
.andExpect(jsonPath("$.data.customerId").value(ApiTestDataSeeder.DEFAULT_CUSTOMER_ID))
.andExpect(jsonPath("$.data.customerNickname").isNotEmpty())
.andExpect(jsonPath("$.data.clerkId").value(ApiTestDataSeeder.DEFAULT_CLERK_ID))
.andExpect(jsonPath("$.data.clerkNickname").isNotEmpty())
.andExpect(jsonPath("$.data.clerkLevelId").value(ApiTestDataSeeder.DEFAULT_CLERK_LEVEL_ID))
.andExpect(jsonPath("$.data.clerkSex").value("2"))
.andExpect(jsonPath("$.data.commodityId").value(ApiTestDataSeeder.DEFAULT_COMMODITY_ID))
.andExpect(jsonPath("$.data.giftId").value(ApiTestDataSeeder.DEFAULT_GIFT_ID));
}
}