Skip to content

Commit

Permalink
[TEAMMATES#10828] MCQ questions: submitted comments not shown (TEAMMA…
Browse files Browse the repository at this point in the history
…TES#10831)

* Refactor loop to use responses

* Add test for comment retrieval
  • Loading branch information
madanalogy authored Nov 5, 2020
1 parent 0035a68 commit dda027e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/main/java/teammates/ui/output/FeedbackResponsesData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package teammates.ui.output;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -16,6 +17,14 @@ public FeedbackResponsesData(List<FeedbackResponseAttributes> responses) {
this.responses = responses.stream().map(FeedbackResponseData::new).collect(Collectors.toList());
}

public FeedbackResponsesData() {
responses = Collections.emptyList();
}

public void setResponses(List<FeedbackResponseData> responses) {
this.responses = responses;
}

public List<FeedbackResponseData> getResponses() {
return responses;
}
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/teammates/ui/webapi/GetFeedbackResponsesAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package teammates.ui.webapi;

import java.util.LinkedList;
import java.util.List;

import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes;
Expand All @@ -14,6 +15,7 @@
import teammates.common.exception.InvalidHttpParameterException;
import teammates.common.util.Const;
import teammates.ui.output.FeedbackResponseCommentData;
import teammates.ui.output.FeedbackResponseData;
import teammates.ui.output.FeedbackResponsesData;
import teammates.ui.request.Intent;

Expand Down Expand Up @@ -77,18 +79,23 @@ JsonResult execute() {
throw new InvalidHttpParameterException("Unknown intent " + intent);
}

FeedbackResponsesData result = new FeedbackResponsesData(responses);
result.getResponses().forEach(response -> {
if (questionAttributes.getQuestionType() != FeedbackQuestionType.MCQ) {
List<FeedbackResponseData> responsesData = new LinkedList<>();
responses.forEach(response -> {
FeedbackResponseData data = new FeedbackResponseData(response);
if (questionAttributes.getQuestionType() == FeedbackQuestionType.MCQ) {
// Only MCQ questions can have participant comment
return;
}
FeedbackResponseCommentAttributes comment =
logic.getFeedbackResponseCommentForResponseFromParticipant(response.getFeedbackResponseId());
if (comment != null) {
response.setGiverComment(new FeedbackResponseCommentData(comment));
FeedbackResponseCommentAttributes comment =
logic.getFeedbackResponseCommentForResponseFromParticipant(response.getId());
if (comment != null) {
data.setGiverComment(new FeedbackResponseCommentData(comment));
}
}
responsesData.add(data);
});
FeedbackResponsesData result = new FeedbackResponsesData();
if (!responsesData.isEmpty()) {
result.setResponses(responsesData);
}

return new JsonResult(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import org.apache.http.HttpStatus;
import org.testng.annotations.Test;

import teammates.common.datatransfer.DataBundle;
import teammates.common.datatransfer.FeedbackParticipantType;
import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes;
import teammates.common.datatransfer.attributes.FeedbackResponseAttributes;
import teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes;
import teammates.common.datatransfer.attributes.FeedbackSessionAttributes;
import teammates.common.datatransfer.attributes.InstructorAttributes;
import teammates.common.datatransfer.attributes.StudentAttributes;
Expand All @@ -17,6 +19,7 @@
import teammates.common.util.Const;
import teammates.common.util.JsonUtils;
import teammates.common.util.StringHelper;
import teammates.ui.output.FeedbackResponseCommentData;
import teammates.ui.output.FeedbackResponseData;
import teammates.ui.output.FeedbackResponsesData;
import teammates.ui.request.Intent;
Expand Down Expand Up @@ -123,6 +126,29 @@ protected void testExecute_instructorSubmission_shouldGetResponseSuccessfully()
verifyFeedbackResponseEquals(expected, actualResponse);
}

@Test
protected void testExecute_commentSubmission_shouldGetCommentsSuccessfully() throws InvalidParametersException {
DataBundle dataBundle = loadDataBundle("/FeedbackResponseCommentCRUDTest.json");
removeAndRestoreDataBundle(dataBundle);
StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
FeedbackQuestionAttributes qn3InSession1 = dataBundle.feedbackQuestions.get("qn3InSession1");
FeedbackResponseAttributes response1ForQ3 = dataBundle.feedbackResponses.get("response1ForQ3");
FeedbackResponseCommentAttributes comment1FromStudent1 =
dataBundle.feedbackResponseComments.get("comment1FromStudent1");

loginAsStudent(student1InCourse1.getGoogleId());
String[] params = {
Const.ParamsNames.FEEDBACK_QUESTION_ID, qn3InSession1.getId(),
Const.ParamsNames.INTENT, Intent.STUDENT_SUBMISSION.toString(),
};
FeedbackResponsesData actualData = getFeedbackResponse(params);
List<FeedbackResponseData> actualResponses = actualData.getResponses();

assertEquals(1, actualResponses.size());
verifyFeedbackResponseEquals(response1ForQ3, actualResponses.get(0));
verifyFeedbackCommentEquals(comment1FromStudent1, actualResponses.get(0).getGiverComment());
}

@Test
@Override
protected void testAccessControl() throws Exception {
Expand Down Expand Up @@ -261,4 +287,12 @@ private void verifyFeedbackResponseEquals(FeedbackResponseAttributes expected, F
assertEquals(JsonUtils.toJson(expected.getResponseDetails()),
JsonUtils.toJson(actual.getResponseDetails()));
}

private void verifyFeedbackCommentEquals(
FeedbackResponseCommentAttributes expected, FeedbackResponseCommentData actual) {
assertNotNull(actual);
assertEquals(expected.getCommentGiver(), actual.getCommentGiver());
assertEquals(expected.getCommentText(), actual.getCommentText());
assertEquals(expected.getLastEditorEmail(), actual.getLastEditorEmail());
}
}

0 comments on commit dda027e

Please sign in to comment.