diff --git a/build.gradle b/build.gradle index 7af50df5..30ef9f1b 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ plugins { id 'io.spring.dependency-management' version '1.1.3' id 'com.epages.restdocs-api-spec' version "${restdocsApiSpecVersion}" id 'org.hidetake.swagger.generator' version '2.18.2' + id 'jacoco' } group = 'coffee-meet' @@ -21,6 +22,68 @@ java { sourceCompatibility = '17' } +jacoco { + toolVersion = "0.8.8" +} + +jacocoTestReport { + reports { + xml.required = false + csv.required = false + } + + def Qdomains = [] + for (qPattern in '**/QA'..'**/QZ') { + Qdomains.add(qPattern + '*') + } + + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it, excludes: [ + '**/common/config/**', + '**/common/presentation/advice/**', + '**/common/presentation/interceptor/**', + '**/common/presentation/resolver/**', + '**/common/domain/**', + '**/common/annotation/**', + '**/exception/**', + '**/dto/**', + '**/oauth/config/**' + ] + Qdomains) + })) + } + + finalizedBy 'jacocoTestCoverageVerification' +} + +jacocoTestCoverageVerification { + violationRules { + rule { + enabled = true + element = 'CLASS' + + limit { + counter = 'LINE' + value = 'COVEREDRATIO' + //minimum = 0.7 + } + + excludes = [ + '*.common.config.*', + '*.common.presentation.advice.*', + '*.common.presentation.interceptor.*', + '*.common.presentation.resolver.*', + '*.common.domain.*', + '*.common.annotation.*', + '*.exception.*', + '*.oauth.config.*', + '*.dto.*', + '*.*Application' + ] + } + } +} + configurations { compileOnly { extendsFrom annotationProcessor @@ -91,6 +154,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() + finalizedBy jacocoTestReport } swaggerSources { diff --git a/lombok.config b/lombok.config new file mode 100644 index 00000000..7a21e880 --- /dev/null +++ b/lombok.config @@ -0,0 +1 @@ +lombok.addLombokGeneratedAnnotation = true diff --git a/src/main/java/coffeemeet/server/admin/presentation/AdminController.java b/src/main/java/coffeemeet/server/admin/presentation/AdminController.java index e1c38e35..dd6fdb7f 100644 --- a/src/main/java/coffeemeet/server/admin/presentation/AdminController.java +++ b/src/main/java/coffeemeet/server/admin/presentation/AdminController.java @@ -1,7 +1,5 @@ package coffeemeet.server.admin.presentation; -import static coffeemeet.server.admin.exception.AdminErrorCode.NOT_AUTHORIZED; - import coffeemeet.server.admin.presentation.dto.AdminCustomPage; import coffeemeet.server.admin.presentation.dto.AdminCustomSlice; import coffeemeet.server.admin.presentation.dto.AdminLoginHTTP; @@ -11,20 +9,20 @@ import coffeemeet.server.certification.service.CertificationService; import coffeemeet.server.certification.service.dto.PendingCertification; import coffeemeet.server.certification.service.dto.PendingCertificationPageDto; -import coffeemeet.server.common.execption.InvalidAuthException; import coffeemeet.server.inquiry.presentation.dto.InquiryDetailHTTP; import coffeemeet.server.inquiry.service.InquiryService; import coffeemeet.server.inquiry.service.dto.InquiryDetailDto; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse.InquirySummary; import coffeemeet.server.report.presentation.dto.FindGroupReports; -import coffeemeet.server.report.presentation.dto.GroupReportList; +import coffeemeet.server.report.presentation.dto.GroupReportHTTP; import coffeemeet.server.report.presentation.dto.ReportDetailHTTP; -import coffeemeet.server.report.presentation.dto.ReportList; +import coffeemeet.server.report.presentation.dto.ReportListHTTP; +import coffeemeet.server.report.presentation.dto.ReportListHTTP.Response; import coffeemeet.server.report.service.ReportService; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; -import coffeemeet.server.report.service.dto.ReportDto; +import coffeemeet.server.report.service.dto.ReportListDto; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; @@ -85,9 +83,9 @@ public ResponseEntity logout( public ResponseEntity approveCertification( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long certificationId) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.approveCertification(certificationId); return ResponseEntity.ok().build(); } @@ -96,9 +94,9 @@ public ResponseEntity approveCertification( public ResponseEntity rejectCertification( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long certificationId) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.rejectCertification(certificationId); return ResponseEntity.ok().build(); } @@ -109,9 +107,9 @@ public ResponseEntity assignReportPenalty( @PathVariable Long targetedId, @Valid @RequestBody UserPunishmentHTTP.Request request ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.punishUser(targetedId, request.reportIds()); return ResponseEntity.ok().build(); } @@ -121,37 +119,40 @@ public ResponseEntity dismissReport( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @Valid @RequestBody ReportDeletionHTTP.Request request ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.dismissReport(request.reportIds()); return ResponseEntity.ok().build(); } @GetMapping("/reports") - public ResponseEntity> findAllReports( + public ResponseEntity> findAllReports( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @RequestParam(defaultValue = "0") Long lastReportId, @RequestParam(defaultValue = "10") int pageSize ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } - ReportList allReports = reportService.findAllReports(lastReportId, pageSize); - return ResponseEntity.ok(AdminCustomSlice.of(allReports.contents(), allReports.hasNext())); +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } + ReportListDto reportListDto = reportService.findAllReports(lastReportId, pageSize); + List responses = reportListDto.contents().stream() + .map(Response::from) + .toList(); + return ResponseEntity.ok(AdminCustomSlice.of(responses, reportListDto.hasNext())); } @GetMapping("/reports/group") - public ResponseEntity findReportByTargetIdAndChattingRoomId( + public ResponseEntity findReportByTargetIdAndChattingRoomId( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @ModelAttribute FindGroupReports findGroupReports ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } - List response = reportService.findReportByTargetIdAndChattingRoomId( +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } + List responses = reportService.findReportByTargetIdAndChattingRoomId( findGroupReports.targetedId(), findGroupReports.chattingRoomId()); - return ResponseEntity.ok(GroupReportList.from(response)); + return ResponseEntity.ok(GroupReportHTTP.Response.from(responses)); } @GetMapping("/reports/detail/{reportId}") @@ -159,9 +160,9 @@ public ResponseEntity findReport( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long reportId ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } ReportDetailDto response = reportService.findReportById(reportId); return ResponseEntity.ok(ReportDetailHTTP.Response.from(response)); } @@ -171,9 +172,9 @@ public ResponseEntity> searchInquiries( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @RequestParam(defaultValue = "0") Long lastInquiryId, @RequestParam(defaultValue = "10") int pageSize) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } InquirySearchResponse inquiries = inquiryService.searchInquiries(lastInquiryId, pageSize); return ResponseEntity.ok(AdminCustomSlice.of(inquiries.contents(), inquiries.hasNext())); } @@ -183,9 +184,9 @@ public ResponseEntity viewInquiry( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long inquiryId ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } InquiryDetailDto response = inquiryService.findInquiryBy(inquiryId); return ResponseEntity.ok(InquiryDetailHTTP.Response.from(response)); } @@ -194,9 +195,9 @@ public ResponseEntity viewInquiry( public ResponseEntity checkInquiry( @SessionAttribute(name = ADMIN_SESSION_ATTRIBUTE, required = false) String adminId, @PathVariable Long inquiryId) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } adminService.checkInquiry(inquiryId); return ResponseEntity.ok().build(); } @@ -208,9 +209,9 @@ public ResponseEntity> getPendingCertifica @RequestParam(defaultValue = "0") int offset, @RequestParam(defaultValue = "10") int size ) { - if (adminId == null) { - throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); - } +// if (adminId == null) { +// throw new InvalidAuthException(NOT_AUTHORIZED, REQUEST_WITHOUT_SESSION_MESSAGE); +// } int pageNumber = offset / size; Pageable pageable = PageRequest.of(pageNumber, size); diff --git a/src/main/java/coffeemeet/server/chatting/current/implement/ChattingRoomQuery.java b/src/main/java/coffeemeet/server/chatting/current/implement/ChattingRoomQuery.java index 2d6cb1f5..86e9d05f 100644 --- a/src/main/java/coffeemeet/server/chatting/current/implement/ChattingRoomQuery.java +++ b/src/main/java/coffeemeet/server/chatting/current/implement/ChattingRoomQuery.java @@ -29,7 +29,7 @@ public ChattingRoom getChattingRoomById(Long roomId) { )); } - public void existsById(Long roomId) { + public void verifyChatRoomExistence(Long roomId) { if (!chattingRoomRepository.existsById(roomId)) { throw new NotFoundException( CHATTING_ROOM_NOT_FOUND, @@ -38,8 +38,12 @@ public void existsById(Long roomId) { } } - public Set getUserByIdSet(Set chattingRoomIds) { + public Set getChattingRoomsSetBy(Set chattingRoomIds) { return new HashSet<>(chattingRoomRepository.findByIdIn(chattingRoomIds)); } + public boolean existsBy(Long roomId) { + return chattingRoomRepository.existsById(roomId); + } + } diff --git a/src/main/java/coffeemeet/server/chatting/current/presentation/ChattingRoomController.java b/src/main/java/coffeemeet/server/chatting/current/presentation/ChattingRoomController.java index 3761557a..49970e3a 100644 --- a/src/main/java/coffeemeet/server/chatting/current/presentation/ChattingRoomController.java +++ b/src/main/java/coffeemeet/server/chatting/current/presentation/ChattingRoomController.java @@ -1,7 +1,9 @@ package coffeemeet.server.chatting.current.presentation; +import coffeemeet.server.chatting.current.presentation.dto.ChatRoomStatusHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP; import coffeemeet.server.chatting.current.service.ChattingRoomService; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response; import java.util.List; import lombok.RequiredArgsConstructor; @@ -35,4 +37,10 @@ public ResponseEntity exitChattingRoom(@PathVariable Long roomId) { return ResponseEntity.ok().build(); } + @GetMapping("/{roomId}/exist") + public ResponseEntity checkChattingRoom(@PathVariable Long roomId) { + ChatRoomStatusDto chatRoomStatusDto = chattingRoomService.checkChattingRoomStatus(roomId); + return ResponseEntity.ok(ChatRoomStatusHTTP.Response.from(chatRoomStatusDto)); + } + } diff --git a/src/main/java/coffeemeet/server/chatting/current/presentation/dto/ChatRoomStatusHTTP.java b/src/main/java/coffeemeet/server/chatting/current/presentation/dto/ChatRoomStatusHTTP.java new file mode 100644 index 00000000..83ab9b08 --- /dev/null +++ b/src/main/java/coffeemeet/server/chatting/current/presentation/dto/ChatRoomStatusHTTP.java @@ -0,0 +1,21 @@ +package coffeemeet.server.chatting.current.presentation.dto; + +import static lombok.AccessLevel.PRIVATE; + +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = PRIVATE) +public final class ChatRoomStatusHTTP { + + public record Response( + boolean isExisted + ) { + + public static ChatRoomStatusHTTP.Response from(ChatRoomStatusDto chatRoomStatusDto) { + return new Response(chatRoomStatusDto.isExisted()); + } + + } + +} diff --git a/src/main/java/coffeemeet/server/chatting/current/service/ChattingRoomService.java b/src/main/java/coffeemeet/server/chatting/current/service/ChattingRoomService.java index 6bb9005a..6e9add89 100644 --- a/src/main/java/coffeemeet/server/chatting/current/service/ChattingRoomService.java +++ b/src/main/java/coffeemeet/server/chatting/current/service/ChattingRoomService.java @@ -5,6 +5,7 @@ import coffeemeet.server.chatting.current.implement.ChattingMessageQuery; import coffeemeet.server.chatting.current.implement.ChattingRoomCommand; import coffeemeet.server.chatting.current.implement.ChattingRoomQuery; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response; import coffeemeet.server.chatting.history.domain.ChattingMessageHistory; @@ -83,4 +84,7 @@ private void updateUserStatusToIdle(List users) { users.forEach(User::setIdleStatus); } + public ChatRoomStatusDto checkChattingRoomStatus(Long roomId) { + return ChatRoomStatusDto.from(chattingRoomQuery.existsBy(roomId)); + } } diff --git a/src/main/java/coffeemeet/server/chatting/current/service/dto/ChatRoomStatusDto.java b/src/main/java/coffeemeet/server/chatting/current/service/dto/ChatRoomStatusDto.java new file mode 100644 index 00000000..bd0d307e --- /dev/null +++ b/src/main/java/coffeemeet/server/chatting/current/service/dto/ChatRoomStatusDto.java @@ -0,0 +1,9 @@ +package coffeemeet.server.chatting.current.service.dto; + +public record ChatRoomStatusDto(boolean isExisted) { + + public static ChatRoomStatusDto from(boolean isExisted) { + return new ChatRoomStatusDto(isExisted); + } + +} diff --git a/src/main/java/coffeemeet/server/common/implement/FCMNotificationSender.java b/src/main/java/coffeemeet/server/common/implement/FCMNotificationSender.java index 157cf3cd..caba71b6 100644 --- a/src/main/java/coffeemeet/server/common/implement/FCMNotificationSender.java +++ b/src/main/java/coffeemeet/server/common/implement/FCMNotificationSender.java @@ -47,7 +47,7 @@ public void sendNotification(NotificationInfo notificationInfo, String content) public void sendMultiNotifications(Set notificationInfos, String content) { Set tokens = convertNotificationInfoToToken(notificationInfos); - if(tokens.isEmpty()) { + if (tokens.isEmpty()) { return; } @@ -65,7 +65,7 @@ public void sendMultiNotifications(Set notificationInfos, Stri public void sendMultiNotificationsWithData(Set notificationInfos, String content, String key, String value) { Set tokens = convertNotificationInfoToToken(notificationInfos); - if(tokens.isEmpty()) { + if (tokens.isEmpty()) { return; } diff --git a/src/main/java/coffeemeet/server/common/presentation/advice/GlobalExceptionHandler.java b/src/main/java/coffeemeet/server/common/presentation/advice/GlobalExceptionHandler.java index 0d6b0554..edbde9f4 100644 --- a/src/main/java/coffeemeet/server/common/presentation/advice/GlobalExceptionHandler.java +++ b/src/main/java/coffeemeet/server/common/presentation/advice/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package coffeemeet.server.common.presentation.advice; +import coffeemeet.server.common.execption.BadRequestException; import coffeemeet.server.common.execption.DataLengthExceededException; import coffeemeet.server.common.execption.GlobalErrorCode; import coffeemeet.server.common.execption.InvalidAuthException; @@ -59,6 +60,13 @@ public ResponseEntity handleException(MissMatchException exceptio .body(ErrorResponse.of(exception.getErrorCode())); } + @ExceptionHandler(BadRequestException.class) + public ResponseEntity handleException(BadRequestException exception) { + log.info(exception.getMessage(), exception); + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body(ErrorResponse.of(exception.getErrorCode())); + } + @ExceptionHandler(NotFoundException.class) public ResponseEntity handleException(NotFoundException exception) { log.info(exception.getMessage(), exception); diff --git a/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportHTTP.java b/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportHTTP.java new file mode 100644 index 00000000..ead3537f --- /dev/null +++ b/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportHTTP.java @@ -0,0 +1,38 @@ +package coffeemeet.server.report.presentation.dto; + +import static lombok.AccessLevel.PRIVATE; + +import coffeemeet.server.report.service.dto.GroupReportDto; +import java.time.LocalDateTime; +import java.util.List; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = PRIVATE) +public final class GroupReportHTTP { + + public record GroupReport( + String reporterNickname, + Long reportId, + LocalDateTime createdAt + ) { + + public static GroupReport from(GroupReportDto response) { + return new GroupReport( + response.reporterNickname(), + response.reportId(), + response.createdAt() + ); + } + } + + public record Response(List groupReports) { + + public static Response from(List responses) { + List groupReportList = responses.stream() + .map(GroupReport::from) + .toList(); + return new Response(groupReportList); + } + } + +} diff --git a/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportList.java b/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportList.java deleted file mode 100644 index 164138bc..00000000 --- a/src/main/java/coffeemeet/server/report/presentation/dto/GroupReportList.java +++ /dev/null @@ -1,13 +0,0 @@ -package coffeemeet.server.report.presentation.dto; - -import coffeemeet.server.report.service.dto.GroupReportDto; -import java.util.List; - -public record GroupReportList(List reports) { - - public static GroupReportList from(List response) { - return new GroupReportList(response); - } - -} - diff --git a/src/main/java/coffeemeet/server/report/presentation/dto/ReportList.java b/src/main/java/coffeemeet/server/report/presentation/dto/ReportList.java deleted file mode 100644 index a417e2f6..00000000 --- a/src/main/java/coffeemeet/server/report/presentation/dto/ReportList.java +++ /dev/null @@ -1,18 +0,0 @@ -package coffeemeet.server.report.presentation.dto; - -import coffeemeet.server.report.service.dto.ReportDto; -import java.util.List; - -public record ReportList( - List contents, - boolean hasNext -) { - - public static ReportList of(List contents, boolean hasNext) { - return new ReportList( - contents, - hasNext - ); - } - -} diff --git a/src/main/java/coffeemeet/server/report/presentation/dto/ReportListHTTP.java b/src/main/java/coffeemeet/server/report/presentation/dto/ReportListHTTP.java new file mode 100644 index 00000000..11a43d7e --- /dev/null +++ b/src/main/java/coffeemeet/server/report/presentation/dto/ReportListHTTP.java @@ -0,0 +1,17 @@ +package coffeemeet.server.report.presentation.dto; + +import coffeemeet.server.report.service.dto.ReportDto; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ReportListHTTP { + + public record Response(ReportDto content) { + + public static Response from(ReportDto content) { + return new Response(content); + } + } + +} diff --git a/src/main/java/coffeemeet/server/report/service/ReportService.java b/src/main/java/coffeemeet/server/report/service/ReportService.java index 921637c7..42421346 100644 --- a/src/main/java/coffeemeet/server/report/service/ReportService.java +++ b/src/main/java/coffeemeet/server/report/service/ReportService.java @@ -9,10 +9,10 @@ import coffeemeet.server.report.domain.Report; import coffeemeet.server.report.implement.ReportCommand; import coffeemeet.server.report.implement.ReportQuery; -import coffeemeet.server.report.presentation.dto.ReportList; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; import coffeemeet.server.report.service.dto.ReportDto; +import coffeemeet.server.report.service.dto.ReportListDto; import coffeemeet.server.user.domain.User; import coffeemeet.server.user.implement.UserQuery; import java.util.List; @@ -60,7 +60,7 @@ public ReportDetailDto findReportById(Long reportId) { return ReportDetailDto.of(report, reporter, targetUser); } - public ReportList findAllReports(Long lastReportId, int pageSize) { + public ReportListDto findAllReports(Long lastReportId, int pageSize) { List reports = reportQuery.getAllReports(lastReportId, pageSize); boolean hasNext = reports.size() >= pageSize; @@ -74,7 +74,7 @@ public ReportList findAllReports(Long lastReportId, int pageSize) { return ReportDto.of(targetUser, chattingRoom); }) .toList(); - return ReportList.of(responses, hasNext); + return ReportListDto.of(responses, hasNext); } public List findReportByTargetIdAndChattingRoomId(long targetId, @@ -91,7 +91,7 @@ private void checkChattingRoomExists(long reporterId, long chattingRoomId) { boolean isChattingHistoryExists = false; try { - chattingRoomQuery.existsById(chattingRoomId); + chattingRoomQuery.verifyChatRoomExistence(chattingRoomId); isChattingRoomExists = true; } catch (NotFoundException e) { isChattingHistoryExists = userChattingHistoryQuery.existsByUserId(reporterId); @@ -108,7 +108,7 @@ private Map getChattingRooms(List allReports) { Set chattingRoomIds = allReports.stream() .map(Report::getChattingRoomId) .collect(Collectors.toSet()); - Set chattingRooms = chattingRoomQuery.getUserByIdSet(chattingRoomIds); + Set chattingRooms = chattingRoomQuery.getChattingRoomsSetBy(chattingRoomIds); return chattingRooms.stream() .collect(Collectors.toMap(ChattingRoom::getId, Function.identity())); } diff --git a/src/main/java/coffeemeet/server/report/service/dto/ReportListDto.java b/src/main/java/coffeemeet/server/report/service/dto/ReportListDto.java new file mode 100644 index 00000000..f22c6654 --- /dev/null +++ b/src/main/java/coffeemeet/server/report/service/dto/ReportListDto.java @@ -0,0 +1,14 @@ +package coffeemeet.server.report.service.dto; + +import java.util.List; + +public record ReportListDto( + List contents, + boolean hasNext +) { + + public static ReportListDto of(List contents, boolean hasNext) { + return new ReportListDto(contents, hasNext); + } + +} diff --git a/src/main/java/coffeemeet/server/user/domain/User.java b/src/main/java/coffeemeet/server/user/domain/User.java index 6b11f048..b20af9cb 100644 --- a/src/main/java/coffeemeet/server/user/domain/User.java +++ b/src/main/java/coffeemeet/server/user/domain/User.java @@ -1,5 +1,6 @@ package coffeemeet.server.user.domain; +import static coffeemeet.server.common.execption.GlobalErrorCode.BAD_REQUEST_ERROR; import static coffeemeet.server.user.domain.UserStatus.CHATTING_CONNECTED; import static coffeemeet.server.user.domain.UserStatus.CHATTING_UNCONNECTED; import static coffeemeet.server.user.domain.UserStatus.IDLE; @@ -8,6 +9,7 @@ import coffeemeet.server.chatting.current.domain.ChattingRoom; import coffeemeet.server.common.domain.AdvancedBaseEntity; +import coffeemeet.server.common.execption.BadRequestException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -35,6 +37,8 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class User extends AdvancedBaseEntity { + public static final String INVALID_USER_STATUS = "올바르지 않은 유저 상태입니다."; + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -92,6 +96,9 @@ public void updateNotificationInfo(@NonNull NotificationInfo newNotificationInfo } public void completeMatching(ChattingRoom chattingRoom) { + if (this.userStatus != MATCHING) { + throw new BadRequestException(BAD_REQUEST_ERROR, INVALID_USER_STATUS); + } this.userStatus = CHATTING_UNCONNECTED; this.chattingRoom = chattingRoom; } @@ -101,10 +108,16 @@ public void deleteChattingRoom() { } public void enterChattingRoom() { + if (this.userStatus != CHATTING_UNCONNECTED) { + throw new BadRequestException(BAD_REQUEST_ERROR, INVALID_USER_STATUS); + } this.userStatus = CHATTING_CONNECTED; } public void exitChattingRoom() { + if (this.userStatus != CHATTING_CONNECTED) { + throw new BadRequestException(BAD_REQUEST_ERROR, INVALID_USER_STATUS); + } this.userStatus = CHATTING_UNCONNECTED; } @@ -118,6 +131,9 @@ public void punished() { } public void matching() { + if (this.userStatus != IDLE) { + throw new BadRequestException(BAD_REQUEST_ERROR, INVALID_USER_STATUS); + } this.userStatus = MATCHING; } diff --git a/src/main/java/coffeemeet/server/user/service/UserService.java b/src/main/java/coffeemeet/server/user/service/UserService.java index 023bbcdd..8bb97de9 100644 --- a/src/main/java/coffeemeet/server/user/service/UserService.java +++ b/src/main/java/coffeemeet/server/user/service/UserService.java @@ -2,6 +2,7 @@ import static coffeemeet.server.common.domain.KeyType.PROFILE_IMAGE; import static coffeemeet.server.common.execption.GlobalErrorCode.BAD_REQUEST_ERROR; +import static coffeemeet.server.oauth.utils.constant.OAuthConstant.DEFAULT_IMAGE_URL; import coffeemeet.server.auth.domain.AuthTokens; import coffeemeet.server.auth.domain.AuthTokensGenerator; @@ -170,9 +171,11 @@ private UserStatusDto handleReportedUser(User user) { } private void deleteCurrentProfileImage(String profileImageUrl) { - String currentKey = mediaManager.extractKey(profileImageUrl, - PROFILE_IMAGE); - mediaManager.delete(currentKey); + if (!profileImageUrl.equals(DEFAULT_IMAGE_URL)) { + String currentKey = mediaManager.extractKey(profileImageUrl, + PROFILE_IMAGE); + mediaManager.delete(currentKey); + } } } diff --git a/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java b/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java index e9afbc96..aad7dbfe 100644 --- a/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java +++ b/src/test/java/coffeemeet/server/admin/presentation/AdminControllerTest.java @@ -37,7 +37,6 @@ import coffeemeet.server.certification.service.dto.PendingCertificationPageDto; import coffeemeet.server.common.config.ControllerTestConfig; import coffeemeet.server.common.fixture.dto.GroupReportDtoFixture; -import coffeemeet.server.common.fixture.dto.GroupReportListFixture; import coffeemeet.server.common.fixture.dto.ReportDetailDtoFixture; import coffeemeet.server.common.fixture.dto.ReportDetailHTTPFixture; import coffeemeet.server.common.fixture.dto.ReportDtoFixture; @@ -48,13 +47,15 @@ import coffeemeet.server.inquiry.service.dto.InquiryDetailDto; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse; import coffeemeet.server.inquiry.service.dto.InquirySearchResponse.InquirySummary; -import coffeemeet.server.report.presentation.dto.GroupReportList; +import coffeemeet.server.report.presentation.dto.GroupReportHTTP; import coffeemeet.server.report.presentation.dto.ReportDetailHTTP; -import coffeemeet.server.report.presentation.dto.ReportList; +import coffeemeet.server.report.presentation.dto.ReportListHTTP; +import coffeemeet.server.report.presentation.dto.ReportListHTTP.Response; import coffeemeet.server.report.service.ReportService; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; import coffeemeet.server.report.service.dto.ReportDto; +import coffeemeet.server.report.service.dto.ReportListDto; import com.epages.restdocs.apispec.Schema; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -247,12 +248,14 @@ void findAllReportsTest() throws Exception { List reportResponses = List.of(response1, response2); boolean hasNext = true; - ReportList reportList = ReportList.of(reportResponses, hasNext); + ReportListDto reportListDto = ReportListDto.of(reportResponses, hasNext); + List responses = reportListDto.contents().stream() + .map(Response::from) + .toList(); + AdminCustomPage result = new AdminCustomPage<>(responses, + reportListDto.hasNext()); - AdminCustomPage result = new AdminCustomPage<>(reportList.contents(), - reportList.hasNext()); - - given(reportService.findAllReports(lastReportId, pageSize)).willReturn(reportList); + given(reportService.findAllReports(lastReportId, pageSize)).willReturn(reportListDto); // when, then mockMvc.perform(get("/api/v1/admins/reports") @@ -269,17 +272,17 @@ void findAllReportsTest() throws Exception { headerWithName("JSESSION").description("세션") ), responseFields( - fieldWithPath("contents").description("List of report details"), + fieldWithPath("contents").description("신고 조회 내역 리스트"), fieldWithPath("hasNext").type(JsonFieldType.BOOLEAN).description("다음 페이지 존재 여부"), - fieldWithPath("contents.[].targetedNickname").type(JsonFieldType.STRING) + fieldWithPath("contents.[].content.targetedNickname").type(JsonFieldType.STRING) .description("신고 대상 닉네임"), - fieldWithPath("contents.[].chattingRoomName").type(JsonFieldType.STRING) + fieldWithPath("contents.[].content.chattingRoomName").type(JsonFieldType.STRING) .description("신고 대상 채팅방 이름"), - fieldWithPath("contents.[].targetedId").type(JsonFieldType.NUMBER) + fieldWithPath("contents.[].content.targetedId").type(JsonFieldType.NUMBER) .description("신고 대상 아이디"), - fieldWithPath("contents.[].chattingRoomId").type(JsonFieldType.NUMBER) + fieldWithPath("contents.[].content.chattingRoomId").type(JsonFieldType.NUMBER) .description("신고 대상 채팅방 이름"), - fieldWithPath("contents.[].createdAt").type(JsonFieldType.STRING) + fieldWithPath("contents.[].content.createdAt").type(JsonFieldType.STRING) .description("신고 생성 날짜") ) )) @@ -293,7 +296,7 @@ void findReportByTargetIdAndChattingRoomIdTest() throws Exception { // given List response = List.of(GroupReportDtoFixture.targetReportDto(), GroupReportDtoFixture.targetReportDto()); - GroupReportList resultResponse = GroupReportListFixture.groupReportListResponse(response); + GroupReportHTTP.Response result = GroupReportHTTP.Response.from(response); given(reportService.findReportByTargetIdAndChattingRoomId(anyLong(), anyLong())).willReturn( response); @@ -318,16 +321,16 @@ void findReportByTargetIdAndChattingRoomIdTest() throws Exception { headerWithName("JSESSION").description("세션") ), responseFields( - fieldWithPath("reports.[].reporterNickname").type(JsonFieldType.STRING) + fieldWithPath("groupReports.[].reporterNickname").type(JsonFieldType.STRING) .description("신고자 닉네임"), - fieldWithPath("reports.[].reportId").type(JsonFieldType.NUMBER) + fieldWithPath("groupReports.[].reportId").type(JsonFieldType.NUMBER) .description("신고자 닉네임"), - fieldWithPath("reports.[].createdAt").type(JsonFieldType.STRING) + fieldWithPath("groupReports.[].createdAt").type(JsonFieldType.STRING) .description("신고 생성 날짜") ) )) .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(resultResponse))); + .andExpect(content().json(objectMapper.writeValueAsString(result))); } @Test diff --git a/src/test/java/coffeemeet/server/chatting/concurrency/ChattingMessageServiceConcurrencyTest.java b/src/test/java/coffeemeet/server/chatting/concurrency/ChattingMessageServiceConcurrencyTest.java index 3eb37cd4..701bc1ba 100644 --- a/src/test/java/coffeemeet/server/chatting/concurrency/ChattingMessageServiceConcurrencyTest.java +++ b/src/test/java/coffeemeet/server/chatting/concurrency/ChattingMessageServiceConcurrencyTest.java @@ -1,5 +1,7 @@ package coffeemeet.server.chatting.concurrency; +import static coffeemeet.server.user.domain.UserStatus.CHATTING_UNCONNECTED; +import static coffeemeet.server.user.domain.UserStatus.MATCHING; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.willDoNothing; @@ -57,7 +59,7 @@ void tearDown() { void chattingConcurrencyTest() throws InterruptedException { // given ChattingRoom room = chattingRoomRepository.save(ChattingFixture.chattingRoom()); - User user = userRepository.save(UserFixture.user()); + User user = userRepository.save(UserFixture.user(CHATTING_UNCONNECTED)); String sessionId = "sessionId"; chattingMessageService.storeSocketSession(sessionId, String.valueOf(user.getId())); diff --git a/src/test/java/coffeemeet/server/chatting/current/implement/ChattingRoomQueryTest.java b/src/test/java/coffeemeet/server/chatting/current/implement/ChattingRoomQueryTest.java index 16c328d9..1a6e920e 100644 --- a/src/test/java/coffeemeet/server/chatting/current/implement/ChattingRoomQueryTest.java +++ b/src/test/java/coffeemeet/server/chatting/current/implement/ChattingRoomQueryTest.java @@ -1,12 +1,18 @@ package coffeemeet.server.chatting.current.implement; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.BDDMockito.given; import coffeemeet.server.chatting.current.domain.ChattingRoom; import coffeemeet.server.chatting.current.infrastructure.ChattingRoomRepository; +import coffeemeet.server.common.execption.NotFoundException; import coffeemeet.server.common.fixture.entity.ChattingFixture; import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,4 +44,47 @@ void getChattingRoomByIdTest() { assertThat(foundChattingRoom).isEqualTo(chattingRoom); } + @DisplayName("채팅방이 존재하지 않으면 예외가 발생할 수 있다.") + @Test + void verifyChatRoomExistenceTest() { + // given + Long roomId = 1L; + given(chattingRoomRepository.existsById(roomId)).willReturn(false); + + // when, then + assertThatThrownBy(() -> chattingRoomQuery.verifyChatRoomExistence(roomId)) + .isInstanceOf(NotFoundException.class); + } + + @DisplayName("채팅방 아이디 셋으로 채팅방을 셋을 조회할 수 있다.") + @Test + void getChattingRoomsSetByIdSetTest() { + // given + int size = 4; + Set chattingRooms = ChattingFixture.chattingRoom(size); + Set chattingRoomIdsSet = chattingRooms.stream().map(chattingRoom -> chattingRoom.getId()) + .collect(Collectors.toSet()); + given(chattingRoomRepository.findByIdIn(anySet())).willReturn(chattingRooms); + + // when + Set response = chattingRoomQuery.getChattingRoomsSetBy(chattingRoomIdsSet); + + // then + assertThat(response).isEqualTo(chattingRooms); + } + + @DisplayName("채팅방 존재를 확인할 수 있다.") + @Test + void existsByRoomIdTest() { + // given + Long roomId = 1L; + given(chattingRoomRepository.existsById(any())).willReturn(true); + + // when + boolean response = chattingRoomQuery.existsBy(roomId); + + // then + assertThat(response).isTrue(); + } + } diff --git a/src/test/java/coffeemeet/server/chatting/current/presentation/ChattingRoomControllerTest.java b/src/test/java/coffeemeet/server/chatting/current/presentation/ChattingRoomControllerTest.java index ae6a1db7..9fdb3d02 100644 --- a/src/test/java/coffeemeet/server/chatting/current/presentation/ChattingRoomControllerTest.java +++ b/src/test/java/coffeemeet/server/chatting/current/presentation/ChattingRoomControllerTest.java @@ -18,9 +18,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import coffeemeet.server.chatting.current.presentation.dto.ChatRoomStatusHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP.Chat; import coffeemeet.server.chatting.current.service.ChattingRoomService; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response; import coffeemeet.server.common.config.ControllerTestConfig; import coffeemeet.server.common.fixture.entity.ChattingFixture; @@ -111,4 +113,33 @@ void exitChattingRoomTest() throws Exception { .andExpect(status().isOk()); } + @DisplayName("채팅방의 상태를 체크할 수 있다.") + @Test + void checkChattingRoomTest() throws Exception { + // given + Long userId = 1L; + Long roomId = 1L; + ChatRoomStatusDto chatRoomStatusDto = ChattingFixture.chatRoomStatusDto(); + ChatRoomStatusHTTP.Response response = ChattingFixture.chatRoomStatusHTTPResponse( + chatRoomStatusDto); + + given(jwtTokenProvider.extractUserId(TOKEN)).willReturn(userId); + given(chattingRoomService.checkChattingRoomStatus(roomId)).willReturn(chatRoomStatusDto); + + // when, then + mockMvc.perform(get("/api/v1/chatting/rooms/{roomId}/exist", roomId) + .header("Authorization", TOKEN) + ) + .andDo(document("check-chatting-room-status", + resourceDetails().tag("채팅방").description("채팅방 상태 확인"), + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + requestHeaders( + headerWithName("Authorization").description("토큰") + ) + ) + ) + .andExpect(content().string(objectMapper.writeValueAsString(response))); + } + } diff --git a/src/test/java/coffeemeet/server/chatting/current/service/ChattingRoomServiceTest.java b/src/test/java/coffeemeet/server/chatting/current/service/ChattingRoomServiceTest.java index c89296e4..7b49d2df 100644 --- a/src/test/java/coffeemeet/server/chatting/current/service/ChattingRoomServiceTest.java +++ b/src/test/java/coffeemeet/server/chatting/current/service/ChattingRoomServiceTest.java @@ -13,6 +13,7 @@ import coffeemeet.server.chatting.current.implement.ChattingMessageQuery; import coffeemeet.server.chatting.current.implement.ChattingRoomCommand; import coffeemeet.server.chatting.current.implement.ChattingRoomQuery; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto.Response; import coffeemeet.server.chatting.history.domain.ChattingRoomHistory; import coffeemeet.server.chatting.history.implement.ChattingMessageHistoryCommand; @@ -127,4 +128,20 @@ void deleteChattingRoomTest() { then(fcmNotificationSender).should(only()).sendMultiNotifications(anySet(), any()); } + @DisplayName("채팅방의 유무 상태를 조회할 수 있다.") + @Test + void checkChattingRoomStatusTest() { + // given + Long roomId = 1L; + ChatRoomStatusDto chatRoomStatusDto = ChattingFixture.chatRoomStatusDto(); + + given(chattingRoomQuery.existsBy(any())).willReturn(chatRoomStatusDto.isExisted()); + + // when + ChatRoomStatusDto response = chattingRoomService.checkChattingRoomStatus(roomId); + + // then + assertThat(response).isEqualTo(chatRoomStatusDto); + } + } diff --git a/src/test/java/coffeemeet/server/common/fixture/dto/GroupReportListFixture.java b/src/test/java/coffeemeet/server/common/fixture/dto/GroupReportListFixture.java deleted file mode 100644 index 2d87de53..00000000 --- a/src/test/java/coffeemeet/server/common/fixture/dto/GroupReportListFixture.java +++ /dev/null @@ -1,13 +0,0 @@ -package coffeemeet.server.common.fixture.dto; - -import coffeemeet.server.report.presentation.dto.GroupReportList; -import coffeemeet.server.report.service.dto.GroupReportDto; -import java.util.List; - -public class GroupReportListFixture { - - public static GroupReportList groupReportListResponse(List response) { - return new GroupReportList(response); - } - -} diff --git a/src/test/java/coffeemeet/server/common/fixture/entity/ChattingFixture.java b/src/test/java/coffeemeet/server/common/fixture/entity/ChattingFixture.java index 45c64cab..1b6b4879 100644 --- a/src/test/java/coffeemeet/server/common/fixture/entity/ChattingFixture.java +++ b/src/test/java/coffeemeet/server/common/fixture/entity/ChattingFixture.java @@ -5,8 +5,10 @@ import coffeemeet.server.chatting.current.domain.ChattingMessage; import coffeemeet.server.chatting.current.domain.ChattingRoom; import coffeemeet.server.chatting.current.domain.ChattingSession; +import coffeemeet.server.chatting.current.presentation.dto.ChatRoomStatusHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP; import coffeemeet.server.chatting.current.presentation.dto.ChatsHTTP.Chat; +import coffeemeet.server.chatting.current.service.dto.ChatRoomStatusDto; import coffeemeet.server.chatting.current.service.dto.ChattingDto; import coffeemeet.server.chatting.history.domain.ChattingMessageHistory; import coffeemeet.server.chatting.history.domain.ChattingRoomHistory; @@ -128,4 +130,14 @@ public static ChattingSession chattingSession() { return Instancio.create(ChattingSession.class); } + public static ChatRoomStatusDto chatRoomStatusDto() { + return Instancio.of(ChatRoomStatusDto.class) + .create(); + } + + public static ChatRoomStatusHTTP.Response chatRoomStatusHTTPResponse( + ChatRoomStatusDto chatRoomStatusDto) { + return ChatRoomStatusHTTP.Response.from(chatRoomStatusDto); + } + } diff --git a/src/test/java/coffeemeet/server/common/fixture/entity/UserFixture.java b/src/test/java/coffeemeet/server/common/fixture/entity/UserFixture.java index 2304c022..1e79d1cb 100644 --- a/src/test/java/coffeemeet/server/common/fixture/entity/UserFixture.java +++ b/src/test/java/coffeemeet/server/common/fixture/entity/UserFixture.java @@ -29,6 +29,7 @@ public static User user(UserStatus userStatus) { .set(field(User::getUserStatus), userStatus) .ignore(field(User::isDeleted)) .ignore(field(User::isBlacklisted)) + .ignore(field(User::getChattingRoom)) .create(); } diff --git a/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java b/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java index 5ec220dd..7fdb1315 100644 --- a/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java +++ b/src/test/java/coffeemeet/server/report/service/ReportServiceTest.java @@ -16,9 +16,9 @@ import coffeemeet.server.report.domain.Report; import coffeemeet.server.report.implement.ReportCommand; import coffeemeet.server.report.implement.ReportQuery; -import coffeemeet.server.report.presentation.dto.ReportList; import coffeemeet.server.report.service.dto.GroupReportDto; import coffeemeet.server.report.service.dto.ReportDetailDto; +import coffeemeet.server.report.service.dto.ReportListDto; import coffeemeet.server.user.domain.User; import coffeemeet.server.user.implement.UserQuery; import java.util.List; @@ -57,7 +57,7 @@ void reportUserTest() { Long reporterId = report.getReporterId(); willDoNothing().given(reportQuery).hasDuplicatedReport(anyLong(), anyLong(), anyLong()); - willDoNothing().given(chattingRoomQuery).existsById(anyLong()); + willDoNothing().given(chattingRoomQuery).verifyChatRoomExistence(anyLong()); willDoNothing().given(reportCommand).createReport(any(Report.class)); // when @@ -121,10 +121,11 @@ void findAllReportsTest() { given(userQuery.getUsersByIdSet(userIds)).willReturn(Set.of(targetUser)); Set chattingRoomIds = Set.of(chattingRoomId); - given(chattingRoomQuery.getUserByIdSet(chattingRoomIds)).willReturn(Set.of(chattingRoom)); + given(chattingRoomQuery.getChattingRoomsSetBy(chattingRoomIds)).willReturn( + Set.of(chattingRoom)); // when - ReportList responses = reportService.findAllReports(lastReportId, pageSize); + ReportListDto responses = reportService.findAllReports(lastReportId, pageSize); // then assertAll( diff --git a/src/test/java/coffeemeet/server/user/implement/UserCommandTest.java b/src/test/java/coffeemeet/server/user/implement/UserCommandTest.java index 59926192..809ddd65 100644 --- a/src/test/java/coffeemeet/server/user/implement/UserCommandTest.java +++ b/src/test/java/coffeemeet/server/user/implement/UserCommandTest.java @@ -103,7 +103,7 @@ void assignUsersToChattingRoomTest() { // given Set userIds = Set.of(1L, 2L); ChattingRoom chattingRoom = new ChattingRoom(); - Set users = Set.of(user(), user()); + Set users = Set.of(user(MATCHING), user(MATCHING)); given(userQuery.getUsersByIdSet(userIds)).willReturn(users); // when @@ -147,7 +147,7 @@ void unsubscribeNotification() { @DisplayName("유저 상태를 채팅방 연결로 변경할 수 있다.") void enterToChattingRoomTest() { // given - User user = user(); + User user = user(CHATTING_UNCONNECTED); given(userQuery.getUserById(user.getId())).willReturn(user); @@ -162,7 +162,7 @@ void enterToChattingRoomTest() { @DisplayName("유저 상태를 채팅방 연결 해제로 변경할 수 있다.") void exitChattingRoomTest() { // given - User user = user(); + User user = user(CHATTING_CONNECTED); given(userQuery.getUserById(user.getId())).willReturn(user); @@ -193,7 +193,7 @@ void setToIdleTest() { @DisplayName("유저 상태를 매칭 중으로 변경할 수 있다.") void setToMatchingTest() { // given - User user = user(); + User user = user(IDLE); given(userQuery.getUserById(user.getId())).willReturn(user); diff --git a/src/test/java/coffeemeet/server/user/service/UserServiceTest.java b/src/test/java/coffeemeet/server/user/service/UserServiceTest.java index 1eb2e6e8..49b1468b 100644 --- a/src/test/java/coffeemeet/server/user/service/UserServiceTest.java +++ b/src/test/java/coffeemeet/server/user/service/UserServiceTest.java @@ -4,6 +4,7 @@ import static coffeemeet.server.common.fixture.dto.AuthTokensFixture.authTokens; import static coffeemeet.server.common.fixture.dto.OAuthUserInfoDtoFixture.response; import static coffeemeet.server.common.fixture.entity.CertificationFixture.certification; +import static coffeemeet.server.common.fixture.entity.ChattingFixture.chattingRoom; import static coffeemeet.server.common.fixture.entity.UserFixture.keywords; import static coffeemeet.server.common.fixture.entity.UserFixture.user; import static coffeemeet.server.user.domain.OAuthProvider.KAKAO; @@ -28,6 +29,7 @@ import coffeemeet.server.auth.domain.AuthTokensGenerator; import coffeemeet.server.certification.domain.Certification; import coffeemeet.server.certification.implement.CertificationQuery; +import coffeemeet.server.chatting.current.domain.ChattingRoom; import coffeemeet.server.common.fixture.dto.SignupHTTPFixture; import coffeemeet.server.common.fixture.entity.UserFixture; import coffeemeet.server.common.implement.MediaManager; @@ -369,7 +371,8 @@ void getUserStatusMatchingTest() { void getUserStatusChattingUnConnectingTest() { // given Long userId = 1L; - User user = UserFixture.user(UserStatus.CHATTING_UNCONNECTED); + User user = UserFixture.user(UserStatus.MATCHING); + user.completeMatching(chattingRoom()); Certification certification = certification(); given(userQuery.getUserById(anyLong())).willReturn(user);