|
| 1 | +package teammates.sqlui.webapi; |
| 2 | + |
| 3 | +import org.testng.annotations.BeforeMethod; |
| 4 | +import org.testng.annotations.Test; |
| 5 | +import teammates.common.datatransfer.attributes.FeedbackQuestionAttributes; |
| 6 | +import teammates.common.datatransfer.attributes.FeedbackSessionAttributes; |
| 7 | +import teammates.common.datatransfer.attributes.InstructorAttributes; |
| 8 | +import teammates.common.exception.EntityDoesNotExistException; |
| 9 | +import teammates.common.exception.InvalidParametersException; |
| 10 | +import teammates.common.util.Const; |
| 11 | +import teammates.common.util.TimeHelper; |
| 12 | +import teammates.storage.sqlentity.Instructor; |
| 13 | +import teammates.ui.request.Intent; |
| 14 | +import teammates.ui.webapi.SubmitFeedbackResponsesAction; |
| 15 | + |
| 16 | +import java.time.Instant; |
| 17 | +import java.util.Map; |
| 18 | + |
| 19 | +/** |
| 20 | + * SUT: {@link SubmitFeedbackResponsesAction} |
| 21 | + * **/ |
| 22 | + |
| 23 | +public class SubmitFeedbackResponsesActionTest extends BaseActionTest<SubmitFeedbackResponsesAction> |
| 24 | +{ |
| 25 | + |
| 26 | + private Instructor instructor; |
| 27 | + private FeedbackSessionAttributes feedbackSessionAttributes; |
| 28 | + |
| 29 | + @Override |
| 30 | + String getActionUri() |
| 31 | + { |
| 32 | + return Const.ResourceURIs.RESPONSES; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + String getRequestMethod() |
| 37 | + { |
| 38 | + return PUT; |
| 39 | + } |
| 40 | + |
| 41 | + @BeforeMethod |
| 42 | + protected void setUp() |
| 43 | + { |
| 44 | + this.instructor = getTypicalInstructor(); |
| 45 | + this.feedbackSessionAttributes = getTypicalFeedbackSessionAttributes(); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | +// private void setEndTime(FeedbackSessionAttributes session, int days) |
| 50 | +// throws InvalidParametersException, EntityDoesNotExistException |
| 51 | +// { |
| 52 | +// String sessionName = session.getFeedbackSessionName(); |
| 53 | +// String courseId = session.getCourseId(); |
| 54 | +// Instant endTime = TimeHelper.getInstantDaysOffsetFromNow(days); |
| 55 | +// |
| 56 | +// logic.updateFeedbackSession( |
| 57 | +// FeedbackSessionAttributes.updateOptionsBuilder(sessionName, courseId) |
| 58 | +// .withEndTime(endTime) |
| 59 | +// .build()); |
| 60 | +// } |
| 61 | +// |
| 62 | +// private void setInstructorDeadline(FeedbackSessionAttributes session, |
| 63 | +// InstructorAttributes instructor, |
| 64 | +// int days) |
| 65 | +// throws InvalidParametersException, EntityDoesNotExistException { |
| 66 | +// String sessionName = session.getFeedbackSessionName(); |
| 67 | +// String courseId = session.getCourseId(); |
| 68 | +// |
| 69 | +// Map<String, Instant> deadlines = Map.of(instructor.getEmail(), TimeHelper.getInstantDaysOffsetFromNow(days)); |
| 70 | +// |
| 71 | +// logic.updateFeedbackSession( |
| 72 | +// FeedbackSessionAttributes.updateOptionsBuilder(sessionName, courseId) |
| 73 | +// .withInstructorDeadlines(deadlines) |
| 74 | +// .build()); |
| 75 | +// } |
| 76 | +// |
| 77 | +// private String[] buildSubmissionParams(FeedbackSessionAttributes session, |
| 78 | +// int questionNumber, |
| 79 | +// Intent intent) { |
| 80 | +// FeedbackQuestionAttributes question = getQuestion(session, questionNumber); |
| 81 | +// return buildSubmissionParams(question, intent); |
| 82 | +// } |
| 83 | +// |
| 84 | +// private String[] buildSubmissionParams(FeedbackQuestionAttributes question, |
| 85 | +// Intent intent) { |
| 86 | +// String questionId = question != null ? question.getId() : ""; |
| 87 | +// |
| 88 | +// return new String[] {Const.ParamsNames.FEEDBACK_QUESTION_ID, questionId, Const.ParamsNames.INTENT, |
| 89 | +// intent.toString()}; |
| 90 | +// } |
| 91 | +// |
| 92 | +// @Test |
| 93 | +// public void testAccessControl_feedbackSubmissionQuestionExists_shouldAllow() throws Exception { |
| 94 | +// FeedbackSessionAttributes session = getSession("session1InCourse2"); |
| 95 | +// InstructorAttributes instructor = loginInstructor("instructor1OfCourse2"); |
| 96 | +// setEndTime(session, 1); |
| 97 | +// setInstructorDeadline(session, instructor, 40); |
| 98 | +// |
| 99 | +// int questionNumber = 2; |
| 100 | +// String[] submissionParams = buildSubmissionParams(session, questionNumber, Intent.INSTRUCTOR_SUBMISSION); |
| 101 | +// |
| 102 | +// verifyCanAccess(submissionParams); |
| 103 | +// } |
| 104 | + |
| 105 | + @Test |
| 106 | + public void testExecute_noHttpParameters_shouldFail() { |
| 107 | + loginAsInstructor(instructor.getGoogleId()); |
| 108 | + |
| 109 | + verifyHttpParameterFailure(new String[] {}); |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void testExecute_noFeedbackQuestionId_shouldFail() { |
| 114 | + loginAsInstructor(instructor.getGoogleId()); |
| 115 | + |
| 116 | + ______TS("Not enough parameters for request; should fail."); |
| 117 | + String[] submissionParams = new String[] {Const.ParamsNames.INTENT, Intent.STUDENT_SUBMISSION.toString()}; |
| 118 | + verifyHttpParameterFailure(submissionParams); |
| 119 | + } |
| 120 | + |
| 121 | + @Test |
| 122 | + public void testExecute_feedbackQuestionDoesNotExist_shouldFail() { |
| 123 | + loginAsInstructor(instructor.getGoogleId()); |
| 124 | + |
| 125 | + String[] submissionParams = new String[] { |
| 126 | + Const.ParamsNames.INTENT, Intent.STUDENT_SUBMISSION.toString(), |
| 127 | + Const.ParamsNames.FEEDBACK_QUESTION_ID, "non-existent id"}; |
| 128 | + verifyEntityNotFound(submissionParams); |
| 129 | + } |
| 130 | +} |
0 commit comments