云
5 天以前 cccbfadcb6e96c23a33c40c0687a27c2f6efa1db
yudao-module-mes/src/test/java/cn/iocoder/yudao/module/mes/service/pd/seal/PdSealServiceTest.java
@@ -21,6 +21,22 @@
    @InjectMocks PdSealService service;
    @Mock JdbcTemplate jdbc;
    @Mock BpmTaskService tasks;
    @Test void imageLookupIsScopedToCurrentTenant() {
        cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder.setTenantId(42L);
        try {
            byte[] image = {1, 2};
            when(jdbc.queryForList(anyString(), any(Object[].class)))
                    .thenReturn(List.of(Map.of("image_data", image)));
            assertArrayEquals(image, service.getImage(7));
            verify(jdbc).queryForList(contains("tenant_id=? AND deleted=0"), eq(7L), eq(42L));
        } finally {
            cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder.clear();
        }
    }
    @Test void refusesImageWhenSealIsNotFound() {
        when(jdbc.queryForList(anyString(), any(Object[].class))).thenReturn(List.of());
        assertThrows(ServiceException.class, () -> service.getImage(7));
    }
    @Test void refusesDownloadWithoutApprovedApplication() {
        when(jdbc.queryForList(anyString(), any(Object[].class))).thenReturn(List.of());
        assertThrows(ServiceException.class, () -> service.download(1, 7));