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);
}
use of de.tum.in.www1.artemis.domain.metis.Reaction in project Artemis by ls1intum.
the class ReactionIntegrationTest method testCreateAnswerPostReactions.
@Test
@WithMockUser(username = "student2", roles = "USER")
public void testCreateAnswerPostReactions() throws Exception {
// student 1 is the author of the answer post and student 2 reacts on this answer post
AnswerPost answerPostReactedOn = existingAnswerPosts.get(0);
Reaction reactionToSaveOnAnswerPost = createReactionOnAnswerPost(answerPostReactedOn);
Reaction createdFirstReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.CREATED);
checkCreatedReaction(reactionToSaveOnAnswerPost, createdFirstReaction);
assertThat(answerPostReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByAnswerPostId(answerPostReactedOn.getId()).size() - 1);
// student 2 reacts again on this answer post
reactionToSaveOnAnswerPost = createReactionOnAnswerPost(answerPostReactedOn);
// change the emojiId to react differently
reactionToSaveOnAnswerPost.setEmojiId("cry");
Reaction createdSecondReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.CREATED);
checkCreatedReaction(reactionToSaveOnAnswerPost, createdSecondReaction);
assertThat(answerPostReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByAnswerPostId(answerPostReactedOn.getId()).size() - 2);
}
use of de.tum.in.www1.artemis.domain.metis.Reaction in project Artemis by ls1intum.
the class ReactionIntegrationTest method saveReactionOfOtherUserOnPost.
private Reaction saveReactionOfOtherUserOnPost(Post postReactedOn) {
Reaction reaction = new Reaction();
reaction.setEmojiId("smiley");
reaction.setPost(postReactedOn);
Reaction savedReaction = reactionRepository.save(reaction);
User user = userRepository.getUserWithGroupsAndAuthorities("student2");
savedReaction.setUser(user);
reactionRepository.save(savedReaction);
return savedReaction;
}
use of de.tum.in.www1.artemis.domain.metis.Reaction in project Artemis by ls1intum.
the class ReactionIntegrationTest method testCreateExistingReaction_badRequest.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateExistingReaction_badRequest() throws Exception {
// student 1 is the author of the answer post and reacts on this answer post
AnswerPost answerPostReactedOn = existingAnswerPosts.get(0);
Reaction reactionToSaveOnAnswerPost = createReactionOnAnswerPost(answerPostReactedOn);
Reaction createdReaction = request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.CREATED);
request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", createdReaction, Reaction.class, HttpStatus.BAD_REQUEST);
checkCreatedReaction(reactionToSaveOnAnswerPost, createdReaction);
assertThat(answerPostReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByAnswerPostId(answerPostReactedOn.getId()).size() - 1);
}
use of de.tum.in.www1.artemis.domain.metis.Reaction 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