Skip to content

Commit

Permalink
Merge pull request #127 from kakao-tech-campus-2nd-step3/weekly
Browse files Browse the repository at this point in the history
오류 일부 수정
  • Loading branch information
sunandrabbit authored Nov 12, 2024
2 parents 2b44ebe + 42880b9 commit 33edf52
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 76 deletions.
2 changes: 2 additions & 0 deletions src/main/java/team1/be/seamless/dto/ProjectDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public ProjectUpdate(
LocalDateTime startDate,
LocalDateTime endDate) {
this.name = name;
this.description = description;
this.imageURL = imageURL;
this.optionIds = optionIds;
this.startDate = startDate;
this.endDate = endDate;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/team1/be/seamless/dto/TaskDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package team1.be.seamless.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
Expand Down Expand Up @@ -32,6 +33,7 @@ public static class TaskCreate {
private Long ownerId;

@NotNull(message = "진행 상태(status)는 필수 입력 사항입니다.")
@JsonProperty("taskStatus")
private TaskStatus taskStatus;

@NotNull(message = "중요도(priority)는 필수 입력 사항입니다.")
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/team1/be/seamless/init/OptionCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import team1.be.seamless.dto.OptionDTO.OptionCreate;
import team1.be.seamless.entity.enums.Role;
import team1.be.seamless.service.OptionService;

@Component
Expand All @@ -19,18 +20,18 @@ public void creator() {
optionService.createOption(new OptionCreate(
"진행률에 따른 나무 성장!",
"진행률이 오를수록 나무가 성장해요.",
"treeGrowth"));
"treeGrowth"), Role.ADMIN.getKey());
optionService.createOption(new OptionCreate(
"진행률에 따른 빵빠레!",
"진행률이 50% 달성될 때 메인 화면에 빵빠레가 울려요!",
"celebration"));
"celebration"), Role.ADMIN.getKey());
optionService.createOption(new OptionCreate(
"마감 기한에 따른 색 변화!",
"마감 기한이 1일 남았을 때 아이콘이 빨간색으로 바뀌어요!",
"colorChange"));
"colorChange"), Role.ADMIN.getKey());
optionService.createOption(new OptionCreate(
"이메일 전송!",
"마감기한이 3일 남았을 때 하루 간격으로 이메일이 전송돼요!",
"emailSend"));
"emailSend"), Role.ADMIN.getKey());
}
}
9 changes: 0 additions & 9 deletions src/main/java/team1/be/seamless/service/OptionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ public OptionDetail deleteOption(Long id, String role) {
return optionMapper.toDetail(option);
}

/**
* 테스트용
*/
@Profile("test")
@Transactional
public OptionEntity createOption(OptionCreate create) {
return optionRepository.save(optionMapper.toEntity(create));
}

private void authRole(String role) {
if(!Role.ADMIN.isRole(role)) {
throw new BaseHandler(HttpStatus.FORBIDDEN, "관리자만 접근 가능합니다.");
Expand Down
144 changes: 144 additions & 0 deletions src/test/java/team1/be/seamless/mapper/ProjectMapperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package team1.be.seamless.mapper;

import java.time.LocalDateTime;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import team1.be.seamless.dto.ProjectDTO;
import team1.be.seamless.dto.ProjectDTO.ProjectCreate;
import team1.be.seamless.dto.ProjectDTO.ProjectDate;
import team1.be.seamless.dto.ProjectDTO.ProjectDetail;
import team1.be.seamless.dto.ProjectDTO.ProjectManager;
import team1.be.seamless.dto.ProjectDTO.ProjectUpdate;
import team1.be.seamless.entity.OptionEntity;
import team1.be.seamless.entity.ProjectEntity;
import team1.be.seamless.entity.ProjectOptionEntity;
import team1.be.seamless.entity.UserEntity;

public class ProjectMapperTest {

private ProjectMapper projectMapper;

private OptionEntity optionEntity1;

private OptionEntity optionEntity2;

private List<ProjectOptionEntity> projectOptions;

private UserEntity userEntity;

private ProjectEntity projectEntity1;

@BeforeEach
void setUp() {
projectMapper = new ProjectMapper();
userEntity = new UserEntity(
"사용자1", "[email protected]", "user1Image.jpg"
);

optionEntity1 = new OptionEntity("옵션1", "옵션 설명1", "타입1");
optionEntity2 = new OptionEntity("옵션2", "옵션 설명2", "타입2");

ProjectOptionEntity projectOption1 = new ProjectOptionEntity(optionEntity1);
ProjectOptionEntity projectOption2 = new ProjectOptionEntity(optionEntity2);
projectOptions = List.of(projectOption1, projectOption2);

projectEntity1 = new ProjectEntity(
"프로젝트1",
"프로젝트 설명1",
"https://example.com/project1.jpg",
userEntity,
projectOptions,
LocalDateTime.of(2024,11,21,0,0,0),
LocalDateTime.of(2025,11,21,0,0,0)
);
}

@Test
void 생성_시_ProjectCreate_에서_Entity_로_변환_검증() {
// Given
ProjectDTO.ProjectCreate create = new ProjectCreate(
"프로젝트1",
"프로젝트 설명1",
"https://example.com/project1.jpg",
List.of(1L, 2L),
LocalDateTime.of(2024, 10, 1, 0, 0, 0),
LocalDateTime.of(2025, 10, 1, 0, 0, 0)
);

//When
ProjectEntity projectEntity = projectMapper.toEntity(create, userEntity, projectOptions);

//Then
Assertions.assertThat(projectEntity.getName()).isEqualTo("프로젝트1");
Assertions.assertThat(projectEntity.getDescription()).isEqualTo("프로젝트 설명1");
Assertions.assertThat(projectEntity.getImageURL()).isEqualTo("https://example.com/project1.jpg");
Assertions.assertThat(projectEntity.getStartDate()).isEqualTo(LocalDateTime.of(2024, 10, 1, 0, 0, 0));
Assertions.assertThat(projectEntity.getEndDate()).isEqualTo(LocalDateTime.of(2025, 10, 1, 0, 0, 0));
Assertions.assertThat(projectEntity.getUserEntity()).isEqualTo(userEntity);
Assertions.assertThat(projectEntity.isActive()).isTrue();
Assertions.assertThat(projectEntity.isExpired()).isFalse();
}

@Test
void 수정시_해당_Entity가_업데이트_되는지_검증() {
// Given
ProjectDTO.ProjectUpdate update = new ProjectUpdate(
"프로젝트2",
"프로젝트 설명2",
"https://example.com/project2.jpg",
List.of(1L, 2L),
LocalDateTime.of(2024, 10, 1, 0, 0, 0),
LocalDateTime.of(2026, 10, 1, 0, 0, 0)
);

// When
ProjectEntity projectEntity = projectMapper.toUpdate(projectEntity1, update, projectOptions);

//Then
Assertions.assertThat(projectEntity.getName()).isEqualTo("프로젝트2");
Assertions.assertThat(projectEntity.getDescription()).isEqualTo("프로젝트 설명2");
Assertions.assertThat(projectEntity.getImageURL()).isEqualTo("https://example.com/project2.jpg");
Assertions.assertThat(projectEntity.getStartDate()).isEqualTo(LocalDateTime.of(2024, 10, 1, 0, 0, 0));
Assertions.assertThat(projectEntity.getEndDate()).isEqualTo(LocalDateTime.of(2026, 10, 1, 0, 0, 0));
}

@Test
void ProjectEntity가_ProjectDetail로_반환_되는_지_검증() {
// Given & When
ProjectDetail projectDetail = projectMapper.toDetail(projectEntity1);

// Then
Assertions.assertThat(projectDetail.getName()).isEqualTo("프로젝트1");
Assertions.assertThat(projectDetail.getDescription()).isEqualTo("프로젝트 설명1");
Assertions.assertThat(projectDetail.getImageURL()).isEqualTo("https://example.com/project1.jpg");
Assertions.assertThat(projectDetail.getTotalMembers()).isEqualTo(0);
Assertions.assertThat(projectDetail.getProjectManager().getName()).isEqualTo(userEntity.getName());
Assertions.assertThat(projectDetail.getProjectManager().getImageURL()).isEqualTo(userEntity.getPicture());
Assertions.assertThat(projectDetail.getStartDate()).isEqualTo(LocalDateTime.of(2024,11,21,0,0,0));
Assertions.assertThat(projectDetail.getEndDate()).isEqualTo(LocalDateTime.of(2025,11,21,0,0,0));
}

@Test
void ProjectEntity가_ProjectDate로_반환_되는_지_검증() {
// Given & When
ProjectDate projectDate = projectMapper.toDate(projectEntity1);

// Then
Assertions.assertThat(projectDate.getName()).isEqualTo("프로젝트1");
Assertions.assertThat(projectDate.getStartDate()).isEqualTo(LocalDateTime.of(2024,11,21,0,0,0));
Assertions.assertThat(projectDate.getEndDate()).isEqualTo(LocalDateTime.of(2025,11,21,0,0,0));
}

@Test
void UserEntity가_ProjectManager로_반환_되는_지_검증() {
// Given & When
ProjectManager projectManager = projectMapper.toManager(userEntity);

// Then
Assertions.assertThat(projectManager.getName()).isEqualTo("사용자1");
Assertions.assertThat(projectManager.getImageURL()).isEqualTo("user1Image.jpg");
}

}
Loading

0 comments on commit 33edf52

Please sign in to comment.