优化
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
||||
package com.baiyue.warehouse.controller;
|
||||
|
||||
import com.baiyue.common.security.AuthenticatedUser;
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.warehouse.dto.SharedOverseasWarehouseResponse;
|
||||
import com.baiyue.warehouse.service.WarehouseApplicationService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
class PlatformOverseasReceivingOptionsControllerTest {
|
||||
private final WarehouseApplicationService service = mock(WarehouseApplicationService.class);
|
||||
private final PlatformOverseasReceivingOptionsController controller = new PlatformOverseasReceivingOptionsController(service);
|
||||
private final AuthenticatedUser platform = new AuthenticatedUser(1L, 0L, 0L, 2L,
|
||||
"tester", "PLATFORM", "PLATFORM", Set.of());
|
||||
|
||||
@Test
|
||||
void pagesAuthoritativeSharedOptionsWithoutExposingMasterWrites() throws Exception {
|
||||
when(service.activeSharedOverseasWarehouses()).thenReturn(List.of(
|
||||
new SharedOverseasWarehouseResponse(21L, "US-LAX", "洛杉矶仓", "US", "ACTIVE")));
|
||||
var page = controller.warehouses(platform, 1, 200).data();
|
||||
assertEquals(1, page.total());
|
||||
assertEquals(21L, page.records().get(0).id());
|
||||
assertEquals(0L, page.records().get(0).customerId());
|
||||
assertEquals("OVERSEAS", page.records().get(0).warehouseType());
|
||||
assertEquals("hasAuthority('platform:overseas-warehouse:warehouse:list')",
|
||||
controller.getClass().getMethod("warehouses", AuthenticatedUser.class, long.class, long.class)
|
||||
.getAnnotation(PreAuthorize.class).value());
|
||||
assertTrue(controller.warehouses(platform, Long.MAX_VALUE, 200).data().records().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsInvalidScopeAndPaginationBeforeReadingDirectory() {
|
||||
var merchant = new AuthenticatedUser(2L, 31L, 31L, 3L, "client", "MERCHANT", "MERCHANT", Set.of());
|
||||
assertThrows(BizException.class, () -> controller.warehouses(merchant, 1, 200));
|
||||
assertThrows(BizException.class, () -> controller.warehouses(null, 1, 200));
|
||||
assertThrows(BizException.class, () -> controller.warehouses(platform, 0, 200));
|
||||
assertThrows(BizException.class, () -> controller.warehouses(platform, 1, 201));
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user