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,314 +0,0 @@
1
- import {
2
- getSubtitle,
3
- getDefaultCTATextForContent,
4
- } from '../../../src/services/progress-row/rows/content-card.js'
5
-
6
- describe('getSubtitle', () => {
7
- describe('parent lesson types', () => {
8
- test.each([
9
- 'course',
10
- 'guided-course',
11
- 'course-collection',
12
- 'song-tutorial',
13
- 'learning-path-v2',
14
- 'skill-pack',
15
- ])('returns "X of Y Lessons Complete" for type %s', (type) => {
16
- const content = {
17
- type,
18
- completed_children: 3,
19
- all_children: 10,
20
- }
21
- expect(getSubtitle(content, 'course', false)).toBe('3 of 10 Lessons Complete')
22
- })
23
-
24
- test('uses 0 when completed_children is missing', () => {
25
- const content = { type: 'course', all_children: 8 }
26
- expect(getSubtitle(content, 'course', false)).toBe('0 of 8 Lessons Complete')
27
- })
28
-
29
- test('falls back to lesson_count when all_children missing', () => {
30
- const content = { type: 'course', completed_children: 2, lesson_count: 5 }
31
- expect(getSubtitle(content, 'course', false)).toBe('2 of 5 Lessons Complete')
32
- })
33
-
34
- test('falls back to child_count when all_children and lesson_count missing', () => {
35
- const content = { type: 'course', completed_children: 1, child_count: 4 }
36
- expect(getSubtitle(content, 'course', false)).toBe('1 of 4 Lessons Complete')
37
- })
38
-
39
- test('prefers all_children over lesson_count and child_count', () => {
40
- const content = {
41
- type: 'course',
42
- completed_children: 1,
43
- all_children: 9,
44
- lesson_count: 5,
45
- child_count: 7,
46
- }
47
- expect(getSubtitle(content, 'course', false)).toBe('1 of 9 Lessons Complete')
48
- })
49
-
50
- test('returns null when all count fields missing', () => {
51
- const content = { type: 'course', completed_children: 2 }
52
- expect(getSubtitle(content, 'course', false)).toBeNull()
53
- })
54
- })
55
-
56
- describe('lesson_count > 1', () => {
57
- test('returns "X of Y Lessons Complete" when lesson_count > 1 even for non-parent type', () => {
58
- const content = {
59
- type: 'song',
60
- completed_children: 2,
61
- all_children: 6,
62
- lesson_count: 6,
63
- }
64
- expect(getSubtitle(content, 'song', false)).toBe('2 of 6 Lessons Complete')
65
- })
66
-
67
- test('does not trigger when lesson_count is 1', () => {
68
- const content = {
69
- type: 'song',
70
- lesson_count: 1,
71
- difficulty_string: 'Beginner',
72
- artist_name: 'Artist',
73
- }
74
- expect(getSubtitle(content, 'song', false)).toBe('Beginner • Artist')
75
- })
76
-
77
- test('does not trigger when lesson_count is 0', () => {
78
- const content = {
79
- type: 'song',
80
- lesson_count: 0,
81
- difficulty_string: 'Intermediate',
82
- artist_name: 'Band',
83
- }
84
- expect(getSubtitle(content, 'song', false)).toBe('Intermediate • Band')
85
- })
86
- })
87
-
88
- describe('lesson and show contentType', () => {
89
- test('returns "X% Complete" for lesson when not live', () => {
90
- const content = { type: 'course-lesson', progressPercentage: 42 }
91
- expect(getSubtitle(content, 'lesson', false)).toBe('42% Complete')
92
- })
93
-
94
- test('returns "X% Complete" for show when not live', () => {
95
- const content = { type: 'show', progressPercentage: 75 }
96
- expect(getSubtitle(content, 'show', false)).toBe('75% Complete')
97
- })
98
-
99
- test('returns "0% Complete" when progressPercentage is 0', () => {
100
- const content = { type: 'course-lesson', progressPercentage: 0 }
101
- expect(getSubtitle(content, 'lesson', false)).toBe('0% Complete')
102
- })
103
-
104
- test('returns null when progressPercentage missing for lesson', () => {
105
- const content = { type: 'course-lesson' }
106
- expect(getSubtitle(content, 'lesson', false)).toBeNull()
107
- })
108
-
109
- test('returns null when progressPercentage missing for show', () => {
110
- const content = { type: 'show' }
111
- expect(getSubtitle(content, 'show', false)).toBeNull()
112
- })
113
-
114
- test('falls through to difficulty/artist when lesson isLive=true', () => {
115
- const content = {
116
- type: 'course-lesson',
117
- progressPercentage: 80,
118
- difficulty_string: 'Advanced',
119
- artist_name: 'Live Artist',
120
- }
121
- expect(getSubtitle(content, 'lesson', true)).toBe('Advanced • Live Artist')
122
- })
123
-
124
- test('falls through to difficulty/artist when show isLive=true', () => {
125
- const content = {
126
- type: 'show',
127
- progressPercentage: 50,
128
- difficulty_string: 'Beginner',
129
- artist_name: 'Live Show',
130
- }
131
- expect(getSubtitle(content, 'show', true)).toBe('Beginner • Live Show')
132
- })
133
- })
134
-
135
- describe('default difficulty/artist subtitle', () => {
136
- test('returns "difficulty • artist" for song', () => {
137
- const content = {
138
- type: 'song',
139
- difficulty_string: 'Intermediate',
140
- artist_name: 'The Beatles',
141
- }
142
- expect(getSubtitle(content, 'song', false)).toBe('Intermediate • The Beatles')
143
- })
144
-
145
- test('returns null when both difficulty and artist missing', () => {
146
- const content = { type: 'song' }
147
- expect(getSubtitle(content, 'song', false)).toBeNull()
148
- })
149
-
150
- test('returns difficulty only when artist missing', () => {
151
- const content = { type: 'song', difficulty_string: 'Beginner' }
152
- expect(getSubtitle(content, 'song', false)).toBe('Beginner')
153
- })
154
-
155
- test('returns artist only when difficulty missing', () => {
156
- const content = { type: 'song', artist_name: 'The Beatles' }
157
- expect(getSubtitle(content, 'song', false)).toBe('The Beatles')
158
- })
159
- })
160
-
161
- describe('priority ordering', () => {
162
- test('parent-type rule wins over lesson contentType', () => {
163
- const content = {
164
- type: 'course',
165
- completed_children: 4,
166
- all_children: 12,
167
- progressPercentage: 33,
168
- }
169
- expect(getSubtitle(content, 'lesson', false)).toBe('4 of 12 Lessons Complete')
170
- })
171
-
172
- test('lesson_count>1 rule wins over lesson contentType', () => {
173
- const content = {
174
- type: 'song',
175
- lesson_count: 3,
176
- completed_children: 1,
177
- all_children: 3,
178
- progressPercentage: 33,
179
- }
180
- expect(getSubtitle(content, 'lesson', false)).toBe('1 of 3 Lessons Complete')
181
- })
182
- })
183
- })
184
-
185
- describe('getDefaultCTATextForContent', () => {
186
- describe('guided-course not started', () => {
187
- test('returns "Start Course" when progressStatus is undefined', () => {
188
- const content = { type: 'guided-course' }
189
- expect(getDefaultCTATextForContent(content, 'guided course')).toBe('Start Course')
190
- })
191
-
192
- test('returns "Start Course" when progressStatus is "not-started"', () => {
193
- const content = { type: 'guided-course', progressStatus: 'not-started' }
194
- expect(getDefaultCTATextForContent(content, 'guided course')).toBe('Start Course')
195
- })
196
-
197
- test('returns "Start Course" when progressPercentage is 0', () => {
198
- const content = {
199
- type: 'guided-course',
200
- progressStatus: 'started',
201
- progressPercentage: 0,
202
- }
203
- expect(getDefaultCTATextForContent(content, 'guided course')).toBe('Start Course')
204
- })
205
-
206
- test('returns "Continue" when guided-course is in-progress', () => {
207
- const content = {
208
- type: 'guided-course',
209
- progressStatus: 'started',
210
- progressPercentage: 25,
211
- }
212
- expect(getDefaultCTATextForContent(content, 'guided course')).toBe('Continue')
213
- })
214
- })
215
-
216
- describe('completed - song variants', () => {
217
- test.each([
218
- ['drumeo', 'transcription'],
219
- ['guitareo', 'tab'],
220
- ['pianote', 'sheet music'],
221
- ['singeo', 'sheet music'],
222
- ['playbass', 'tab'],
223
- ])('returns "Replay Song" when completed for brand %s with song contentType %s', (brand, contentType) => {
224
- const content = { type: 'song', brand, progressStatus: 'completed' }
225
- expect(getDefaultCTATextForContent(content, contentType)).toBe('Replay Song')
226
- })
227
-
228
- test('returns "Replay Song" when completed and contentType is "play along"', () => {
229
- const content = { type: 'play-along', brand: 'drumeo', progressStatus: 'completed' }
230
- expect(getDefaultCTATextForContent(content, 'play along')).toBe('Replay Song')
231
- })
232
-
233
- test('returns "Replay Song" when completed and contentType is "jam track"', () => {
234
- const content = { type: 'jam-track', brand: 'drumeo', progressStatus: 'completed' }
235
- expect(getDefaultCTATextForContent(content, 'jam track')).toBe('Replay Song')
236
- })
237
-
238
- test('does not return "Replay Song" when brand song contentType mismatches', () => {
239
- const content = { type: 'song', brand: 'drumeo', progressStatus: 'completed' }
240
- expect(getDefaultCTATextForContent(content, 'tab')).toBe('Continue')
241
- })
242
- })
243
-
244
- describe('completed - lesson/show', () => {
245
- test('returns "Revisit Lesson" when completed lesson', () => {
246
- const content = { type: 'course-lesson', progressStatus: 'completed' }
247
- expect(getDefaultCTATextForContent(content, 'lesson')).toBe('Revisit Lesson')
248
- })
249
-
250
- test('returns "Revisit Lesson" when completed show', () => {
251
- const content = { type: 'show', progressStatus: 'completed' }
252
- expect(getDefaultCTATextForContent(content, 'show')).toBe('Revisit Lesson')
253
- })
254
- })
255
-
256
- describe('completed - parent lesson types', () => {
257
- test.each([
258
- 'course',
259
- 'guided-course',
260
- 'course-collection',
261
- 'song-tutorial',
262
- 'learning-path-v2',
263
- 'skill-pack',
264
- ])('returns "Revisit Lessons" when completed for type %s', (type) => {
265
- const content = { type, progressStatus: 'completed' }
266
- expect(getDefaultCTATextForContent(content, 'course')).toBe('Revisit Lessons')
267
- })
268
- })
269
-
270
- describe('completed - other', () => {
271
- test('returns "Continue" when completed and no rule matches', () => {
272
- const content = { type: 'some-type', progressStatus: 'completed' }
273
- expect(getDefaultCTATextForContent(content, 'unknown')).toBe('Continue')
274
- })
275
- })
276
-
277
- describe('default fallback', () => {
278
- test('returns "Continue" when no progressStatus for non-guided-course', () => {
279
- const content = { type: 'song' }
280
- expect(getDefaultCTATextForContent(content, 'song')).toBe('Continue')
281
- })
282
-
283
- test('returns "Continue" when progressStatus is "started"', () => {
284
- const content = {
285
- type: 'course-lesson',
286
- progressStatus: 'started',
287
- progressPercentage: 50,
288
- }
289
- expect(getDefaultCTATextForContent(content, 'lesson')).toBe('Continue')
290
- })
291
-
292
- test('returns "Continue" when not-started and not guided-course', () => {
293
- const content = { type: 'course-lesson', progressStatus: 'not-started' }
294
- expect(getDefaultCTATextForContent(content, 'lesson')).toBe('Continue')
295
- })
296
- })
297
-
298
- describe('priority ordering', () => {
299
- test('guided-course not-started wins even when contentType is lesson', () => {
300
- const content = { type: 'guided-course', progressPercentage: 0 }
301
- expect(getDefaultCTATextForContent(content, 'lesson')).toBe('Start Course')
302
- })
303
-
304
- test('completed song-match wins over completed lesson contentType', () => {
305
- const content = { type: 'song', brand: 'drumeo', progressStatus: 'completed' }
306
- expect(getDefaultCTATextForContent(content, 'transcription')).toBe('Replay Song')
307
- })
308
-
309
- test('completed lesson contentType wins over parent-type rule', () => {
310
- const content = { type: 'course', progressStatus: 'completed' }
311
- expect(getDefaultCTATextForContent(content, 'lesson')).toBe('Revisit Lesson')
312
- })
313
- })
314
- })
@@ -1,104 +0,0 @@
1
- import { processPlaylistItem, getRecentPlaylists, getPlaylistEngagedOnContent } from '../../../src/services/progress-row/rows/playlist-card.js'
2
- jest.mock('../../../src/services/content-org/playlists.js', () => ({
3
- fetchUserPlaylists: jest.fn(),
4
- }))
5
- jest.mock('../../../src/services/sanity.js', () => ({
6
- ...jest.requireActual('../../../src/services/sanity.js'),
7
- fetchByRailContentIds: jest.fn(),
8
- }))
9
- jest.mock('../../../src/services/contentAggregator.js', () => ({
10
- addContextToContent: jest.fn(),
11
- }))
12
- import { fetchUserPlaylists } from '../../../src/services/content-org/playlists.js'
13
- const mockPlaylistItem = {
14
- pinned: false,
15
- progressTimestamp: 1234567890,
16
- playlist: {
17
- id: 1,
18
- name: 'My Playlist',
19
- brand: 'drumeo',
20
- duration_formated: '1h 30m',
21
- total_items: 10,
22
- likes: 5,
23
- first_items_thumbnail_url: [
24
- {
25
- thumbnail: 'https://cdn.example.com/thumb.jpg',
26
- type: 'song',
27
- artist_name: 'Kiss',
28
- title: "Mwaa"
29
- }
30
- ],
31
- navigateTo: { id: 42, content_id: 99 },
32
- user: { display_name: 'John Doe' },
33
- },
34
- }
35
- describe('processPlaylistItem', () => {
36
- test('returns correctly shaped object from playlist item', () => {
37
- const result = processPlaylistItem(mockPlaylistItem)
38
- expect(result).toMatchObject({
39
- id: 1,
40
- progressType: 'playlist',
41
- header: 'playlist',
42
- pinned: false,
43
- progressTimestamp: 1234567890,
44
- cta: {
45
- text: 'Continue',
46
- action: {
47
- brand: 'drumeo',
48
- item_id: 42,
49
- content_id: 99,
50
- type: 'playlists',
51
- id: 1,
52
- },
53
- },
54
- })
55
- })
56
- test('pinned defaults to false when not set', () => {
57
- const item = { ...mockPlaylistItem, pinned: undefined }
58
- const result = processPlaylistItem(item)
59
- expect(result.pinned).toBe(false)
60
- })
61
- test('pinned is true when set', () => {
62
- const item = { ...mockPlaylistItem, pinned: true }
63
- const result = processPlaylistItem(item)
64
- expect(result.pinned).toBe(true)
65
- })
66
- test('subtitle combines duration, total_items, likes and display_name', () => {
67
- const result = processPlaylistItem(mockPlaylistItem)
68
- expect(result.body.subtitle).toBe('1h 30m • 10 items • 5 likes • John Doe')
69
- })
70
- })
71
- describe('getRecentPlaylists', () => {
72
- test('filters out playlists with no last_progress', async () => {
73
- (fetchUserPlaylists as jest.Mock).mockResolvedValue({
74
- data: [
75
- { id: 1, last_progress: '2024-01-01 10:00:00', last_engaged_on: 123 },
76
- { id: 2, last_progress: null, last_engaged_on: 123 },
77
- ]
78
- })
79
- const result = await getRecentPlaylists('drumeo', 10)
80
- expect(result).toHaveLength(1)
81
- expect(result[0].id).toBe(1)
82
- })
83
- test('converts last_progress date string to UTC timestamp', async () => {
84
- (fetchUserPlaylists as jest.Mock).mockResolvedValue({
85
- data: [
86
- { id: 1, last_progress: '2024-01-01 10:00:00', last_engaged_on: 123 },
87
- ]
88
- })
89
- const result = await getRecentPlaylists('drumeo', 10)
90
- expect(typeof result[0].progressTimestamp).toBe('number')
91
- expect(result[0].progressTimestamp).toBe(new Date('2024-01-01T10:00:00Z').getTime())
92
- })
93
- test('returns empty array when response has no data', async () => {
94
- (fetchUserPlaylists as jest.Mock).mockResolvedValue({ data: [] })
95
- const result = await getRecentPlaylists('drumeo', 10)
96
- expect(result).toHaveLength(0)
97
- })
98
- })
99
- describe('getPlaylistEngagedOnContent', () => {
100
- test('returns empty array when recentPlaylists is empty', async () => {
101
- const result = await getPlaylistEngagedOnContent([])
102
- expect(result).toEqual([])
103
- })
104
- })
@@ -1,243 +0,0 @@
1
- import { getProgressRows } from '../../src/services/progress-row/base.js';
2
- import { fetchUserPlaylists } from '../../src/services/content-org/playlists.js';
3
- import { fetchByRailContentIds } from '../../src/services/sanity.js';
4
- import {getAllStartedOrCompleted, getProgressStateByIds} from '../../src/services/contentProgress.js';
5
- import { initializeTestService } from '../initializeTests.js';
6
- import mockData_progress_content from '../mockData/mockData_progress_content.json';
7
- import mockData_sanity_progress_content from "../mockData/mockData_sanity_progress_content.json";
8
-
9
- jest.mock('../../src/services/progress-row/rows/method-card.js', () => ({
10
- getMethodCard: jest.fn().mockResolvedValue(null),
11
- }))
12
-
13
- jest.mock('../../src/services/sync/repository-proxy.ts', () => {
14
- const mockFns = {
15
- contentProgress: {
16
- pull: jest.fn().mockResolvedValue(undefined),
17
- getSomeProgressByContentIds: jest.fn().mockResolvedValue({ data: [] }),
18
- }
19
- }
20
- return { default: mockFns, ...mockFns }
21
- })
22
-
23
- jest.mock('../../src/infrastructure/http/HttpClient.ts', () => ({
24
- GET: jest.fn().mockResolvedValue(null),
25
- PUT: jest.fn().mockResolvedValue(null),
26
- POST: jest.fn().mockResolvedValue(null),
27
- PATCH: jest.fn().mockResolvedValue(null),
28
- DELETE: jest.fn().mockResolvedValue(null),
29
- HttpClient: jest.fn(),
30
- }))
31
-
32
- jest.mock('../../src/services/content-org/playlists.js');
33
- jest.mock('../../src/services/sanity.js', () => ({
34
- ...jest.requireActual('../../src/services/sanity'),
35
- fetchByRailContentIds: jest.fn(),
36
- }));
37
- jest.mock('../../src/services/contentProgress.js', () => ({
38
- ...jest.requireActual('../../src/services/contentProgress'),
39
- getAllStartedOrCompleted: jest.fn(),
40
- getProgressStateByIds: jest.fn(),
41
- }));
42
-
43
- describe('getProgressRows', () => {
44
- beforeEach(() => {
45
- jest.clearAllMocks();
46
- initializeTestService();
47
- });
48
-
49
- it('returns progress rows successfully', async () => {
50
- const mockPlaylists = [
51
- {
52
- id: 1,
53
- name: 'Playlist 1',
54
- last_progress: '2025-05-19 10:00:00',
55
- last_engaged_on: 101,
56
- items: [{ content_id: 201 }],
57
- duration_formated: '10m',
58
- total_items: 1,
59
- likes: 100,
60
- user: { display_name: 'User1' },
61
- brand: 'brand1',
62
- first_items_thumbnail_url: 'url1',
63
- navigateTo: { id: null, content_id: null },
64
- },
65
- ];
66
-
67
- const mockPlaylistContents = [
68
- {
69
- id: 201,
70
- railcontent_id: 201,
71
- parent_content_data: [],
72
- type: 'play-along',
73
- thumbnail: 'thumb1',
74
- title: 'Lesson 1',
75
- difficulty_string: 'Easy',
76
- artist_name: 'Artist 1',
77
- lesson_count: 1,
78
- completed_children: 0,
79
- brand: 'brand1',
80
- slug: 'lesson-1',
81
- },
82
- ];
83
-
84
- fetchUserPlaylists.mockResolvedValue({ data: mockPlaylists })
85
- fetchByRailContentIds.mockResolvedValue(mockPlaylistContents)
86
- getAllStartedOrCompleted.mockResolvedValue([201])
87
- getProgressStateByIds.mockResolvedValue({ '201': 'in_progress' })
88
-
89
- const result = await getProgressRows({ brand: 'brand1', limit: 8 })
90
-
91
- expect(result).toHaveProperty('type', 'progress_rows')
92
- expect(result).toHaveProperty('data');
93
- expect(Array.isArray(result.data)).toBe(true)
94
- expect(result.data.length).toBe(2)
95
- expect(result.data[0]).toHaveProperty('id')
96
- expect(result.data[0]).toHaveProperty('progressType')
97
- expect(result.data[0]).toHaveProperty('header')
98
- expect(result.data[0]).toHaveProperty('body')
99
- expect(result.data[0]).toHaveProperty('cta')
100
- expect(result.data[0].progressType).toBe('playlist')
101
- expect(result.data[0].body).toHaveProperty('first_items_thumbnail_url')
102
- expect(result.data[0].body).toHaveProperty('title')
103
- expect(result.data[0].body).toHaveProperty('subtitle')
104
- expect(result.data[0].cta).toHaveProperty('text')
105
- expect(result.data[0].cta).toHaveProperty('action')
106
-
107
- });
108
-
109
- it('handles no progress', async () => {
110
- fetchUserPlaylists.mockResolvedValue({ data: [] });
111
- getAllStartedOrCompleted.mockResolvedValue([]);
112
- fetchByRailContentIds.mockResolvedValue([]);
113
- getProgressStateByIds.mockResolvedValue({});
114
-
115
- const result = await getProgressRows({ brand: 'brand1', limit: 8 });
116
- expect(result).toHaveProperty('type', 'progress_rows');
117
- expect(result.data).toEqual([]);
118
- });
119
-
120
- it.skip('check progress rows logic', async () => {
121
- // SKIPPED: Sanity mock data for course 280498 has empty children array.
122
- // getNavigateTo returns null child — mock data needs children populated to test navigate-to logic.
123
- fetchUserPlaylists.mockResolvedValue({ data: [] });
124
- fetchByRailContentIds
125
- .mockImplementationOnce(() => Promise.resolve(mockData_sanity_progress_content));
126
- const sortedIds = Object.entries(mockData_progress_content)
127
- .sort(([, a], [, b]) => b.last_update - a.last_update)
128
- .map(([id]) => Number(id))
129
- getAllStartedOrCompleted.mockResolvedValue(sortedIds)
130
- getProgressStateByIds
131
- .mockImplementationOnce(() => Promise.resolve({
132
- "287853": "completed",
133
- "287854": "completed",
134
- "287855": "completed",
135
- "287858": "completed",
136
- "287859": ""
137
- })) // course lessons
138
- .mockImplementationOnce(() => Promise.resolve({
139
- "257243": "started",
140
- "257245": "started",
141
- "257246": "",
142
- "257247": "",
143
- "257248": "",
144
- "257249": "completed",
145
- "257250": "completed",
146
- "257251": "",
147
- "257252": "",
148
- "257253": "",
149
- "257254": "",
150
- "257255": "",
151
- "257256": "",
152
- "257257": "",
153
- "257258": "",
154
- "257259": "",
155
- "257260": "",
156
- "259235": "",
157
- "259236": ""
158
- })) //pack
159
- .mockImplementationOnce(() => Promise.resolve({
160
- "410479": "",
161
- "410480": "completed",
162
- "410481": "completed",
163
- "410482": "",
164
- "410483": "",
165
- "410484": "",
166
- "410485": "",
167
- "410486": "",
168
- "410487": ""
169
- }) // challenge
170
- );
171
-
172
-
173
- const result = await getProgressRows({ brand: 'brand1', limit: 8 });
174
- expect(fetchByRailContentIds).toHaveBeenCalledTimes(1);
175
-
176
- expect(result).toHaveProperty('type', 'progress_rows');
177
- expect(result.data.length).toBeGreaterThan(0);
178
- expect(result.data.length).toBeLessThanOrEqual(8);
179
- //course 280498
180
- const lesson1Progress = result.data.find(row => row.id === 280498);
181
- expect(lesson1Progress).toBeDefined();
182
- expect(lesson1Progress.cta).toHaveProperty('text');
183
- expect(lesson1Progress.cta.text.toLowerCase()).toContain('continue');
184
- expect(lesson1Progress.cta.action).toHaveProperty('type');
185
- expect(lesson1Progress.cta.action.type).toBe('course');
186
- expect(lesson1Progress.cta.action.id).toBe(280498);
187
- expect(lesson1Progress.cta.action.child).toBeDefined();
188
- expect(lesson1Progress.cta.action.child.type).toBe('course-part');
189
- expect(lesson1Progress.cta.action.child.id).toBe(287859);
190
- //pack 257242
191
- const lesson2Progress = result.data.find(row => row.id === 257242);
192
- expect(lesson2Progress).toBeDefined();
193
- expect(lesson2Progress.cta).toHaveProperty('text');
194
- expect(lesson2Progress.cta.text.toLowerCase()).toContain('continue');
195
- console.log(lesson2Progress.cta.action)
196
- expect(lesson2Progress.cta.action).toHaveProperty('type');
197
- expect(lesson2Progress.cta.action.type).toBe('pack');
198
- expect(lesson2Progress.cta.action.id).toBe(257242);
199
- expect(lesson2Progress.cta.action.child).toBeDefined();
200
- expect(lesson2Progress.cta.action.child.type).toBe('pack-bundle');
201
- expect(lesson2Progress.cta.action.child.child).toBeDefined();
202
- expect(lesson2Progress.cta.action.child.child.type).toBe('pack-bundle-lesson');
203
- expect(lesson2Progress.cta.action.child.child.id).toBe(257251);
204
-
205
- //challenge 410478
206
-
207
- const lesson3Progress = result.data.find(row => row.id === 410478);
208
- expect(lesson3Progress).toBeDefined();
209
- expect(lesson3Progress.cta).toHaveProperty('text');
210
- expect(lesson3Progress.cta.text.toLowerCase()).toContain('continue');
211
- expect(lesson3Progress.cta.action).toHaveProperty('type');
212
- expect(lesson3Progress.cta.action.type).toBe('challenge');
213
- expect(lesson3Progress.cta.action.id).toBe(410478);
214
- expect(lesson3Progress.cta.action.child).toBeDefined();
215
- expect(lesson3Progress.cta.action.child.type).toBe('challenge-part');
216
- expect(lesson3Progress.cta.action.child.id).toBe(410479);
217
-
218
- //completed play-along 316772
219
- const lesson4Progress = result.data.find(row => row.id === 316772);
220
- expect(lesson4Progress).toBeDefined();
221
- expect(lesson4Progress.cta).toHaveProperty('text');
222
- expect(lesson4Progress.cta.text).toContain('Replay Song');
223
- expect(lesson4Progress.cta.action).toHaveProperty('type');
224
- expect(lesson4Progress.cta.action.type).toBe('play-along');
225
- expect(lesson4Progress.cta.action.id).toBe(316772);
226
- expect(lesson4Progress.body.progressPercent).toBe(100);
227
-
228
- //in progress quick-tips 325826
229
- const lesson5Progress = result.data.find(row => row.id === 325826);
230
- expect(lesson5Progress).toBeDefined();
231
- expect(lesson5Progress.cta).toHaveProperty('text');
232
- expect(lesson5Progress.cta.text).toContain('Continue');
233
- expect(lesson5Progress.cta.action).toHaveProperty('type');
234
- expect(lesson5Progress.cta.action.type).toBe('quick-tips');
235
- expect(lesson5Progress.cta.action.id).toBe(325826);
236
- expect(lesson5Progress.body.progressPercent).toBeLessThan(100);
237
- });
238
-
239
-
240
-
241
- });
242
-
243
-