use of de.tum.in.www1.artemis.domain.metis.Reaction in project Artemis by ls1intum.
the class ReactionIntegrationTest method createReactionOnPost.
// HELPER METHODS
private Reaction createReactionOnPost(Post postReactedOn) {
Reaction reaction = new Reaction();
reaction.setEmojiId("smiley");
reaction.setPost(postReactedOn);
return reaction;
}
use of de.tum.in.www1.artemis.domain.metis.Reaction in project Artemis by ls1intum.
the class ReactionIntegrationTest method createReactionOnAnswerPost.
private Reaction createReactionOnAnswerPost(AnswerPost answerPostReactedOn) {
Reaction reaction = new Reaction();
reaction.setEmojiId("smiley");
reaction.setAnswerPost(answerPostReactedOn);
return reaction;
}
use of de.tum.in.www1.artemis.domain.metis.Reaction 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.domain.metis.Reaction in project ArTEMiS by ls1intum.
the class ReactionIntegrationTest method testCreateOwnPostReaction.
// CREATE
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateOwnPostReaction() throws Exception {
// student 1 is the author of the post and reacts on this post
Post postReactedOn = existingPostsWithAnswers.get(0);
Reaction reactionToSaveOnPost = createReactionOnPost(postReactedOn);
Reaction createdReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnPost, Reaction.class, HttpStatus.CREATED);
checkCreatedReaction(reactionToSaveOnPost, createdReaction);
assertThat(postReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByPostId(postReactedOn.getId()).size() - 1);
}
use of de.tum.in.www1.artemis.domain.metis.Reaction in project ArTEMiS by ls1intum.
the class ReactionIntegrationTest method testCreateMultipleOwnPostReaction_internalServerError.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateMultipleOwnPostReaction_internalServerError() throws Exception {
// student 1 is the author of the post and reacts on this post
Post postReactedOn = existingPostsWithAnswers.get(0);
Reaction reactionToSaveOnPost = createReactionOnPost(postReactedOn);
Reaction createdReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnPost, Reaction.class, HttpStatus.CREATED);
checkCreatedReaction(reactionToSaveOnPost, createdReaction);
assertThat(postReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByPostId(postReactedOn.getId()).size() - 1);
// try again
request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnPost, Reaction.class, HttpStatus.INTERNAL_SERVER_ERROR);
}
Aggregations