优化
This commit is contained in:
+9
-9
@@ -33,11 +33,11 @@ class HttpUnloadPhotoFileGatewayTest {
|
||||
|
||||
@Test
|
||||
void forgedImageBusinessFailureMapsToBadRequestInsteadOfInternalError() {
|
||||
server.expect(requestTo("http://file-service/internal/file/v1/business-files/100/OVERSEAS_UNLOAD_PHOTO/8"))
|
||||
server.expect(requestTo("http://file-service/internal/file/v1/business-files/0/OVERSEAS_UNLOAD_PHOTO/8"))
|
||||
.andRespond(withSuccess("{\"code\":\"A0400\",\"message\":\"上传内容不是有效图片\",\"data\":null}",
|
||||
MediaType.APPLICATION_JSON));
|
||||
|
||||
assertThatThrownBy(() -> gateway.upload("100", 8L, 7L,
|
||||
assertThatThrownBy(() -> gateway.upload("0", 8L, 7L,
|
||||
new MockMultipartFile("file", "forged.png", "image/png", "<script>".getBytes())))
|
||||
.isInstanceOfSatisfying(ResponseStatusException.class,
|
||||
error -> assertThat(error.getStatusCode().value()).isEqualTo(400));
|
||||
@@ -46,11 +46,11 @@ class HttpUnloadPhotoFileGatewayTest {
|
||||
|
||||
@Test
|
||||
void mismatchedPhotoMetadataMapsToBadRequest() {
|
||||
server.expect(requestTo("http://file-service/internal/file/v1/business-files/100/OVERSEAS_UNLOAD_PHOTO/8/9"))
|
||||
.andRespond(withSuccess("{\"code\":\"200\",\"data\":{\"fileId\":9,\"tenantId\":101,\"businessType\":\"OVERSEAS_UNLOAD_PHOTO\",\"businessId\":\"8\"}}",
|
||||
server.expect(requestTo("http://file-service/internal/file/v1/business-files/0/OVERSEAS_UNLOAD_PHOTO/8/9"))
|
||||
.andRespond(withSuccess("{\"code\":\"200\",\"data\":{\"fileId\":9,\"tenantId\":1,\"businessType\":\"OVERSEAS_UNLOAD_PHOTO\",\"businessId\":\"8\"}}",
|
||||
MediaType.APPLICATION_JSON));
|
||||
|
||||
assertThatThrownBy(() -> gateway.validate("100", 8L, 9L))
|
||||
assertThatThrownBy(() -> gateway.validate("0", 8L, 9L))
|
||||
.isInstanceOfSatisfying(ResponseStatusException.class,
|
||||
error -> assertThat(error.getStatusCode().value()).isEqualTo(400));
|
||||
server.verify();
|
||||
@@ -59,12 +59,12 @@ class HttpUnloadPhotoFileGatewayTest {
|
||||
@Test
|
||||
void downloadUsesBusinessOwnershipPathAndPreservesBlobMetadata() {
|
||||
server.expect(requestTo(
|
||||
"http://file-service/internal/file/v1/business-files/100/OVERSEAS_UNLOAD_PHOTO/8/9/content"))
|
||||
"http://file-service/internal/file/v1/business-files/0/OVERSEAS_UNLOAD_PHOTO/8/9/content"))
|
||||
.andExpect(header("X-Internal-Service-Token", "internal-token"))
|
||||
.andRespond(withSuccess("photo-bytes".getBytes(), MediaType.IMAGE_JPEG)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=door.jpg"));
|
||||
|
||||
UnloadPhotoFileGateway.DownloadedFile result = gateway.download("100", 8L, 9L);
|
||||
UnloadPhotoFileGateway.DownloadedFile result = gateway.download("0", 8L, 9L);
|
||||
|
||||
assertThat(result.content()).containsExactly("photo-bytes".getBytes());
|
||||
assertThat(result.fileName()).isEqualTo("door.jpg");
|
||||
@@ -75,10 +75,10 @@ class HttpUnloadPhotoFileGatewayTest {
|
||||
@Test
|
||||
void missingOwnedPhotoMapsToNotFound() {
|
||||
server.expect(requestTo(
|
||||
"http://file-service/internal/file/v1/business-files/100/OVERSEAS_UNLOAD_PHOTO/8/9/content"))
|
||||
"http://file-service/internal/file/v1/business-files/0/OVERSEAS_UNLOAD_PHOTO/8/9/content"))
|
||||
.andRespond(withStatus(HttpStatus.NOT_FOUND));
|
||||
|
||||
assertThatThrownBy(() -> gateway.download("100", 8L, 9L))
|
||||
assertThatThrownBy(() -> gateway.download("0", 8L, 9L))
|
||||
.isInstanceOfSatisfying(ResponseStatusException.class,
|
||||
error -> assertThat(error.getStatusCode().value()).isEqualTo(404));
|
||||
server.verify();
|
||||
|
||||
Reference in New Issue
Block a user