Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public void approveMentorApplication(Long mentorApplicationId) {
.orElseThrow(() -> new CustomException(MENTOR_APPLICATION_NOT_FOUND));

mentorApplication.approve();

SiteUser siteUser = siteUserRepository.findById(mentorApplication.getSiteUserId())
.orElseThrow(() -> new CustomException(USER_NOT_FOUND));

siteUser.becomeMentor();
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ public void updatePassword(String newEncodedPassword) {
public void updateUserStatus(UserStatus status) {
this.userStatus = status;
}

public void becomeMentor() {
this.role = Role.MENTOR;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import com.example.solidconnection.mentor.domain.UniversitySelectType;
import com.example.solidconnection.mentor.fixture.MentorApplicationFixture;
import com.example.solidconnection.mentor.repository.MentorApplicationRepository;
import com.example.solidconnection.siteuser.domain.Role;
import com.example.solidconnection.siteuser.domain.SiteUser;
import com.example.solidconnection.siteuser.fixture.SiteUserFixture;
import com.example.solidconnection.siteuser.repository.SiteUserRepository;
import com.example.solidconnection.support.TestContainerSpringBootTest;
import com.example.solidconnection.university.domain.HostUniversity;
import com.example.solidconnection.university.fixture.UniversityFixture;
Expand Down Expand Up @@ -56,6 +58,9 @@ class AdminMentorApplicationServiceTest {
@Autowired
private MentorApplicationRepository mentorApplicationRepository;

@Autowired
private SiteUserRepository siteUserRepository;

private MentorApplication mentorApplication1;
private MentorApplication mentorApplication2;
private MentorApplication mentorApplication3;
Expand Down Expand Up @@ -100,7 +105,7 @@ class 멘토_승격_지원서_목록_조회 {
@Test
void 멘토_승격_상태를_조건으로_페이징하여_조회한다() {
// given
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(MentorApplicationStatus.PENDING,null, null, null);
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(MentorApplicationStatus.PENDING, null, null, null);
Pageable pageable = PageRequest.of(0, 10);
List<MentorApplication> expectedMentorApplications = List.of(mentorApplication2, mentorApplication5, mentorApplication7);

Expand All @@ -122,7 +127,7 @@ class 멘토_승격_지원서_목록_조회 {
}

@Test
void 닉네임_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){
void 닉네임_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다() {
// given
String nickname = "test1";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, nickname, null, null);
Expand All @@ -147,7 +152,7 @@ class 멘토_승격_지원서_목록_조회 {
}

@Test
void 대학명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){
void 대학명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다() {
// given
String universityKoreanName = "메이지 대학";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, universityKoreanName, null, null);
Expand All @@ -172,7 +177,7 @@ class 멘토_승격_지원서_목록_조회 {
}

@Test
void 지역명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){
void 지역명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다() {
// given
String regionKoreanName = "유럽";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, regionKoreanName, null, null);
Expand All @@ -197,10 +202,10 @@ class 멘토_승격_지원서_목록_조회 {
}

@Test
void 나라명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다(){
void 나라명_keyword_에_맞는_멘토_지원서를_페이징하여_조회한다() {
// given
String countryKoreanName = "오스트리아";
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, countryKoreanName, null,null);
MentorApplicationSearchCondition condition = new MentorApplicationSearchCondition(null, countryKoreanName, null, null);
Pageable pageable = PageRequest.of(0, 10);
List<MentorApplication> expectedMentorApplications = List.of(mentorApplication3, mentorApplication4);

Expand Down Expand Up @@ -302,7 +307,7 @@ class 멘토_승격_지원서_목록_조회 {
}

@Nested
class 멘토_승격_지원서_승인{
class 멘토_승격_지원서_승인 {

@Test
void 대기중인_멘토_지원서를_승인한다() {
Expand All @@ -314,14 +319,16 @@ class 멘토_승격_지원서_승인{

// then
MentorApplication result = mentorApplicationRepository.findById(mentorApplication2.getId()).get();
SiteUser mentor = siteUserRepository.findById(result.getSiteUserId()).get();
assertAll(
() -> assertThat(result.getMentorApplicationStatus()).isEqualTo(MentorApplicationStatus.APPROVED),
() -> assertThat(result.getApprovedAt()).isNotNull()
() -> assertThat(result.getApprovedAt()).isNotNull(),
() -> assertThat(mentor.getRole()).isEqualTo(Role.MENTOR)
);
}

@Test
void 대학이_선택되지_않은_멘토_지원서를_승인하면_예외가_발생한다(){
void 대학이_선택되지_않은_멘토_지원서를_승인하면_예외가_발생한다() {
// given
SiteUser user = siteUserFixture.사용자();
MentorApplication noUniversityIdMentorApplication = mentorApplicationFixture.대기중_멘토신청(user.getId(), UniversitySelectType.OTHER, null);
Expand Down Expand Up @@ -367,7 +374,7 @@ class 멘토_승격_지원서_승인{
}

@Nested
class 멘토_승격_지원서_거절{
class 멘토_승격_지원서_거절 {

@Test
void 대기중인_멘토_지원서를_거절한다() {
Expand Down Expand Up @@ -517,7 +524,7 @@ class 멘토_지원서에_대학_매핑 {
.hasMessage(UNIVERSITY_NOT_FOUND.getMessage());
}
}

@Nested
class 멘토_지원서_이력_조회 {

Expand All @@ -539,7 +546,7 @@ class 멘토_지원서_이력_조회 {
.containsExactly(app3.getId(), app2.getId(), app1.getId()),
() -> assertThat(response)
.extracting(MentorApplicationHistoryResponse::applicationOrder)
.containsExactly(3,2,1)
.containsExactly(3, 2, 1)
);
}

Expand All @@ -565,7 +572,7 @@ class 멘토_지원서_이력_조회 {
.containsExactly(app7.getId(), app6.getId(), app5.getId(), app4.getId(), app3.getId()),
() -> assertThat(response)
.extracting(MentorApplicationHistoryResponse::applicationOrder)
.containsExactly(7,6,5,4,3)
.containsExactly(7, 6, 5, 4, 3)
);
}

Expand Down
Loading