This commit is contained in:
2026-08-21 10:38:28 +08:00
parent 361e6be3be
commit d5e9ba6d4c
21 changed files with 1705 additions and 15 deletions
@@ -0,0 +1,39 @@
package com.baiyue.lastleg.masterdata.quote.service;
import com.baiyue.lastleg.masterdata.quote.dto.OverseasQuoteRequests;
import com.baiyue.lastleg.masterdata.quote.entity.OverseasQuote;
import com.baiyue.lastleg.masterdata.quote.mapper.OverseasQuoteMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.server.ResponseStatusException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class OverseasQuoteServiceTest {
private OverseasQuoteMapper mapper;
private OverseasQuoteService service;
@BeforeEach
void setUp() {
mapper = mock(OverseasQuoteMapper.class);
service = new OverseasQuoteService();
ReflectionTestUtils.setField(service, "quotes", mapper);
}
@Test
void rejectsStaleVersionAsConflict() {
OverseasQuote quote = new OverseasQuote();
quote.setId(1L);
quote.setRecordVersion(4L);
quote.setStatus(OverseasQuoteService.INACTIVE);
when(mapper.lockById(1L)).thenReturn(quote);
assertThatThrownBy(() -> service.changeStatus(1L, "9",
new OverseasQuoteRequests.ChangeStatus(OverseasQuoteService.ACTIVE, 3L)))
.isInstanceOf(ResponseStatusException.class)
.hasMessageContaining("409 CONFLICT");
}
}
@@ -53,4 +53,17 @@ class PartnerWarehouseDirectoryTest {
directory.options();
verify(client, times(2)).activePartners("internal-token");
}
@Test
void emptyDomesticResultIsNotCachedForThirtyMinutes() {
when(client.activePartners("internal-token"))
.thenReturn(ApiResponse.success(List.of()))
.thenReturn(ApiResponse.success(List.of(new DomesticPartnerWarehouseClient.Option(
101L, "US-ONT", "安大略合作仓", "US"))));
assertThat(directory.options()).isEmpty();
assertThat(directory.options()).singleElement().satisfies(option ->
assertThat(option.warehouseId()).isEqualTo("101"));
verify(client, times(2)).activePartners("internal-token");
}
}