|
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
4 | 4 |
|
5 | | -import com.github.f4b6a3.uuid.UuidCreator; |
6 | | -import com.navercorp.fixturemonkey.FixtureMonkey; |
7 | | -import ddingdong.ddingdongBE.common.support.FixtureMonkeyFactory; |
| 5 | +import ddingdong.ddingdongBE.common.fixture.ClubFixture; |
| 6 | +import ddingdong.ddingdongBE.common.fixture.UserFixture; |
8 | 7 | import ddingdong.ddingdongBE.common.support.TestContainerSupport; |
9 | 8 | import ddingdong.ddingdongBE.domain.club.entity.Club; |
10 | | -import ddingdong.ddingdongBE.domain.club.entity.Location; |
11 | | -import ddingdong.ddingdongBE.domain.club.entity.PhoneNumber; |
12 | 9 | import ddingdong.ddingdongBE.domain.club.repository.ClubRepository; |
13 | 10 | import ddingdong.ddingdongBE.domain.club.service.dto.command.UpdateClubInfoCommand; |
14 | 11 | import ddingdong.ddingdongBE.domain.club.service.dto.query.MyClubInfoQuery; |
15 | | -import ddingdong.ddingdongBE.domain.filemetadata.entity.DomainType; |
16 | | -import ddingdong.ddingdongBE.domain.filemetadata.entity.FileMetaData; |
17 | | -import ddingdong.ddingdongBE.domain.filemetadata.entity.FileStatus; |
18 | | -import ddingdong.ddingdongBE.domain.filemetadata.repository.FileMetaDataRepository; |
19 | | -import ddingdong.ddingdongBE.domain.form.repository.FormRepository; |
20 | | -import ddingdong.ddingdongBE.domain.scorehistory.entity.Score; |
21 | 12 | import ddingdong.ddingdongBE.domain.user.entity.User; |
22 | 13 | import ddingdong.ddingdongBE.domain.user.repository.UserRepository; |
23 | | -import java.math.BigDecimal; |
24 | | -import java.util.List; |
25 | | -import java.util.UUID; |
| 14 | +import java.util.Optional; |
26 | 15 | import org.junit.jupiter.api.DisplayName; |
27 | 16 | import org.junit.jupiter.api.Test; |
28 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
|
31 | 20 | @SpringBootTest |
32 | 21 | class FacadeCentralClubServiceImplTest extends TestContainerSupport { |
33 | 22 |
|
34 | | - @Autowired |
35 | | - private FacadeCentralClubService facadeCentralClubService; |
36 | 23 | @Autowired |
37 | 24 | private ClubRepository clubRepository; |
38 | 25 | @Autowired |
39 | 26 | private UserRepository userRepository; |
40 | 27 | @Autowired |
41 | | - private FileMetaDataRepository fileMetaDataRepository; |
42 | | - |
43 | | - private final FixtureMonkey fixture = FixtureMonkeyFactory.getNotNullBuilderIntrospectorMonkey(); |
44 | | - @Autowired |
45 | | - private FormRepository formRepository; |
| 28 | + private FacadeCentralClubService facadeCentralClubService; |
46 | 29 |
|
47 | 30 | @DisplayName("중앙동아리: 내 동아리 정보 조회") |
48 | 31 | @Test |
49 | 32 | void getMyClubInfo() { |
50 | | - //given |
51 | | - User savedUser = userRepository.save(fixture.giveMeBuilder(User.class).set("id", null).sample()); |
52 | | - Club club = fixture.giveMeBuilder(Club.class) |
53 | | - .set("id", null) |
54 | | - .set("user", savedUser) |
55 | | - .set("score", Score.from(BigDecimal.ZERO)) |
56 | | - .set("phoneNumber", PhoneNumber.from("010-1234-5678")) |
57 | | - .set("location", Location.from("S1111")) |
58 | | - .set("clubMembers", null) |
59 | | - .set("deletedAt", null) |
60 | | - .sample(); |
61 | | - Club savedClub = clubRepository.save(club); |
62 | | - UUID id1 = UuidCreator.getTimeOrderedEpoch(); |
63 | | - UUID id2 = UuidCreator.getTimeOrderedEpoch(); |
64 | | - FileMetaData clubProfileImageFileMetaData = fixture.giveMeBuilder(FileMetaData.class) |
65 | | - .set("id", id1) |
66 | | - .set("fileKey", "test/IMAGE/2024-01-01/" + id1) |
67 | | - .set("entityType", DomainType.CLUB_PROFILE) |
68 | | - .set("entityId", savedClub.getId()) |
69 | | - .set("fileStatus", FileStatus.COUPLED) |
70 | | - .sample(); |
71 | | - FileMetaData clubIntroductionImageFileMetaData = fixture.giveMeBuilder(FileMetaData.class) |
72 | | - .set("id", id2) |
73 | | - .set("fileKey", "test/IMAGE/2024-01-01/" + id2) |
74 | | - .set("entityType", DomainType.CLUB_INTRODUCTION) |
75 | | - .set("entityId", savedClub.getId()) |
76 | | - .set("fileStatus", FileStatus.COUPLED) |
77 | | - .sample(); |
78 | | - fileMetaDataRepository.saveAll(List.of(clubProfileImageFileMetaData, clubIntroductionImageFileMetaData)); |
| 33 | + // given |
| 34 | + User savedUser = userRepository.save(UserFixture.createClubUser()); |
| 35 | + Club savedClub = clubRepository.save(ClubFixture.createClub(savedUser)); |
79 | 36 |
|
80 | | - //when |
| 37 | + // when |
81 | 38 | MyClubInfoQuery result = facadeCentralClubService.getMyClubInfo(savedUser.getId()); |
82 | 39 |
|
83 | | - //then |
| 40 | + // then |
84 | 41 | assertThat(result).isNotNull(); |
| 42 | + assertThat(result.name()).isEqualTo(savedClub.getName()); |
| 43 | + assertThat(result.category()).isEqualTo(savedClub.getCategory()); |
| 44 | + assertThat(result.tag()).isEqualTo(savedClub.getTag()); |
| 45 | + assertThat(result.leader()).isEqualTo(savedClub.getLeader()); |
| 46 | + assertThat(result.phoneNumber()).isEqualTo(savedClub.getPhoneNumber().getNumber()); |
| 47 | + assertThat(result.location()).isEqualTo(savedClub.getLocation().getValue()); |
85 | 48 | } |
86 | 49 |
|
87 | 50 | @DisplayName("중앙동아리: 동아리 정보 수정") |
88 | 51 | @Test |
89 | 52 | void updateClubInfo() { |
90 | | - //given |
91 | | - User savedUser = userRepository.save(fixture.giveMeBuilder(User.class).set("id", null).sample()); |
92 | | - Club club = fixture.giveMeBuilder(Club.class) |
93 | | - .set("id", null) |
94 | | - .set("user", savedUser) |
95 | | - .set("score", Score.from(BigDecimal.ZERO)) |
96 | | - .set("phoneNumber", PhoneNumber.from("010-1234-5678")) |
97 | | - .set("location", Location.from("S1111")) |
98 | | - .set("clubMembers", null) |
99 | | - .set("deletedAt", null) |
100 | | - .sample(); |
101 | | - Club savedClub = clubRepository.save(club); |
| 53 | + // given |
| 54 | + User savedUser = userRepository.save(UserFixture.createClubUser()); |
| 55 | + Club savedClub = clubRepository.save(ClubFixture.createClub(savedUser)); |
| 56 | + |
102 | 57 | UpdateClubInfoCommand command = new UpdateClubInfoCommand( |
103 | 58 | savedUser.getId(), |
104 | | - "testname", |
105 | | - "testcategory", |
106 | | - "testtag", |
107 | | - "testclubLeader", |
| 59 | + "updatedName", |
| 60 | + "updatedCategory", |
| 61 | + "updatedTag", |
| 62 | + "updatedClubLeader", |
108 | 63 | "010-1234-5678", |
109 | 64 | "S1111", |
110 | | - "testregularMeeting", |
111 | | - "testintroduction", |
112 | | - "testactivity", |
113 | | - "testideal", |
| 65 | + "updatedRegularMeeting", |
| 66 | + "updatedIntroduction", |
| 67 | + "updatedActivity", |
| 68 | + "updatedIdeal", |
114 | 69 | null, |
115 | 70 | null |
116 | 71 | ); |
117 | 72 |
|
118 | | - |
119 | | - //when |
| 73 | + // when |
120 | 74 | facadeCentralClubService.updateClubInfo(command); |
121 | 75 |
|
122 | | - //then |
123 | | - Club result = clubRepository.findById(savedClub.getId()).orElseThrow(); |
124 | | - assertThat(result.getName()).isEqualTo("testname"); |
| 76 | + // then |
| 77 | + Optional<Club> result = clubRepository.findById(savedClub.getId()); |
| 78 | + assertThat(result).isPresent(); |
| 79 | + assertThat(result.get().getName()).isEqualTo(command.name()); |
| 80 | + assertThat(result.get().getCategory()).isEqualTo(command.category()); |
| 81 | + assertThat(result.get().getLeader()).isEqualTo(command.clubLeader()); |
125 | 82 | } |
126 | 83 | } |
0 commit comments