|
1 | | -//package ddingdong.ddingdongBE.domain.form.service; |
2 | | -// |
3 | | -//import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; |
4 | | -// |
5 | | -//import com.navercorp.fixturemonkey.FixtureMonkey; |
6 | | -//import ddingdong.ddingdongBE.common.support.FixtureMonkeyFactory; |
7 | | -//import ddingdong.ddingdongBE.common.support.TestContainerSupport; |
8 | | -//import ddingdong.ddingdongBE.domain.club.entity.Club; |
9 | | -//import ddingdong.ddingdongBE.domain.club.repository.ClubRepository; |
10 | | -//import ddingdong.ddingdongBE.domain.form.entity.Form; |
11 | | -//import ddingdong.ddingdongBE.domain.form.repository.FormRepository; |
12 | | -//import ddingdong.ddingdongBE.domain.form.service.dto.query.FormSectionQuery; |
13 | | -//import ddingdong.ddingdongBE.domain.user.entity.Role; |
14 | | -//import ddingdong.ddingdongBE.domain.user.entity.User; |
15 | | -//import ddingdong.ddingdongBE.domain.user.repository.UserRepository; |
16 | | -//import java.util.ArrayList; |
17 | | -//import java.util.List; |
18 | | -//import org.junit.jupiter.api.DisplayName; |
19 | | -//import org.junit.jupiter.api.Test; |
20 | | -//import org.springframework.beans.factory.annotation.Autowired; |
21 | | -//import org.springframework.boot.test.context.SpringBootTest; |
22 | | -// |
23 | | -//@SpringBootTest |
24 | | -//class FacadeUserFormServiceImplTest extends TestContainerSupport { |
25 | | -// |
26 | | -// @Autowired |
27 | | -// private FacadeUserFormService facadeUserFormService; |
28 | | -// |
29 | | -// @Autowired |
30 | | -// private FormRepository formRepository; |
31 | | -// |
32 | | -// @Autowired |
33 | | -// private ClubRepository clubRepository; |
34 | | -// |
35 | | -// @Autowired |
36 | | -// private UserRepository userRepository; |
37 | | -// |
38 | | -// private static final FixtureMonkey fixtureMonkey = FixtureMonkeyFactory.getNotNullBuilderIntrospectorMonkey(); |
39 | | -// |
40 | | -// @DisplayName("유저는 섹션 목록을 조회할 수 있다.") |
41 | | -// @Test |
42 | | -// void getFormSection() { |
43 | | -// // given |
44 | | -// User user = fixtureMonkey.giveMeBuilder(User.class) |
45 | | -// .set("id", 1L) |
46 | | -// .set("Role", Role.CLUB) |
47 | | -// .set("deletedAt", null) |
48 | | -// .sample(); |
49 | | -// User savedUser = userRepository.save(user); |
50 | | -// |
51 | | -// Club club = fixtureMonkey.giveMeBuilder(Club.class) |
52 | | -// .set("id", 1L) |
53 | | -// .set("user", savedUser) |
54 | | -// .set("score", null) |
55 | | -// .set("clubMembers", null) |
56 | | -// .set("deletedAt", null) |
57 | | -// .sample(); |
58 | | -// clubRepository.save(club); |
59 | | -// |
60 | | -// List<String> savedSections = new ArrayList<>(); |
61 | | -// savedSections.add("section1"); |
62 | | -// savedSections.add("section2"); |
63 | | -// |
64 | | -// Form form = fixtureMonkey.giveMeBuilder(Form.class) |
65 | | -// .set("id", 1L) |
66 | | -// .set("title", "띵동 폼") |
67 | | -// .set("description", "저희 동아리는 띵동입니다.") |
68 | | -// .set("hasInterview", false) |
69 | | -// .set("club", club) |
70 | | -// .set("sections", savedSections) |
71 | | -// .sample(); |
72 | | -// Form savedForm = formRepository.save(form); |
73 | | -// |
74 | | -// FormSectionQuery sectionQuery = facadeUserFormService.getFormSection(savedForm.getId()); |
75 | | -// |
76 | | -// assertThat(sectionQuery.sections()).isEqualTo(savedSections); |
77 | | -// } |
78 | | -//} |
| 1 | +package ddingdong.ddingdongBE.domain.form.service; |
| 2 | + |
| 3 | +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; |
| 4 | + |
| 5 | +import ddingdong.ddingdongBE.common.support.TestContainerSupport; |
| 6 | +import ddingdong.ddingdongBE.domain.club.entity.Club; |
| 7 | +import ddingdong.ddingdongBE.domain.club.repository.ClubRepository; |
| 8 | +import ddingdong.ddingdongBE.domain.form.entity.FieldType; |
| 9 | +import ddingdong.ddingdongBE.domain.form.entity.Form; |
| 10 | +import ddingdong.ddingdongBE.domain.form.entity.FormField; |
| 11 | +import ddingdong.ddingdongBE.domain.form.repository.FormFieldRepository; |
| 12 | +import ddingdong.ddingdongBE.domain.form.repository.FormRepository; |
| 13 | +import ddingdong.ddingdongBE.domain.form.service.dto.query.FormSectionQuery; |
| 14 | +import ddingdong.ddingdongBE.domain.form.service.dto.query.UserFormQuery; |
| 15 | +import ddingdong.ddingdongBE.domain.user.entity.Role; |
| 16 | +import ddingdong.ddingdongBE.domain.user.entity.User; |
| 17 | +import ddingdong.ddingdongBE.domain.user.repository.UserRepository; |
| 18 | +import java.time.LocalDate; |
| 19 | +import java.util.Arrays; |
| 20 | +import java.util.List; |
| 21 | +import org.junit.jupiter.api.BeforeEach; |
| 22 | +import org.junit.jupiter.api.DisplayName; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | +import org.springframework.beans.factory.annotation.Autowired; |
| 25 | +import org.springframework.boot.test.context.SpringBootTest; |
| 26 | + |
| 27 | +@SpringBootTest |
| 28 | +class FacadeUserFormServiceImplTest extends TestContainerSupport { |
| 29 | + |
| 30 | + @Autowired |
| 31 | + private FacadeUserFormService facadeUserFormService; |
| 32 | + |
| 33 | + @Autowired |
| 34 | + private FormRepository formRepository; |
| 35 | + |
| 36 | + @Autowired |
| 37 | + private ClubRepository clubRepository; |
| 38 | + |
| 39 | + @Autowired |
| 40 | + private UserRepository userRepository; |
| 41 | + |
| 42 | + @Autowired |
| 43 | + private FormFieldRepository formFieldRepository; |
| 44 | + |
| 45 | + private User savedUser; |
| 46 | + private Club savedClub; |
| 47 | + private Form savedForm; |
| 48 | + private List<String> savedSections; |
| 49 | + |
| 50 | + @BeforeEach |
| 51 | + void setUp() { |
| 52 | + User user = User.builder() |
| 53 | + .id(1L) |
| 54 | + .role(Role.CLUB) |
| 55 | + .build(); |
| 56 | + savedUser = userRepository.save(user); |
| 57 | + |
| 58 | + Club club = Club.builder() |
| 59 | + .id(1L) |
| 60 | + .user(savedUser) |
| 61 | + .score(null) |
| 62 | + .clubMembers(null) |
| 63 | + .deletedAt(null) |
| 64 | + .build(); |
| 65 | + savedClub = clubRepository.save(club); |
| 66 | + |
| 67 | + savedSections = Arrays.asList("section1", "section2"); |
| 68 | + |
| 69 | + Form form = Form.builder() |
| 70 | + .title("띵동 폼") |
| 71 | + .description("저희 동아리는 띵동입니다.") |
| 72 | + .hasInterview(false) |
| 73 | + .club(savedClub) |
| 74 | + .sections(savedSections) |
| 75 | + .endDate(LocalDate.now().plusMonths(1)) |
| 76 | + .startDate(LocalDate.now()) |
| 77 | + .build(); |
| 78 | + savedForm = formRepository.save(form); |
| 79 | + } |
| 80 | + |
| 81 | + @DisplayName("유저는 섹션 목록을 조회할 수 있다.") |
| 82 | + @Test |
| 83 | + void getFormSection() { |
| 84 | + // given |
| 85 | + |
| 86 | + // when |
| 87 | + FormSectionQuery sectionQuery = facadeUserFormService.getFormSection(savedForm.getId()); |
| 88 | + |
| 89 | + // then |
| 90 | + assertThat(sectionQuery.sections()).isEqualTo(savedSections); |
| 91 | + } |
| 92 | + |
| 93 | + @DisplayName("유저는 폼지를 상세조회 할 수 있다.") |
| 94 | + @Test |
| 95 | + void getForm() { |
| 96 | + // given |
| 97 | + FormField savedFormField1 = createFormField("질문1", 1, savedSections.get(0), savedForm); |
| 98 | + FormField savedFormField2 = createFormField("질문2", 2, savedSections.get(1), savedForm); |
| 99 | + |
| 100 | + String selectedSection = savedSections.get(0); |
| 101 | + |
| 102 | + // when |
| 103 | + UserFormQuery userFormQuery = facadeUserFormService.getUserForm(savedForm.getId(), selectedSection); |
| 104 | + |
| 105 | + // then |
| 106 | + assertThat(userFormQuery.formFields().get(0).id()).isEqualTo(savedFormField1.getId()); |
| 107 | + } |
| 108 | + |
| 109 | + private FormField createFormField(String question, int order, String section, Form form) { |
| 110 | + FormField formField = FormField.builder() |
| 111 | + .question(question) |
| 112 | + .required(true) |
| 113 | + .fieldOrder(order) |
| 114 | + .section(section) |
| 115 | + .fieldType(FieldType.TEXT) |
| 116 | + .form(form) |
| 117 | + .build(); |
| 118 | + return formFieldRepository.save(formField); |
| 119 | + } |
| 120 | +} |
0 commit comments