musora-content-services 2.167.2 → 2.167.4

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 (140) 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/.idea/codeStyles/Project.xml +61 -0
  4. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/musora-content-services.iml +8 -0
  7. package/.idea/php.xml +19 -0
  8. package/.idea/prettier.xml +6 -0
  9. package/.idea/vcs.xml +7 -0
  10. package/.yarn/install-state.gz +0 -0
  11. package/CHANGELOG.md +10 -0
  12. package/package.json +2 -1
  13. package/src/contentTypeConfig.js +1 -0
  14. package/src/lib/sanity/query.ts +5 -0
  15. package/src/services/config.js +15 -0
  16. package/src/services/content/artist.ts +1 -3
  17. package/src/services/content/counts.ts +47 -0
  18. package/src/services/content/genre.ts +1 -3
  19. package/src/services/content/instructor.ts +1 -3
  20. package/src/services/multi-user-accounts/multi-user-accounts.ts +1 -0
  21. package/src/services/userActivity.js +2 -0
  22. package/src/version-info.js +1 -0
  23. package/.claude/settings.local.json +0 -53
  24. package/test/initializeTests.js +0 -60
  25. package/test/integration/awards/award-exclusion-handling.test.ts +0 -275
  26. package/test/integration/awards/internal/image-utils.test.ts +0 -86
  27. package/test/integration/content-progress/__mocks__/mocks.ts +0 -104
  28. package/test/integration/content-progress/contentProgress.test.ts +0 -335
  29. package/test/integration/content-progress/e2eOfflineProgress.test.ts +0 -352
  30. package/test/integration/content-progress/e2eProgress.test.ts +0 -612
  31. package/test/integration/content-progress/getters.test.ts +0 -334
  32. package/test/integration/content-progress/helpers.test.ts +0 -263
  33. package/test/integration/content-progress/offlineContentProgress.test.ts +0 -226
  34. package/test/integration/forums.test.ts +0 -209
  35. package/test/integration/infrastructure/FetchRequestExecutor.test.ts +0 -88
  36. package/test/integration/initializeTestDB.ts +0 -80
  37. package/test/integration/learning-paths.test.ts +0 -854
  38. package/test/integration/notifications.test.ts +0 -178
  39. package/test/integration/progress-row/content-card.test.ts +0 -283
  40. package/test/integration/sync/adapters/idb-errors.test.ts +0 -144
  41. package/test/integration/sync/adapters/sqlite-errors.test.ts +0 -173
  42. package/test/integration/sync/fetch.test.ts +0 -224
  43. package/test/integration/sync/repositories/content-likes.test.ts +0 -99
  44. package/test/integration/sync/repositories/practices.test.ts +0 -179
  45. package/test/integration/sync/repositories/progress.test.ts +0 -245
  46. package/test/integration/sync/repositories/user-award-progress.static.test.ts +0 -68
  47. package/test/integration/sync/repositories/user-award-progress.test.ts +0 -387
  48. package/test/integration/sync/store/cross-user-protection.test.ts +0 -217
  49. package/test/integration/sync/store/store-idb.test.ts +0 -180
  50. package/test/integration/sync/store/store.test.ts +0 -361
  51. package/test/integration/user/permissions.test.js +0 -20
  52. package/test/integration/userActivity.test.ts +0 -102
  53. package/test/live/README.md +0 -29
  54. package/test/live/content.test.js +0 -116
  55. package/test/localStorageMock.js +0 -21
  56. package/test/log.js +0 -5
  57. package/test/mockData/award-definitions.js +0 -171
  58. package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -35
  59. package/test/mockData/mockData_progress_content.json +0 -182
  60. package/test/mockData/mockData_sanity_progress_content.json +0 -1451
  61. package/test/mockData/mockData_user_practices.json +0 -9
  62. package/test/setupConsole.js +0 -6
  63. package/test/setupNetworkGuard.js +0 -3
  64. package/test/setupTimers.js +0 -13
  65. package/test/unit/HttpClient.test.ts +0 -267
  66. package/test/unit/awards/award-alacarte-observer.test.ts +0 -199
  67. package/test/unit/awards/award-auto-refresh.test.ts +0 -84
  68. package/test/unit/awards/award-calculations.test.ts +0 -34
  69. package/test/unit/awards/award-callbacks.test.ts +0 -144
  70. package/test/unit/awards/award-certificate-display.test.ts +0 -330
  71. package/test/unit/awards/award-collection-edge-cases.test.ts +0 -212
  72. package/test/unit/awards/award-collection-filtering.test.ts +0 -287
  73. package/test/unit/awards/award-completion-flow.test.ts +0 -306
  74. package/test/unit/awards/award-multi-lesson.test.ts +0 -243
  75. package/test/unit/awards/award-observer-integration.test.ts +0 -327
  76. package/test/unit/awards/award-query-messages.test.ts +0 -448
  77. package/test/unit/awards/award-user-collection.test.ts +0 -416
  78. package/test/unit/awards/duplicate-prevention.test.ts +0 -120
  79. package/test/unit/awards/helpers/completion-mock.ts +0 -56
  80. package/test/unit/awards/helpers/index.ts +0 -3
  81. package/test/unit/awards/helpers/mock-setup.ts +0 -79
  82. package/test/unit/awards/helpers/progress-emitter.ts +0 -45
  83. package/test/unit/awards/message-generator.test.ts +0 -162
  84. package/test/unit/content-progress/bubbleTrickle.test.ts +0 -322
  85. package/test/unit/content-progress/helpers.test.ts +0 -329
  86. package/test/unit/content-progress/navigateTo.test.ts +0 -392
  87. package/test/unit/contentLikes.test.ts +0 -62
  88. package/test/unit/contentMetaData.test.ts +0 -58
  89. package/test/unit/dataContext.test.ts +0 -38
  90. package/test/unit/dateUtils.test.ts +0 -188
  91. package/test/unit/endScreen.test.js +0 -712
  92. package/test/unit/eventsAPI.test.ts +0 -159
  93. package/test/unit/imageSRCBuilder.test.ts +0 -37
  94. package/test/unit/imageSRCVerify.test.ts +0 -155
  95. package/test/unit/infrastructure/DefaultHeaderProvider.test.ts +0 -39
  96. package/test/unit/infrastructure/sanity/ContentClient.test.ts +0 -168
  97. package/test/unit/infrastructure/sanity/DefaultConfigProvider.test.ts +0 -93
  98. package/test/unit/infrastructure/sanity/FetchQueryExecutor.test.ts +0 -174
  99. package/test/unit/infrastructure/sanity/SanityClient.test.ts +0 -140
  100. package/test/unit/lib/__snapshots__/filter.test.ts.snap +0 -5
  101. package/test/unit/lib/filter.test.ts +0 -1154
  102. package/test/unit/lib/lastUpdated.test.ts +0 -21
  103. package/test/unit/lib/query.test.ts +0 -1469
  104. package/test/unit/lib/sanity/decorators/base.test.ts +0 -368
  105. package/test/unit/lib/sanity/decorators/navigate-to.test.ts +0 -361
  106. package/test/unit/lib/sanity/decorators/need-access.test.ts +0 -89
  107. package/test/unit/lib/sanity/decorators/need-lifetime-upgrade.test.ts +0 -85
  108. package/test/unit/lib/sanity/decorators/page-type.test.ts +0 -81
  109. package/test/unit/playerSettings.test.ts +0 -73
  110. package/test/unit/progress-row/content-card.test.ts +0 -314
  111. package/test/unit/progress-row/playlist-card.test.ts +0 -104
  112. package/test/unit/progressRows.test.ts +0 -243
  113. package/test/unit/recommendations.test.js +0 -47
  114. package/test/unit/sanityQueryService.test.ts +0 -200
  115. package/test/unit/search.test.ts +0 -44
  116. package/test/unit/sentry.test.ts +0 -62
  117. package/test/unit/services/progress-internal/bubble.test.ts +0 -279
  118. package/test/unit/services/progress.test.ts +0 -396
  119. package/test/unit/streakMessage.test.ts +0 -251
  120. package/test/unit/sync/context.test.ts +0 -51
  121. package/test/unit/sync/effects/logout-warning.test.ts +0 -158
  122. package/test/unit/sync/effects/push-failure-notification.test.ts +0 -196
  123. package/test/unit/sync/errors/sync-errors.test.ts +0 -106
  124. package/test/unit/sync/errors/validators.test.ts +0 -61
  125. package/test/unit/sync/helpers/TestModel.ts +0 -44
  126. package/test/unit/sync/helpers/index.ts +0 -172
  127. package/test/unit/sync/manager.test.ts +0 -303
  128. package/test/unit/sync/models/user-award-progress.test.ts +0 -82
  129. package/test/unit/sync/resolver.test.ts +0 -229
  130. package/test/unit/sync/retry.test.ts +0 -314
  131. package/test/unit/sync/run-scope.test.ts +0 -23
  132. package/test/unit/sync/stale-record-cleanup.test.ts +0 -107
  133. package/test/unit/sync/store/push-coalescer.test.ts +0 -156
  134. package/test/unit/sync/store-configs.test.ts +0 -37
  135. package/test/unit/sync/telemetry/sync-telemetry.test.ts +0 -118
  136. package/test/unit/sync/utils/event-emitter.test.ts +0 -64
  137. package/test/unit/sync/utils/throttle.test.ts +0 -245
  138. package/test/unit/url-builder.test.ts +0 -72
  139. package/test/unit/user/account.test.ts +0 -66
  140. package/test/unit/user/permissions.test.js +0 -191
@@ -1,329 +0,0 @@
1
- import { initializeTestService } from '../../initializeTests.js'
2
- import {
3
- duplicateProgressForIds,
4
- extractFromRecordId,
5
- filterOutLearningPathsForDuplication,
6
- filterOutNegativeProgress,
7
- generateRecordId,
8
- normalizeCollection,
9
- normalizeContentId,
10
- normalizeContentIds,
11
- } from '../../../src/services/contentProgress.js'
12
- import { COLLECTION_ID_SELF, COLLECTION_TYPE } from '../../../src/services/sync/models/ContentProgress'
13
-
14
- let mockProgressRecords: any[] = []
15
-
16
- jest.mock('../../../src/services/sync/repository-proxy', () => {
17
- const mockFns = {
18
- contentProgress: {
19
- getOneProgressByContentId: jest.fn().mockImplementation((contentId) => {
20
- const record = mockProgressRecords.find(r => r.content_id === contentId)
21
- return Promise.resolve({ data: record || null })
22
- }),
23
- getSomeProgressByContentIds: jest.fn().mockImplementation((contentIds) => {
24
- const records = mockProgressRecords.filter(r => contentIds.includes(r.content_id))
25
- return Promise.resolve({ data: records })
26
- }),
27
- recordProgress: jest.fn().mockResolvedValue({ data: null }),
28
- requestPushUnsynced: jest.fn(),
29
- },
30
- practices: {
31
- queryAll: jest.fn().mockResolvedValue({ data: [] }),
32
- getAll: jest.fn().mockResolvedValue({ data: [] }),
33
- },
34
- }
35
- return { default: mockFns, ...mockFns }
36
- })
37
-
38
- jest.mock('../../../src/services/sanity.js', () => ({
39
- getHierarchy: jest.fn().mockResolvedValue({ metadata: {}, parents: {}, children: {} }),
40
- getHierarchies: jest.fn().mockResolvedValue({ metadata: {}, parents: {}, children: {} }),
41
- getSanityDate: jest.fn((date: Date) => date.toISOString()),
42
- }))
43
-
44
- jest.mock('../../../src/services/content-org/learning-paths', () => ({
45
- getDailySession: jest.fn(),
46
- onLearningPathCompletedActions: jest.fn(),
47
- }))
48
-
49
- const flushPromises = () => new Promise(resolve => setImmediate(resolve))
50
-
51
- const mockRepo = jest.requireMock('../../../src/services/sync/repository-proxy')
52
-
53
- describe('filterOutNegativeProgress', () => {
54
- beforeEach(() => {
55
- initializeTestService()
56
- mockProgressRecords = []
57
- })
58
-
59
- test('drops entry when new progress is less than existing', () => {
60
- const result = filterOutNegativeProgress({ 101: 30 }, { 101: { progress: 70 } })
61
- expect(result).not.toHaveProperty('101')
62
- })
63
-
64
- test('keeps entry when new progress equals existing', () => {
65
- const result = filterOutNegativeProgress({ 101: 50 }, { 101: { progress: 50 } })
66
- expect(result).toHaveProperty('101', 50)
67
- })
68
-
69
- test('keeps entry when new progress is greater than existing', () => {
70
- const result = filterOutNegativeProgress({ 101: 80 }, { 101: { progress: 50 } })
71
- expect(result).toHaveProperty('101', 80)
72
- })
73
-
74
- test('keeps entry when existing progress is 0 and new is also 0', () => {
75
- const result = filterOutNegativeProgress({ 101: 0 }, { 101: { progress: 0 } })
76
- expect(result).toHaveProperty('101', 0)
77
- })
78
-
79
- test('drops only entries below existing, keeps others in mixed set', () => {
80
- const result = filterOutNegativeProgress(
81
- { 101: 20, 102: 80, 103: 40 },
82
- { 101: { progress: 70 }, 102: { progress: 20 }, 103: { progress: 0 } },
83
- )
84
- expect(result).not.toHaveProperty('101')
85
- expect(result).toHaveProperty('102')
86
- expect(result).toHaveProperty('103')
87
- })
88
-
89
- test('returns a new object and does not mutate input', () => {
90
- const progresses: Record<string, number> = { 101: 10 }
91
- const result = filterOutNegativeProgress(progresses, { 101: { progress: 50 } })
92
- expect(result).not.toBe(progresses)
93
- expect(progresses).toHaveProperty('101', 10)
94
- expect(result).not.toHaveProperty('101')
95
- })
96
- })
97
-
98
- describe('filterOutLearningPathsForDuplication', () => {
99
- beforeEach(() => {
100
- initializeTestService()
101
- mockProgressRecords = []
102
- })
103
-
104
- test('non-LP collection — all entries pass through', () => {
105
- const progresses = { 101: 30, 102: 50 }
106
- const result = filterOutLearningPathsForDuplication(progresses, {
107
- type: COLLECTION_TYPE.SELF,
108
- id: COLLECTION_ID_SELF,
109
- })
110
- expect(result).toEqual({ 101: 30, 102: 50 })
111
- })
112
-
113
- test('LP collection — excludes entry whose id matches collection id', () => {
114
- const progresses = { 200: 50, 101: 30, 102: 60 }
115
- const result = filterOutLearningPathsForDuplication(progresses, {
116
- type: COLLECTION_TYPE.LEARNING_PATH,
117
- id: 200,
118
- })
119
- expect(result).not.toHaveProperty('200')
120
- expect(result).toEqual({ 101: 30, 102: 60 })
121
- })
122
-
123
- test('LP collection — string key is coerced via +id comparison', () => {
124
- const progresses = { '300': 40, 101: 30 }
125
- const result = filterOutLearningPathsForDuplication(progresses, {
126
- type: COLLECTION_TYPE.LEARNING_PATH,
127
- id: 300,
128
- })
129
- expect(result).not.toHaveProperty('300')
130
- expect(result).toHaveProperty('101')
131
- })
132
-
133
- test('returns a new object, not the original', () => {
134
- const progresses = { 101: 30 }
135
- const result = filterOutLearningPathsForDuplication(progresses, {
136
- type: COLLECTION_TYPE.SELF,
137
- id: COLLECTION_ID_SELF,
138
- })
139
- expect(result).not.toBe(progresses)
140
- })
141
- })
142
-
143
- describe('duplicateProgressForIds', () => {
144
- beforeEach(() => {
145
- initializeTestService()
146
- mockProgressRecords = []
147
- jest.clearAllMocks()
148
- })
149
-
150
- test('empty object — no recordProgress and no requestPushUnsynced', async () => {
151
- await duplicateProgressForIds({})
152
- await flushPromises()
153
- expect(mockRepo.contentProgress.recordProgress).not.toHaveBeenCalled()
154
- expect(mockRepo.contentProgress.requestPushUnsynced).not.toHaveBeenCalled()
155
- })
156
-
157
- test('single entry — calls recordProgress once and skips push', async () => {
158
- await duplicateProgressForIds({ 101: 50 })
159
- await flushPromises()
160
- expect(mockRepo.contentProgress.recordProgress).toHaveBeenCalledTimes(1)
161
- expect(mockRepo.contentProgress.requestPushUnsynced).not.toHaveBeenCalled()
162
- })
163
-
164
- test('multiple entries — calls recordProgress per entry and skips push', async () => {
165
- await duplicateProgressForIds({ 101: 30, 102: 50, 103: 70 })
166
- await flushPromises()
167
- expect(mockRepo.contentProgress.recordProgress).toHaveBeenCalledTimes(3)
168
- expect(mockRepo.contentProgress.requestPushUnsynced).not.toHaveBeenCalled()
169
- })
170
- })
171
-
172
- describe('normalizeContentId', () => {
173
- beforeEach(() => {
174
- initializeTestService()
175
- mockProgressRecords = []
176
- })
177
-
178
- test('number — returns same number', () => {
179
- expect(normalizeContentId(123)).toBe(123)
180
- })
181
-
182
- test('numeric string — returns number', () => {
183
- expect(normalizeContentId('123')).toBe(123)
184
- })
185
-
186
- test('"0" — returns 0', () => {
187
- expect(normalizeContentId('0')).toBe(0)
188
- })
189
-
190
- test('non-numeric string — throws with correct message', () => {
191
- expect(() => normalizeContentId('abc')).toThrow('Invalid content id: abc')
192
- })
193
- })
194
-
195
- describe('normalizeContentIds', () => {
196
- beforeEach(() => {
197
- initializeTestService()
198
- mockProgressRecords = []
199
- })
200
-
201
- test('mixed array — all normalized to numbers', () => {
202
- expect(normalizeContentIds([1, '2', 3])).toEqual([1, 2, 3])
203
- })
204
-
205
- test('empty array — returns empty array', () => {
206
- expect(normalizeContentIds([])).toEqual([])
207
- })
208
-
209
- test('throws on invalid entry', () => {
210
- expect(() => normalizeContentIds([1, 'abc' as any])).toThrow('Invalid content id: abc')
211
- })
212
- })
213
-
214
- describe('normalizeCollection', () => {
215
- beforeEach(() => {
216
- initializeTestService()
217
- mockProgressRecords = []
218
- })
219
-
220
- test('null — returns null', () => {
221
- expect(normalizeCollection(null)).toBeNull()
222
- })
223
-
224
- test('undefined — returns null', () => {
225
- expect(normalizeCollection(undefined)).toBeNull()
226
- })
227
-
228
- test('valid with numeric id — returns { type, id }', () => {
229
- expect(normalizeCollection({ type: COLLECTION_TYPE.SELF, id: 123 })).toEqual({
230
- type: 'self',
231
- id: 123,
232
- })
233
- })
234
-
235
- test('valid with string id — returns { type, id: number }', () => {
236
- expect(normalizeCollection({ type: COLLECTION_TYPE.LEARNING_PATH, id: '456' as any })).toEqual({
237
- type: 'learning-path-v2',
238
- id: 456,
239
- })
240
- })
241
-
242
- test('invalid type — throws', () => {
243
- expect(() => normalizeCollection({ type: 'invalid' as any, id: 1 })).toThrow(
244
- 'Invalid collection type: invalid',
245
- )
246
- })
247
-
248
- test('non-numeric string id — throws', () => {
249
- expect(() => normalizeCollection({ type: COLLECTION_TYPE.SELF, id: 'abc' as any })).toThrow(
250
- 'Invalid collection id: abc',
251
- )
252
- })
253
- })
254
-
255
- describe('generateRecordId', () => {
256
- beforeEach(() => {
257
- initializeTestService()
258
- mockProgressRecords = []
259
- })
260
-
261
- test('0 contentId — returns null (falsy check)', () => {
262
- expect(generateRecordId(0, null)).toBeNull()
263
- })
264
-
265
- test('null contentId — returns null', () => {
266
- expect(generateRecordId(null as any, null)).toBeNull()
267
- })
268
-
269
- test('null collection — uses SELF defaults', () => {
270
- expect(generateRecordId(123, null)).toBe(
271
- `123:${COLLECTION_TYPE.SELF}:${COLLECTION_ID_SELF}`,
272
- )
273
- })
274
-
275
- test('LP collection — returns correct format', () => {
276
- expect(
277
- generateRecordId(123, { type: COLLECTION_TYPE.LEARNING_PATH, id: 456 }),
278
- ).toBe('123:learning-path-v2:456')
279
- })
280
-
281
- test('string contentId — normalized before use', () => {
282
- expect(generateRecordId('123' as any, null)).toBe(
283
- `123:${COLLECTION_TYPE.SELF}:${COLLECTION_ID_SELF}`,
284
- )
285
- })
286
- })
287
-
288
- describe('extractFromRecordId', () => {
289
- beforeEach(() => {
290
- initializeTestService()
291
- mockProgressRecords = []
292
- })
293
-
294
- test('null — returns null', () => {
295
- expect(extractFromRecordId(null)).toBeNull()
296
- })
297
-
298
- test('undefined — returns null', () => {
299
- expect(extractFromRecordId(undefined as any)).toBeNull()
300
- })
301
-
302
- test('self record id — correct parse', () => {
303
- expect(extractFromRecordId('123:self:0')).toEqual({
304
- contentId: 123,
305
- collection: { type: 'self', id: 0 },
306
- })
307
- })
308
-
309
- test('LP record id — correct parse', () => {
310
- expect(extractFromRecordId('456:learning-path-v2:789')).toEqual({
311
- contentId: 456,
312
- collection: { type: 'learning-path-v2', id: 789 },
313
- })
314
- })
315
-
316
- test('missing collection type — defaults to SELF', () => {
317
- expect(extractFromRecordId('123::')).toEqual({
318
- contentId: 123,
319
- collection: { type: COLLECTION_TYPE.SELF, id: COLLECTION_ID_SELF },
320
- })
321
- })
322
-
323
- test('missing collection id — defaults to COLLECTION_ID_SELF', () => {
324
- expect(extractFromRecordId('123:self:')).toEqual({
325
- contentId: 123,
326
- collection: { type: 'self', id: COLLECTION_ID_SELF },
327
- })
328
- })
329
- })