use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class ReactionIntegrationTest method testDeletePostReactionWithWrongCourseId_badRequest.
@Test
@WithMockUser(username = "student2", roles = "USER")
public void testDeletePostReactionWithWrongCourseId_badRequest() throws Exception {
Course dummyCourse = database.createCourse();
Post postToReactOn = existingPostsWithAnswers.get(0);
Reaction reactionToSaveOnPost = createReactionOnPost(postToReactOn);
request.delete("/api/courses/" + dummyCourse.getCourseIcon() + "/postings/reactions/" + reactionToSaveOnPost.getId(), HttpStatus.BAD_REQUEST);
assertThat(postToReactOn.getReactions()).hasSameSizeAs(postRepository.findById(postToReactOn.getId()).get().getReactions());
}
use of de.tum.in.www1.artemis.domain.metis.Post 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.Post in project ArTEMiS by ls1intum.
the class ReactionIntegrationTest method testCreateMultipleOwnAnswerPostReaction_internalServerError.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateMultipleOwnAnswerPostReaction_internalServerError() 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);
checkCreatedReaction(reactionToSaveOnAnswerPost, createdReaction);
assertThat(answerPostReactedOn.getReactions()).hasSize(reactionRepository.findReactionsByAnswerPostId(answerPostReactedOn.getId()).size() - 1);
// try again
request.postWithResponseBody("/api/courses/" + courseId + "/postings/reactions", reactionToSaveOnAnswerPost, Reaction.class, HttpStatus.INTERNAL_SERVER_ERROR);
}
use of de.tum.in.www1.artemis.domain.metis.Post 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.Post 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);
}
Aggregations