musora-content-services 2.167.1 → 2.167.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/.agent/decisions/2026-07-17-onboarding-statuses.md +21 -0
  2. package/.agent/decisions/2026-07-20-mu2-1724-songs-lessons-counts.md +33 -0
  3. package/.agent/decisions/2026-07-20-query-builder-tostring.md +37 -0
  4. package/CHANGELOG.md +15 -0
  5. package/package.json +2 -1
  6. package/src/contentTypeConfig.js +2 -0
  7. package/src/index.d.ts +2 -0
  8. package/src/index.js +2 -0
  9. package/src/lib/sanity/query.ts +5 -0
  10. package/src/services/config.js +15 -0
  11. package/src/services/content/artist.ts +1 -3
  12. package/src/services/content/counts.ts +47 -0
  13. package/src/services/content/genre.ts +1 -3
  14. package/src/services/content/instructor.ts +1 -3
  15. package/src/services/contentProgress.js +1 -1
  16. package/src/services/eventsAPI.js +49 -7
  17. package/src/services/user/onboarding.ts +22 -0
  18. package/src/services/userActivity.js +2 -0
  19. package/src/version-info.js +1 -0
  20. package/.claude/settings.local.json +0 -52
  21. package/test/initializeTests.js +0 -60
  22. package/test/integration/awards/award-exclusion-handling.test.ts +0 -275
  23. package/test/integration/awards/internal/image-utils.test.ts +0 -86
  24. package/test/integration/content-progress/__mocks__/mocks.ts +0 -104
  25. package/test/integration/content-progress/contentProgress.test.ts +0 -335
  26. package/test/integration/content-progress/e2eOfflineProgress.test.ts +0 -352
  27. package/test/integration/content-progress/e2eProgress.test.ts +0 -612
  28. package/test/integration/content-progress/getters.test.ts +0 -334
  29. package/test/integration/content-progress/helpers.test.ts +0 -263
  30. package/test/integration/content-progress/offlineContentProgress.test.ts +0 -226
  31. package/test/integration/forums.test.ts +0 -209
  32. package/test/integration/infrastructure/FetchRequestExecutor.test.ts +0 -88
  33. package/test/integration/initializeTestDB.ts +0 -80
  34. package/test/integration/learning-paths.test.ts +0 -854
  35. package/test/integration/notifications.test.ts +0 -178
  36. package/test/integration/progress-row/content-card.test.ts +0 -283
  37. package/test/integration/sync/adapters/idb-errors.test.ts +0 -144
  38. package/test/integration/sync/adapters/sqlite-errors.test.ts +0 -173
  39. package/test/integration/sync/fetch.test.ts +0 -224
  40. package/test/integration/sync/repositories/content-likes.test.ts +0 -99
  41. package/test/integration/sync/repositories/practices.test.ts +0 -179
  42. package/test/integration/sync/repositories/progress.test.ts +0 -245
  43. package/test/integration/sync/repositories/user-award-progress.static.test.ts +0 -68
  44. package/test/integration/sync/repositories/user-award-progress.test.ts +0 -387
  45. package/test/integration/sync/store/cross-user-protection.test.ts +0 -217
  46. package/test/integration/sync/store/store-idb.test.ts +0 -180
  47. package/test/integration/sync/store/store.test.ts +0 -361
  48. package/test/integration/user/permissions.test.js +0 -20
  49. package/test/integration/userActivity.test.ts +0 -102
  50. package/test/live/README.md +0 -29
  51. package/test/live/content.test.js +0 -116
  52. package/test/localStorageMock.js +0 -21
  53. package/test/log.js +0 -5
  54. package/test/mockData/award-definitions.js +0 -171
  55. package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -35
  56. package/test/mockData/mockData_progress_content.json +0 -182
  57. package/test/mockData/mockData_sanity_progress_content.json +0 -1451
  58. package/test/mockData/mockData_user_practices.json +0 -9
  59. package/test/setupConsole.js +0 -6
  60. package/test/setupNetworkGuard.js +0 -3
  61. package/test/setupTimers.js +0 -13
  62. package/test/unit/HttpClient.test.ts +0 -267
  63. package/test/unit/awards/award-alacarte-observer.test.ts +0 -199
  64. package/test/unit/awards/award-auto-refresh.test.ts +0 -84
  65. package/test/unit/awards/award-calculations.test.ts +0 -34
  66. package/test/unit/awards/award-callbacks.test.ts +0 -144
  67. package/test/unit/awards/award-certificate-display.test.ts +0 -330
  68. package/test/unit/awards/award-collection-edge-cases.test.ts +0 -212
  69. package/test/unit/awards/award-collection-filtering.test.ts +0 -287
  70. package/test/unit/awards/award-completion-flow.test.ts +0 -306
  71. package/test/unit/awards/award-multi-lesson.test.ts +0 -243
  72. package/test/unit/awards/award-observer-integration.test.ts +0 -327
  73. package/test/unit/awards/award-query-messages.test.ts +0 -448
  74. package/test/unit/awards/award-user-collection.test.ts +0 -416
  75. package/test/unit/awards/duplicate-prevention.test.ts +0 -120
  76. package/test/unit/awards/helpers/completion-mock.ts +0 -56
  77. package/test/unit/awards/helpers/index.ts +0 -3
  78. package/test/unit/awards/helpers/mock-setup.ts +0 -79
  79. package/test/unit/awards/helpers/progress-emitter.ts +0 -45
  80. package/test/unit/awards/message-generator.test.ts +0 -162
  81. package/test/unit/content-progress/bubbleTrickle.test.ts +0 -322
  82. package/test/unit/content-progress/helpers.test.ts +0 -329
  83. package/test/unit/content-progress/navigateTo.test.ts +0 -381
  84. package/test/unit/contentLikes.test.ts +0 -62
  85. package/test/unit/contentMetaData.test.ts +0 -58
  86. package/test/unit/dataContext.test.ts +0 -38
  87. package/test/unit/dateUtils.test.ts +0 -188
  88. package/test/unit/endScreen.test.js +0 -712
  89. package/test/unit/imageSRCBuilder.test.ts +0 -37
  90. package/test/unit/imageSRCVerify.test.ts +0 -155
  91. package/test/unit/infrastructure/DefaultHeaderProvider.test.ts +0 -39
  92. package/test/unit/infrastructure/sanity/ContentClient.test.ts +0 -168
  93. package/test/unit/infrastructure/sanity/DefaultConfigProvider.test.ts +0 -93
  94. package/test/unit/infrastructure/sanity/FetchQueryExecutor.test.ts +0 -174
  95. package/test/unit/infrastructure/sanity/SanityClient.test.ts +0 -140
  96. package/test/unit/lib/__snapshots__/filter.test.ts.snap +0 -5
  97. package/test/unit/lib/filter.test.ts +0 -1154
  98. package/test/unit/lib/lastUpdated.test.ts +0 -21
  99. package/test/unit/lib/query.test.ts +0 -1469
  100. package/test/unit/lib/sanity/decorators/base.test.ts +0 -368
  101. package/test/unit/lib/sanity/decorators/navigate-to.test.ts +0 -361
  102. package/test/unit/lib/sanity/decorators/need-access.test.ts +0 -89
  103. package/test/unit/lib/sanity/decorators/need-lifetime-upgrade.test.ts +0 -85
  104. package/test/unit/lib/sanity/decorators/page-type.test.ts +0 -81
  105. package/test/unit/playerSettings.test.ts +0 -73
  106. package/test/unit/progress-row/content-card.test.ts +0 -314
  107. package/test/unit/progress-row/playlist-card.test.ts +0 -104
  108. package/test/unit/progressRows.test.ts +0 -243
  109. package/test/unit/recommendations.test.js +0 -47
  110. package/test/unit/sanityQueryService.test.ts +0 -200
  111. package/test/unit/search.test.ts +0 -44
  112. package/test/unit/sentry.test.ts +0 -62
  113. package/test/unit/services/progress-internal/bubble.test.ts +0 -279
  114. package/test/unit/services/progress.test.ts +0 -396
  115. package/test/unit/streakMessage.test.ts +0 -251
  116. package/test/unit/sync/context.test.ts +0 -51
  117. package/test/unit/sync/effects/logout-warning.test.ts +0 -158
  118. package/test/unit/sync/effects/push-failure-notification.test.ts +0 -196
  119. package/test/unit/sync/errors/sync-errors.test.ts +0 -106
  120. package/test/unit/sync/errors/validators.test.ts +0 -61
  121. package/test/unit/sync/helpers/TestModel.ts +0 -44
  122. package/test/unit/sync/helpers/index.ts +0 -172
  123. package/test/unit/sync/manager.test.ts +0 -303
  124. package/test/unit/sync/models/user-award-progress.test.ts +0 -82
  125. package/test/unit/sync/resolver.test.ts +0 -229
  126. package/test/unit/sync/retry.test.ts +0 -314
  127. package/test/unit/sync/run-scope.test.ts +0 -23
  128. package/test/unit/sync/stale-record-cleanup.test.ts +0 -107
  129. package/test/unit/sync/store/push-coalescer.test.ts +0 -156
  130. package/test/unit/sync/store-configs.test.ts +0 -37
  131. package/test/unit/sync/telemetry/sync-telemetry.test.ts +0 -118
  132. package/test/unit/sync/utils/event-emitter.test.ts +0 -64
  133. package/test/unit/sync/utils/throttle.test.ts +0 -245
  134. package/test/unit/url-builder.test.ts +0 -72
  135. package/test/unit/user/account.test.ts +0 -66
  136. package/test/unit/user/permissions.test.js +0 -191
@@ -1,712 +0,0 @@
1
- // Mock sync module to prevent TypeScript compilation errors
2
- jest.mock('../../src/services/sync/index.ts', () => ({}))
3
- jest.mock('../../src/services/sync/manager.ts', () => ({}))
4
- jest.mock('../../src/services/sync/models/index.ts', () => ({}))
5
- jest.mock('../../src/services/sync/repositories/index.ts', () => ({}))
6
- jest.mock('../../src/services/sync/database/factory.ts', () => ({}))
7
-
8
- // Mock modules that use sync to prevent compilation errors
9
- jest.mock('../../src/services/user/streakCalculator.ts', () => ({
10
- calculateStreak: jest.fn(),
11
- getStreakMessage: jest.fn()
12
- }))
13
- jest.mock('../../src/services/contentProgress.js', () => ({
14
- ...jest.requireActual('../../src/services/contentProgress'),
15
- }))
16
- jest.mock('../../src/services/contentLikes.js', () => ({
17
- ...jest.requireActual('../../src/services/contentLikes'),
18
- }))
19
- jest.mock('../../src/services/userActivity.js', () => ({
20
- ...jest.requireActual('../../src/services/userActivity'),
21
- }))
22
- jest.mock('../../src/services/content-org/learning-paths.ts', () => ({
23
- enrollInLearningPath: jest.fn(),
24
- getLearningPathProgress: jest.fn()
25
- }))
26
- jest.mock('../../src/services/content-org/guided-courses.ts', () => ({
27
- enrollInGuidedCourse: jest.fn()
28
- }))
29
-
30
- // Mock getSanityDate before other modules load to avoid circular dependency issues
31
- jest.mock('../../src/services/sanity.js', () => ({
32
- ...jest.requireActual('../../src/services/sanity.js'),
33
- getSanityDate: jest.fn((date) => date.toISOString()),
34
- fetchByRailContentIds: jest.fn(),
35
- fetchCourseCollectionData: jest.fn(),
36
- fetchRelatedLessons: jest.fn()
37
- }))
38
-
39
- jest.mock('../../src/services/recommendations.js', () => ({
40
- ...jest.requireActual('../../src/services/recommendations.js'),
41
- fetchSimilarItems: jest.fn(),
42
- rankCategories: jest.fn()
43
- }))
44
-
45
- jest.mock('../../src/services/contentAggregator.js', () => ({
46
- addContextToContent: jest.fn(async (getter) => getter()),
47
- }))
48
-
49
- jest.mock('../../src/services/user/management.js', () => ({
50
- getUserData: jest.fn(async () => ({ is_admin: false }))
51
- }))
52
-
53
- import { getEndScreen } from '../../src/services/endScreen/endScreen.ts'
54
- import * as recommendationsModule from '../../src/services/recommendations.js'
55
- import * as sanityModule from '../../src/services/sanity.js'
56
-
57
- describe('getEndScreen', () => {
58
- beforeEach(() => {
59
- jest.clearAllMocks()
60
- })
61
-
62
- describe('Single Lessons', () => {
63
- test('single lesson without course returns countdown with RecSys recommendation', async () => {
64
- const mockRecommendation = { id: 999, type: 'lesson', title: 'Recommended Lesson', status: 'published' }
65
- mockFetchRecommendation([mockRecommendation])
66
-
67
- const result = await getEndScreen({
68
- lesson: { id: 123, type: 'quick-tips' },
69
- course: null,
70
- collection: null,
71
- brand: 'drumeo'
72
- })
73
-
74
- expect(result).toEqual({
75
- variant: 'countdown-up-next',
76
- upNext: mockRecommendation,
77
- countdownAutoplay: true,
78
- ctaLabels: { primary: 'Play Now', secondary: 'Replay' }
79
- })
80
- expect(recommendationsModule.fetchSimilarItems).toHaveBeenCalledWith(123, 'drumeo', 20)
81
- })
82
-
83
- test('single lesson uses fallback lesson when RecSys returns empty array', async () => {
84
- const fallbackLesson = { id: 373201, type: 'lesson', title: 'Fallback Lesson', status: 'published' }
85
- jest.spyOn(recommendationsModule, 'fetchSimilarItems').mockResolvedValue([])
86
- jest.spyOn(sanityModule, 'fetchRelatedLessons').mockResolvedValue({ related_lessons: [{ id: 373201, status: 'published', type: 'lesson', title: 'Fallback Lesson' }] })
87
- jest.spyOn(sanityModule, 'fetchByRailContentIds').mockResolvedValue([fallbackLesson])
88
-
89
- const result = await getEndScreen({
90
- lesson: { id: 123, type: 'lesson' },
91
- brand: 'drumeo'
92
- })
93
-
94
- expect(result.variant).toBe('countdown-up-next')
95
- expect(result.upNext).toEqual(fallbackLesson)
96
- })
97
-
98
- test('single lesson returns null upNext when RecSys throws error', async () => {
99
- jest.spyOn(recommendationsModule, 'fetchSimilarItems').mockRejectedValue(new Error('API Error'))
100
-
101
- const result = await getEndScreen({
102
- lesson: { id: 123, type: 'lesson' },
103
- brand: 'drumeo'
104
- })
105
-
106
- expect(result.variant).toBe('countdown-up-next')
107
- expect(result.upNext).toBeNull()
108
- })
109
- })
110
-
111
- describe('Single Song Lessons (Play-Along and Jam Tracks)', () => {
112
- test('play-along lesson returns countdown with RecSys recommendation', async () => {
113
- const mockRecommendation = { id: 888, type: 'play-along', title: 'Recommended Play-Along', status: 'published' }
114
- mockFetchRecommendation([mockRecommendation])
115
-
116
- const result = await getEndScreen({
117
- lesson: { id: 456, type: 'play-along' },
118
- course: null,
119
- brand: 'drumeo'
120
- })
121
-
122
- expect(result).toEqual({
123
- variant: 'countdown-up-next',
124
- upNext: mockRecommendation,
125
- countdownAutoplay: true,
126
- ctaLabels: { primary: 'Play Now', secondary: 'Replay' }
127
- })
128
- })
129
-
130
- test('jam track lesson returns countdown with RecSys recommendation', async () => {
131
- const mockRecommendation = { id: 777, type: 'jam-track', title: 'Recommended Jam Track', status: 'published' }
132
- mockFetchRecommendation([mockRecommendation])
133
-
134
- const result = await getEndScreen({
135
- lesson: { id: 789, type: 'jam-track' },
136
- course: null,
137
- brand: 'guitareo'
138
- })
139
-
140
- expect(result).toEqual({
141
- variant: 'countdown-up-next',
142
- upNext: mockRecommendation,
143
- countdownAutoplay: true,
144
- ctaLabels: { primary: 'Play Now', secondary: 'Replay' }
145
- })
146
- })
147
-
148
- test('play-along inside course still uses RecSys (ignores course context)', async () => {
149
- const mockRecommendation = { id: 999, type: 'play-along', status: 'published' }
150
- mockFetchRecommendation([mockRecommendation])
151
-
152
- const result = await getEndScreen({
153
- lesson: { id: 456, type: 'play-along' },
154
- course: { id: 100, children: [{ id: 456 }, { id: 457 }] },
155
- brand: 'drumeo'
156
- })
157
-
158
- expect(result.variant).toBe('countdown-up-next')
159
- expect(result.upNext).toEqual(mockRecommendation)
160
- expect(recommendationsModule.fetchSimilarItems).toHaveBeenCalled()
161
- })
162
- })
163
-
164
- describe('Course - Not Last Lesson', () => {
165
- test('returns next lesson in course with countdown', async () => {
166
- const result = await getEndScreen({
167
- lesson: { id: 200, type: 'course-lesson' },
168
- course: {
169
- id: 100,
170
- children: [
171
- { id: 200, status: 'published' },
172
- { id: 201, status: 'published', title: 'Next Lesson' },
173
- { id: 202, status: 'published' }
174
- ]
175
- },
176
- brand: 'pianote'
177
- })
178
-
179
- expect(result).toEqual({
180
- variant: 'countdown-up-next',
181
- upNext: { id: 201, status: 'published', title: 'Next Lesson' },
182
- countdownAutoplay: true,
183
- ctaLabels: { primary: 'Play Now'}
184
- })
185
- })
186
-
187
- test('skips unreleased lessons and returns next published lesson', async () => {
188
- const result = await getEndScreen({
189
- lesson: { id: 200, type: 'course-lesson' },
190
- course: {
191
- id: 100,
192
- children: [
193
- { id: 200, status: 'published' },
194
- { id: 201, status: 'draft' },
195
- { id: 202, status: 'published', title: 'Next Published Lesson' }
196
- ]
197
- },
198
- brand: 'drumeo'
199
- })
200
-
201
- expect(result.upNext).toEqual({ id: 202, status: 'published', title: 'Next Published Lesson' })
202
- })
203
- })
204
-
205
- describe('Course - Last Lesson (Not in Collection)', () => {
206
- test('returns RecSys recommendation with course-complete variant', async () => {
207
- const mockRecommendation = { id: 888, type: 'course', title: 'Recommended Course', status: 'published' }
208
- mockFetchRecommendation([mockRecommendation])
209
-
210
- const result = await getEndScreen({
211
- lesson: { id: 202, type: 'course-lesson' },
212
- course: {
213
- id: 100,
214
- children: [
215
- { id: 200, status: 'published' },
216
- { id: 201, status: 'published' },
217
- { id: 202, status: 'published' }
218
- ]
219
- },
220
- brand: 'drumeo'
221
- })
222
-
223
- expect(result).toEqual({
224
- variant: 'course-complete',
225
- upNext: mockRecommendation,
226
- countdownAutoplay: false,
227
- ctaLabels: { primary: 'Play Now', secondary: 'Back to Home' }
228
- })
229
- })
230
-
231
- test('last lesson with all remaining lessons being drafts uses RecSys', async () => {
232
- const mockRecommendation = { id: 999, type: 'course', status: 'published' }
233
- mockFetchRecommendation([mockRecommendation])
234
-
235
- const result = await getEndScreen({
236
- lesson: { id: 200, type: 'course-lesson' },
237
- course: {
238
- id: 100,
239
- children: [
240
- { id: 200, status: 'published' },
241
- { id: 201, status: 'draft' },
242
- { id: 202, status: 'draft' }
243
- ]
244
- },
245
- brand: 'drumeo'
246
- })
247
-
248
- expect(result.variant).toBe('course-complete')
249
- expect(result.upNext).toEqual(mockRecommendation)
250
- })
251
- })
252
-
253
- describe('Course Collection - Not Last Lesson in Course', () => {
254
- test('returns next lesson in same course with countdown', async () => {
255
- const result = await getEndScreen({
256
- lesson: { id: 300, type: 'course-lesson' },
257
- course: {
258
- id: 100,
259
- children: [
260
- { id: 300, status: 'published' },
261
- { id: 301, status: 'published', title: 'Next in Course' }
262
- ]
263
- },
264
- collection: {
265
- id: 10,
266
- type: 'course-collection',
267
- children: [
268
- { id: 100, children: [{ id: 300 }, { id: 301 }] },
269
- { id: 101, children: [{ id: 400 }] }
270
- ]
271
- },
272
- brand: 'drumeo'
273
- })
274
-
275
- expect(result).toEqual({
276
- variant: 'countdown-up-next',
277
- upNext: { id: 301, status: 'published', title: 'Next in Course' },
278
- countdownAutoplay: true,
279
- ctaLabels: { primary: 'Play Now'}
280
- })
281
- })
282
- })
283
-
284
- describe('Course Collection - Last Lesson, Not Last Course', () => {
285
- test('returns first lesson of next course with course-complete (no autoplay)', async () => {
286
- const result = await getEndScreen({
287
- lesson: { id: 301, type: 'course-lesson' },
288
- course: {
289
- id: 100,
290
- status: 'published',
291
- children: [
292
- { id: 300, status: 'published' },
293
- { id: 301, status: 'published' }
294
- ]
295
- },
296
- collection: {
297
- id: 10,
298
- type: 'course-collection',
299
- status: 'published',
300
- children: [
301
- { id: 100, status: 'published', children: [{ id: 300, status: 'published' }, { id: 301, status: 'published' }] },
302
- { id: 101, status: 'published', children: [{ id: 400, status: 'published', title: 'First Lesson Next Course' }, { id: 401, status: 'published' }] }
303
- ]
304
- },
305
- brand: 'drumeo'
306
- })
307
-
308
- expect(result).toEqual({
309
- variant: 'course-complete',
310
- upNext: { id: 400, status: 'published', title: 'First Lesson Next Course' },
311
- countdownAutoplay: false,
312
- ctaLabels: { primary: 'Play Now', secondary: 'Back to Home' }
313
- })
314
- })
315
-
316
- test('fetches collection data if children not provided', async () => {
317
- const mockCollectionData = {
318
- id: 10,
319
- type: 'course-collection',
320
- children: [
321
- { id: 100, status: 'published', children: [{ id: 301, status: 'published' }] },
322
- { id: 101, status: 'published', children: [{ id: 400, status: 'published', title: 'Fetched Next Course First Lesson' }] }
323
- ]
324
- }
325
- jest.spyOn(sanityModule, 'fetchCourseCollectionData').mockResolvedValue(mockCollectionData)
326
-
327
- const result = await getEndScreen({
328
- lesson: { id: 301, type: 'course-lesson' },
329
- course: {
330
- id: 100,
331
- children: [{ id: 301 }]
332
- },
333
- collection: {
334
- id: 100,
335
- type: 'course',
336
- parent_id: 10
337
- },
338
- brand: 'drumeo'
339
- })
340
-
341
- expect(sanityModule.fetchCourseCollectionData).toHaveBeenCalledWith(10)
342
- expect(result.upNext).toEqual({ id: 400, status: 'published', title: 'Fetched Next Course First Lesson' })
343
- })
344
- })
345
-
346
- describe('Course Collection - Last Lesson, Last Course', () => {
347
- test('returns RecSys recommendation with course-complete', async () => {
348
- const mockRecommendation = { id: 999, type: 'course', title: 'Recommended After Collection', status: 'published' }
349
- mockFetchRecommendation([mockRecommendation])
350
-
351
- const result = await getEndScreen({
352
- lesson: { id: 401, type: 'course-lesson' },
353
- course: {
354
- id: 101,
355
- children: [
356
- { id: 400, status: 'published' },
357
- { id: 401, status: 'published' }
358
- ]
359
- },
360
- collection: {
361
- id: 10,
362
- type: 'course-collection',
363
- children: [
364
- { id: 100, children: [{ id: 300 }, { id: 301 }] },
365
- { id: 101, children: [{ id: 400 }, { id: 401 }] }
366
- ]
367
- },
368
- brand: 'drumeo'
369
- })
370
-
371
- expect(result).toEqual({
372
- variant: 'course-complete',
373
- upNext: mockRecommendation,
374
- countdownAutoplay: false,
375
- ctaLabels: { primary: 'Play Now', secondary: 'Back to Home' }
376
- })
377
- })
378
- })
379
-
380
- describe('Playlists', () => {
381
- test('returns next item in playlist with countdown', async () => {
382
- const result = await getEndScreen({
383
- lesson: { id: 500, type: 'lesson' },
384
- playlist: {
385
- id: 10,
386
- items: [
387
- { id: 500, status: 'published' },
388
- { id: 501, status: 'published', title: 'Next in Playlist' },
389
- { id: 502, status: 'published' }
390
- ]
391
- },
392
- brand: 'drumeo'
393
- })
394
-
395
- expect(result).toEqual({
396
- variant: 'countdown-up-next',
397
- upNext: { id: 501, status: 'published', title: 'Next in Playlist' },
398
- countdownAutoplay: true,
399
- ctaLabels: { primary: 'Play Now'}
400
- })
401
- })
402
-
403
- test('skips unreleased items in playlist', async () => {
404
- const result = await getEndScreen({
405
- lesson: { id: 500, type: 'lesson' },
406
- playlist: {
407
- id: 10,
408
- items: [
409
- { id: 500, status: 'published' },
410
- { id: 501, status: 'draft' },
411
- { id: 502, status: 'published', title: 'Next Published in Playlist' }
412
- ]
413
- },
414
- brand: 'drumeo'
415
- })
416
-
417
- expect(result.upNext).toEqual({ id: 502, status: 'published', title: 'Next Published in Playlist' })
418
- })
419
-
420
- test('handles playlist with empty items array', async () => {
421
- const result = await getEndScreen({
422
- lesson: { id: 500, type: 'lesson' },
423
- playlist: { id: 10, items: [] },
424
- brand: 'drumeo'
425
- })
426
-
427
- expect(result).toBeNull()
428
- })
429
-
430
- test('handles playlist with undefined items', async () => {
431
- const result = await getEndScreen({
432
- lesson: { id: 500, type: 'lesson' },
433
- playlist: { id: 10 },
434
- brand: 'drumeo'
435
- })
436
-
437
- expect(result).toBeNull()
438
- })
439
-
440
- test('handles item not found in playlist', async () => {
441
- const result = await getEndScreen({
442
- lesson: { id: 999, type: 'lesson' },
443
- playlist: {
444
- id: 10,
445
- items: [{ id: 500 }, { id: 501 }]
446
- },
447
- brand: 'drumeo'
448
- })
449
-
450
- expect(result).toBeNull()
451
- })
452
-
453
- test('transcriptions in playlist still show end screen', async () => {
454
- const result = await getEndScreen({
455
- lesson: { id: 500, type: 'lesson' },
456
- playlist: {
457
- id: 10,
458
- items: [
459
- { id: 500, type: 'lesson', status: 'published' },
460
- { id: 501, type: 'transcription', status: 'published', title: 'Transcription Next' }
461
- ]
462
- },
463
- brand: 'drumeo'
464
- })
465
-
466
- expect(result.upNext).toEqual({ id: 501, type: 'transcription', status: 'published', title: 'Transcription Next' })
467
- })
468
-
469
- test('uses user_playlist_item_index directly instead of searching by lesson id', async () => {
470
- const result = await getEndScreen({
471
- lesson: { id: 999, type: 'lesson' },
472
- playlist: {
473
- id: 10,
474
- items: [
475
- { id: 500, status: 'published' },
476
- { id: 501, status: 'published', title: 'Next in Playlist' },
477
- { id: 502, status: 'published' }
478
- ]
479
- },
480
- user_playlist_item_index: 0,
481
- brand: 'drumeo'
482
- })
483
-
484
- expect(result).toEqual({
485
- variant: 'countdown-up-next',
486
- upNext: { id: 501, status: 'published', title: 'Next in Playlist' },
487
- countdownAutoplay: true,
488
- ctaLabels: { primary: 'Play Now'}
489
- })
490
- })
491
-
492
- test('user_playlist_item_index 0 is treated as valid index, not falsy', async () => {
493
- const result = await getEndScreen({
494
- lesson: { id: 999, type: 'lesson' },
495
- playlist: {
496
- id: 10,
497
- items: [{ id: 500, status: 'published' }]
498
- },
499
- user_playlist_item_index: 0,
500
- brand: 'drumeo'
501
- })
502
-
503
- expect(result).toBeNull()
504
- })
505
- })
506
-
507
- describe('Edge Cases', () => {
508
- test('handles course with empty children array', async () => {
509
- const mockRecommendation = { id: 999, type: 'course', status: 'published' }
510
- mockFetchRecommendation([mockRecommendation])
511
-
512
- const result = await getEndScreen({
513
- lesson: { id: 123, type: 'course-lesson' },
514
- course: { id: 100, children: [] },
515
- brand: 'drumeo'
516
- })
517
-
518
- expect(result.variant).toBe('course-complete')
519
- expect(result.upNext).toEqual(mockRecommendation)
520
- })
521
-
522
- test('handles course with undefined children', async () => {
523
- const mockRecommendation = { id: 999, type: 'course', status: 'published' }
524
- mockFetchRecommendation([mockRecommendation])
525
-
526
- const result = await getEndScreen({
527
- lesson: { id: 123, type: 'course-lesson' },
528
- course: { id: 100 },
529
- brand: 'drumeo'
530
- })
531
-
532
- expect(result.variant).toBe('course-complete')
533
- })
534
-
535
- test('handles lesson not found in course children', async () => {
536
- const mockRecommendation = { id: 999, type: 'course', status: 'published' }
537
- mockFetchRecommendation([mockRecommendation])
538
-
539
- const result = await getEndScreen({
540
- lesson: { id: 999, type: 'course-lesson' },
541
- course: {
542
- id: 100,
543
- children: [{ id: 200 }, { id: 201 }]
544
- },
545
- brand: 'drumeo'
546
- })
547
-
548
- expect(result.variant).toBe('course-complete')
549
- expect(result.upNext).toEqual(mockRecommendation)
550
- })
551
-
552
- test('handles collection with empty children', async () => {
553
- const mockRecommendation = { id: 999, type: 'course', status: 'published' }
554
- mockFetchRecommendation([mockRecommendation])
555
-
556
- const result = await getEndScreen({
557
- lesson: { id: 301, type: 'course-lesson' },
558
- course: {
559
- id: 100,
560
- children: [{ id: 301 }]
561
- },
562
- collection: {
563
- id: 10,
564
- type: 'course-collection',
565
- children: []
566
- },
567
- brand: 'drumeo'
568
- })
569
-
570
- expect(result.variant).toBe('course-complete')
571
- })
572
-
573
- test('handles collection with undefined children', async () => {
574
- const mockRecommendation = { id: 999, type: 'course', status: 'published' }
575
- mockFetchRecommendation([mockRecommendation])
576
-
577
- const result = await getEndScreen({
578
- lesson: { id: 301, type: 'course-lesson' },
579
- course: {
580
- id: 100,
581
- children: [{ id: 301 }]
582
- },
583
- collection: {
584
- id: 10,
585
- type: 'course-collection'
586
- },
587
- brand: 'drumeo'
588
- })
589
-
590
- expect(result.variant).toBe('course-complete')
591
- })
592
-
593
- test('handles course not found in collection children', async () => {
594
- const mockRecommendation = { id: 999, type: 'course', status: 'published' }
595
- mockFetchRecommendation([mockRecommendation])
596
-
597
- const result = await getEndScreen({
598
- lesson: { id: 301, type: 'course-lesson' },
599
- course: {
600
- id: 999,
601
- children: [{ id: 301 }]
602
- },
603
- collection: {
604
- id: 10,
605
- type: 'course-collection',
606
- children: [{ id: 100, children: [{ id: 300 }] }]
607
- },
608
- brand: 'drumeo'
609
- })
610
-
611
- expect(result.variant).toBe('course-complete')
612
- })
613
-
614
- test('handles next course with empty children', async () => {
615
- const mockRecommendation = { id: 999, type: 'course', status: 'published' }
616
- mockFetchRecommendation([mockRecommendation])
617
-
618
- const result = await getEndScreen({
619
- lesson: { id: 301, type: 'course-lesson' },
620
- course: {
621
- id: 100,
622
- children: [{ id: 301 }]
623
- },
624
- collection: {
625
- id: 10,
626
- type: 'course-collection',
627
- children: [
628
- { id: 100, children: [{ id: 301 }] },
629
- { id: 101, children: [] }
630
- ]
631
- },
632
- brand: 'drumeo'
633
- })
634
-
635
- expect(result.variant).toBe('course-complete')
636
- expect(result.upNext).toEqual(mockRecommendation)
637
- })
638
-
639
- test('handles next course with undefined children', async () => {
640
- const mockRecommendation = { id: 999, type: 'course' }
641
- mockFetchRecommendation([mockRecommendation])
642
-
643
- const result = await getEndScreen({
644
- lesson: { id: 301, type: 'course-lesson' },
645
- course: {
646
- id: 100,
647
- children: [{ id: 301 }]
648
- },
649
- collection: {
650
- id: 10,
651
- type: 'course-collection',
652
- children: [
653
- { id: 100, children: [{ id: 301 }] },
654
- { id: 101 }
655
- ]
656
- },
657
- brand: 'drumeo'
658
- })
659
-
660
- expect(result.variant).toBe('course-complete')
661
- })
662
-
663
- test('handles non-course-collection collection type', async () => {
664
- const mockRecommendation = { id: 999, type: 'course' }
665
- mockFetchRecommendation([mockRecommendation])
666
-
667
- const result = await getEndScreen({
668
- lesson: { id: 301, type: 'course-lesson' },
669
- course: {
670
- id: 100,
671
- children: [{ id: 301 }]
672
- },
673
- collection: {
674
- id: 10,
675
- type: 'learning-path',
676
- children: [{ id: 100 }, { id: 101 }]
677
- },
678
- brand: 'drumeo'
679
- })
680
-
681
- expect(result.variant).toBe('course-complete')
682
- })
683
-
684
- test('RecSys filters out lessons from the same course (parent_id === excludeId)', async () => {
685
- // Course 100 is finished (lesson 301 is last). excludeId = course.id = 100.
686
- // id 888 belongs to course 100 → filtered out. id 999 has no parent → returned.
687
- const mockContents = [
688
- { id: 888, parent_id: 100, type: 'course-lesson' },
689
- { id: 999, type: 'course', title: 'Standalone Course', status: 'published' }
690
- ]
691
- jest.spyOn(recommendationsModule, 'fetchSimilarItems').mockResolvedValue([888, 999])
692
- jest.spyOn(sanityModule, 'fetchByRailContentIds').mockResolvedValue(mockContents)
693
-
694
- const result = await getEndScreen({
695
- lesson: { id: 301, type: 'course-lesson' },
696
- course: { id: 100, children: [{ id: 301 }] },
697
- brand: 'drumeo'
698
- })
699
-
700
- expect(result.variant).toBe('course-complete')
701
- expect(result.upNext).toEqual({ id: 999, type: 'course', title: 'Standalone Course', status: 'published'})
702
- })
703
-
704
- })
705
- })
706
-
707
- function mockFetchRecommendation(contents) {
708
- const ids = contents.map(c => c.id)
709
- jest.spyOn(recommendationsModule, 'fetchSimilarItems').mockResolvedValue(ids)
710
- jest.spyOn(recommendationsModule, 'rankCategories').mockResolvedValue([{ slug: 'recommended', items: ids }])
711
- jest.spyOn(sanityModule, 'fetchByRailContentIds').mockResolvedValue(contents)
712
- }