Skip to content

Commit

Permalink
refactor & update/clear feedback not owner
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTgl committed Feb 17, 2024
1 parent 049fb27 commit 2b510ce
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void createFeedbackFormForbidden() {
@Test
@TestSecurity(user = "Prof", roles = { UserRole.PROF})
@JwtSecurity(claims = { @Claim(key = "email", value = "[email protected]") })
public void getFeedbackForm() {
public void getFeedbackFormWithoutResult() {
//create & get courses + ids
List<Course> courses = createCourse();
String courseId = courses.getFirst().getId().toString();
Expand Down Expand Up @@ -159,6 +159,26 @@ public void clearResults() {
feedbackFormService.clearFeedbackFormResults(courses.get(0).id.toString(), feedbackForm.id.toString());
FeedbackForm feedbackFormCleared = feedbackFormService.getFeedbackForm(courses.get(0).id.toString(), formId, true);
Assertions.assertEquals(0, feedbackFormCleared.questions.get(0).results.size());
}

@Test
@TestSecurity(user = "Prof", roles = { UserRole.PROF})
@JwtSecurity(claims = { @Claim(key = "sub", value = "111111111111111111111111") })
public void clearResultsNotOwner() {
//create & get courses + ids
List<Course> courses = createCourse();
String courseId = courses.getFirst().getId().toString();
String formId = courses.getFirst().getFeedbackForms().get(0).getId().toString();
String questionId = courses.getFirst().feedbackForms.get(0).questions.get(0).getId().toString();
// add a result & get feedback forms
addResult(courseId, formId, questionId);
FeedbackForm feedbackForm = feedbackFormService.getFeedbackForm(courses.get(0).id.toString(), formId, true);

// Todo Assert that results were not cleared (not owner)
Assertions.assertEquals(1, feedbackForm.questions.get(0).results.size());
feedbackFormService.clearFeedbackFormResults(courses.get(0).id.toString(), feedbackForm.id.toString());
FeedbackForm feedbackFormCleared = feedbackFormService.getFeedbackForm(courses.get(0).id.toString(), formId, true);
Assertions.assertEquals(0, feedbackFormCleared.questions.get(0).results.size());
}

@Test
Expand Down Expand Up @@ -198,6 +218,25 @@ public void updateFeedbackForm() {
Assertions.assertEquals(0, updatedFeedbackForms.get(0).questions.size());
}

@Test
@TestSecurity(user = "Prof", roles = { UserRole.PROF})
@JwtSecurity(claims = { @Claim(key = "sub", value = "111111111111111111111111") })
public void updateFeedbackFormNotOwner() {
//create & get courses + ids
List<Course> courses = createCourse();
String courseId = courses.getFirst().getId().toString();
String formId = courses.getFirst().getFeedbackForms().get(0).getId().toString();

// update the feedback form name, description and questions
FeedbackForm feedbackFormUpdate = new FeedbackForm(courses.get(0).id, "nameUpdate", "descriptionUpdate", List.of(), FormStatus.NOT_STARTED);
feedbackFormService.updateFeedbackForm(courseId, formId, feedbackFormUpdate);

// Todo Assert that results were not cleared (not owner)
List<FeedbackForm> updatedFeedbackForms = feedbackFormService.getFeedbackForms(courses.get(0).id.toString());
Assertions.assertEquals("nameUpdate", updatedFeedbackForms.get(0).name);
Assertions.assertEquals("descriptionUpdate", updatedFeedbackForms.get(0).description);
Assertions.assertEquals(0, updatedFeedbackForms.get(0).questions.size());
}

@Test
@TestSecurity(user = "Student", roles = { UserRole.STUDENT})
Expand Down Expand Up @@ -256,6 +295,9 @@ private void addResult(String courseId, String formId, String questionId) {
}
}

@Test
@TestSecurity(user = "Prof", roles = { UserRole.PROF})
@JwtSecurity(claims = { @Claim(key = "email", value = "[email protected]") })
private List<Course> createCourse() {
// create a course via the json api
ApiCourse apiCourse = new ApiCourse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class QuizFormServiceTest {

private String profJwt = "";
private String profId = "";
private String studentJwt = "";

@BeforeEach
void init(TestInfo testInfo){
Expand Down Expand Up @@ -123,7 +122,7 @@ public void participateUniqueAlias() {
String courseId = courses.getFirst().getId().toString();
String formId = courses.getFirst().getQuizForms().get(0).getId().toString();
createProfUser();
createStudentUser();
String studentJwt = createStudentUser();

// Check successful RestResponse
given()
Expand Down Expand Up @@ -240,7 +239,8 @@ public void createProfUser() {
}
}

public void createStudentUser() {
public String createStudentUser() {
String studentJwt = null;
try {
Response response = userService.login("Basic U3R1ZGVudDo=");
studentJwt = response.getEntity().toString();
Expand All @@ -252,6 +252,7 @@ public void createStudentUser() {
} catch (Exception e) {
Assertions.fail(e);
}
return studentJwt;
}

}

0 comments on commit 2b510ce

Please sign in to comment.