优化
This commit is contained in:
@@ -179,6 +179,39 @@ class FinanceServiceValidationTest {
|
||||
assertThrows(RuntimeException.class, () -> service.createCost(9L, 2L, request, "k5"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsAuthoritativeContainerSnapshotBeforeFeeSourceArrival() {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class, invocation ->
|
||||
"update".equals(invocation.getMethod().getName()) && invocation.getMethod().getReturnType() == int.class
|
||||
? 1 : RETURNS_DEFAULTS.answer(invocation));
|
||||
FinanceFileClient files = mock(FinanceFileClient.class);
|
||||
when(files.metadata("internal-token", 9L, 9L, 77L)).thenReturn(ApiResponse.success(
|
||||
new FinanceFileClient.Metadata(77L, 9L, "FINANCE_VOUCHER", "9", "cost.jpg", "sha", "image/jpeg", 9L)));
|
||||
when(jdbc.queryForList(startsWith("SELECT request_hash"), eq(9L), eq(2L), eq("COST_CREATE"), eq("container-cost-key")))
|
||||
.thenReturn(List.of());
|
||||
when(jdbc.queryForMap(startsWith("SELECT * FROM fin_cost WHERE id="), eq(701L)))
|
||||
.thenReturn(java.util.Map.of("id", 701L));
|
||||
doAnswer(invocation -> {
|
||||
org.springframework.jdbc.support.KeyHolder holder = invocation.getArgument(1);
|
||||
holder.getKeyList().add(java.util.Map.of("GENERATED_KEY", 701L));
|
||||
return 1;
|
||||
}).when(jdbc).update(any(org.springframework.jdbc.core.PreparedStatementCreator.class), any(org.springframework.jdbc.support.KeyHolder.class));
|
||||
FinanceService service = new FinanceService(jdbc, new ObjectMapper());
|
||||
ReflectionTestUtils.setField(service, "fileClient", files);
|
||||
ReflectionTestUtils.setField(service, "fileToken", "internal-token");
|
||||
var request = new FinanceService.CostRequest("C-3", "CONTAINER_SHARED", null, null, 88L,
|
||||
null, null, "MANUAL", "整柜成本", new BigDecimal("300.00"), List.of("77"), null);
|
||||
var snapshot = List.of(new FinanceService.ContainerOrderVolume(
|
||||
99L, 1001L, 88L, 9L, new BigDecimal("1.25")));
|
||||
|
||||
service.createCost(9L, 2L, request, snapshot, "container-cost-key");
|
||||
|
||||
verify(jdbc, never()).queryForObject(startsWith("SELECT COUNT(*) FROM fin_fee_source"), eq(Number.class), any(), any());
|
||||
verify(jdbc).update(startsWith("INSERT INTO fin_cost_allocation"), eq(9L), eq(701L), eq(99L),
|
||||
eq(1001L), eq(new BigDecimal("1.25")), eq(new BigDecimal("1.25")),
|
||||
any(BigDecimal.class), any(BigDecimal.class), eq(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsBillRevisionHistoryOnlyForOwningCustomer() {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
|
||||
Reference in New Issue
Block a user