-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from DayByQuest/test/userApplication
[Test] 사용자 서비스 테스트를 작성한다
- Loading branch information
Showing
16 changed files
with
493 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package daybyquest.user.domain; | ||
|
||
import static daybyquest.global.error.ExceptionCode.INVALID_VISIBILITY; | ||
|
||
import daybyquest.global.error.exception.InvalidDomainException; | ||
|
||
public enum UserVisibility { | ||
|
||
PUBLIC, | ||
PRIVATE | ||
PRIVATE; | ||
|
||
public static UserVisibility fromString(final String name) { | ||
try { | ||
return valueOf(name); | ||
} catch (final IllegalArgumentException e) { | ||
throw new InvalidDomainException(INVALID_VISIBILITY); | ||
} | ||
} | ||
} |
27 changes: 2 additions & 25 deletions
27
src/main/java/daybyquest/user/dto/response/MyProfileResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 1 addition & 9 deletions
10
src/main/java/daybyquest/user/dto/response/UserVisibilityResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/daybyquest/user/application/CheckUsernameServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package daybyquest.user.application; | ||
|
||
import static daybyquest.global.error.ExceptionCode.DUPLICATED_USERNAME; | ||
import static daybyquest.support.fixture.UserFixtures.ALICE; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import daybyquest.global.error.exception.InvalidDomainException; | ||
import daybyquest.support.test.ServiceTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class CheckUsernameServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private CheckUsernameService checkUsernameService; | ||
|
||
@Test | ||
void 사용자_이름_중복을_검사한다() { | ||
// given & when & then | ||
assertThatCode(() -> checkUsernameService.invoke(ALICE.username)) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
void 사용자_이름이_이미_있다면_예외를_던진다() { | ||
// given | ||
ALICE를_저장한다(); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> checkUsernameService.invoke(ALICE.username)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(DUPLICATED_USERNAME.getMessage()); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/daybyquest/user/application/DeleteUserImageServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package daybyquest.user.application; | ||
|
||
import static daybyquest.support.fixture.UserFixtures.BOB; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import daybyquest.image.domain.BaseImageProperties; | ||
import daybyquest.support.config.StubImages; | ||
import daybyquest.support.test.ServiceTest; | ||
import daybyquest.user.domain.User; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class DeleteUserImageServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private DeleteUserImageService deleteUserImageService; | ||
|
||
@Autowired | ||
private BaseImageProperties properties; | ||
|
||
@Autowired | ||
private StubImages images; | ||
|
||
@Test | ||
void 사용자_사진을_삭제한다() { | ||
// given | ||
final Long id = BOB을_저장한다(); | ||
images.upload(BOB.imageIdentifier, null); | ||
|
||
// when | ||
deleteUserImageService.invoke(id); | ||
|
||
// then | ||
final User user = users.getById(id); | ||
assertAll(() -> { | ||
assertThat(images.hasUploadImage(BOB.imageIdentifier)).isFalse(); | ||
assertThat(user.getImageIdentifier()).isEqualTo(properties.getUserIdentifier()); | ||
}); | ||
} | ||
|
||
@Test | ||
void 기본_사진이라면_삭제하지_않는다() { | ||
// given | ||
final Long id = ALICE를_저장한다(); | ||
images.upload(properties.getUserIdentifier(), null); | ||
|
||
// when | ||
deleteUserImageService.invoke(id); | ||
|
||
// then | ||
final User user = users.getById(id); | ||
assertAll(() -> { | ||
assertThat(images.hasUploadImage(properties.getUserIdentifier())).isTrue(); | ||
assertThat(user.getImageIdentifier()).isEqualTo(properties.getUserIdentifier()); | ||
}); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/test/java/daybyquest/user/application/GetMyProfileServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package daybyquest.user.application; | ||
|
||
import static daybyquest.support.fixture.PostFixtures.POST_1; | ||
import static daybyquest.support.fixture.PostFixtures.POST_2; | ||
import static daybyquest.support.fixture.PostFixtures.POST_3; | ||
import static daybyquest.support.fixture.UserFixtures.ALICE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import daybyquest.post.domain.Posts; | ||
import daybyquest.relation.domain.Follow; | ||
import daybyquest.relation.domain.Follows; | ||
import daybyquest.support.test.ServiceTest; | ||
import daybyquest.user.dto.response.MyProfileResponse; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class GetMyProfileServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private GetMyProfileService getMyProfileService; | ||
|
||
@Autowired | ||
private Posts posts; | ||
|
||
@Autowired | ||
private Follows follows; | ||
|
||
@Test | ||
void 사용자_프로필을_조회한다() { | ||
// given | ||
final Long id = ALICE를_저장한다(); | ||
|
||
// when | ||
final MyProfileResponse response = getMyProfileService.invoke(id); | ||
|
||
// then | ||
assertAll(() -> { | ||
assertThat(response.username()).isEqualTo(ALICE.username); | ||
assertThat(response.name()).isEqualTo(ALICE.name); | ||
assertThat(response.imageIdentifier()).isEqualTo(ALICE.imageIdentifier); | ||
}); | ||
} | ||
|
||
@Test | ||
void 게시물_수가_함께_조회된다() { | ||
// given | ||
final Long id = ALICE를_저장한다(); | ||
posts.save(POST_1.생성(id)); | ||
posts.save(POST_2.생성(id)); | ||
posts.save(POST_3.생성(id)); | ||
|
||
// when | ||
final MyProfileResponse response = getMyProfileService.invoke(id); | ||
|
||
// then | ||
assertThat(response.postCount()).isEqualTo(3); | ||
} | ||
|
||
@Test | ||
void 팔로워_수가_함께_조회된다() { | ||
// given | ||
final Long id = ALICE를_저장한다(); | ||
follows.save(new Follow(BOB을_저장한다(), id)); | ||
follows.save(new Follow(CHARLIE를_저장한다(), id)); | ||
follows.save(new Follow(DAVID를_저장한다(), id)); | ||
|
||
// when | ||
final MyProfileResponse response = getMyProfileService.invoke(id); | ||
|
||
// then | ||
assertThat(response.followerCount()).isEqualTo(3); | ||
} | ||
|
||
@Test | ||
void 팔로잉_수가_함께_조회된다() { | ||
// given | ||
final Long id = ALICE를_저장한다(); | ||
follows.save(new Follow(id, BOB을_저장한다())); | ||
follows.save(new Follow(id, CHARLIE를_저장한다())); | ||
follows.save(new Follow(id, DAVID를_저장한다())); | ||
|
||
// when | ||
final MyProfileResponse response = getMyProfileService.invoke(id); | ||
|
||
// then | ||
assertThat(response.followingCount()).isEqualTo(3); | ||
} | ||
} |
Oops, something went wrong.