Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin API's for course batch management #16

Open
wants to merge 6 commits into
base: 4.8.0-adminApis
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class CourseEnrolmentActor @Inject()(@Named("course-batch-notification-actor") c

def validateEnrolment(batchData: CourseBatch, enrolmentData: UserCourses, isEnrol: Boolean): Unit = {
if(null == batchData) ProjectCommonException.throwClientErrorException(ResponseCode.invalidCourseBatchId, ResponseCode.invalidCourseBatchId.getErrorMessage)

if(!(EnrolmentType.inviteOnly.getVal.equalsIgnoreCase(batchData.getEnrollmentType) ||
EnrolmentType.open.getVal.equalsIgnoreCase(batchData.getEnrollmentType)))
ProjectCommonException.throwClientErrorException(ResponseCode.enrollmentTypeValidation, ResponseCode.enrollmentTypeValidation.getErrorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class CourseEnrollmentControllerTest extends BaseApplicationTest {
String GET_ENROLLED_COURSES_URL = "/v1/user/courses/list/"+USER_ID;
String GET_ENROLLED_COURSE_URL_V2 = "/v2/user/courses/list";
String GET_ENROLLED_COURSE_URL_CACHE = "/v1/user/courses/list/" + USER_ID + "?cache=false";
String ADMIN_ENROLL_BATCH_URL = "/v1/course/admin/enroll";
String ADMIN_UENROLL_BATCH_URL = "/v1/course/admin/unenroll";
String ADMIN_GET_ENROLLED_COURSE_URL_V2 = "/v2/user/courses/admin/list";

@Before
public void before() {
Expand Down Expand Up @@ -179,4 +182,105 @@ private JsonNode createCourseEnrollmentRequest(
String data = mapToJson(requestMap);
return Json.parse(data);
}

@Test
public void testAdminEnrollCourseSuccess(){
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_ENROLL_BATCH_URL)
.bodyJson(createCourseEnrollmentRequest(COURSE_ID, BATCH_ID, USER_ID))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 200, result.status());
}

@Test
public void testAdminEnrollCourseFailureWithoutCourseId() {
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_ENROLL_BATCH_URL)
.bodyJson(createCourseEnrollmentRequest(null, BATCH_ID, USER_ID))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 400, result.status());
}

@Test
public void testAdminEnrollCourseFailureWithoutBatchId() {
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_ENROLL_BATCH_URL)
.bodyJson(createCourseEnrollmentRequest(COURSE_ID, null, USER_ID))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 400, result.status());
}

@Test
public void testAdminEnrollCourseFailureWithoutUserId() {
PowerMockito.when(RequestInterceptor.verifyRequestData(Mockito.any())).thenReturn(JsonKey.ANONYMOUS);
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_ENROLL_BATCH_URL)
.bodyJson(createCourseEnrollmentRequest(COURSE_ID, BATCH_ID, null))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 401, result.status());
}

@Test
public void testAdminUnenrollCourseSuccess(){
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_UENROLL_BATCH_URL)
.bodyJson(createCourseEnrollmentRequest(COURSE_ID, BATCH_ID, USER_ID))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 200, result.status());
}

@Test
public void testAdminUnenrollCourseBatchFailureWithoutCourseId() {
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_UENROLL_BATCH_URL)
.bodyJson(createCourseEnrollmentRequest(null, BATCH_ID, USER_ID))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 400, result.status());
}

@Test
public void testAdminUnenrollCourseBatchFailureWithoutBatchId() {
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_UENROLL_BATCH_URL)
.bodyJson(createCourseEnrollmentRequest(COURSE_ID, null, USER_ID))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 400, result.status());
}

@Test
public void testAdminUnenrollCourseBatchFailureWithoutUserId() {
PowerMockito.when(RequestInterceptor.verifyRequestData(Mockito.any())).thenReturn(JsonKey.ANONYMOUS);
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_UENROLL_BATCH_URL)
.bodyJson(createCourseEnrollmentRequest(COURSE_ID, BATCH_ID, null))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 401, result.status());
}

@Test
public void testAdminGetUserEnrolledCourses(){
Http.RequestBuilder req =
new Http.RequestBuilder()
.uri(ADMIN_GET_ENROLLED_COURSE_URL_V2)
.bodyJson(createCourseEnrollmentRequest(null,null, USER_ID))
.method("POST");
Result result = Helpers.route(application, req);
Assert.assertEquals( 200, result.status());
}
}