Handle expired enrollments on the program detail page

Learners should be able to enroll in future runs of courses in which they have an expired enrollment. Previously, the course card model populated itself by selecting the first course run in which the user was enrolled. When the user tried to enroll in another run, nothing would happen because they were already enrolled in the run the page was trying to enroll them in.

Instead of blindly choosing the first run in which the user is enrolled, we now fall through to the same behavior we use for courses in which the user is not enrolled when the user has expired enrollments.

LEARNER-933
This commit is contained in:
Renzo Lucioni
2017-05-15 17:59:57 -04:00
parent 1bc34a63ae
commit 5314784a4d
2 changed files with 27 additions and 7 deletions

View File

@@ -14,18 +14,18 @@
initialize: function(data) {
if (data) {
this.context = data;
this.setActiveCourseRun(this.getCourseRun(data.course_runs), data.user_preferences);
this.setActiveCourseRun(this.getCourseRun(data), data.user_preferences);
}
},
getCourseRun: function(courseRuns) {
var enrolledCourseRun = _.findWhere(courseRuns, {is_enrolled: true}),
getCourseRun: function(course) {
var enrolledCourseRun = _.findWhere(course.course_runs, {is_enrolled: true}),
openEnrollmentCourseRuns = this.getEnrollableCourseRuns(),
desiredCourseRun;
// We populate our model by looking at the course runs.
if (enrolledCourseRun) {
// If the learner is already enrolled in a course run, return that one.
// If the learner has an existing, unexpired enrollment,
// use it to populate the model.
if (enrolledCourseRun && !course.expired) {
desiredCourseRun = enrolledCourseRun;
} else if (openEnrollmentCourseRuns.length > 0) {
if (openEnrollmentCourseRuns.length === 1) {
@@ -34,7 +34,7 @@
desiredCourseRun = this.getUnselectedCourseRun(openEnrollmentCourseRuns);
}
} else {
desiredCourseRun = this.getUnselectedCourseRun(courseRuns);
desiredCourseRun = this.getUnselectedCourseRun(course.course_runs);
}
return desiredCourseRun;

View File

@@ -145,6 +145,26 @@ define([
expect(view.$('.course-certificate .certificate-status').length).toEqual(0);
});
it('should allow enrollment in future runs when the user has an expired enrollment', function() {
var newRun = $.extend({}, course.course_runs[0]),
newRunKey = 'course-v1:foo+bar+baz',
advertisedStart = 'Summer';
newRun.key = newRunKey;
newRun.is_enrolled = false;
newRun.advertised_start = advertisedStart;
course.course_runs.push(newRun);
course.expired = true;
setupView(course, true);
expect(courseCardModel.get('course_run_key')).toEqual(newRunKey);
expect(view.$('.course-details .course-text .run-period').html()).toEqual(
advertisedStart + ' - ' + endDate
);
});
it('should show a message if an there is an upcoming course run', function() {
course.course_runs[0].is_enrollment_open = false;