Skip to content

Commit

Permalink
Merge pull request #208 from coffee-meet/feat/#193
Browse files Browse the repository at this point in the history
feat: 매칭 취소 시 유저 상태 확인
  • Loading branch information
smartandhandsome authored Dec 21, 2023
2 parents f621cab + f976f42 commit 1960414
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@RequiredArgsConstructor
public enum MatchingErrorCode implements ErrorCode {
NOT_CERTIFICATED_USER("M003", "인증되지 않은 사용자입니다."),
INVALID_USER_STATUS("M000", "올바르지 않은 유저 상태입니다."),
;

private final String errorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package coffeemeet.server.matching.service;

import static coffeemeet.server.matching.exception.MatchingErrorCode.INVALID_USER_STATUS;
import static coffeemeet.server.user.domain.UserStatus.MATCHING;

import coffeemeet.server.certification.domain.Certification;
import coffeemeet.server.certification.implement.CertificationQuery;
import coffeemeet.server.chatting.current.domain.ChattingRoom;
import coffeemeet.server.chatting.current.implement.ChattingRoomCommand;
import coffeemeet.server.common.execption.BadRequestException;
import coffeemeet.server.common.implement.FCMNotificationSender;
import coffeemeet.server.matching.implement.MatchingQueueCommand;
import coffeemeet.server.matching.implement.MatchingQueueQuery;
import coffeemeet.server.user.domain.NotificationInfo;
import coffeemeet.server.user.domain.User;
import coffeemeet.server.user.implement.UserCommand;
import coffeemeet.server.user.implement.UserQuery;
import java.util.Set;
Expand Down Expand Up @@ -58,6 +63,11 @@ private void processMatching(String companyName) {
}

public void cancelMatching(Long userId) {
User user = userQuery.getUserById(userId);
if (user.getUserStatus() != MATCHING) {
throw new BadRequestException(INVALID_USER_STATUS,
String.format("유저 상태가 %s이 아닙니다.", MATCHING));
}
String companyName = certificationQuery.getCompanyNameByUserId(userId);
matchingQueueCommand.deleteUserByUserId(companyName, userId);
userCommand.setToIdle(userId);
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/coffeemeet/server/common/fixture/UserFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public static User user(UserStatus userStatus) {
.create();
}

public static User userExcludingStatus(UserStatus excludingStatus) {
return Instancio.of(User.class).set(field(User::getProfile), profile())
.generate(field(User::getUserStatus),
gen -> gen.enumOf(UserStatus.class).excluding(excludingStatus))
.ignore(field(User::isDeleted))
.ignore(field(User::isBlacklisted))
.ignore(field(User::getChattingRoom))
.create();
}

public static List<User> users() {
return Instancio.ofList(User.class)
.generate(field(User::getId), gen -> gen.longSeq().start(1L))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import static coffeemeet.server.common.fixture.CertificationFixture.certificatedCertifications;
import static coffeemeet.server.common.fixture.ChattingFixture.chattingRoom;
import static coffeemeet.server.common.fixture.UserFixture.fourUsers;
import static coffeemeet.server.common.fixture.UserFixture.user;
import static coffeemeet.server.common.fixture.UserFixture.userExcludingStatus;
import static coffeemeet.server.user.domain.UserStatus.MATCHING;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.BDDMockito.willDoNothing;
Expand All @@ -12,6 +16,7 @@
import coffeemeet.server.certification.implement.CertificationQuery;
import coffeemeet.server.chatting.current.domain.ChattingRoom;
import coffeemeet.server.chatting.current.implement.ChattingRoomCommand;
import coffeemeet.server.common.execption.BadRequestException;
import coffeemeet.server.common.implement.FCMNotificationSender;
import coffeemeet.server.matching.implement.MatchingQueueCommand;
import coffeemeet.server.matching.implement.MatchingQueueQuery;
Expand Down Expand Up @@ -96,19 +101,34 @@ void startTest() {

@Test
@DisplayName("매칭을 취소할 수 있다.")
void cancelMatching() {
void cancelMatchingTest() {
// given
Long userId = 1L;
User user = user(MATCHING);
String companyName = "회사명";

given(certificationQuery.getCompanyNameByUserId(userId)).willReturn(companyName);
willDoNothing().given(matchingQueueCommand).deleteUserByUserId(companyName, userId);
given(userQuery.getUserById(user.getId())).willReturn(user);
given(certificationQuery.getCompanyNameByUserId(user.getId())).willReturn(companyName);
willDoNothing().given(matchingQueueCommand).deleteUserByUserId(companyName, user.getId());

// when
matchingService.cancelMatching(userId);
matchingService.cancelMatching(user.getId());

// then
then(userCommand).should(only()).setToIdle(userId);
then(userCommand).should(only()).setToIdle(user.getId());
}

@Test
@DisplayName("매칭을 취소할 수 있다.")
void cancelMatchingTest_BadRequestException() {
// given
User user = userExcludingStatus(MATCHING);
Long userId = user.getId();

given(userQuery.getUserById(userId)).willReturn(user);

// when, then
assertThatThrownBy(() -> matchingService.cancelMatching(userId))
.isInstanceOf(BadRequestException.class);
}

}

0 comments on commit 1960414

Please sign in to comment.