|
|
@@ -17,16 +17,20 @@ import org.junit.jupiter.api.Test;
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
import static org.mockito.ArgumentMatchers.isNull;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.times;
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
@@ -88,8 +92,8 @@ public class MaTechnicianServiceImplTest {
|
|
|
technician.setTeBrief("新简介");
|
|
|
request.setTechnician(technician);
|
|
|
|
|
|
- MerchantApplyFileDto updateFile = buildFile(7, "1", "new-image.jpg", "https://file/new-image.jpg");
|
|
|
- MerchantApplyFileDto insertFile = buildFile(7, "2", "life.jpg", "https://file/life.jpg");
|
|
|
+ MerchantApplyFileDto updateFile = buildFile("1", "new-image.jpg", "https://file/new-image.jpg");
|
|
|
+ MerchantApplyFileDto insertFile = buildFile("2", "life.jpg", "https://file/life.jpg");
|
|
|
request.setReq(Arrays.asList(updateFile, insertFile));
|
|
|
|
|
|
service.updateTechnician(request);
|
|
|
@@ -117,6 +121,85 @@ public class MaTechnicianServiceImplTest {
|
|
|
assertEquals(0, insertedFile.getIsDelete());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void merchantApplyFileDtoDoesNotExposeMerchantIdInRequestPayload() {
|
|
|
+ for (Field field : MerchantApplyFileDto.class.getDeclaredFields()) {
|
|
|
+ assertNotEquals("merchantId", field.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void applyFileReplacesRequestedTypesAndInsertsAllFilesInGroups() {
|
|
|
+ MaTechnicianMapper maTechnicianMapper = mock(MaTechnicianMapper.class);
|
|
|
+ MerchantApplyFileMapper merchantApplyFileMapper = mock(MerchantApplyFileMapper.class);
|
|
|
+ when(maTechnicianMapper.update(isNull(), any(LambdaUpdateWrapper.class))).thenReturn(1);
|
|
|
+ MaTechnicianServiceImpl service = buildService(maTechnicianMapper, merchantApplyFileMapper);
|
|
|
+
|
|
|
+ MerchantApplyFileRequestDto request = new MerchantApplyFileRequestDto();
|
|
|
+ MaTechnician technician = new MaTechnician();
|
|
|
+ technician.setId(7);
|
|
|
+ technician.setTeNickName("新昵称");
|
|
|
+ technician.setTeBrief("新简介");
|
|
|
+ request.setTechnician(technician);
|
|
|
+ request.setReq(Arrays.asList(
|
|
|
+ buildFileGroup("1",
|
|
|
+ buildFile(null, "portrait-1.jpg", "https://file/portrait-1.jpg"),
|
|
|
+ buildFile(null, "portrait-2.jpg", "https://file/portrait-2.jpg")),
|
|
|
+ buildFileGroup("3",
|
|
|
+ buildFile(null, "video.mp4", "https://file/video.mp4"))
|
|
|
+ ));
|
|
|
+
|
|
|
+ service.applyFile(request);
|
|
|
+
|
|
|
+ verify(merchantApplyFileMapper, times(2)).delete(any(LambdaQueryWrapper.class));
|
|
|
+ ArgumentCaptor<MerchantApplyFile> insertCaptor = ArgumentCaptor.forClass(MerchantApplyFile.class);
|
|
|
+ verify(merchantApplyFileMapper, times(3)).insert(insertCaptor.capture());
|
|
|
+ List<MerchantApplyFile> insertedFiles = insertCaptor.getAllValues();
|
|
|
+ assertEquals("1", insertedFiles.get(0).getFileType());
|
|
|
+ assertEquals("portrait-1.jpg", insertedFiles.get(0).getFileName());
|
|
|
+ assertEquals("1", insertedFiles.get(1).getFileType());
|
|
|
+ assertEquals("portrait-2.jpg", insertedFiles.get(1).getFileName());
|
|
|
+ assertEquals("3", insertedFiles.get(2).getFileType());
|
|
|
+ assertEquals("video.mp4", insertedFiles.get(2).getFileName());
|
|
|
+ insertedFiles.forEach(file -> {
|
|
|
+ assertEquals(7, file.getMerchantId());
|
|
|
+ assertEquals("7", file.getCreateBy());
|
|
|
+ assertEquals("7", file.getUpdateBy());
|
|
|
+ assertEquals(0, file.getIsDelete());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void applyFileUsesTechnicianIdWhenReqHasNoMerchantId() {
|
|
|
+ MaTechnicianMapper maTechnicianMapper = mock(MaTechnicianMapper.class);
|
|
|
+ MerchantApplyFileMapper merchantApplyFileMapper = mock(MerchantApplyFileMapper.class);
|
|
|
+ when(maTechnicianMapper.update(isNull(), any(LambdaUpdateWrapper.class))).thenReturn(1);
|
|
|
+ MaTechnicianServiceImpl service = buildService(maTechnicianMapper, merchantApplyFileMapper);
|
|
|
+
|
|
|
+ MerchantApplyFileRequestDto request = new MerchantApplyFileRequestDto();
|
|
|
+ MaTechnician technician = new MaTechnician();
|
|
|
+ technician.setId(7);
|
|
|
+ technician.setTeNickName("新昵称");
|
|
|
+ technician.setTeBrief("新简介");
|
|
|
+ request.setTechnician(technician);
|
|
|
+ request.setReq(Collections.singletonList(
|
|
|
+ buildFileGroup("2",
|
|
|
+ buildFile(null, "life.jpg", "https://file/life.jpg"))
|
|
|
+ ));
|
|
|
+
|
|
|
+ service.applyFile(request);
|
|
|
+
|
|
|
+ ArgumentCaptor<MerchantApplyFile> insertCaptor = ArgumentCaptor.forClass(MerchantApplyFile.class);
|
|
|
+ verify(merchantApplyFileMapper).insert(insertCaptor.capture());
|
|
|
+ MerchantApplyFile insertedFile = insertCaptor.getValue();
|
|
|
+ assertEquals(7, insertedFile.getMerchantId());
|
|
|
+ assertEquals("2", insertedFile.getFileType());
|
|
|
+ assertEquals("life.jpg", insertedFile.getFileName());
|
|
|
+ assertEquals("7", insertedFile.getCreateBy());
|
|
|
+ assertEquals("7", insertedFile.getUpdateBy());
|
|
|
+ assertEquals(0, insertedFile.getIsDelete());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void getTechnicianInfoFindsMerchantByOpenidWithFiles() {
|
|
|
MaTechnicianMapper maTechnicianMapper = mock(MaTechnicianMapper.class);
|
|
|
@@ -187,9 +270,8 @@ public class MaTechnicianServiceImplTest {
|
|
|
return file;
|
|
|
}
|
|
|
|
|
|
- private MerchantApplyFileDto buildFile(Integer merchantId, String fileType, String fileName, String fileUrl) {
|
|
|
+ private MerchantApplyFileDto buildFile(String fileType, String fileName, String fileUrl) {
|
|
|
MerchantApplyFileDto file = new MerchantApplyFileDto();
|
|
|
- file.setMerchantId(merchantId);
|
|
|
file.setFileType(fileType);
|
|
|
file.setFileName(fileName);
|
|
|
file.setFileUrl(fileUrl);
|
|
|
@@ -197,4 +279,11 @@ public class MaTechnicianServiceImplTest {
|
|
|
file.setContentType("image/jpeg");
|
|
|
return file;
|
|
|
}
|
|
|
+
|
|
|
+ private MerchantApplyFileDto buildFileGroup(String fileType, MerchantApplyFileDto... files) {
|
|
|
+ MerchantApplyFileDto group = new MerchantApplyFileDto();
|
|
|
+ group.setFileType(fileType);
|
|
|
+ group.setFiles(Arrays.asList(files));
|
|
|
+ return group;
|
|
|
+ }
|
|
|
}
|