fix(file): converge delivery documents to three categories

This commit is contained in:
2026-09-09 11:21:36 +08:00
parent 156520b560
commit 81b729929c
6 changed files with 62 additions and 23 deletions
@@ -28,7 +28,7 @@ class DeliveryBusinessFileTest {
}
@ParameterizedTest
@ValueSource(strings={"DELIVERY_BOL","DELIVERY_CUSTOMER_DOCUMENT","DELIVERY_BILL_OF_LADING","DELIVERY_POD","DELIVERY_PHOTO","DELIVERY_LOADING_PHOTO","DELIVERY_EXPRESS_RECEIPT"})
@ValueSource(strings={"DELIVERY_LOADING_PHOTO","DELIVERY_BOL","DELIVERY_RECEIPT"})
void immutableUploadsPreserveOldContentAndRealTimestamp(String type) {
var storage = storage();
var files = mock(FileObjectMapper.class);
@@ -50,7 +50,7 @@ class DeliveryBusinessFileTest {
}
@ParameterizedTest
@ValueSource(strings={"DELIVERY_BOL","DELIVERY_CUSTOMER_DOCUMENT","DELIVERY_BILL_OF_LADING","DELIVERY_POD","DELIVERY_PHOTO","DELIVERY_LOADING_PHOTO","DELIVERY_EXPRESS_RECEIPT"})
@ValueSource(strings={"DELIVERY_LOADING_PHOTO","DELIVERY_BOL","DELIVERY_RECEIPT"})
void enforcesFiftyMibAndNonemptyBoundary(String type) throws Exception {
var storage = storage(); var category = BusinessFileCategory.require(type);
assertThatThrownBy(() -> storage.store(11,"71",new MockMultipartFile("file",new byte[0]),category)).isInstanceOf(BizException.class);
@@ -65,7 +65,7 @@ class DeliveryBusinessFileTest {
}
@ParameterizedTest
@ValueSource(strings={"DELIVERY_BOL","DELIVERY_CUSTOMER_DOCUMENT","DELIVERY_BILL_OF_LADING","DELIVERY_POD","DELIVERY_PHOTO","DELIVERY_LOADING_PHOTO","DELIVERY_EXPRESS_RECEIPT"})
@ValueSource(strings={"DELIVERY_LOADING_PHOTO","DELIVERY_BOL","DELIVERY_RECEIPT"})
void downloadQueriesEveryOwnershipKeyAndRejectsUnauthorizedAccess(String type) {
var files=mock(FileObjectMapper.class); var storage=mock(BusinessFileStorage.class); var service=service(files,storage);
when(files.selectOne(any())).thenAnswer(call -> {
@@ -82,6 +82,13 @@ class DeliveryBusinessFileTest {
assertThatThrownBy(() -> controller.download("bad",11,type,"71",801)).isInstanceOf(BizException.class);
verifyNoInteractions(storage);
}
@ParameterizedTest
@ValueSource(strings={"DELIVERY_CUSTOMER_DOCUMENT","DELIVERY_BILL_OF_LADING","DELIVERY_POD","DELIVERY_PHOTO","DELIVERY_EXPRESS_RECEIPT"})
void rejectsRemovedCategoriesWithoutAliases(String type) {
assertThatThrownBy(() -> BusinessFileCategory.require(type))
.isInstanceOf(BizException.class).hasMessageContaining("不支持的附件业务类型");
}
private BusinessFileStorage storage() {
var storage=new BusinessFileStorage(); ReflectionTestUtils.setField(storage,"configuredRoot",root); storage.initializeRoot(); return storage;
}
@@ -0,0 +1,35 @@
package com.baiyue.file.service;
import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.Yaml;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
class DeliveryFileContractTest {
@Test
@SuppressWarnings("unchecked")
void freezesThreeOrderedCategoriesAndMatchesRuntimePolicy() throws Exception {
String text = Files.readString(Path.of("src/main/resources/openapi/delivery-files-v1.yaml"));
Map<String, Object> yaml = new Yaml().load(text);
Map<String, Object> info = (Map<String, Object>) yaml.get("info");
Map<String, String> mapping = (Map<String, String>) info.get("x-category-mapping");
assertThat(mapping.keySet()).containsExactly("LOADING_PHOTO", "BOL", "RECEIPT");
List<String> types = List.of("DELIVERY_LOADING_PHOTO", "DELIVERY_BOL", "DELIVERY_RECEIPT");
assertThat(mapping.values()).containsExactlyElementsOf(types);
Map<String, String> titles = (Map<String, String>) info.get("x-category-titles");
assertThat(titles.keySet()).containsExactlyElementsOf(mapping.keySet());
assertThat(titles.values()).containsExactly("装车照片", "BOL文件(含签名)", "签收文件(POD签收/快递签收)");
Map<String, Object> components = (Map<String, Object>) yaml.get("components");
Map<String, Object> parameters = (Map<String, Object>) components.get("parameters");
Map<String, Object> type = (Map<String, Object>) parameters.get("Type");
Map<String, Object> schema = (Map<String, Object>) type.get("schema");
assertThat((List<String>) schema.get("enum")).containsExactlyElementsOf(types);
assertThat(Arrays.stream(BusinessFileCategory.values()).map(Enum::name)
.filter(name -> name.startsWith("DELIVERY_")).toList()).containsExactlyElementsOf(types);
assertThat(text).contains("totalCategoryCount固定3", "非空类别x/3", "每类0至20", "不强制必传", "不增加完成门禁或签名识别");
}
}