| | |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.system.api.model.LoginUserApplet; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.order.api.model.TVinChargingOrder; |
| | | import com.ruoyi.order.dto.MyVinChargingOrderList; |
| | | import com.ruoyi.order.mapper.TVinChargingOrderMapper; |
| | | import com.ruoyi.order.util.mongodb.service.UploadRealTimeMonitoringDataService; |
| | | import org.junit.jupiter.api.BeforeEach; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.junit.jupiter.api.extension.ExtendWith; |
| | |
| | | import org.mockito.junit.jupiter.MockitoExtension; |
| | | import org.springframework.test.util.ReflectionTestUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.Map; |
| | | |
| | | import static org.junit.jupiter.api.Assertions.assertEquals; |
| | | import static org.junit.jupiter.api.Assertions.assertTrue; |
| | | import static org.mockito.ArgumentMatchers.anyList; |
| | | import static org.mockito.ArgumentMatchers.anyLong; |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.Mockito.never; |
| | | import static org.mockito.Mockito.verify; |
| | |
| | | private SiteClient siteClient; |
| | | @Mock |
| | | private ChargingGunClient chargingGunClient; |
| | | @Mock |
| | | private UploadRealTimeMonitoringDataService monitoringDataService; |
| | | |
| | | @BeforeEach |
| | | void setUp() { |
| | |
| | | loginUser.setUserId(88L); |
| | | when(tokenService.getLoginUserApplet()).thenReturn(loginUser); |
| | | when(vinManagementClient.getVinIdsByAppUserId(88L)).thenReturn(R.ok(Arrays.asList(11L, 22L))); |
| | | when(mapper.countAppletOrders(Arrays.asList(11L, 22L))).thenReturn(1L); |
| | | when(mapper.countAppletOrders(88L, Arrays.asList(11L, 22L))).thenReturn(1L); |
| | | MyVinChargingOrderList order = new MyVinChargingOrderList(); |
| | | order.setId(1001L); |
| | | when(mapper.pageAppletOrders(Arrays.asList(11L, 22L), 10L, 10L)) |
| | | when(mapper.pageAppletOrders(88L, Arrays.asList(11L, 22L), 10L, 10L)) |
| | | .thenReturn(Collections.singletonList(order)); |
| | | |
| | | PageInfo<MyVinChargingOrderList> result = service.pageAppletOrders(2, 10); |
| | |
| | | assertEquals(1L, result.getTotal()); |
| | | assertEquals(1001L, result.getRecords().get(0).getId()); |
| | | verify(vinManagementClient).getVinIdsByAppUserId(88L); |
| | | verify(mapper).pageAppletOrders(Arrays.asList(11L, 22L), 10L, 10L); |
| | | verify(mapper).countAppletOrders(88L, Arrays.asList(11L, 22L)); |
| | | verify(mapper).pageAppletOrders(88L, Arrays.asList(11L, 22L), 10L, 10L); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | assertEquals(0L, result.getTotal()); |
| | | assertEquals(0, result.getRecords().size()); |
| | | verify(mapper, never()).countAppletOrders(anyList()); |
| | | verify(mapper, never()).pageAppletOrders(anyList(), eq(0L), eq(10L)); |
| | | verify(mapper, never()).countAppletOrders(anyLong(), anyList()); |
| | | verify(mapper, never()).pageAppletOrders(anyLong(), anyList(), eq(0L), eq(10L)); |
| | | } |
| | | |
| | | @Test |
| | | void returnsVinDetailWithRequiredFeeFieldsForOwner() { |
| | | LoginUserApplet loginUser = new LoginUserApplet(); |
| | | loginUser.setUserId(88L); |
| | | when(tokenService.getLoginUserApplet()).thenReturn(loginUser); |
| | | when(vinManagementClient.getVinIdsByAppUserId(88L)).thenReturn(R.ok(Collections.singletonList(11L))); |
| | | TVinChargingOrder order = new TVinChargingOrder(); |
| | | order.setId(1001L); |
| | | order.setVinId(11L); |
| | | order.setAppUserId(88L); |
| | | order.setCode("VD_1001"); |
| | | order.setOrderAmount(new BigDecimal("18.50")); |
| | | order.setElectrovalence(new BigDecimal("12.30")); |
| | | order.setServiceCharge(new BigDecimal("6.20")); |
| | | when(mapper.selectById(1001L)).thenReturn(order); |
| | | when(mapper.accountingStrategyList(1001L)).thenReturn(Collections.emptyList()); |
| | | when(monitoringDataService.getDataByOrderCode("VD_1001")).thenReturn(Collections.emptyList()); |
| | | |
| | | Map<String, Object> result = service.appletDetail(1001L); |
| | | |
| | | assertEquals("1001", result.get("id")); |
| | | assertEquals(new BigDecimal("18.50"), result.get("orderAmount")); |
| | | assertEquals(new BigDecimal("12.30"), result.get("electricMoney")); |
| | | assertEquals(new BigDecimal("6.20"), result.get("serviceMoney")); |
| | | } |
| | | |
| | | @Test |
| | | void returnsEmptyDetailWhenVinIsNotBoundToCurrentUser() { |
| | | LoginUserApplet loginUser = new LoginUserApplet(); |
| | | loginUser.setUserId(88L); |
| | | when(tokenService.getLoginUserApplet()).thenReturn(loginUser); |
| | | when(vinManagementClient.getVinIdsByAppUserId(88L)).thenReturn(R.ok(Collections.singletonList(22L))); |
| | | TVinChargingOrder order = new TVinChargingOrder(); |
| | | order.setId(1001L); |
| | | order.setVinId(11L); |
| | | when(mapper.selectById(1001L)).thenReturn(order); |
| | | |
| | | assertTrue(service.appletDetail(1001L).isEmpty()); |
| | | verify(mapper, never()).accountingStrategyList(1001L); |
| | | } |
| | | |
| | | @Test |
| | | void returnsEmptyDetailWhenVinReboundAndOrderBelongsToPreviousUser() { |
| | | LoginUserApplet loginUser = new LoginUserApplet(); |
| | | loginUser.setUserId(88L); |
| | | when(tokenService.getLoginUserApplet()).thenReturn(loginUser); |
| | | // VIN 11 当前绑定用户 88,但该订单是换绑前用户 99 下单的,不能查看 |
| | | when(vinManagementClient.getVinIdsByAppUserId(88L)).thenReturn(R.ok(Collections.singletonList(11L))); |
| | | TVinChargingOrder order = new TVinChargingOrder(); |
| | | order.setId(1001L); |
| | | order.setVinId(11L); |
| | | order.setAppUserId(99L); |
| | | when(mapper.selectById(1001L)).thenReturn(order); |
| | | |
| | | assertTrue(service.appletDetail(1001L).isEmpty()); |
| | | verify(mapper, never()).accountingStrategyList(1001L); |
| | | } |
| | | } |