Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface MuteRepository extends JpaRepository<Mute, Long> {

@Modifying
@Transactional
@Query(value = "INSERT INTO mutes (muting_id, muted_id, created_at) VALUES (:currentUserId, :targetUserId, CURRENT_TIMESTAMP)", nativeQuery = true)
@Query(value = "INSERT INTO mutes (muting_id, muted_id, created_at, updated_at) VALUES (:currentUserId, :targetUserId, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)", nativeQuery = true)
void createMuteRelationship(@Param("currentUserId") Long currentUserId, @Param("targetUserId") Long targetUserId);

@Modifying
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package se.jensen.yuki.springboot.service;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
import se.jensen.yuki.springboot.dto.like.CommentLikeResponse;
import se.jensen.yuki.springboot.dto.like.LikeResponse;
import se.jensen.yuki.springboot.dto.like.PostLikeResponse;
import se.jensen.yuki.springboot.model.Comment;
import se.jensen.yuki.springboot.model.Post;
import se.jensen.yuki.springboot.model.User;
import se.jensen.yuki.springboot.repository.*;

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using a wildcard repository import in tests; it makes it harder to see which repositories are actually used and is inconsistent with the other integration tests in this package (which import repositories explicitly). Replace se.jensen.yuki.springboot.repository.* with the specific repository imports used by this test.

Suggested change
import se.jensen.yuki.springboot.repository.*;
import se.jensen.yuki.springboot.repository.UserRepository;
import se.jensen.yuki.springboot.repository.PostRepository;
import se.jensen.yuki.springboot.repository.CommentRepository;
import se.jensen.yuki.springboot.repository.PostLikeRepository;
import se.jensen.yuki.springboot.repository.CommentLikeRepository;

Copilot uses AI. Check for mistakes.

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@ActiveProfiles("test")
@Transactional
class LikeServiceIntegrationTest {

@Autowired
private LikeService likeService;

@Autowired
private UserRepository userRepository;

@Autowired
private PostRepository postRepository;

@Autowired
private CommentRepository commentRepository;

@Autowired
private PostLikeRepository postLikeRepository;

@Autowired
private CommentLikeRepository commentLikeRepository;

private User user;
private Post post;
private Comment comment;

@BeforeEach
void setUp() {

user = userRepository.save(
User.builder()
.username("user1")
.email("user1@test.com")
.password("pass")
.displayName("User1")
.bio("bio")
.role("USER")
.build()
);

post = postRepository.save(
Post.builder()
.content("test post")
.user(user)
.build()
);

comment = commentRepository.save(
Comment.builder()
.content("test comment")
.author(user)
.post(post)
.build()
);
}

// -----------------------
// Post Like
// -----------------------

@Test
void likePost_shouldCreateLike() {

LikeResponse res =
likeService.likePost(post.getId(), user.getId());

assertThat(res.liked()).isTrue();
assertThat(res.likeCount()).isEqualTo(1);

assertThat(
postLikeRepository.findByPostIdAndUserId(
post.getId(), user.getId()
)
).isPresent();
}


@Test
void likePost_shouldNotDuplicate() {

likeService.likePost(post.getId(), user.getId());

LikeResponse res =
likeService.likePost(post.getId(), user.getId());

assertThat(res.likeCount()).isEqualTo(1);
}


@Test
void unlikePost_shouldRemoveLike() {

likeService.likePost(post.getId(), user.getId());

LikeResponse res =
likeService.unlikePost(post.getId(), user.getId());

assertThat(res.liked()).isFalse();
assertThat(res.likeCount()).isEqualTo(0);

assertThat(
postLikeRepository.findByPostIdAndUserId(
post.getId(), user.getId()
)
).isEmpty();
}


// -----------------------
// Post Like List
// -----------------------

@Test
void getPostLikes_shouldReturnList() {

likeService.likePost(post.getId(), user.getId());

Slice<PostLikeResponse> slice =
likeService.getPostLikesByPostId(
post.getId(),
PageRequest.of(0, 10)
);

assertThat(slice).isNotNull();
assertThat(slice.getContent()).hasSize(1);

PostLikeResponse res =
slice.getContent().get(0);

assertThat(res.userId()).isEqualTo(user.getId());
}


// -----------------------
// Comment Like
// -----------------------

@Test
void likeComment_shouldCreateLike() {

LikeResponse res =
likeService.likeComment(comment.getId(), user.getId());

assertThat(res.liked()).isTrue();
assertThat(res.likeCount()).isEqualTo(1);

assertThat(
commentLikeRepository.findByCommentIdAndUserId(
comment.getId(), user.getId()
)
).isPresent();
}


@Test
void unlikeComment_shouldRemoveLike() {

likeService.likeComment(comment.getId(), user.getId());

LikeResponse res =
likeService.unlikeComment(comment.getId(), user.getId());

assertThat(res.liked()).isFalse();
assertThat(res.likeCount()).isEqualTo(0);

assertThat(
commentLikeRepository.findByCommentIdAndUserId(
comment.getId(), user.getId()
)
).isEmpty();
}


// -----------------------
// Comment Like List
// -----------------------

@Test
void getCommentLikes_shouldReturnList() {

likeService.likeComment(comment.getId(), user.getId());

Slice<CommentLikeResponse> slice =
likeService.getCommentLikesByCommentId(
comment.getId(),
PageRequest.of(0, 10)
);

assertThat(slice).isNotNull();
assertThat(slice.getContent()).hasSize(1);

CommentLikeResponse res =
slice.getContent().get(0);

assertThat(res.userId()).isEqualTo(user.getId());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package se.jensen.yuki.springboot.service;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
import se.jensen.yuki.springboot.dto.mute.MuteMutingResponse;
import se.jensen.yuki.springboot.dto.mute.MuteResponse;
import se.jensen.yuki.springboot.model.User;
import se.jensen.yuki.springboot.repository.UserRepository;

import static org.assertj.core.api.Assertions.assertThat;


@SpringBootTest
@ActiveProfiles("test")
@Transactional
class MuteServiceIntegrationTest {

@Autowired
private MuteService muteService;

@Autowired
private UserRepository userRepository;


private User user1;
private User user2;


@BeforeEach
void setUp() {

user1 = userRepository.save(
User.builder()
.username("user1")
.email("user1@test.com")
.password("pass")
.displayName("User1")
.bio("bio")
.role("USER")
.build()
);

user2 = userRepository.save(
User.builder()
.username("user2")
.email("user2@test.com")
.password("pass")
.displayName("User2")
.bio("bio")
.role("USER")
.build()
);
}


// -----------------------
// Mute
// -----------------------

@Test
void muteUser_shouldCreateMute() {

MuteResponse res =
muteService.muteUser(user1.getId(), user2.getId());

assertThat(res).isNotNull();
assertThat(res.mutedUserId()).isEqualTo(user2.getId());
}


@Test
void muteUser_shouldNotDuplicate() {

muteService.muteUser(user1.getId(), user2.getId());

MuteResponse res =
muteService.muteUser(user1.getId(), user2.getId());

assertThat(res).isNotNull();
Comment on lines +79 to +85

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is named muteUser_shouldNotDuplicate but it only asserts the second call returns non-null; it doesn’t verify that only one mute relationship exists. Consider asserting the mutings list size remains 1 (e.g., via muteService.getMutings(...)) after calling muteUser twice, or otherwise checking the persisted relationship count, so the test actually covers the behavior implied by its name.

Suggested change
muteService.muteUser(user1.getId(), user2.getId());
MuteResponse res =
muteService.muteUser(user1.getId(), user2.getId());
assertThat(res).isNotNull();
// First mute call creates the relationship
muteService.muteUser(user1.getId(), user2.getId());
// Second mute call should not create a duplicate
MuteResponse res =
muteService.muteUser(user1.getId(), user2.getId());
assertThat(res).isNotNull();
// Verify only one mute relationship exists
Slice<MuteMutingResponse> slice =
muteService.getMutings(
user1.getId(),
PageRequest.of(0, 10)
);
assertThat(slice).isNotNull();
assertThat(slice.getContent()).hasSize(1);
assertThat(slice.getContent().get(0).mutedUserId()).isEqualTo(user2.getId());

Copilot uses AI. Check for mistakes.
}


@Test
void unmuteUser_shouldRemoveMute() {

muteService.muteUser(user1.getId(), user2.getId());

boolean result =
muteService.unmuteUser(user1.getId(), user2.getId());

assertThat(result).isTrue();

// 再度解除は false
boolean second =
muteService.unmuteUser(user1.getId(), user2.getId());

assertThat(second).isFalse();
}


// -----------------------
// List
// -----------------------

@Test
void getMutings_shouldReturnList() {

muteService.muteUser(user1.getId(), user2.getId());

Slice<MuteMutingResponse> slice =
muteService.getMutings(
user1.getId(),
PageRequest.of(0, 10)
);

assertThat(slice).isNotNull();
assertThat(slice.getContent()).hasSize(1);

MuteMutingResponse res =
slice.getContent().get(0);

assertThat(res.mutedUserId()).isEqualTo(user2.getId());
}
}
Loading