Skip to content

Commit

Permalink
Add tests and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FergusMok committed Feb 19, 2024
1 parent 8fdc414 commit 469403e
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.testng.annotations.Test;

import teammates.common.datatransfer.InstructorPrivileges;
import teammates.common.datatransfer.attributes.FeedbackSessionAttributes;
import teammates.common.datatransfer.attributes.StudentAttributes;
import teammates.common.datatransfer.questions.FeedbackResponseDetails;
import teammates.common.datatransfer.questions.FeedbackTextResponseDetails;
import teammates.common.exception.EntityAlreadyExistsException;
Expand Down Expand Up @@ -466,7 +468,8 @@ public void testAccessControl_submissionBeforeEndTimeBeforeDeadline_shouldAllow(
verifyCanAccess(submissionParams);
}

@Test
// TODO: Enable after fixing issue #12758
@Test(enabled = false)
public void testAccessControl_submissionPastEndTime_shouldAllowIfBeforeDeadline() throws Exception {
FeedbackSession session = getSession("session1InCourse1");
Instructor instructor = loginInstructor("instructor1OfCourse1");
Expand Down Expand Up @@ -527,10 +530,11 @@ public void testAccessControl_studentSubmissionNotStudentAnswerableQuestion_shou
verifyCannotAccess(submissionParams);
}

// TODO: Failing test
@Test
public void testAccessControl_studentSubmissionLoggedOut_shouldFail() throws Exception {
FeedbackSession session = getSession("session1InCourse1");
Student student = loginStudent("student2InCourse1");
Student student = getStudent("student2InCourse1");
setEndTime(session, 1);
setStudentDeadline(session, student, 1);

Expand All @@ -540,10 +544,11 @@ public void testAccessControl_studentSubmissionLoggedOut_shouldFail() throws Exc
verifyCannotAccess(submissionParams);
}

// TODO: Failing test
@Test
public void testAccessControl_studentSubmissionLoggedInAsInstructor_shouldFail() throws Exception {
FeedbackSession session = getSession("session1InCourse1");
Student student = loginStudent("student2InCourse1");
Student student = getStudent("student2InCourse1");
setEndTime(session, 1);
setStudentDeadline(session, student, 1);

Expand All @@ -554,10 +559,11 @@ public void testAccessControl_studentSubmissionLoggedInAsInstructor_shouldFail()
verifyCannotAccess(submissionParams);
}

// TODO: Failing test
@Test
public void testAccessControl_studentSubmissionLoggedInAsAdmin_shouldFail() throws Exception {
FeedbackSession session = getSession("session1InCourse2");
Student student = getStudent("student1InCourse2");
FeedbackSession session = getSession("session1InCourse1");
Student student = getStudent("student2InCourse1");
setEndTime(session, 1);
setStudentDeadline(session, student, 1);

Expand All @@ -568,6 +574,7 @@ public void testAccessControl_studentSubmissionLoggedInAsAdmin_shouldFail() thro
verifyCannotAccess(submissionParams);
}

// TODO: Failing test
@Test
public void testAccessControl_studentSubmissionLoggedInAsAdminMasqueradeAsStudent_shouldFail() throws Exception {
FeedbackSession session = getSession("gracePeriodSession");
Expand All @@ -585,43 +592,44 @@ public void testAccessControl_studentSubmissionLoggedInAsAdminMasqueradeAsStuden
//INSTRUCTOR
@Test
public void testAccessControl_instructorSubmissionToInstructorAnswerableQuestion_shouldAllow() throws Exception {
FeedbackSession session = getSession("session1InCourse2");
Instructor instructor = loginInstructor("instructor2OfCourse2");
FeedbackSession session = getSession("session1InCourse1");
Instructor instructor = loginInstructor("instructor1OfCourse1");
setEndTime(session, 3);
setInstructorDeadline(session, instructor, 3);

int questionNumber = 1;
int questionNumber = 4;
String[] submissionParams = buildSubmissionParams(session, questionNumber, Intent.INSTRUCTOR_SUBMISSION);

verifyCanAccess(submissionParams);
}

@Test
public void testAccessControl_instructorSubmissionToSelfAnswerableQuestion_shouldAllow() throws Exception {
FeedbackSession session = getSession("session2InCourse2");
Instructor instructor = loginInstructor("instructor1OfCourse2");
FeedbackSession session = getSession("session1InCourse1");
Instructor instructor = loginInstructor("instructor1OfCourse1");
setEndTime(session, 3);
setInstructorDeadline(session, instructor, 3);

int questionNumber = 1;
int questionNumber = 6;
String[] submissionParams = buildSubmissionParams(session, questionNumber, Intent.INSTRUCTOR_SUBMISSION);

verifyCanAccess(submissionParams);
}

@Test
public void testAccessControl_instructorSubmissionToNotInstructorAnswerableQuestion_shouldFail() throws Exception {
FeedbackSession session = getSession("gracePeriodSession");
FeedbackSession session = getSession("session1InCourse1");
Instructor instructor = loginInstructor("instructor2OfCourse1");
setEndTime(session, 3);
setInstructorDeadline(session, instructor, 3);

int questionNumber = 3;
int questionNumber = 2;
String[] submissionParams = buildSubmissionParams(session, questionNumber, Intent.INSTRUCTOR_SUBMISSION);

verifyCannotAccess(submissionParams);
}

// TODO: Failing test
@Test
public void testAccessControl_instructorSubmissionLoggedOut_shouldFail() throws Exception {
FeedbackSession session = getSession("session2InCourse2");
Expand All @@ -635,6 +643,7 @@ public void testAccessControl_instructorSubmissionLoggedOut_shouldFail() throws
verifyEntityNotFoundAcl(submissionParams);
}

// TODO: Failing test
@Test
public void testAccessControl_instructorSubmissionLoggedInAsAdmin_shouldFail() throws Exception {
FeedbackSession session = getSession("session2InCourse2");
Expand All @@ -649,6 +658,7 @@ public void testAccessControl_instructorSubmissionLoggedInAsAdmin_shouldFail() t
verifyEntityNotFoundAcl(submissionParams);
}

// TODO: Failing test
@Test
protected void testAccessControl_submissionLoggedInAsAdminMasqueradeAsInstructor_shouldAllow() throws Exception {
FeedbackSession session = getSession("session2InCourse2");
Expand All @@ -663,6 +673,7 @@ protected void testAccessControl_submissionLoggedInAsAdminMasqueradeAsInstructor
verifyCanMasquerade(instructor.getGoogleId(), submissionParams);
}

// TODO: Failing test
@Test
public void testAccessControl_instructorSubmissionLoggedInAsStudent_shouldFail() throws Exception {
FeedbackSession session = getSession("session2InCourse1");
Expand All @@ -679,7 +690,7 @@ public void testAccessControl_instructorSubmissionLoggedInAsStudent_shouldFail()

@Test
protected void testAccessControl_instructorsWithSufficientPreviewPrivilege_shouldAllow() throws Exception {
FeedbackSession session = getSession("closedSession");
FeedbackSession session = getSession("closedSessionInCourse1");
Instructor instructor = loginInstructor("instructor1OfCourse1");
setEndTime(session, 1);
setInstructorDeadline(session, instructor, 1);
Expand All @@ -690,13 +701,14 @@ protected void testAccessControl_instructorsWithSufficientPreviewPrivilege_shoul
String[] submissionParams = buildSubmissionParams(session, questionNumber, Intent.INSTRUCTOR_SUBMISSION);
setPreviewPerson(submissionParams, instructor.getEmail());

// TODO: Verify if this is really it, compared to below. Is this a bug?
verifyCannotAccess(submissionParams);
verifyCannotMasquerade(instructor.getGoogleId(), submissionParams);
verifyCannotMasquerade(instructor.getGoogleId(), submissionParams);
}

@Test
protected void testAccessControl_instructorsWithInsufficientPreviewPrivilege_shouldFail() throws Exception {
FeedbackSession session = getSession("closedSession");
FeedbackSession session = getSession("closedSessionInCourse1");
Instructor instructor = loginInstructor("instructor1OfCourse1");
setEndTime(session, 1);
setInstructorDeadline(session, instructor, 1);
Expand All @@ -707,13 +719,14 @@ protected void testAccessControl_instructorsWithInsufficientPreviewPrivilege_sho
String[] submissionParams = buildSubmissionParams(session, questionNumber, Intent.INSTRUCTOR_SUBMISSION);
setPreviewPerson(submissionParams, instructor.getEmail());

// TODO: Verify if this is really it, compared to below. Is this a bug?
verifyCannotAccess(submissionParams);
verifyCannotMasquerade(instructor.getGoogleId(), submissionParams);
verifyCannotMasquerade(instructor.getGoogleId(), submissionParams);
}

@Test
protected void testAccessControl_instructorsWithInsufficientModeratorPrivilege_shouldFail() throws Exception {
FeedbackSession session = getSession("closedSession");
FeedbackSession session = getSession("closedSessionInCourse1");
Instructor instructor = loginInstructor("instructor1OfCourse1");
setEndTime(session, 1);
setInstructorDeadline(session, instructor, 1);
Expand All @@ -724,6 +737,7 @@ protected void testAccessControl_instructorsWithInsufficientModeratorPrivilege_s
String[] submissionParams = buildSubmissionParams(session, questionNumber, Intent.INSTRUCTOR_SUBMISSION);
setModeratorPerson(submissionParams, instructor.getEmail());

// TODO: Verify if this is really it, compared to below. Is this a bug?
verifyCannotAccess(submissionParams);
verifyCannotMasquerade(instructor.getGoogleId(), submissionParams);
}
Expand Down Expand Up @@ -777,8 +791,8 @@ protected void testExecute_invalidIntent_shouldFail() {

@Test
protected void testExecute_noRequestBody_shouldFail() {
FeedbackSession session = getSession("session2InCourse1");
loginStudent("student4InCourse1");
FeedbackSession session = getSession("ongoingSession2InCourse1");
loginStudent("student3InCourse1");

int questionNumber = 2;
String[] submissionParams = buildSubmissionParams(session, questionNumber, Intent.STUDENT_SUBMISSION);
Expand All @@ -787,7 +801,7 @@ protected void testExecute_noRequestBody_shouldFail() {

@Test
protected void testExecute_requestBodyNoRecipient_shouldFail() {
FeedbackSession session = getSession("session2InCourse1");
FeedbackSession session = getSession("ongoingSession2InCourse1");
loginInstructor("instructor1OfCourse1");

int questionNumber = 1;
Expand Down
61 changes: 54 additions & 7 deletions src/it/resources/data/typicalDataBundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,33 @@
"isClosedEmailSent": false,
"isPublishedEmailSent": true
},
"session2InTypicalCourse": {
"closedSessionInCourse1": {
"id": "00000000-0000-4000-8000-000000000702",
"course": {
"id": "course-1"
},
"name": "Closed Session",
"creatorEmail": "[email protected]",
"instructions": "Please please fill in the following questions.",
"startTime": "2013-06-01T22:00:00Z",
"endTime": "2013-06-01T22:00:00Z",
"sessionVisibleFromTime": "2013-03-20T22:00:00Z",
"resultsVisibleFromTime": "2013-04-29T22:00:00Z",
"gracePeriod": 5,
"isOpeningEmailEnabled": true,
"isClosingEmailEnabled": true,
"isPublishedEmailEnabled": true,
"isOpeningSoonEmailSent": true,
"isOpenEmailSent": true,
"isClosingSoonEmailSent": false,
"isClosedEmailSent": false,
"isPublishedEmailSent": false
},
"session2InTypicalCourse": {
"id": "00000000-0000-4000-8000-000000000703",
"course": {
"id": "course-1"
},
"name": "Second feedback session",
"creatorEmail": "[email protected]",
"instructions": "Please please fill in the following questions.",
Expand All @@ -721,7 +743,7 @@
"isPublishedEmailSent": false
},
"unpublishedSession1InTypicalCourse": {
"id": "00000000-0000-4000-8000-000000000703",
"id": "00000000-0000-4000-8000-000000000704",
"course": {
"id": "course-1"
},
Expand All @@ -743,7 +765,7 @@
"isPublishedEmailSent": false
},
"ongoingSession1InCourse1": {
"id": "00000000-0000-4000-8000-000000000704",
"id": "00000000-0000-4000-8000-000000000705",
"course": {
"id": "course-1"
},
Expand All @@ -765,7 +787,7 @@
"isPublishedEmailSent": true
},
"ongoingSession2InCourse1": {
"id": "00000000-0000-4000-8000-000000000705",
"id": "00000000-0000-4000-8000-000000000706",
"course": {
"id": "course-1"
},
Expand All @@ -787,7 +809,7 @@
"isPublishedEmailSent": true
},
"ongoingSession3InCourse1": {
"id": "00000000-0000-4000-8000-000000000706",
"id": "00000000-0000-4000-8000-000000000707",
"course": {
"id": "course-1"
},
Expand All @@ -809,7 +831,7 @@
"isPublishedEmailSent": true
},
"ongoingSession1InCourse3": {
"id": "00000000-0000-4000-8000-000000000707",
"id": "00000000-0000-4000-8000-000000000708",
"course": {
"id": "course-3"
},
Expand All @@ -831,7 +853,7 @@
"isPublishedEmailSent": true
},
"ongoingSession2InCourse3": {
"id": "00000000-0000-4000-8000-000000000707",
"id": "00000000-0000-4000-8000-000000000709",
"course": {
"id": "course-3"
},
Expand Down Expand Up @@ -1019,6 +1041,31 @@
"showResponsesTo": ["INSTRUCTORS"],
"showGiverNameTo": ["INSTRUCTORS"],
"showRecipientNameTo": ["INSTRUCTORS"]
},
"qn1InClosedSessionInCourse1": {
"id": "00000000-0000-4000-8001-000000000807",
"feedbackSession": {
"id": "00000000-0000-4000-8000-000000000702"
},
"questionDetails": {
"recommendedLength": 100,
"questionType": "TEXT",
"questionText": "Give feedback to yourself."
},
"description": "This is a mcq question.",
"questionNumber": 1,
"giverType": "INSTRUCTORS",
"recipientType": "SELF",
"numOfEntitiesToGiveFeedbackTo": 1,
"showResponsesTo": [
"RECEIVER"
],
"showGiverNameTo": [
"RECEIVER"
],
"showRecipientNameTo": [
"RECEIVER"
]
}
},
"feedbackResponses": {
Expand Down

0 comments on commit 469403e

Please sign in to comment.