-
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.
- Loading branch information
Showing
5 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/test/java/daybyquest/relation/application/DeleteFollowServiceTest.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,45 @@ | ||
package daybyquest.relation.application; | ||
|
||
import static daybyquest.global.error.ExceptionCode.NOT_FOLLOWING_USER; | ||
import static daybyquest.support.fixture.UserFixtures.BOB; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import daybyquest.global.error.exception.InvalidDomainException; | ||
import daybyquest.relation.domain.Follow; | ||
import daybyquest.support.test.ServiceTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class DeleteFollowServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private DeleteFollowService deleteFollowService; | ||
|
||
@Test | ||
void 팔로우를_취소한다() { | ||
// given | ||
final Long aliceId = ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
follows.save(new Follow(aliceId, bobId)); | ||
|
||
// when | ||
deleteFollowService.invoke(aliceId, BOB.username); | ||
|
||
// then | ||
assertThatThrownBy(() -> follows.getByUserIdAndTargetId(aliceId, bobId)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(NOT_FOLLOWING_USER.getMessage()); | ||
} | ||
|
||
@Test | ||
void 팔로우하지_않은_대상은_취소_할_수_없다() { | ||
// given | ||
final Long aliceId = ALICE를_저장한다(); | ||
BOB을_저장한다(); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> deleteFollowService.invoke(aliceId, BOB.username)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(NOT_FOLLOWING_USER.getMessage()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/daybyquest/relation/application/DeleteFollowerServiceTest.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,45 @@ | ||
package daybyquest.relation.application; | ||
|
||
import static daybyquest.global.error.ExceptionCode.NOT_FOLLOWING_USER; | ||
import static daybyquest.support.fixture.UserFixtures.ALICE; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import daybyquest.global.error.exception.InvalidDomainException; | ||
import daybyquest.relation.domain.Follow; | ||
import daybyquest.support.test.ServiceTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class DeleteFollowerServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private DeleteFollowerService deleteFollowerService; | ||
|
||
@Test | ||
void 팔로워를_삭제한다() { | ||
// given | ||
final Long aliceId = ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
follows.save(new Follow(aliceId, bobId)); | ||
|
||
// when | ||
deleteFollowerService.invoke(bobId, ALICE.username); | ||
|
||
// then | ||
assertThatThrownBy(() -> follows.getByUserIdAndTargetId(aliceId, bobId)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(NOT_FOLLOWING_USER.getMessage()); | ||
} | ||
|
||
@Test | ||
void 팔로워가_아닌_대상은_삭제_할_수_없다() { | ||
// given | ||
ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> deleteFollowerService.invoke(bobId, ALICE.username)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(NOT_FOLLOWING_USER.getMessage()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/daybyquest/relation/application/GetFollowersServiceTest.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,40 @@ | ||
package daybyquest.relation.application; | ||
|
||
import static daybyquest.support.fixture.UserFixtures.BOB; | ||
import static daybyquest.support.fixture.UserFixtures.CHARLIE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import daybyquest.relation.domain.Follow; | ||
import daybyquest.support.test.ServiceTest; | ||
import daybyquest.user.dto.response.PageProfilesResponse; | ||
import daybyquest.user.dto.response.ProfileResponse; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class GetFollowersServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private GetFollowersService getFollowersService; | ||
|
||
@Test | ||
void 팔로워_목록을_조회한다() { | ||
// given | ||
final Long aliceId = ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
final Long charlieId = CHARLIE를_저장한다(); | ||
final Long davidId = DAVID를_저장한다(); | ||
follows.save(new Follow(bobId, aliceId)); | ||
follows.save(new Follow(charlieId, aliceId)); | ||
follows.save(new Follow(aliceId, davidId)); | ||
|
||
final List<String> expected = List.of(BOB.username, CHARLIE.username); | ||
|
||
// when | ||
final PageProfilesResponse response = getFollowersService.invoke(aliceId, 페이지()); | ||
final List<String> actual = response.users().stream().map(ProfileResponse::username).toList(); | ||
|
||
// then | ||
assertThat(actual).containsExactlyInAnyOrderElementsOf(expected); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/daybyquest/relation/application/GetFollowingsServiceTest.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,40 @@ | ||
package daybyquest.relation.application; | ||
|
||
import static daybyquest.support.fixture.UserFixtures.BOB; | ||
import static daybyquest.support.fixture.UserFixtures.CHARLIE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import daybyquest.relation.domain.Follow; | ||
import daybyquest.support.test.ServiceTest; | ||
import daybyquest.user.dto.response.PageProfilesResponse; | ||
import daybyquest.user.dto.response.ProfileResponse; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class GetFollowingsServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private GetFollowingsService getFollowingsService; | ||
|
||
@Test | ||
void 팔로잉_목록을_조회한다() { | ||
// given | ||
final Long aliceId = ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
final Long charlieId = CHARLIE를_저장한다(); | ||
final Long davidId = DAVID를_저장한다(); | ||
follows.save(new Follow(aliceId, bobId)); | ||
follows.save(new Follow(aliceId, charlieId)); | ||
follows.save(new Follow(davidId, aliceId)); | ||
|
||
final List<String> expected = List.of(BOB.username, CHARLIE.username); | ||
|
||
// when | ||
final PageProfilesResponse response = getFollowingsService.invoke(aliceId, 페이지()); | ||
final List<String> actual = response.users().stream().map(ProfileResponse::username).toList(); | ||
|
||
// then | ||
assertThat(actual).containsExactlyInAnyOrderElementsOf(expected); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/daybyquest/relation/application/SaveFollowServiceTest.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,49 @@ | ||
package daybyquest.relation.application; | ||
|
||
import static daybyquest.global.error.ExceptionCode.ALREADY_FOLLOWING_USER; | ||
import static daybyquest.support.fixture.UserFixtures.BOB; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import daybyquest.global.error.exception.InvalidDomainException; | ||
import daybyquest.relation.domain.Follow; | ||
import daybyquest.support.test.ServiceTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class SaveFollowServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private SaveFollowService saveFollowService; | ||
|
||
@Test | ||
void 팔로우를_저장한다() { | ||
// given | ||
final Long aliceId = ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
|
||
// when | ||
saveFollowService.invoke(aliceId, BOB.username); | ||
|
||
// then | ||
final Follow follow = follows.getByUserIdAndTargetId(aliceId, bobId); | ||
assertAll(() -> { | ||
assertThat(follow.getUserId()).isEqualTo(aliceId); | ||
assertThat(follow.getTargetId()).isEqualTo(bobId); | ||
}); | ||
} | ||
|
||
@Test | ||
void 이미_팔로우한_대상은_팔로우_할_수_없다() { | ||
// given | ||
final Long aliceId = ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
follows.save(new Follow(aliceId, bobId)); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> saveFollowService.invoke(aliceId, BOB.username)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(ALREADY_FOLLOWING_USER.getMessage()); | ||
} | ||
} |