-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
5a323fc
commit c8723d5
Showing
11 changed files
with
305 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 191 additions & 0 deletions
191
src/it/java/teammates/it/ui/webapi/GetCourseJoinStatusActionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": { | ||
|
@@ -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": { | ||
|
@@ -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": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.