-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post crud task #41
base: main
Are you sure you want to change the base?
Post crud task #41
Conversation
User는 빼고 커밋해야할듯 |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
팀원과 컨벤션을 다시 맞춰 주세요.
@Test | ||
void getAllPosts() throws Exception { | ||
|
||
//given | ||
when(postService.getAllPosts()).thenReturn(Arrays.asList( | ||
new Post(1L, "First post", LocalDateTime.now(), LocalDateTime.now(), 0L, 0L, 0L, new User()), | ||
new Post(2L, "Second post", LocalDateTime.now(), LocalDateTime.now(), 0L, 0L, 0L, new User()) | ||
)); | ||
|
||
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(postController).build(); | ||
|
||
//when | ||
mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/posts")) | ||
//then | ||
.andExpect(status().isOk()) | ||
.andExpect(MockMvcResultMatchers.content().json(objectMapper.writeValueAsString(Arrays.asList( | ||
new Post(1L, "First post", LocalDateTime.now(), LocalDateTime.now(), 0L, 0L, 0L, new User()), | ||
new Post(2L, "Second post", LocalDateTime.now(), LocalDateTime.now(), 0L, 0L, 0L, new User()) | ||
)))); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test를 빠르게 확인하기 위해, 메소드를 한글명으로 하거나 @DisplayName을 사용해 주세요.
그리고, service에서는 필요한 테스트가 없었나요?
public Post updatePost(Long id, Post postDetails) { | ||
Post post = postRepository.findById(id) | ||
.orElseThrow(() -> new RuntimeException()); | ||
|
||
post.setContents(postDetails.getContents()); | ||
|
||
return postRepository.save(post); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
팀원의 업데이트 방식과 상이합니다. 경호씨는 dirty check 사용하셨어요!
@Getter @Setter | ||
public class Post { | ||
@Id | ||
@GeneratedValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ID 생성 전략이 기본 값으로 돼 있어서 MySQL을 사용하신다면 sequence 전략일 겁니다.
경호씨는 다른 전략 사용하셨던데, 테이블마다 전략이 다른게 아니라면 맞춰주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
시정하겠습니다 !! 대가리 박겠습니다!!
@DisplayName("게시글 전부 조회 예외 테스트") | ||
@Test | ||
void 게시글전부조회예외테스트() { | ||
when(postRepository.findAll()).thenThrow(new RuntimeException()); | ||
assertThrows(RuntimeException.class, () -> postService.getAllPosts()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그냥 Runtime 예외보다는 구체적으로 어떤 예외인지 정의해서 예외처리하는 것이 좋을 것 같습니다.
@Test | ||
void 게시글수정테스트() { | ||
//given | ||
when(postRepository.findById(1L)).thenReturn(Optional.of(post)); | ||
when(postRepository.save(any(Post.class))).thenReturn(post); | ||
Post updatedPost = new Post(); | ||
//when | ||
updatedPost.setContents("Updated Contents"); | ||
Post result = postService.updatePost(1L, updatedPost); | ||
//then | ||
assertThat(result.getContents()).isEqualTo("Updated Contents"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#47 참고해주서 업데이트 리팩토링 해주세요
@Entity | ||
@Getter @Setter | ||
public class PostReply { | ||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
private String contents; | ||
|
||
private LocalDateTime createdAt; | ||
|
||
private LocalDateTime updatedAt; | ||
|
||
private Long likes; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "post_id") | ||
private Post post; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dto가 있는데 왜 entity로 postReply가 있는건가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
경호가 잘못봤대요
public Post(long l, String firstPost, LocalDateTime now, LocalDateTime now1, long l1, long l2, long l3, User user) { | ||
} | ||
|
||
|
||
public Post() { | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
생성자가 왜 비워져있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정완료
좋아요 |
cf14851
to
c416a97
Compare
name: Post crud task
about: Post crud task
작업 내용:
게시판 CRUD 구현
이번에 공들였던 부분:
질문:
제출 전 필수 확인 사항: