use of de.tum.in.www1.artemis.domain.metis.AnswerPost in project ArTEMiS by ls1intum.
the class AnswerPostIntegrationTest method testEditAnswerPost_asStudent2_forbidden.
@Test
@WithMockUser(username = "student2", roles = "USER")
public void testEditAnswerPost_asStudent2_forbidden() throws Exception {
// update post from another student (index 1)--> forbidden
AnswerPost answerPostNotToUpdate = editExistingAnswerPost(existingAnswerPosts.get(1));
AnswerPost notUpdatedAnswerPost = request.putWithResponseBody("/api/courses/" + courseId + "/answer-posts/" + answerPostNotToUpdate.getId(), answerPostNotToUpdate, AnswerPost.class, HttpStatus.FORBIDDEN);
assertThat(notUpdatedAnswerPost).isNull();
}
use of de.tum.in.www1.artemis.domain.metis.AnswerPost in project ArTEMiS by ls1intum.
the class AnswerPostIntegrationTest method testCreateAnswerPostCourseWide.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateAnswerPostCourseWide() throws Exception {
AnswerPost answerPostToSave = createAnswerPost(existingPostsWithAnswersCourseWide.get(0));
AnswerPost createdAnswerPost = request.postWithResponseBody("/api/courses/" + courseId + "/answer-posts", answerPostToSave, AnswerPost.class, HttpStatus.CREATED);
// should not be automatically post resolving
assertThat(createdAnswerPost.doesResolvePost()).isFalse();
checkCreatedAnswerPost(answerPostToSave, createdAnswerPost);
assertThat(existingAnswerPosts.size() + 1).isEqualTo(answerPostRepository.count());
}
use of de.tum.in.www1.artemis.domain.metis.AnswerPost in project ArTEMiS by ls1intum.
the class AnswerPostIntegrationTest method testToggleResolvesPost_asPostAuthor.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testToggleResolvesPost_asPostAuthor() throws Exception {
// author of the associated original post is student1
AnswerPost answerPost = existingAnswerPosts.get(0);
// confirm that answer post resolves the original post
answerPost.setResolvesPost(true);
AnswerPost resolvingAnswerPost = request.putWithResponseBody("/api/courses/" + courseId + "/answer-posts/" + answerPost.getId(), answerPost, AnswerPost.class, HttpStatus.OK);
assertThat(resolvingAnswerPost).isEqualTo(answerPost);
// revoke that answer post resolves the original post
answerPost.setResolvesPost(false);
AnswerPost notResolvingAnswerPost = request.putWithResponseBody("/api/courses/" + courseId + "/answer-posts/" + answerPost.getId(), answerPost, AnswerPost.class, HttpStatus.OK);
assertThat(notResolvingAnswerPost).isEqualTo(answerPost);
}
use of de.tum.in.www1.artemis.domain.metis.AnswerPost in project ArTEMiS by ls1intum.
the class AnswerPostIntegrationTest method testToggleResolvesPost_notAuthor_forbidden.
@Test
@WithMockUser(username = "student2", roles = "USER")
public void testToggleResolvesPost_notAuthor_forbidden() throws Exception {
// author of the associated original post is student1, author of answer post is also student1
AnswerPost answerPost = existingAnswerPosts.get(0);
// confirm that answer post resolves the original post
answerPost.setResolvesPost(true);
AnswerPost resolvingAnswerPost = request.putWithResponseBody("/api/courses/" + courseId + "/answer-posts/" + answerPost.getId(), answerPost, AnswerPost.class, HttpStatus.FORBIDDEN);
assertThat(resolvingAnswerPost).isNull();
// revoke that answer post resolves the original post
answerPost.setResolvesPost(false);
AnswerPost notResolvingAnswerPost = request.putWithResponseBody("/api/courses/" + courseId + "/answer-posts/" + answerPost.getId(), answerPost, AnswerPost.class, HttpStatus.FORBIDDEN);
assertThat(notResolvingAnswerPost).isNull();
}
use of de.tum.in.www1.artemis.domain.metis.AnswerPost in project ArTEMiS by ls1intum.
the class AnswerPostIntegrationTest method testEditAnswerPost_asTutor.
// UPDATE
@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testEditAnswerPost_asTutor() throws Exception {
// update post of student1 (index 0)--> OK
AnswerPost answerPostToUpdate = editExistingAnswerPost(existingAnswerPosts.get(0));
AnswerPost updatedAnswerPost = request.putWithResponseBody("/api/courses/" + courseId + "/answer-posts/" + answerPostToUpdate.getId(), answerPostToUpdate, AnswerPost.class, HttpStatus.OK);
assertThat(answerPostToUpdate).isEqualTo(updatedAnswerPost);
}
Aggregations