use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostIntegrationTest method testEditPostByChangingContext3_asTutor.
@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void testEditPostByChangingContext3_asTutor() throws Exception {
// update course-wide post
Post postToUpdate = existingCourseWidePosts.get(0);
// change to context to lecture
postToUpdate.setCourseWideContext(null);
postToUpdate.setCourse(null);
postToUpdate.setLecture(this.existingLecturePosts.get(0).getLecture());
Post updatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToUpdate.getId(), postToUpdate, Post.class, HttpStatus.OK);
database.assertSensitiveInformationHidden(updatedPost);
assertThat(updatedPost).isEqualTo(postToUpdate);
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostIntegrationTest method testCreateExamExercisePost_badRequest.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateExamExercisePost_badRequest() throws Exception {
Exam exam = database.setupSimpleExamWithExerciseGroupExercise(course);
Post postToSave = createPostWithoutContext();
Exercise examExercise = exam.getExerciseGroups().get(0).getExercises().stream().findFirst().orElseThrow();
postToSave.setExercise(examExercise);
request.postWithResponseBody("/api/courses/" + courseId + "/posts", postToSave, Post.class, HttpStatus.BAD_REQUEST);
assertThat(existingExercisePosts).hasSameSizeAs(postRepository.findPostsByExerciseId(exerciseId, false, false, false, null));
verify(groupNotificationService, times(0)).notifyAllGroupsAboutNewPostForExercise(any(), any());
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostIntegrationTest method testEditPost_forbidden.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testEditPost_forbidden() throws Exception {
// update own post (index 0)--> OK
Post postToUpdate = editExistingPost(existingPosts.get(0));
Post updatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToUpdate.getId(), postToUpdate, Post.class, HttpStatus.OK);
database.assertSensitiveInformationHidden(updatedPost);
assertThat(updatedPost).isEqualTo(postToUpdate);
// update post from another student (index 1)--> forbidden
Post postToNotUpdate = editExistingPost(existingPosts.get(1));
Post notUpdatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToNotUpdate.getId(), postToNotUpdate, Post.class, HttpStatus.FORBIDDEN);
assertThat(notUpdatedPost).isNull();
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostIntegrationTest method testEditPostWithIdIsNull_badRequest.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testEditPostWithIdIsNull_badRequest() throws Exception {
Post postToUpdate = existingPosts.get(0);
postToUpdate.setId(null);
Post updatedPost = request.putWithResponseBody("/api/courses/" + courseId + "/posts/" + postToUpdate.getId(), postToUpdate, Post.class, HttpStatus.BAD_REQUEST);
assertThat(updatedPost).isNull();
}
use of de.tum.in.www1.artemis.domain.metis.Post in project ArTEMiS by ls1intum.
the class PostIntegrationTest method testPinPost_asStudent_forbidden.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testPinPost_asStudent_forbidden() throws Exception {
Post postToNotPin = editExistingPost(existingPosts.get(1));
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("displayPriority", DisplayPriority.PINNED.toString());
// try to change display priority to PINNED
Post notUpdatedPost = request.putWithResponseBodyAndParams("/api/courses/" + courseId + "/posts/" + postToNotPin.getId() + "/display-priority", null, Post.class, HttpStatus.FORBIDDEN, params);
assertThat(notUpdatedPost).isNull();
}
Aggregations