Merge branch 'test' of http://8.163.30.128:10082/java-project/baiyue-firstleg into dev
This commit is contained in:
@@ -77,6 +77,26 @@ class ProductImageControllerContractTest {
|
||||
assertThatThrownBy(() -> controller.upload(platform, file)).isInstanceOf(BizException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void platformDownloadUsesTenantScopeAndOrderListPermission() throws Exception {
|
||||
RequestMapping mapping = PlatformProductImageController.class.getAnnotation(RequestMapping.class);
|
||||
assertThat(mapping.value()).contains("/api/platform/v1/files/product-images");
|
||||
var download = PlatformProductImageController.class.getDeclaredMethod(
|
||||
"download", AuthenticatedUser.class, long.class, long.class);
|
||||
assertThat(download.getAnnotation(PreAuthorize.class).value())
|
||||
.isEqualTo("hasAuthority('platform:order:list')");
|
||||
|
||||
ProductImageService service = mock(ProductImageService.class);
|
||||
PlatformProductImageController controller = new PlatformProductImageController();
|
||||
ReflectionTestUtils.setField(controller, "images", service);
|
||||
when(service.download(10001L, 31L)).thenReturn(
|
||||
new ProductImageService.Download("product.png", "image/png", new byte[] {1}));
|
||||
|
||||
var platform = new AuthenticatedUser(1L, 0L, 0L, 1L, "admin", "PLATFORM", "WEB", Set.of());
|
||||
assertThat(controller.download(platform, 10001L, 31L).getBody()).containsExactly(1);
|
||||
verify(service).download(10001L, 31L);
|
||||
}
|
||||
|
||||
private static AuthenticatedUser merchant(long tenantId) {
|
||||
return new AuthenticatedUser(2L, tenantId, tenantId, 2L, "merchant", "MERCHANT", "WEB", Set.of());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user