/api/user/summary: streak.activeToday and streak.lost for the app's lit / at-risk / frozen flame
activeToday: activity recorded today (Tehran date). lost: length of a streak that broke (last active day before yesterday), so the app can show it frozen. Same rule as effective_current_streak; the weekly report keeps its own two-field streak serializer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ from accounts.authentication import issue_access_token
|
||||
from accounts.models import User
|
||||
from content.models import Choice, Grade, Lesson, Node, Question, Unit
|
||||
from progress.models import StreakRecord
|
||||
from progress.services import effective_current_streak, record_activity
|
||||
from progress.services import effective_current_streak, record_activity, streak_state
|
||||
|
||||
|
||||
class StreakTests(TestCase):
|
||||
@@ -50,6 +50,19 @@ class StreakTests(TestCase):
|
||||
self.assertEqual(effective_current_streak(streak, today=date(2026, 9, 23)), 0)
|
||||
self.assertEqual(effective_current_streak(None), 0)
|
||||
|
||||
def test_state_tells_lit_at_risk_and_frozen_apart(self):
|
||||
"""اپ سه حالت نشان میدهد: امروز روشن، امروز هنوز نه (در خطر)، و شکسته («یخزده» با طولِ قبلی)."""
|
||||
for day in (20, 21, 22):
|
||||
streak = record_activity(1, today=date(2026, 9, day))
|
||||
|
||||
self.assertEqual(streak_state(streak, today=date(2026, 9, 22)), (3, True, 0))
|
||||
self.assertEqual(streak_state(streak, today=date(2026, 9, 23)), (3, False, 0))
|
||||
self.assertEqual(streak_state(streak, today=date(2026, 9, 24)), (0, False, 3))
|
||||
self.assertEqual(streak_state(None), (0, False, 0))
|
||||
# فعالیتِ بعد از شکستن زنجیرهی تازه میسازد و «یخ» میرود.
|
||||
streak = record_activity(1, today=date(2026, 9, 24))
|
||||
self.assertEqual(streak_state(streak, today=date(2026, 9, 24)), (1, True, 0))
|
||||
|
||||
|
||||
class ActivityFeedsStreakAndLeaderboardTests(TestCase):
|
||||
def setUp(self):
|
||||
@@ -74,6 +87,8 @@ class ActivityFeedsStreakAndLeaderboardTests(TestCase):
|
||||
|
||||
summary = self.client.get('/api/user/summary', **self.auth).json()
|
||||
self.assertEqual(summary['streak']['current'], 1)
|
||||
self.assertIs(summary['streak']['activeToday'], True)
|
||||
self.assertEqual(summary['streak']['lost'], 0)
|
||||
calendar = self.client.get('/api/user/streak/calendar', **self.auth).json()
|
||||
self.assertEqual(len(calendar['activeDays']), 1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user