修复V4目录初始化和lookup空结果元数据
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package cn.nianxx.thhotel.workflows.reservation.control;
|
||||
|
||||
import static cn.nianxx.thhotel.support.MockMvcAuthTestSupport.loginToken;
|
||||
import static cn.nianxx.thhotel.support.MockMvcAuthTestSupport.performAuthorized;
|
||||
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 cn.nianxx.thhotel.ThHotelApplication;
|
||||
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.test.context.ActiveProfiles;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
@SpringBootTest(
|
||||
classes = ThHotelApplication.class,
|
||||
properties = {
|
||||
"spring.datasource.url=jdbc:h2:mem:reservation_v4_catalog_bootstrap_runner_test;MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE",
|
||||
"auth.bootstrap.admin.username=v4-catalog-fresh-admin",
|
||||
"auth.bootstrap.admin.password=Admin@123456",
|
||||
"auth.bootstrap.admin.display-name=V4目录新酒店管理员",
|
||||
"auth.bootstrap.default-hotel-id=HOTEL-FRESH",
|
||||
"auth.bootstrap.default-hotel-name=新酒店",
|
||||
"auth.bootstrap.default-hotel-time-zone=Asia/Bangkok",
|
||||
"auth.session.ttl-minutes=720"
|
||||
})
|
||||
@AutoConfigureMockMvc
|
||||
@ActiveProfiles("test")
|
||||
class ReservationV4CatalogBootstrapRunnerTest {
|
||||
|
||||
private static final String HOTEL_ID = "HOTEL-FRESH";
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
void shouldSeedCatalogForBootstrapDefaultHotelWhenFlywayDidNotSeeHotel() throws Exception {
|
||||
String token = loginToken(mockMvc, "v4-catalog-fresh-admin", "Admin@123456");
|
||||
|
||||
performAuthorized(mockMvc, token, get("/api/reservation/lookups/accounts")
|
||||
.param("hotel_id", HOTEL_ID)
|
||||
.param("keyword", "QBD"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.hotel_id").value(HOTEL_ID))
|
||||
.andExpect(jsonPath("$.catalog_source").value("FIXED_SEED_IMPORT"))
|
||||
.andExpect(jsonPath("$.catalog_version").value("seed-20260719-v1"))
|
||||
.andExpect(jsonPath("$.items[0].code").value("QBD_TRAVEL"));
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,20 @@ class ReservationV4CatalogLookupControllerTest {
|
||||
.andExpect(jsonPath("$.items[0].pricing_available").value(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldKeepCatalogMetadataWhenKeywordMatchesNothing() throws Exception {
|
||||
performAuthorized(mockMvc, adminToken(), get("/api/reservation/lookups/accounts")
|
||||
.param("hotel_id", HOTEL_ID)
|
||||
.param("keyword", "NO_SUCH_ACCOUNT"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.hotel_id").value(HOTEL_ID))
|
||||
.andExpect(jsonPath("$.catalog_type").value("ACCOUNT"))
|
||||
.andExpect(jsonPath("$.catalog_source").value("FIXED_SEED_IMPORT"))
|
||||
.andExpect(jsonPath("$.catalog_version").value("seed-20260719-v1"))
|
||||
.andExpect(jsonPath("$.items").isEmpty())
|
||||
.andExpect(jsonPath("$.page.total").value(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRejectCatalogLookupWithoutPermissionOrHotelAccess() throws Exception {
|
||||
performAuthorized(mockMvc, noPermissionToken(), get("/api/reservation/lookups/accounts")
|
||||
|
||||
Reference in New Issue
Block a user