Skip to content

Commit

Permalink
[#12048] Migrate GetCourseJoinStatusAction (#12713)
Browse files Browse the repository at this point in the history
* Migrate get course join status

* Add IT for getCourseJoinStatusAction

* Fix checkstyle

* Update testcases

* Update testcases

* Refactor code

---------

Co-authored-by: dishenggg <[email protected]>
Co-authored-by: FergusMok <[email protected]>
  • Loading branch information
3 people authored Feb 4, 2024
1 parent 5a323fc commit c8723d5
Show file tree
Hide file tree
Showing 11 changed files with 305 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testCreateReadDeleteAccountRequest() throws Exception {
______TS("Read account request using the given registration key");

AccountRequest actualAccReqRegistrationKey =
accountRequestDb.getAccountRequest(accountRequest.getRegistrationKey());
accountRequestDb.getAccountRequestByRegistrationKey(accountRequest.getRegistrationKey());
verifyEquals(accountRequest, actualAccReqRegistrationKey);

______TS("Read account request using the given start and end timing");
Expand Down
14 changes: 10 additions & 4 deletions src/it/java/teammates/it/storage/sqlsearch/InstructorSearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void allTests() throws Exception {
Instructor insInUnregCourse = typicalBundle.instructors.get("instructorOfUnregisteredCourse");
Instructor insUniqueDisplayName = typicalBundle.instructors.get("instructorOfCourse2WithUniqueDisplayName");
Instructor ins1InCourse3 = typicalBundle.instructors.get("instructor1OfCourse3");
Instructor unregisteredInsInCourse1 = typicalBundle.instructors.get("unregisteredInstructorOfCourse1");

______TS("success: search for instructors in whole system; query string does not match anyone");

Expand Down Expand Up @@ -80,12 +81,12 @@ public void allTests() throws Exception {
______TS("success: search for instructors in whole system; instructors should be searchable by course id");

results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results, ins1InCourse1, ins2InCourse1);
verifySearchResults(results, ins1InCourse1, ins2InCourse1, unregisteredInsInCourse1);

______TS("success: search for instructors in whole system; instructors should be searchable by course name");

results = usersDb.searchInstructorsInWholeSystem("\"Typical Course 1\"");
verifySearchResults(results, ins1InCourse1, ins2InCourse1);
verifySearchResults(results, ins1InCourse1, ins2InCourse1, unregisteredInsInCourse1);

______TS("success: search for instructors in whole system; instructors should be searchable by their name");

Expand Down Expand Up @@ -136,17 +137,22 @@ public void testSearchInstructor_deleteAfterSearch_shouldNotBeSearchable() throw

Instructor ins1InCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
Instructor ins2InCourse1 = typicalBundle.instructors.get("instructor2OfCourse1");
Instructor unregisteredInsInCourse1 = typicalBundle.instructors.get("unregisteredInstructorOfCourse1");

List<Instructor> results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results, ins1InCourse1, ins2InCourse1);
verifySearchResults(results, ins1InCourse1, ins2InCourse1, unregisteredInsInCourse1);

usersDb.deleteUser(ins1InCourse1);
results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results, ins2InCourse1);
verifySearchResults(results, ins2InCourse1, unregisteredInsInCourse1);

// This used to test .deleteInstructors, but we don't seem to have a similar method to delete all users in course
usersDb.deleteUser(ins2InCourse1);
results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results, unregisteredInsInCourse1);

usersDb.deleteUser(unregisteredInsInCourse1);
results = usersDb.searchInstructorsInWholeSystem("\"course-1\"");
verifySearchResults(results);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ protected void testExecute() throws Exception {
Instructor instructor = typicalBundle.instructors.get("instructor1OfCourse1");
String courseId = instructor.getCourseId();
// TODO Remove limit after migration completes
int deleteLimit = 3;
int deleteLimit = 4;

______TS("Typical Success Case delete a limited number of students");
loginAsInstructor(instructor.getGoogleId());

List<Student> studentsToDelete = logic.getStudentsForCourse(courseId);

assertEquals(3, studentsToDelete.size());
assertEquals(4, studentsToDelete.size());

String[] params = new String[] {
Const.ParamsNames.COURSE_ID, courseId,
Expand All @@ -59,7 +59,7 @@ protected void testExecute() throws Exception {
getJsonResult(deleteStudentsAction);

for (Student student : studentsToDelete) {
assertNull(logic.getStudentByGoogleId(courseId, student.getGoogleId()));
assertNull(logic.getStudentByRegistrationKey(student.getRegKey()));
}

______TS("Random course given, fails silently");
Expand Down
191 changes: 191 additions & 0 deletions src/it/java/teammates/it/ui/webapi/GetCourseJoinStatusActionIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package teammates.it.ui.webapi;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import teammates.common.util.Const;
import teammates.common.util.HibernateUtil;
import teammates.ui.output.JoinStatus;
import teammates.ui.webapi.GetCourseJoinStatusAction;
import teammates.ui.webapi.JsonResult;

/**
* SUT: {@link GetCourseJoinStatusAction}.
*/
public class GetCourseJoinStatusActionIT extends BaseActionIT<GetCourseJoinStatusAction> {

@Override
@BeforeMethod
protected void setUp() throws Exception {
super.setUp();
this.typicalBundle = loadSqlDataBundle("/typicalDataBundle.json");
persistDataBundle(typicalBundle);
HibernateUtil.flushSession();
}

@Override
protected String getActionUri() {
return Const.ResourceURIs.JOIN;
}

@Override
protected String getRequestMethod() {
return GET;
}

@Override
@Test
protected void testExecute() {

loginAsUnregistered("unreg.user");

______TS("Not enough parameters");

verifyHttpParameterFailure();
verifyHttpParameterFailure(
Const.ParamsNames.REGKEY, "regkey"
);
verifyHttpParameterFailure(
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.STUDENT
);

______TS("Normal case: student is already registered");
String registeredStudentKey =
logic.getStudentForEmail("course-1", "[email protected]").getRegKey();

String[] params = new String[] {
Const.ParamsNames.REGKEY, registeredStudentKey,
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.STUDENT,
};

GetCourseJoinStatusAction getCourseJoinStatusAction = getAction(params);
JsonResult result = getJsonResult(getCourseJoinStatusAction);

JoinStatus output = (JoinStatus) result.getOutput();
assertTrue(output.getHasJoined());

______TS("Normal case: student is not registered");
String unregisteredStudentKey =
logic.getStudentForEmail("course-1", "[email protected]").getRegKey();

params = new String[] {
Const.ParamsNames.REGKEY, unregisteredStudentKey,
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.STUDENT,
};

getCourseJoinStatusAction = getAction(params);
result = getJsonResult(getCourseJoinStatusAction);

output = (JoinStatus) result.getOutput();
assertFalse(output.getHasJoined());

______TS("Failure case: regkey is not valid for student");

params = new String[] {
Const.ParamsNames.REGKEY, "ANXKJZNZXNJCZXKJDNKSDA",
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.STUDENT,
};

verifyEntityNotFound(params);

______TS("Normal case: instructor is already registered");

String registeredInstructorKey =
logic.getInstructorForEmail("course-1", "[email protected]").getRegKey();

params = new String[] {
Const.ParamsNames.REGKEY, registeredInstructorKey,
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.INSTRUCTOR,
};

getCourseJoinStatusAction = getAction(params);
result = getJsonResult(getCourseJoinStatusAction);

output = (JoinStatus) result.getOutput();
assertTrue(output.getHasJoined());

______TS("Normal case: instructor is not registered");

String unregisteredInstructorKey =
logic.getInstructorForEmail("course-1", "[email protected]").getRegKey();

params = new String[] {
Const.ParamsNames.REGKEY, unregisteredInstructorKey,
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.INSTRUCTOR,
};

getCourseJoinStatusAction = getAction(params);
result = getJsonResult(getCourseJoinStatusAction);

output = (JoinStatus) result.getOutput();
assertFalse(output.getHasJoined());

______TS("Failure case: regkey is not valid for instructor");

params = new String[] {
Const.ParamsNames.REGKEY, "ANXKJZNZXNJCZXKJDNKSDA",
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.INSTRUCTOR,
};

verifyEntityNotFound(params);

______TS("Normal case: account request not used, instructor has not joined course");

String accountRequestNotUsedKey = logic.getAccountRequest("[email protected]",
"TEAMMATES Test Institute 1").getRegistrationKey();

params = new String[] {
Const.ParamsNames.REGKEY, accountRequestNotUsedKey,
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.INSTRUCTOR,
Const.ParamsNames.IS_CREATING_ACCOUNT, "true",
};

getCourseJoinStatusAction = getAction(params);
result = getJsonResult(getCourseJoinStatusAction);

output = (JoinStatus) result.getOutput();
assertFalse(output.getHasJoined());

______TS("Normal case: account request already used, instructor has joined course");

String accountRequestUsedKey =
logic.getAccountRequest("[email protected]", "TEAMMATES Test Institute 1").getRegistrationKey();

params = new String[] {
Const.ParamsNames.REGKEY, accountRequestUsedKey,
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.INSTRUCTOR,
Const.ParamsNames.IS_CREATING_ACCOUNT, "true",
};

getCourseJoinStatusAction = getAction(params);
result = getJsonResult(getCourseJoinStatusAction);

output = (JoinStatus) result.getOutput();
assertTrue(output.getHasJoined());

______TS("Failure case: account request regkey is not valid");

params = new String[] {
Const.ParamsNames.REGKEY, "invalid-registration-key",
Const.ParamsNames.ENTITY_TYPE, Const.EntityType.INSTRUCTOR,
Const.ParamsNames.IS_CREATING_ACCOUNT, "true",
};

verifyEntityNotFound(params);

______TS("Failure case: invalid entity type");

params = new String[] {
Const.ParamsNames.REGKEY, unregisteredStudentKey,
Const.ParamsNames.ENTITY_TYPE, "unknown",
};

verifyHttpParameterFailure(params);
}

@Test
@Override
protected void testAccessControl() throws Exception {
verifyAnyLoggedInUserCanAccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void testExecute() throws Exception {
InstructorsData output = (InstructorsData) jsonResult.getOutput();
List<InstructorData> instructors = output.getInstructors();

assertEquals(2, instructors.size());
assertEquals(3, instructors.size());

______TS("Typical Success Case with no intent");
params = new String[] {
Expand All @@ -71,7 +71,7 @@ protected void testExecute() throws Exception {
output = (InstructorsData) jsonResult.getOutput();
instructors = output.getInstructors();

assertEquals(2, instructors.size());
assertEquals(3, instructors.size());

for (InstructorData instructorData : instructors) {
assertNull(instructorData.getGoogleId());
Expand Down
4 changes: 2 additions & 2 deletions src/it/java/teammates/it/ui/webapi/GetStudentsActionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void testExecute() throws Exception {
StudentsData response = (StudentsData) jsonResult.getOutput();
List<StudentData> students = response.getStudents();

assertEquals(3, students.size());
assertEquals(4, students.size());

StudentData firstStudentInStudents = students.get(0);

Expand All @@ -82,7 +82,7 @@ protected void testExecute() throws Exception {

Student expectedOtherTeamMember = typicalBundle.students.get("student2InCourse1");

assertEquals(3, students.size());
assertEquals(4, students.size());

StudentData actualOtherTeamMember = students.get(1);

Expand Down
43 changes: 43 additions & 0 deletions src/it/resources/data/typicalDataBundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1",
"registeredAt": "2015-02-14T00:00:00Z"
},
"unregisteredInstructor": {
"id": "00000000-0000-4000-8000-000000000103",
"name": "Unregistered Instructor",
"email": "[email protected]",
"institute": "TEAMMATES Test Institute 1"
}
},
"courses": {
Expand Down Expand Up @@ -328,6 +334,31 @@
"sectionLevel": {},
"sessionLevel": {}
}
},
"unregisteredInstructorOfCourse1": {
"id": "00000000-0000-4000-8000-000000000507",
"course": {
"id": "course-1"
},
"name": "Unregistered Instructor",
"email": "[email protected]",
"role": "INSTRUCTOR_PERMISSION_ROLE_TUTOR",
"isDisplayedToStudents": true,
"displayName": "Unregistered Instructor",
"privileges": {
"courseLevel": {
"canModifyCourse": false,
"canModifyInstructor": false,
"canModifySession": false,
"canModifyStudent": false,
"canViewStudentInSections": true,
"canViewSessionInSections": true,
"canSubmitSessionInSections": true,
"canModifySessionCommentsInSections": false
},
"sectionLevel": {},
"sessionLevel": {}
}
}
},
"students": {
Expand Down Expand Up @@ -387,6 +418,18 @@
"email": "[email protected]",
"name": "student1 In Course2",
"comments": ""
},
"unregisteredStudentInCourse1": {
"id": "00000000-0000-4000-8000-000000000605",
"course": {
"id": "course-1"
},
"team": {
"id": "00000000-0000-4000-8000-000000000301"
},
"email": "[email protected]",
"name": "Unregistered Student In Course1",
"comments": ""
}
},
"feedbackSessions": {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/teammates/sqllogic/api/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ public AccountRequest getAccountRequest(String email, String institute) {
return accountRequestLogic.getAccountRequest(email, institute);
}

/**
* Gets the account request with the associated {@code regkey}.
*
* @return account request with the associated {@code regkey}.
*/
public AccountRequest getAccountRequestByRegistrationKey(String regkey) {
return accountRequestLogic.getAccountRequestByRegistrationKey(regkey);
}

/**
* Creates/Resets the account request with the given email and institute
* such that it is not registered.
Expand Down
Loading

0 comments on commit c8723d5

Please sign in to comment.