musora-content-services 2.167.2 → 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 (131) hide show
  1. package/.agent/decisions/2026-07-20-mu2-1724-songs-lessons-counts.md +33 -0
  2. package/.agent/decisions/2026-07-20-query-builder-tostring.md +37 -0
  3. package/CHANGELOG.md +8 -0
  4. package/package.json +2 -1
  5. package/src/contentTypeConfig.js +1 -0
  6. package/src/lib/sanity/query.ts +5 -0
  7. package/src/services/config.js +15 -0
  8. package/src/services/content/artist.ts +1 -3
  9. package/src/services/content/counts.ts +47 -0
  10. package/src/services/content/genre.ts +1 -3
  11. package/src/services/content/instructor.ts +1 -3
  12. package/src/services/userActivity.js +2 -0
  13. package/src/version-info.js +1 -0
  14. package/.claude/settings.local.json +0 -53
  15. package/test/initializeTests.js +0 -60
  16. package/test/integration/awards/award-exclusion-handling.test.ts +0 -275
  17. package/test/integration/awards/internal/image-utils.test.ts +0 -86
  18. package/test/integration/content-progress/__mocks__/mocks.ts +0 -104
  19. package/test/integration/content-progress/contentProgress.test.ts +0 -335
  20. package/test/integration/content-progress/e2eOfflineProgress.test.ts +0 -352
  21. package/test/integration/content-progress/e2eProgress.test.ts +0 -612
  22. package/test/integration/content-progress/getters.test.ts +0 -334
  23. package/test/integration/content-progress/helpers.test.ts +0 -263
  24. package/test/integration/content-progress/offlineContentProgress.test.ts +0 -226
  25. package/test/integration/forums.test.ts +0 -209
  26. package/test/integration/infrastructure/FetchRequestExecutor.test.ts +0 -88
  27. package/test/integration/initializeTestDB.ts +0 -80
  28. package/test/integration/learning-paths.test.ts +0 -854
  29. package/test/integration/notifications.test.ts +0 -178
  30. package/test/integration/progress-row/content-card.test.ts +0 -283
  31. package/test/integration/sync/adapters/idb-errors.test.ts +0 -144
  32. package/test/integration/sync/adapters/sqlite-errors.test.ts +0 -173
  33. package/test/integration/sync/fetch.test.ts +0 -224
  34. package/test/integration/sync/repositories/content-likes.test.ts +0 -99
  35. package/test/integration/sync/repositories/practices.test.ts +0 -179
  36. package/test/integration/sync/repositories/progress.test.ts +0 -245
  37. package/test/integration/sync/repositories/user-award-progress.static.test.ts +0 -68
  38. package/test/integration/sync/repositories/user-award-progress.test.ts +0 -387
  39. package/test/integration/sync/store/cross-user-protection.test.ts +0 -217
  40. package/test/integration/sync/store/store-idb.test.ts +0 -180
  41. package/test/integration/sync/store/store.test.ts +0 -361
  42. package/test/integration/user/permissions.test.js +0 -20
  43. package/test/integration/userActivity.test.ts +0 -102
  44. package/test/live/README.md +0 -29
  45. package/test/live/content.test.js +0 -116
  46. package/test/localStorageMock.js +0 -21
  47. package/test/log.js +0 -5
  48. package/test/mockData/award-definitions.js +0 -171
  49. package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -35
  50. package/test/mockData/mockData_progress_content.json +0 -182
  51. package/test/mockData/mockData_sanity_progress_content.json +0 -1451
  52. package/test/mockData/mockData_user_practices.json +0 -9
  53. package/test/setupConsole.js +0 -6
  54. package/test/setupNetworkGuard.js +0 -3
  55. package/test/setupTimers.js +0 -13
  56. package/test/unit/HttpClient.test.ts +0 -267
  57. package/test/unit/awards/award-alacarte-observer.test.ts +0 -199
  58. package/test/unit/awards/award-auto-refresh.test.ts +0 -84
  59. package/test/unit/awards/award-calculations.test.ts +0 -34
  60. package/test/unit/awards/award-callbacks.test.ts +0 -144
  61. package/test/unit/awards/award-certificate-display.test.ts +0 -330
  62. package/test/unit/awards/award-collection-edge-cases.test.ts +0 -212
  63. package/test/unit/awards/award-collection-filtering.test.ts +0 -287
  64. package/test/unit/awards/award-completion-flow.test.ts +0 -306
  65. package/test/unit/awards/award-multi-lesson.test.ts +0 -243
  66. package/test/unit/awards/award-observer-integration.test.ts +0 -327
  67. package/test/unit/awards/award-query-messages.test.ts +0 -448
  68. package/test/unit/awards/award-user-collection.test.ts +0 -416
  69. package/test/unit/awards/duplicate-prevention.test.ts +0 -120
  70. package/test/unit/awards/helpers/completion-mock.ts +0 -56
  71. package/test/unit/awards/helpers/index.ts +0 -3
  72. package/test/unit/awards/helpers/mock-setup.ts +0 -79
  73. package/test/unit/awards/helpers/progress-emitter.ts +0 -45
  74. package/test/unit/awards/message-generator.test.ts +0 -162
  75. package/test/unit/content-progress/bubbleTrickle.test.ts +0 -322
  76. package/test/unit/content-progress/helpers.test.ts +0 -329
  77. package/test/unit/content-progress/navigateTo.test.ts +0 -392
  78. package/test/unit/contentLikes.test.ts +0 -62
  79. package/test/unit/contentMetaData.test.ts +0 -58
  80. package/test/unit/dataContext.test.ts +0 -38
  81. package/test/unit/dateUtils.test.ts +0 -188
  82. package/test/unit/endScreen.test.js +0 -712
  83. package/test/unit/eventsAPI.test.ts +0 -159
  84. package/test/unit/imageSRCBuilder.test.ts +0 -37
  85. package/test/unit/imageSRCVerify.test.ts +0 -155
  86. package/test/unit/infrastructure/DefaultHeaderProvider.test.ts +0 -39
  87. package/test/unit/infrastructure/sanity/ContentClient.test.ts +0 -168
  88. package/test/unit/infrastructure/sanity/DefaultConfigProvider.test.ts +0 -93
  89. package/test/unit/infrastructure/sanity/FetchQueryExecutor.test.ts +0 -174
  90. package/test/unit/infrastructure/sanity/SanityClient.test.ts +0 -140
  91. package/test/unit/lib/__snapshots__/filter.test.ts.snap +0 -5
  92. package/test/unit/lib/filter.test.ts +0 -1154
  93. package/test/unit/lib/lastUpdated.test.ts +0 -21
  94. package/test/unit/lib/query.test.ts +0 -1469
  95. package/test/unit/lib/sanity/decorators/base.test.ts +0 -368
  96. package/test/unit/lib/sanity/decorators/navigate-to.test.ts +0 -361
  97. package/test/unit/lib/sanity/decorators/need-access.test.ts +0 -89
  98. package/test/unit/lib/sanity/decorators/need-lifetime-upgrade.test.ts +0 -85
  99. package/test/unit/lib/sanity/decorators/page-type.test.ts +0 -81
  100. package/test/unit/playerSettings.test.ts +0 -73
  101. package/test/unit/progress-row/content-card.test.ts +0 -314
  102. package/test/unit/progress-row/playlist-card.test.ts +0 -104
  103. package/test/unit/progressRows.test.ts +0 -243
  104. package/test/unit/recommendations.test.js +0 -47
  105. package/test/unit/sanityQueryService.test.ts +0 -200
  106. package/test/unit/search.test.ts +0 -44
  107. package/test/unit/sentry.test.ts +0 -62
  108. package/test/unit/services/progress-internal/bubble.test.ts +0 -279
  109. package/test/unit/services/progress.test.ts +0 -396
  110. package/test/unit/streakMessage.test.ts +0 -251
  111. package/test/unit/sync/context.test.ts +0 -51
  112. package/test/unit/sync/effects/logout-warning.test.ts +0 -158
  113. package/test/unit/sync/effects/push-failure-notification.test.ts +0 -196
  114. package/test/unit/sync/errors/sync-errors.test.ts +0 -106
  115. package/test/unit/sync/errors/validators.test.ts +0 -61
  116. package/test/unit/sync/helpers/TestModel.ts +0 -44
  117. package/test/unit/sync/helpers/index.ts +0 -172
  118. package/test/unit/sync/manager.test.ts +0 -303
  119. package/test/unit/sync/models/user-award-progress.test.ts +0 -82
  120. package/test/unit/sync/resolver.test.ts +0 -229
  121. package/test/unit/sync/retry.test.ts +0 -314
  122. package/test/unit/sync/run-scope.test.ts +0 -23
  123. package/test/unit/sync/stale-record-cleanup.test.ts +0 -107
  124. package/test/unit/sync/store/push-coalescer.test.ts +0 -156
  125. package/test/unit/sync/store-configs.test.ts +0 -37
  126. package/test/unit/sync/telemetry/sync-telemetry.test.ts +0 -118
  127. package/test/unit/sync/utils/event-emitter.test.ts +0 -64
  128. package/test/unit/sync/utils/throttle.test.ts +0 -245
  129. package/test/unit/url-builder.test.ts +0 -72
  130. package/test/unit/user/account.test.ts +0 -66
  131. package/test/unit/user/permissions.test.js +0 -191
@@ -1,396 +0,0 @@
1
- let mockProgressRecords: any[] = []
2
- let mockRecordsById: Record<string, any> = {}
3
- let mockLastInteracted: string | null = null
4
- let mockStarted: any = { data: [] }
5
- let mockCompleted: any = { data: [] }
6
- let mockCompletedByContentIds: any = { data: [] }
7
- let mockStartedOrCompleted: any = { data: [] }
8
- let mockMethodAccessed: any = { data: [] }
9
-
10
- const repoMocks = {
11
- contentProgress: {
12
- getOneProgressByContentId: jest.fn().mockImplementation((contentId: number) => {
13
- const record = mockProgressRecords.find((r) => r.content_id === contentId)
14
- return Promise.resolve({ data: record || null })
15
- }),
16
- getSomeProgressByContentIds: jest.fn().mockImplementation((contentIds: number[]) => {
17
- const records = mockProgressRecords.filter((r) => contentIds.includes(r.content_id))
18
- return Promise.resolve({ data: records })
19
- }),
20
- getSomeProgressByRecordIds: jest.fn().mockImplementation((ids: string[]) => {
21
- const records = ids.map((id) => mockRecordsById[id]).filter(Boolean)
22
- return Promise.resolve({ data: records })
23
- }),
24
- mostRecentlyUpdatedId: jest.fn().mockImplementation(() => {
25
- return Promise.resolve({ data: mockLastInteracted })
26
- }),
27
- started: jest.fn().mockImplementation(() => Promise.resolve(mockStarted)),
28
- completed: jest.fn().mockImplementation(() => Promise.resolve(mockCompleted)),
29
- completedByContentIds: jest
30
- .fn()
31
- .mockImplementation(() => Promise.resolve(mockCompletedByContentIds)),
32
- startedOrCompleted: jest.fn().mockImplementation(() => Promise.resolve(mockStartedOrCompleted)),
33
- getSomeProgressWhereLastAccessedFromMethod: jest
34
- .fn()
35
- .mockImplementation(() => Promise.resolve(mockMethodAccessed)),
36
- },
37
- }
38
-
39
- jest.mock('../../../src/services/sync/repository-proxy', () => ({
40
- __esModule: true,
41
- default: repoMocks,
42
- ...repoMocks,
43
- }))
44
-
45
- import { Progress } from '../../../src/services/progress'
46
- import { COLLECTION_ID_SELF, COLLECTION_TYPE } from '../../../src/services/sync/models/ContentProgress'
47
-
48
- beforeEach(() => {
49
- jest.clearAllMocks()
50
- mockProgressRecords = []
51
- mockRecordsById = {}
52
- mockLastInteracted = null
53
- mockStarted = { data: [] }
54
- mockCompleted = { data: [] }
55
- mockCompletedByContentIds = { data: [] }
56
- mockStartedOrCompleted = { data: [] }
57
- mockMethodAccessed = { data: [] }
58
- })
59
-
60
- describe('Progress.state', () => {
61
- test('returns state from record', async () => {
62
- mockProgressRecords = [{ content_id: 100, state: 'started' }]
63
- expect(await Progress.state(100)).toBe('started')
64
- })
65
-
66
- test('returns empty string when record missing', async () => {
67
- expect(await Progress.state(999)).toBe('')
68
- })
69
-
70
- test('returns empty string when contentId is 0', async () => {
71
- expect(await Progress.state(0)).toBe('')
72
- expect(repoMocks.contentProgress.getOneProgressByContentId).not.toHaveBeenCalled()
73
- })
74
-
75
- test('forwards collection argument', async () => {
76
- const collection = { id: 5, type: COLLECTION_TYPE.LEARNING_PATH }
77
- await Progress.state(100, collection)
78
- expect(repoMocks.contentProgress.getOneProgressByContentId).toHaveBeenCalledWith(
79
- 100,
80
- collection
81
- )
82
- })
83
- })
84
-
85
- describe('Progress.stateByIds', () => {
86
- test('returns Map with states for found ids and defaults for missing', async () => {
87
- mockProgressRecords = [
88
- { content_id: 100, state: 'started' },
89
- { content_id: 300, state: 'completed' },
90
- ]
91
- const result = await Progress.stateByIds([100, 300, 999])
92
- expect(result.get(100)).toBe('started')
93
- expect(result.get(300)).toBe('completed')
94
- expect(result.get(999)).toBe('')
95
- })
96
-
97
- test('returns empty Map for empty input without hitting db', async () => {
98
- const result = await Progress.stateByIds([])
99
- expect(result.size).toBe(0)
100
- expect(repoMocks.contentProgress.getSomeProgressByContentIds).not.toHaveBeenCalled()
101
- })
102
-
103
- test('forwards collection argument', async () => {
104
- const collection = { id: 7, type: COLLECTION_TYPE.PLAYLIST }
105
- await Progress.stateByIds([1, 2], collection)
106
- expect(repoMocks.contentProgress.getSomeProgressByContentIds).toHaveBeenCalledWith(
107
- [1, 2],
108
- collection
109
- )
110
- })
111
- })
112
-
113
- describe('Progress.stateByRecordIds', () => {
114
- test('returns object with states keyed by record id', async () => {
115
- mockRecordsById = {
116
- '100:self:0': { id: '100:self:0', state: 'started' },
117
- '300:self:0': { id: '300:self:0', state: 'completed' },
118
- }
119
- const result = await Progress.stateByRecordIds(['100:self:0', '300:self:0', '999:self:0'])
120
- expect(result['100:self:0']).toBe('started')
121
- expect(result['300:self:0']).toBe('completed')
122
- expect(result['999:self:0']).toBe('')
123
- })
124
- })
125
-
126
- describe('Progress.playbackPositionByIds', () => {
127
- test('returns Map with resume_time_seconds for found ids and 0 default', async () => {
128
- mockProgressRecords = [
129
- { content_id: 1, resume_time_seconds: 42 },
130
- { content_id: 2, resume_time_seconds: 0 },
131
- ]
132
- const result = await Progress.playbackPositionByIds([1, 2, 3])
133
- expect(result.get(1)).toBe(42)
134
- expect(result.get(2)).toBe(0)
135
- expect(result.get(3)).toBe(0)
136
- })
137
-
138
- test('returns default 0 when field is null', async () => {
139
- mockProgressRecords = [{ content_id: 1, resume_time_seconds: null }]
140
- const result = await Progress.playbackPositionByIds([1])
141
- expect(result.get(1)).toBe(0)
142
- })
143
- })
144
-
145
- describe('Progress.playbackPositionByRecordIds', () => {
146
- test('returns object with resume_time_seconds keyed by record id', async () => {
147
- mockRecordsById = {
148
- '100:self:0': { id: '100:self:0', resume_time_seconds: 120 },
149
- '300:self:0': { id: '300:self:0', resume_time_seconds: 0 },
150
- }
151
- const result = await Progress.playbackPositionByRecordIds(['100:self:0', '300:self:0', '999:self:0'])
152
- expect(result['100:self:0']).toBe(120)
153
- expect(result['300:self:0']).toBe(0)
154
- expect(result['999:self:0']).toBe(0)
155
- })
156
-
157
- test('returns default 0 when field is null', async () => {
158
- mockRecordsById = { '100:self:0': { id: '100:self:0', resume_time_seconds: null } }
159
- const result = await Progress.playbackPositionByRecordIds(['100:self:0'])
160
- expect(result['100:self:0']).toBe(0)
161
- })
162
- })
163
-
164
- describe('Progress.lastInteractedOf', () => {
165
- test('parses numeric string to integer', async () => {
166
- mockLastInteracted = '101'
167
- expect(await Progress.lastInteractedOf([100, 101])).toBe(101)
168
- })
169
-
170
- test('returns undefined when repository returns null', async () => {
171
- mockLastInteracted = null
172
- expect(await Progress.lastInteractedOf([100, 101])).toBeUndefined()
173
- })
174
-
175
- test('forwards args to repository', async () => {
176
- const collection = { id: 9, type: COLLECTION_TYPE.LEARNING_PATH }
177
- await Progress.lastInteractedOf([1, 2, 3], collection)
178
- expect(repoMocks.contentProgress.mostRecentlyUpdatedId).toHaveBeenCalledWith(
179
- [1, 2, 3],
180
- collection
181
- )
182
- })
183
- })
184
-
185
- describe('Progress.incompleteLesson', () => {
186
- test('guided-course returns first non-completed id', () => {
187
- const states = new Map<number, string>([
188
- [1, 'completed'],
189
- [2, 'started'],
190
- [3, ''],
191
- ])
192
- expect(Progress.incompleteLesson(states, 'guided-course', 999)).toBe(2)
193
- })
194
-
195
- test('learning-path returns first non-completed id', () => {
196
- const states = new Map<number, string>([
197
- [1, 'completed'],
198
- [2, 'completed'],
199
- [3, 'started'],
200
- ])
201
- expect(Progress.incompleteLesson(states, COLLECTION_TYPE.LEARNING_PATH, 999)).toBe(3)
202
- })
203
-
204
- test('guided-course falls back to first id when all completed', () => {
205
- const states = new Map<number, string>([
206
- [10, 'completed'],
207
- [20, 'completed'],
208
- ])
209
- expect(Progress.incompleteLesson(states, 'guided-course', 999)).toBe(10)
210
- })
211
-
212
- test('other type: returns next non-completed after currentContentId', () => {
213
- const states = new Map<number, string>([
214
- [1, 'completed'],
215
- [2, 'started'],
216
- [3, 'completed'],
217
- [4, 'started'],
218
- ])
219
- expect(Progress.incompleteLesson(states, 'course', 2)).toBe(4)
220
- })
221
-
222
- test('other type: wraps to first id when no incomplete after current', () => {
223
- const states = new Map<number, string>([
224
- [1, 'started'],
225
- [2, 'started'],
226
- [3, 'completed'],
227
- ])
228
- expect(Progress.incompleteLesson(states, 'course', 3)).toBe(1)
229
- })
230
-
231
- test('other type: scans from start when currentContentId not in map → first incomplete', () => {
232
- const states = new Map<number, string>([
233
- [1, 'completed'],
234
- [2, 'started'],
235
- ])
236
- expect(Progress.incompleteLesson(states, 'course', 999)).toBe(2)
237
- })
238
-
239
- test('other type: scans from start when currentContentId not in map and all complete → first id', () => {
240
- const states = new Map<number, string>([
241
- [1, 'completed'],
242
- [2, 'completed'],
243
- ])
244
- expect(Progress.incompleteLesson(states, 'course', 999)).toBe(1)
245
- })
246
- })
247
-
248
- describe('Progress.allStarted', () => {
249
- test('delegates to repo and applies default options', async () => {
250
- mockStarted = { data: [1, 2, 3] }
251
- const result = await Progress.allStarted()
252
- expect(result).toEqual({ data: [1, 2, 3] })
253
- expect(repoMocks.contentProgress.started).toHaveBeenCalledWith(null, {
254
- onlyIds: true,
255
- include: { aLaCarte: true, learningPaths: false },
256
- })
257
- })
258
-
259
- test('forwards custom limit and options', async () => {
260
- const opts = { onlyIds: false, include: { aLaCarte: false, learningPaths: true } }
261
- await Progress.allStarted(10, opts)
262
- expect(repoMocks.contentProgress.started).toHaveBeenCalledWith(10, opts)
263
- })
264
- })
265
-
266
- describe('Progress.allCompleted', () => {
267
- test('delegates to repo with default options', async () => {
268
- mockCompleted = { data: [9] }
269
- const result = await Progress.allCompleted()
270
- expect(result).toEqual({ data: [9] })
271
- expect(repoMocks.contentProgress.completed).toHaveBeenCalledWith(null, {
272
- onlyIds: true,
273
- include: { aLaCarte: true, learningPaths: false },
274
- })
275
- })
276
- })
277
-
278
- describe('Progress.allCompletedByIds', () => {
279
- test('delegates to repo with passed contentIds', async () => {
280
- mockCompletedByContentIds = { data: [{ content_id: 5 }] }
281
- const result = await Progress.allCompletedByIds([5, 6])
282
- expect(result).toEqual({ data: [{ content_id: 5 }] })
283
- expect(repoMocks.contentProgress.completedByContentIds).toHaveBeenCalledWith([5, 6])
284
- })
285
- })
286
-
287
- describe('Progress.allStartedOrCompleted', () => {
288
- test('unwraps r.data from repo response', async () => {
289
- mockStartedOrCompleted = { data: [{ content_id: 1 }, { content_id: 2 }] }
290
- const result = await Progress.allStartedOrCompleted()
291
- expect(result).toEqual([{ content_id: 1 }, { content_id: 2 }])
292
- })
293
-
294
- test('passes limit and updatedAfter window (60 days)', async () => {
295
- const before = Math.floor(Date.now() / 1000) - 60 * 24 * 60 * 60
296
- await Progress.allStartedOrCompleted(25, { brand: 'drumeo' })
297
- const after = Math.floor(Date.now() / 1000) - 60 * 24 * 60 * 60
298
-
299
- const args = repoMocks.contentProgress.startedOrCompleted.mock.calls[0][0]
300
- expect(args.limit).toBe(25)
301
- expect(args.brand).toBe('drumeo')
302
- expect(args.updatedAfter).toBeGreaterThanOrEqual(before)
303
- expect(args.updatedAfter).toBeLessThanOrEqual(after)
304
- })
305
- })
306
-
307
- describe('Progress.snapshotByIds', () => {
308
- test('returns snapshot keyed by content_id with defaults for missing', async () => {
309
- mockProgressRecords = [
310
- { content_id: 1, last_interacted_a_la_carte: 111, progress_percent: 50, state: 'started' },
311
- ]
312
- const result = await Progress.snapshotByIds([1, 2])
313
- expect(result.get(1)).toEqual({ last_update: 111, progress: 50, status: 'started' })
314
- expect(result.get(2)).toEqual({ last_update: 0, progress: 0, status: '' })
315
- })
316
-
317
- test('returns empty defaults when no records match', async () => {
318
- const result = await Progress.snapshotByIds([99])
319
- expect(result.get(99)).toEqual({ last_update: 0, progress: 0, status: '' })
320
- })
321
- })
322
-
323
- describe('Progress.snapshotByRecordIds', () => {
324
- test('returns snapshot keyed by record id with defaults for missing', async () => {
325
- mockRecordsById = {
326
- '1:self:0': { id: '1:self:0', updated_at: 222, progress_percent: 75, state: 'completed' },
327
- }
328
- const result = await Progress.snapshotByRecordIds(['1:self:0', '2:self:0'])
329
- expect(result['1:self:0']).toEqual({ last_update: 222, progress: 75, status: 'completed' })
330
- expect(result['2:self:0']).toEqual({ last_update: 0, progress: 0, status: '' })
331
- })
332
- })
333
-
334
- describe('Progress.methodAccessedIds', () => {
335
- test('returns content_ids from records', async () => {
336
- mockMethodAccessed = { data: [{ content_id: 10 }, { content_id: 20 }] }
337
- const result = await Progress.methodAccessedIds([10, 20, 30])
338
- expect(result).toEqual([10, 20])
339
- })
340
-
341
- test('returns empty array when no records', async () => {
342
- const result = await Progress.methodAccessedIds([1])
343
- expect(result).toEqual([])
344
- })
345
-
346
- test('forwards contentIds to repository', async () => {
347
- await Progress.methodAccessedIds([5, 6])
348
- expect(
349
- repoMocks.contentProgress.getSomeProgressWhereLastAccessedFromMethod
350
- ).toHaveBeenCalledWith([5, 6])
351
- })
352
- })
353
-
354
- describe('Progress.generateRecordId', () => {
355
- test('no collection uses SELF defaults', () => {
356
- expect(Progress.generateRecordId(123)).toBe(
357
- `123:${COLLECTION_TYPE.SELF}:${COLLECTION_ID_SELF}`
358
- )
359
- })
360
-
361
- test('LP collection returns correct format', () => {
362
- expect(
363
- Progress.generateRecordId(123, { type: COLLECTION_TYPE.LEARNING_PATH, id: 456 })
364
- ).toBe('123:learning-path-v2:456')
365
- })
366
- })
367
-
368
- describe('Progress.extractFromRecordId', () => {
369
- test('self record id parses correctly', () => {
370
- expect(Progress.extractFromRecordId('123:self:0')).toEqual({
371
- contentId: 123,
372
- collection: { type: 'self', id: 0 },
373
- })
374
- })
375
-
376
- test('LP record id parses correctly', () => {
377
- expect(Progress.extractFromRecordId('456:learning-path-v2:789')).toEqual({
378
- contentId: 456,
379
- collection: { type: 'learning-path-v2', id: 789 },
380
- })
381
- })
382
-
383
- test('missing collection type defaults to SELF', () => {
384
- expect(Progress.extractFromRecordId('123::')).toEqual({
385
- contentId: 123,
386
- collection: { type: COLLECTION_TYPE.SELF, id: COLLECTION_ID_SELF },
387
- })
388
- })
389
-
390
- test('missing collection id defaults to COLLECTION_ID_SELF', () => {
391
- expect(Progress.extractFromRecordId('123:self:')).toEqual({
392
- contentId: 123,
393
- collection: { type: 'self', id: COLLECTION_ID_SELF },
394
- })
395
- })
396
- })
@@ -1,251 +0,0 @@
1
- import { initializeTestService } from '../initializeTests.js'
2
- import {getUserWeeklyStats, userActivityContext} from '../../src/services/userActivity.js'
3
- import { streakCalculator } from '../../src/services/user/streakCalculator'
4
- import {log} from '../log.js'
5
-
6
- let mockPracticeData: { date: string; duration_seconds: number }[] = []
7
-
8
- jest.mock('../../src/services/sync/repository-proxy.ts', () => {
9
- const mockFns = {
10
- practices: {
11
- queryAll: jest.fn().mockImplementation(() => Promise.resolve({ data: mockPracticeData })),
12
- getAll: jest.fn().mockImplementation(() => Promise.resolve({ data: mockPracticeData })),
13
- }
14
- }
15
- return { default: mockFns, ...mockFns }
16
- })
17
-
18
-
19
- // Test Examples are taken from this document
20
- // https://docs.google.com/spreadsheets/d/1pBmBTAODeRWI5uIO84lXjaQFW-lRPNh6gi7GV0lCwyc/edit?gid=0#gid=0
21
- describe('Streak Messages', function () {
22
- beforeEach(() => {
23
- initializeTestService()
24
- mockPracticeData = []
25
- const userLocalMidnight = new Date();
26
- userLocalMidnight.setFullYear(2025, 2, 24);
27
- jest.useFakeTimers();
28
- jest.setSystemTime(userLocalMidnight);
29
- })
30
-
31
- test('streak message - example1', async () => {
32
- const fixedDate = new Date('2025-03-24T12:00:00.000Z');
33
- const allData = [
34
- { day: 1, date: '2025-03-24', duration_seconds: 120 },
35
- { day: 2, date: '2025-03-25', duration_seconds: 120 },
36
- { day: 3, date: '2025-03-26', duration_seconds: 120 },
37
- { day: 7, date: '2025-03-30', duration_seconds: 120 },
38
- { day: 8, date: '2025-03-31', duration_seconds: 120 },
39
- { day: 22, date: '2025-04-14', duration_seconds: 120 },
40
- { day: 23, date: '2025-04-15', duration_seconds: 120 },
41
- ]
42
-
43
- const expectedMessages = [
44
- {day: 1, incomplete: 'Start your streak by taking any lesson!', complete: 'Nice! You have a 1 day streak!'},
45
- {day: 2, incomplete: 'You have a 1 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 2 day streak! Way to keep it going!'},
46
- {day: 3, incomplete: 'You have a 2 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 3 day streak! Way to keep it going!'},
47
- {day: 4, incomplete: 'You have a 3 day streak! Keep it going with any lesson or song!', complete: ''},
48
- {day: 5, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: ''},
49
- {day: 6, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: ''},
50
- {day: 7, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: 'You have a 1 week streak! Way to keep up the momentum!'},
51
- {day: 8, incomplete: 'You have a 1 week streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 2 day streak! Way to keep it going!'},
52
- {day: 9, incomplete: 'You have a 2 day streak! Keep it going with any lesson or song!', complete: ''},
53
- {day: 10, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
54
- {day: 11, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
55
- {day: 12, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
56
- {day: 13, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
57
- {day: 14, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
58
- {day: 15, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
59
- {day: 16, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
60
- {day: 17, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
61
- {day: 18, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
62
- {day: 19, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
63
- {day: 20, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
64
- {day: 21, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
65
- {day: 22, incomplete: 'Restart your streak by taking any lesson!', complete: 'Nice! You have a 1 day streak!'},
66
- {day: 23, incomplete: 'You have a 1 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 2 day streak! Way to keep it going!'},
67
- {day: 24, incomplete: 'You have a 2 day streak! Keep it going with any lesson or song!', complete: ''},
68
- ]
69
-
70
- // you can test a specific day by setting this value to the correct date and the test will only run that day
71
- // this is 0 indexed
72
- const testSpecificDay = null;
73
- await testExpectedMessageForDays(allData, expectedMessages, fixedDate, testSpecificDay)
74
- })
75
-
76
- test('streak message - example2', async () => {
77
- const fixedDate = new Date('2025-03-24T12:00:00.000Z');
78
- const allData = [
79
- { day: 1, date: '2025-03-24', duration_seconds: 120 },
80
- { day: 8, date: '2025-03-31', duration_seconds: 120 },
81
- { day: 10, date: '2025-04-02', duration_seconds: 120 },
82
- { day: 11, date: '2025-04-03', duration_seconds: 120 },
83
- { day: 13, date: '2025-04-05', duration_seconds: 120 },
84
- { day: 16, date: '2025-04-08', duration_seconds: 120 },
85
- ]
86
-
87
- const expectedMessages = [
88
- {day: 1, incomplete: 'Start your streak by taking any lesson!', complete: 'Nice! You have a 1 day streak!'},
89
- {day: 2, incomplete: 'You have a 1 day streak! Keep it going with any lesson or song!', complete: ''},
90
- {day: 3, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: ''},
91
- {day: 4, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: ''},
92
- {day: 5, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: ''},
93
- {day: 6, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: ''},
94
- {day: 7, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: ''},
95
- {day: 8, incomplete: 'You have a 1 week streak! Keep it going with any lesson or song!', complete: 'Great job! You have a 2 week streak! Way to keep it going!'},
96
- {day: 9, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
97
- {day: 10, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: 'You have a 2 week streak! Way to keep up the momentum!'},
98
- {day: 11, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: 'Nice! You have a 2 day streak! Way to keep it going!'},
99
- {day: 12, incomplete: 'You have a 2 day streak! Keep it going with any lesson or song!', complete: ''},
100
- {day: 13, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: 'You have a 2 week streak! Way to keep up the momentum!'},
101
- {day: 14, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
102
- {day: 15, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
103
- {day: 16, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: 'Great job! You have a 3 week streak! Way to keep it going!'},
104
- {day: 17, incomplete: 'You have a 3 week streak! Keep up the momentum!', complete: ''},
105
- {day: 18, incomplete: 'You have a 3 week streak! Keep up the momentum!', complete: ''},
106
- {day: 19, incomplete: 'You have a 3 week streak! Keep up the momentum!', complete: ''},
107
- {day: 20, incomplete: 'You have a 3 week streak! Keep up the momentum!', complete: ''},
108
- {day: 21, incomplete: 'You have a 3 week streak! Keep up the momentum!', complete: ''},
109
- {day: 22, incomplete: 'You have a 3 week streak! Keep it going with any lesson or song!', complete: ''},
110
- {day: 23, incomplete: 'You have a 3 week streak! Keep it going with any lesson or song!', complete: ''},
111
- {day: 24, incomplete: 'You have a 3 week streak! Keep it going with any lesson or song!', complete: ''},
112
- {day: 25, incomplete: 'You have a 3 week streak! Keep it going with any lesson or song!', complete: ''},
113
- {day: 26, incomplete: 'You have a 3 week streak! Keep it going with any lesson or song!', complete: ''},
114
- {day: 27, incomplete: 'You have a 3 week streak! Keep it going with any lesson or song!', complete: ''},
115
- {day: 28, incomplete: 'You have a 3 week streak! Keep it going with any lesson or song!', complete: ''},
116
- ]
117
-
118
- // you can test a specific day by setting this value to the correct date and the test will only run that day
119
- // this is zero indexed so do 1 day below the day you want to test
120
- const testSpecificDay = null;
121
- await testExpectedMessageForDays(allData, expectedMessages, fixedDate, testSpecificDay)
122
- })
123
-
124
- test('streak message - example3', async () => {
125
- const fixedDate = new Date('2025-03-24T12:00:00.000Z');
126
- const allData = [
127
- { day: 2, date: '2025-03-25', duration_seconds: 120 },
128
- { day: 5, date: '2025-03-28', duration_seconds: 120 },
129
- { day: 6, date: '2025-03-29', duration_seconds: 120 },
130
- { day: 7, date: '2025-03-30', duration_seconds: 120 },
131
- { day: 9, date: '2025-04-01', duration_seconds: 120 },
132
- { day: 11, date: '2025-04-03', duration_seconds: 120 },
133
- { day: 12, date: '2025-04-04', duration_seconds: 120 },
134
- { day: 17, date: '2025-04-09', duration_seconds: 120 },
135
- { day: 19, date: '2025-04-11', duration_seconds: 120 },
136
- ]
137
-
138
- const expectedMessages = [
139
- {day: 1, incomplete: 'Start your streak by taking any lesson!', complete: ''},
140
- {day: 2, incomplete: 'Start your streak by taking any lesson!', complete: 'Nice! You have a 1 day streak!'},
141
- {day: 3, incomplete: 'You have a 1 day streak! Keep it going with any lesson or song!', complete: ''},
142
- {day: 4, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: ''},
143
- {day: 5, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: 'You have a 1 week streak! Way to keep up the momentum!'},
144
- {day: 6, incomplete: 'You have a 1 week streak! Keep up the momentum!', complete: 'Nice! You have a 2 day streak! Way to keep it going!'},
145
- {day: 7, incomplete: 'You have a 2 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 3 day streak! Way to keep it going!'},
146
- {day: 8, incomplete: 'You have a 3 day streak! Keep it going with any lesson or song!', complete: ''},
147
- {day: 9, incomplete: 'You have a 1 week streak! Keep it going with any lesson or song!', complete: 'Great job! You have a 2 week streak! Way to keep it going!'},
148
- {day: 10, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
149
- {day: 11, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: 'You have a 2 week streak! Way to keep up the momentum!'},
150
- {day: 12, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: 'Nice! You have a 2 day streak! Way to keep it going!'},
151
- {day: 13, incomplete: 'You have a 2 day streak! Keep it going with any lesson or song!', complete: ''},
152
- {day: 14, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: ''},
153
- {day: 15, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
154
- {day: 16, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: ''},
155
- {day: 17, incomplete: 'You have a 2 week streak! Keep it going with any lesson or song!', complete: 'Great job! You have a 3 week streak! Way to keep it going!'},
156
- {day: 18, incomplete: 'You have a 3 week streak! Keep up the momentum!', complete: ''},
157
- {day: 19, incomplete: 'You have a 3 week streak! Keep up the momentum!', complete: 'You have a 3 week streak! Way to keep up the momentum!'},
158
- {day: 20, incomplete: 'You have a 3 week streak! Keep up the momentum!', complete: ''},
159
- ]
160
-
161
- // you can test a specific day by setting this value to the correct date and the test will only run that day
162
- // this is 0 indexed
163
- const testSpecificDay = null;
164
- await testExpectedMessageForDays(allData, expectedMessages, fixedDate, testSpecificDay)
165
- })
166
-
167
- test('streak message - example4', async () => {
168
- const fixedDate = new Date('2025-03-24T12:00:00.000Z');
169
- const allData = [
170
- { day: 1, date: '2025-03-24', duration_seconds: 120},
171
- { day: 2, date: '2025-03-25', duration_seconds: 120},
172
- { day: 3, date: '2025-03-26', duration_seconds: 120},
173
- { day: 4, date: '2025-03-27', duration_seconds: 120},
174
- { day: 5, date: '2025-03-28', duration_seconds: 120},
175
- { day: 6, date: '2025-03-29', duration_seconds: 120},
176
- { day: 7, date: '2025-03-30', duration_seconds: 120},
177
- { day: 8, date: '2025-03-31', duration_seconds: 120},
178
- ]
179
-
180
- const expectedMessages = [
181
- {day: 1, incomplete: 'Start your streak by taking any lesson!', complete: 'Nice! You have a 1 day streak!'},
182
- {day: 2, incomplete: 'You have a 1 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 2 day streak! Way to keep it going!'},
183
- {day: 3, incomplete: 'You have a 2 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 3 day streak! Way to keep it going!'},
184
- {day: 4, incomplete: 'You have a 3 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 4 day streak! Way to keep it going!'},
185
- {day: 5, incomplete: 'You have a 4 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 5 day streak! Way to keep it going!'},
186
- {day: 6, incomplete: 'You have a 5 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 6 day streak! Way to keep it going!'},
187
- {day: 7, incomplete: 'You have a 6 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have a 7 day streak! Way to keep it going!'},
188
- {day: 8, incomplete: 'You have a 7 day streak! Keep it going with any lesson or song!', complete: 'Nice! You have an 8 day streak! Way to keep it going!'},
189
- {day: 9, incomplete: 'You have an 8 day streak! Keep it going with any lesson or song!', complete: ''},
190
- {day: 10, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: 'You have a 2 week streak! Keep up the momentum!'},
191
- {day: 11, incomplete: 'You have a 2 week streak! Keep up the momentum!', complete: 'You have a 2 week streak! Keep up the momentum!'},
192
- ]
193
-
194
- // you can test a specific day by setting this value to the correct date and the test will only run that day
195
- // this is 0 indexed
196
- const testSpecificDay = null;
197
- await testExpectedMessageForDays(allData, expectedMessages, fixedDate, testSpecificDay)
198
- })
199
- })
200
-
201
- function incrementFakeDate(nDays = 1) {
202
- let today = new Date();
203
- today.setFullYear(today.getFullYear(), today.getMonth(), (today.getDate() + nDays));
204
- jest.useFakeTimers();
205
- jest.setSystemTime(today);
206
- }
207
-
208
- function sliceExampleData(startDate, nDays, includeToday, activeDays) {
209
- if (nDays === 0 && !includeToday) {
210
- return []
211
- }
212
- nDays = includeToday ? nDays : nDays - 1
213
- let target = new Date(startDate)
214
- target.setDate(target.getDate() + nDays)
215
- return activeDays.filter((obj) => {
216
- let activeDate = new Date(obj.date)
217
- return activeDate <= target
218
- })
219
- }
220
-
221
- async function testExpectedMessageForDays(exampleData, expectedMessages, startDate, testDayN = null) {
222
- const start = testDayN ?? 0;
223
- const end = testDayN != null ? testDayN + 1 : expectedMessages.length
224
- if (testDayN != null) incrementFakeDate(testDayN)
225
- for (let i = start; i < end; i++) {
226
- let target = new Date(startDate)
227
- target.setDate(target.getDate() + i)
228
- const setDataAndCheckStreakMessage = async function(includeToday) {
229
- let activeDays = sliceExampleData(startDate, i, includeToday, exampleData)
230
- mockPracticeData = activeDays.map(({ date, duration_seconds }) => ({ date, duration_seconds }))
231
- userActivityContext.clearCache()
232
- streakCalculator.invalidate()
233
- let practices = await getUserWeeklyStats()
234
- const state = includeToday ? 'STARTED' : 'NOT-STARTED'
235
- const expected = includeToday && !!expectedMessages[i].complete ? expectedMessages[i].complete :
236
- expectedMessages[i].incomplete
237
- const day = expectedMessages[i].day
238
- log(`Running ${state} content tests for Day ${day} on ${target}`)
239
- log(`Expecting ${expected}`)
240
- expect(practices.data.streakMessage).toBeDefined()
241
- if (practices.data.streakMessage !== expected) {
242
- throw new Error(`Mismatch on Day ${expectedMessages[i].day} [${target.toDateString()}]:
243
- Expected: "${expected}"
244
- Received: "${practices.data.streakMessage}"`);
245
- }
246
- }
247
- await setDataAndCheckStreakMessage(false)
248
- await setDataAndCheckStreakMessage(true)
249
- incrementFakeDate(1)
250
- }
251
- }