feat: AA-1138: Adds ability to have Weekly Goal Celebration Modal in MFE
Adds celebrate_weekly_goal to the CourseEnrollmentCelebration and includes logic for only returning True if the db field is true and the learner has hit their goal this week. Adds ability to set to false via the API already used by the frontend. Default db value is False, but all new enrollments after merge will be set to True.
This commit is contained in:
@@ -166,6 +166,8 @@ class CourseApiTestViews(BaseCoursewareTests, MasqueradeMixin):
|
||||
assert found, 'external link not in course tabs'
|
||||
|
||||
assert not response.data['user_has_passing_grade']
|
||||
assert response.data['celebrations']['first_section']
|
||||
assert not response.data['celebrations']['weekly_goal']
|
||||
|
||||
# This import errors in cms if it is imported at the top level
|
||||
from lms.djangoapps.course_goals.api import get_course_goal
|
||||
@@ -532,13 +534,15 @@ class CelebrationApiTestViews(BaseCoursewareTests, MasqueradeMixin):
|
||||
@ddt.data(True, False)
|
||||
def test_happy_path(self, update):
|
||||
if update:
|
||||
CourseEnrollmentCelebrationFactory(enrollment=self.enrollment, celebrate_first_section=False)
|
||||
CourseEnrollmentCelebrationFactory(enrollment=self.enrollment)
|
||||
|
||||
response = self.client.post(self.url, {'first_section': True}, content_type='application/json')
|
||||
data = {'first_section': True, 'weekly_goal': True}
|
||||
response = self.client.post(self.url, data, content_type='application/json')
|
||||
assert response.status_code == (200 if update else 201)
|
||||
|
||||
celebration = CourseEnrollmentCelebration.objects.first()
|
||||
assert celebration.celebrate_first_section
|
||||
assert celebration.celebrate_weekly_goal
|
||||
assert celebration.enrollment.id == self.enrollment.id
|
||||
|
||||
def test_extra_data(self):
|
||||
@@ -572,12 +576,16 @@ class CelebrationApiTestViews(BaseCoursewareTests, MasqueradeMixin):
|
||||
user = UserFactory()
|
||||
CourseEnrollment.enroll(user, self.course.id, 'verified')
|
||||
|
||||
response = self.client.post(self.url, {'first_section': True}, content_type='application/json')
|
||||
data = {'first_section': True, 'weekly_goal': False}
|
||||
response = self.client.post(self.url, data, content_type='application/json')
|
||||
assert response.status_code == 201
|
||||
|
||||
self.update_masquerade(username=user.username)
|
||||
response = self.client.post(self.url, {'first_section': False}, content_type='application/json')
|
||||
data = {'first_section': False, 'weekly_goal': True}
|
||||
response = self.client.post(self.url, data, content_type='application/json')
|
||||
assert response.status_code == 202
|
||||
|
||||
celebration = CourseEnrollmentCelebration.objects.first()
|
||||
assert celebration.celebrate_first_section # make sure it didn't change during masquerade attempt
|
||||
# make sure they didn't change during masquerade attempt
|
||||
assert celebration.celebrate_first_section
|
||||
assert not celebration.celebrate_weekly_goal
|
||||
|
||||
@@ -20,6 +20,7 @@ def get_celebrations_dict(user, enrollment, course, browser_timezone):
|
||||
'first_section': False,
|
||||
'streak_length_to_celebrate': None,
|
||||
'streak_discount_enabled': False,
|
||||
'weekly_goal': False,
|
||||
}
|
||||
|
||||
streak_length_to_celebrate = UserCelebration.perform_streak_updates(
|
||||
@@ -29,6 +30,7 @@ def get_celebrations_dict(user, enrollment, course, browser_timezone):
|
||||
'first_section': CourseEnrollmentCelebration.should_celebrate_first_section(enrollment),
|
||||
'streak_length_to_celebrate': streak_length_to_celebrate,
|
||||
'streak_discount_enabled': False,
|
||||
'weekly_goal': CourseEnrollmentCelebration.should_celebrate_weekly_goal(enrollment),
|
||||
}
|
||||
|
||||
if streak_length_to_celebrate:
|
||||
|
||||
@@ -407,6 +407,12 @@ class CoursewareInformation(RetrieveAPIView):
|
||||
* masquerading_expired_course: (bool) Whether this course is expired for the masqueraded user
|
||||
* upgrade_deadline: (str) Last chance to upgrade, in ISO 8601 notation (or None if can't upgrade anymore)
|
||||
* upgrade_url: (str) Upgrade linke (or None if can't upgrade anymore)
|
||||
* celebrations: An object detailing which celebrations to render
|
||||
* first_section: (bool) If the first section celebration should render
|
||||
Note: Also uses information from frontend so this value is not final
|
||||
* streak_length_to_celebrate: (int) The streak length to celebrate for the learner
|
||||
* streak_discount_enabled: (bool) If the frontend should render an upgrade discount for hitting the streak
|
||||
* weekly_goal: (bool) If the weekly goal celebration should render
|
||||
* course_goals:
|
||||
* selected_goal:
|
||||
* days_per_week: (int) The number of days the learner wants to learn per week
|
||||
@@ -697,6 +703,7 @@ class Celebration(DeveloperErrorViewMixin, APIView):
|
||||
Body consists of the following fields:
|
||||
|
||||
* first_section (bool): whether we should celebrate when a user finishes their first section of a course
|
||||
* weekly_goal (bool): whether we should celebrate when a user hits their weekly learning goal in a course
|
||||
|
||||
**Returns**
|
||||
|
||||
@@ -731,6 +738,7 @@ class Celebration(DeveloperErrorViewMixin, APIView):
|
||||
|
||||
data = dict(request.data)
|
||||
first_section = data.pop('first_section', None)
|
||||
weekly_goal = data.pop('weekly_goal', None)
|
||||
if data:
|
||||
return Response(status=400) # there were parameters we didn't recognize
|
||||
|
||||
@@ -741,6 +749,8 @@ class Celebration(DeveloperErrorViewMixin, APIView):
|
||||
defaults = {}
|
||||
if first_section is not None:
|
||||
defaults['celebrate_first_section'] = first_section
|
||||
if weekly_goal is not None:
|
||||
defaults['celebrate_weekly_goal'] = weekly_goal
|
||||
|
||||
if defaults:
|
||||
_, created = CourseEnrollmentCelebration.objects.update_or_create(enrollment=enrollment, defaults=defaults)
|
||||
|
||||
Reference in New Issue
Block a user