组件新增状态字段,禁用状态不参与拼装

This commit is contained in:
lxp
2026-10-20 18:07:55 +08:00
parent 5d94bc7871
commit 7eef6e3994
21 changed files with 265 additions and 16 deletions
@@ -234,6 +234,71 @@ class AdminApiTest {
.isEqualTo(changed);
}
@Test
void componentStatusDefaultsToEnabledWhenOmittedOrNull() throws Exception {
JsonNode omitted = create(uploaded());
Map<String, Object> body = uploaded();
body.put("status", null);
JsonNode explicitNull = create(body);
for (JsonNode created : List.of(omitted, explicitNull)) {
assertThat(created.path("status").asText()).isEqualTo("ENABLED");
assertThat(componentMapper.selectById(created.path("id").asLong()).getStatus().name()).isEqualTo("ENABLED");
}
}
@Test
void componentStatusRoundTripsAndOmittedUpdatesPreserveDisabledStatus() throws Exception {
Map<String, Object> body = uploaded();
body.put("status", "DISABLED");
JsonNode created = create(body);
long id = created.path("id").asLong();
assertThat(created.path("status").asText()).isEqualTo("DISABLED");
mvc.perform(get("/admin-api/components/{id}", id)).andExpect(status().isOk())
.andExpect(jsonPath("$.data.status").value("DISABLED"));
mvc.perform(get("/admin-api/components").param("keyword", created.path("componentCode").asText()))
.andExpect(status().isOk()).andExpect(jsonPath("$.data.items[0].status").value("DISABLED"));
for (long version = 1; version <= 2; version++) {
Map<String, Object> form = update(version);
if (version == 2) form.put("status", null);
JsonNode changed = data(mvc.perform(put("/admin-api/components/{id}", id).contentType(MediaType.APPLICATION_JSON)
.content(json.writeValueAsString(form))).andExpect(status().isOk()).andReturn());
assertThat(changed.path("status").asText()).isEqualTo("DISABLED");
assertThat(changed.path("version").asLong()).isEqualTo(version + 1);
}
Map<String, Object> enable = update(3);
enable.put("status", "ENABLED");
JsonNode enabled = data(mvc.perform(put("/admin-api/components/{id}", id).contentType(MediaType.APPLICATION_JSON)
.content(json.writeValueAsString(enable))).andExpect(status().isOk()).andReturn());
assertThat(enabled.path("status").asText()).isEqualTo("ENABLED");
assertThat(enabled.path("version").asLong()).isEqualTo(4);
Map<String, Object> disable = update(4);
disable.put("status", "DISABLED");
mvc.perform(put("/admin-api/components/{id}", id).contentType(MediaType.APPLICATION_JSON)
.content(json.writeValueAsString(disable))).andExpect(status().isOk())
.andExpect(jsonPath("$.data.status").value("DISABLED"));
expectUpdateError(id, enable, 409, "COMPONENT_REVISION_CONFLICT");
assertThat(componentMapper.selectById(id).getStatus().name()).isEqualTo("DISABLED");
assertThat(componentMapper.selectById(id).getVersion()).isEqualTo(5L);
}
@Test
void invalidComponentStatusValuesNeverCreateOrUpdateComponents() throws Exception {
long id = create(uploaded()).path("id").asLong();
Map<String, Object> body = uploaded();
Map<String, Object> form = update(1);
for (Object invalid : List.of("", "enabled", "disabled", " ENABLED ", "ACTIVE", 0, 1, true,
List.of("ENABLED"), Map.of("status", "ENABLED"))) {
body.put("status", invalid);
form.put("status", invalid);
expectCreateError(body, 422, "INVALID_REQUEST");
expectUpdateError(id, form, 422, "INVALID_REQUEST");
}
assertThat(count("component")).isEqualTo(1);
assertThat(componentMapper.selectById(id).getStatus().name()).isEqualTo("ENABLED");
assertThat(componentMapper.selectById(id).getVersion()).isEqualTo(1L);
}
@ParameterizedTest
@ValueSource(strings = {"X", "Y", "Z"})
void rotationAxisRoundTripsThroughCreateUpdateDetailAndList(String axis) throws Exception {
@@ -15,6 +15,7 @@ final class TestSchemaSupport {
component_code VARCHAR(64) NOT NULL DEFAULT '' UNIQUE,
component_name VARCHAR(128) NOT NULL DEFAULT '',
category VARCHAR(64) NOT NULL DEFAULT '',
status VARCHAR(16) NOT NULL DEFAULT 'ENABLED' CHECK (status IN ('ENABLED','DISABLED')) COMMENT '组件状态:ENABLED-启用,DISABLED-禁用',
description CLOB NOT NULL DEFAULT '',
material VARCHAR(128) NOT NULL DEFAULT '',
mass_kg DECIMAL(18,6) NOT NULL DEFAULT 0,