use of de.tum.in.www1.artemis.config.Constants.VOTE_EMOJI_ID in project ArTEMiS by ls1intum.
the class ReactionIntegrationTest method testGetPostsForCourse_OrderByVoteCountASC.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetPostsForCourse_OrderByVoteCountASC() throws Exception {
PostSortCriterion sortCriterion = PostSortCriterion.VOTES;
SortingOrder sortingOrder = SortingOrder.ASCENDING;
User student1 = database.getUserByLogin("student1");
User student2 = database.getUserByLogin("student2");
Post postReactedOn = existingPostsWithAnswers.get(0);
createVoteReactionOnPost(postReactedOn, student1);
createVoteReactionOnPost(postReactedOn, student2);
Post post2ReactedOn = existingPostsWithAnswers.get(1);
createVoteReactionOnPost(post2ReactedOn, student2);
// refresh posts after reactions are added
existingPostsWithAnswers = postRepository.findPostsForCourse(courseId, null, false, false, false, null);
var params = new LinkedMultiValueMap<String, String>();
// ordering only available in course discussions page, where paging is enabled
params.add("pagingEnabled", "true");
params.add("page", "0");
params.add("size", String.valueOf(MAX_POSTS_PER_PAGE));
params.add("postSortCriterion", sortCriterion.toString());
params.add("sortingOrder", sortingOrder.toString());
List<Post> returnedPosts = request.getList("/api/courses/" + courseId + "/posts", HttpStatus.OK, Post.class, params);
existingPostsWithAnswers.sort(Comparator.comparing((Post post) -> post.getReactions().stream().filter(reaction -> reaction.getEmojiId().equals(VOTE_EMOJI_ID)).count()));
assertThat(returnedPosts).isEqualTo(existingPostsWithAnswers);
}
use of de.tum.in.www1.artemis.config.Constants.VOTE_EMOJI_ID in project Artemis by ls1intum.
the class ReactionIntegrationTest method testGetPostsForCourse_OrderByVoteCountDESC.
// GET
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetPostsForCourse_OrderByVoteCountDESC() throws Exception {
PostSortCriterion sortCriterion = PostSortCriterion.VOTES;
SortingOrder sortingOrder = SortingOrder.DESCENDING;
User student1 = database.getUserByLogin("student1");
User student2 = database.getUserByLogin("student2");
// student 1 is the author of the post and reacts on this post
Post postReactedOn = existingPostsWithAnswers.get(0);
createVoteReactionOnPost(postReactedOn, student1);
Post postReactedOn2 = existingPostsWithAnswers.get(1);
createVoteReactionOnPost(postReactedOn2, student1);
createVoteReactionOnPost(postReactedOn2, student2);
// refresh posts after reactions are added
existingPostsWithAnswers = postRepository.findPostsForCourse(courseId, null, false, false, false, null);
var params = new LinkedMultiValueMap<String, String>();
// ordering only available in course discussions page, where paging is enabled
params.add("pagingEnabled", "true");
params.add("page", "0");
params.add("size", String.valueOf(MAX_POSTS_PER_PAGE));
params.add("postSortCriterion", sortCriterion.toString());
params.add("sortingOrder", sortingOrder.toString());
List<Post> returnedPosts = request.getList("/api/courses/" + courseId + "/posts", HttpStatus.OK, Post.class, params);
existingPostsWithAnswers.sort(Comparator.comparing((Post post) -> post.getReactions().stream().filter(reaction -> reaction.getEmojiId().equals(VOTE_EMOJI_ID)).count()).reversed());
assertThat(returnedPosts).isEqualTo(existingPostsWithAnswers);
}
use of de.tum.in.www1.artemis.config.Constants.VOTE_EMOJI_ID in project Artemis by ls1intum.
the class ReactionIntegrationTest method createVoteReactionOnPost.
private Reaction createVoteReactionOnPost(Post postReactedOn, User user) {
Reaction reaction = new Reaction();
reaction.setUser(user);
reaction.setEmojiId(VOTE_EMOJI_ID);
reaction.setPost(postReactedOn);
reactionRepository.save(reaction);
return reaction;
}
use of de.tum.in.www1.artemis.config.Constants.VOTE_EMOJI_ID in project ArTEMiS by ls1intum.
the class ReactionIntegrationTest method testGetPostsForCourse_OrderByVoteCountDESC.
// GET
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetPostsForCourse_OrderByVoteCountDESC() throws Exception {
PostSortCriterion sortCriterion = PostSortCriterion.VOTES;
SortingOrder sortingOrder = SortingOrder.DESCENDING;
User student1 = database.getUserByLogin("student1");
User student2 = database.getUserByLogin("student2");
// student 1 is the author of the post and reacts on this post
Post postReactedOn = existingPostsWithAnswers.get(0);
createVoteReactionOnPost(postReactedOn, student1);
Post postReactedOn2 = existingPostsWithAnswers.get(1);
createVoteReactionOnPost(postReactedOn2, student1);
createVoteReactionOnPost(postReactedOn2, student2);
// refresh posts after reactions are added
existingPostsWithAnswers = postRepository.findPostsForCourse(courseId, null, false, false, false, null);
var params = new LinkedMultiValueMap<String, String>();
// ordering only available in course discussions page, where paging is enabled
params.add("pagingEnabled", "true");
params.add("page", "0");
params.add("size", String.valueOf(MAX_POSTS_PER_PAGE));
params.add("postSortCriterion", sortCriterion.toString());
params.add("sortingOrder", sortingOrder.toString());
List<Post> returnedPosts = request.getList("/api/courses/" + courseId + "/posts", HttpStatus.OK, Post.class, params);
existingPostsWithAnswers.sort(Comparator.comparing((Post post) -> post.getReactions().stream().filter(reaction -> reaction.getEmojiId().equals(VOTE_EMOJI_ID)).count()).reversed());
assertThat(returnedPosts).isEqualTo(existingPostsWithAnswers);
}
use of de.tum.in.www1.artemis.config.Constants.VOTE_EMOJI_ID in project ArTEMiS by ls1intum.
the class ReactionIntegrationTest method createVoteReactionOnPost.
private Reaction createVoteReactionOnPost(Post postReactedOn, User user) {
Reaction reaction = new Reaction();
reaction.setUser(user);
reaction.setEmojiId(VOTE_EMOJI_ID);
reaction.setPost(postReactedOn);
reactionRepository.save(reaction);
return reaction;
}
Aggregations