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,612 +0,0 @@
1
- import { initializeTestDB } from '../initializeTestDB'
2
- import {
3
- contentStatusCompleted,
4
- contentStatusReset,
5
- flushWatchSession,
6
- recordWatchSession,
7
- } from '../../../src/services/contentProgress.js'
8
- import {
9
- COLLECTION_ID_SELF,
10
- COLLECTION_TYPE,
11
- CollectionParameter,
12
- } from '../../../src/services/sync/models/ContentProgress'
13
- import db from '../../../src/services/sync/repository-proxy'
14
- import { clearHierarchies, setHierarchy } from './__mocks__/mocks'
15
-
16
- jest.mock('../../../src/services/sanity.js', () => require('./__mocks__/mocks').mockSanity())
17
- jest.mock('../../../src/services/content-org/learning-paths.ts', () => require('./__mocks__/mocks').mockLearningPaths())
18
- jest.mock('../../../src/services/awards/internal/content-progress-observer', () => require('./__mocks__/mocks').mockContentProgressObserver())
19
- jest.mock('../../../src/services/progress-events', () => require('./__mocks__/mocks').mockProgressEvents())
20
-
21
- jest.mock('../../../src/services/userActivity', () => ({
22
- trackUserPractice: jest.fn().mockResolvedValue(undefined),
23
- }))
24
-
25
- const selfCollection = { type: COLLECTION_TYPE.SELF, id: COLLECTION_ID_SELF }
26
- const playlistCollection = { type: COLLECTION_TYPE.PLAYLIST, id: 123 }
27
- const lpCollection = { type: COLLECTION_TYPE.LEARNING_PATH, id: 999 }
28
-
29
- const testMetadata = { brand: 'test-brand', type: 'test-type', parent_id: 0 }
30
-
31
- const learningPathsMock = jest.requireMock('../../../src/services/content-org/learning-paths.ts')
32
-
33
- const ctx = initializeTestDB()
34
-
35
- beforeEach(() => {
36
- clearHierarchies()
37
- learningPathsMock.onLearningPathCompletedActions.mockClear()
38
- learningPathsMock.getDailySession.mockClear()
39
- })
40
-
41
- type ExpectedProgress = {
42
- state?: string
43
- percent?: number
44
- collection?: CollectionParameter
45
- }
46
-
47
-
48
- function expectProgress(data: any, expected: ExpectedProgress) {
49
- const expectedState = expected.state ?? (expected.percent === 100 ? 'completed' : 'started')
50
- expect(data).not.toBeNull()
51
- if (expected.state !== undefined) expect(data.state).toBe(expectedState)
52
- if (expected.percent !== undefined) expect(data.progress_percent).toBe(expected.percent)
53
- if (expected.collection !== undefined) expect(data.collection_type).toBe(expected.collection.type)
54
- if (expected.collection !== undefined) expect(data.collection_id).toBe(expected.collection.id)
55
- }
56
-
57
- async function getOne(contentId: number, collection: CollectionParameter = null) {
58
- const result = await db.contentProgress.getOneProgressByContentId(contentId, collection)
59
- return result.data
60
- }
61
-
62
- async function writeOne(contentId: number, progress: number, collection: CollectionParameter = null) {
63
- await db.contentProgress.recordProgress(contentId, collection, progress, testMetadata, 0, { skipPush: true })
64
- }
65
-
66
- async function writeSome(contentIds: Record<string, number>, collection: CollectionParameter = null) {
67
- const contentMetadataMap = Object.fromEntries(Object.keys(contentIds).map(id => [id, testMetadata]))
68
- await db.contentProgress.recordProgressMany(contentIds, collection, contentMetadataMap, { skipPush: true })
69
- }
70
-
71
- describe('contentStatusCompleted', () => {
72
-
73
- describe('a-la-carte collection', () => {
74
- test('singular a-la-carte lesson', async () => {
75
- await contentStatusCompleted(500)
76
- const record = await getOne(500, null)
77
-
78
- expectProgress(record, { percent: 100, collection: selfCollection })
79
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
80
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('set-started-or-completed-status')
81
- })
82
-
83
- test('child a-la-carte lesson', async () => {
84
- setHierarchy({
85
- id: 1, type: 'course', children: [
86
- { id: 100, type: 'lesson' },
87
- { id: 200, type: 'lesson' },
88
- ],
89
- })
90
-
91
- await contentStatusCompleted(100)
92
-
93
- const child = await getOne(100, null)
94
- const sibling = await getOne(200, null)
95
- const parent = await getOne(1, null)
96
-
97
- expectProgress(child, { percent: 100, collection: selfCollection })
98
- expect(sibling).toBeNull()
99
- expectProgress(parent, { percent: 50, collection: selfCollection })
100
-
101
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
102
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('set-started-or-completed-status')
103
- })
104
-
105
- test('a-la-carte course within a course-collection', async () => {
106
- setHierarchy({
107
- id: 1, type: 'course-collection', children: [
108
- {
109
- id: 10, type: 'course', children: [
110
- { id: 100, type: 'lesson' },
111
- { id: 200, type: 'lesson' },
112
- ],
113
- },
114
- { id: 20, type: 'course' },
115
- ],
116
- })
117
-
118
- await contentStatusCompleted(10)
119
-
120
- const course = await getOne(10, null)
121
- const child100 = await getOne(100, null)
122
- const child200 = await getOne(200, null)
123
- const sibling = await getOne(20, null)
124
- const collection = await getOne(1, null)
125
-
126
- expectProgress(course, { percent: 100, collection: selfCollection })
127
- expectProgress(child100, { percent: 100, collection: selfCollection })
128
- expectProgress(child200, { percent: 100, collection: selfCollection })
129
- expect(sibling).toBeNull()
130
- expectProgress(collection, { percent: 50, collection: selfCollection })
131
-
132
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
133
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('set-started-or-completed-status')
134
- })
135
- })
136
-
137
- describe('playlist collection', () => {
138
- test('singular lesson in playlist', async () => {
139
- await contentStatusCompleted(500, playlistCollection)
140
-
141
- const playlistRecord = await getOne(500, playlistCollection)
142
- const aLaCarteRecord = await getOne(500, null)
143
-
144
- expectProgress(aLaCarteRecord, { percent: 100, collection: selfCollection })
145
- expect(playlistRecord).toBeNull()
146
-
147
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
148
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('set-started-or-completed-status')
149
- })
150
-
151
- test('child lesson in playlist', async () => {
152
- setHierarchy({
153
- id: 1, type: 'course', children: [
154
- { id: 100, type: 'lesson' },
155
- { id: 200, type: 'lesson' },
156
- ],
157
- })
158
-
159
- await contentStatusCompleted(100, playlistCollection)
160
-
161
- const childALC = await getOne(100, null)
162
- const childPL = await getOne(100, playlistCollection)
163
- const siblingALC = await getOne(200, null)
164
- const parentALC = await getOne(1, null)
165
-
166
- expectProgress(childALC, { percent: 100, collection: selfCollection })
167
- expectProgress(parentALC, { percent: 50, collection: selfCollection })
168
- expect(siblingALC).toBeNull()
169
- expect(childPL).toBeNull()
170
-
171
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
172
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('set-started-or-completed-status')
173
- })
174
- })
175
-
176
- describe('learning path collection', () => {
177
- test('learning path lesson', async () => {
178
- setHierarchy({
179
- id: 50, type: 'course', children: [
180
- { id: 100, type: 'lesson' },
181
- { id: 200, type: 'lesson' },
182
- ],
183
- })
184
- setHierarchy({
185
- id: 999, type: 'learning-path-v2', children: [
186
- { id: 100, type: 'lesson' },
187
- { id: 300, type: 'lesson' },
188
- ],
189
- }, { lp: true })
190
-
191
- await contentStatusCompleted(100, lpCollection)
192
-
193
- const childLP = await getOne(100, lpCollection)
194
- const lpLP = await getOne(999, lpCollection)
195
- const childALC = await getOne(100, null)
196
- const parentALC = await getOne(50, null)
197
- const lpALC = await getOne(999, null)
198
-
199
- expectProgress(childLP, { percent: 100, collection: lpCollection })
200
- expectProgress(lpLP, { percent: 50, collection: lpCollection })
201
- expectProgress(childALC, { percent: 100, collection: selfCollection })
202
- expectProgress(parentALC, { percent: 50, collection: selfCollection })
203
- expect(lpALC).toBeNull()
204
-
205
- expect(learningPathsMock.onLearningPathCompletedActions).not.toHaveBeenCalled()
206
-
207
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
208
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('set-started-or-completed-status')
209
- })
210
-
211
- test('learning path', async () => {
212
- setHierarchy({
213
- id: 50, type: 'course', children: [
214
- { id: 100, type: 'lesson' },
215
- { id: 200, type: 'lesson' },
216
- ],
217
- })
218
- setHierarchy({
219
- id: 999, type: 'learning-path-v2', children: [
220
- { id: 100, type: 'lesson' },
221
- { id: 300, type: 'lesson' },
222
- ],
223
- }, { lp: true })
224
-
225
- await contentStatusCompleted(999, lpCollection)
226
-
227
- const lpLP = await getOne(999, lpCollection)
228
- const child1LP = await getOne(100, lpCollection)
229
- const child2LP = await getOne(300, lpCollection)
230
- const lpALC = await getOne(999, null)
231
- const child1ALC = await getOne(100, null)
232
- const child2ALC = await getOne(300, null)
233
- const orphanALC = await getOne(200, null)
234
- const parentALC = await getOne(50, null)
235
-
236
- expectProgress(lpLP, { percent: 100, collection: lpCollection })
237
- expectProgress(child1LP, { percent: 100, collection: lpCollection })
238
- expectProgress(child2LP, { percent: 100, collection: lpCollection })
239
- expect(lpALC).toBeNull()
240
- expectProgress(child1ALC, { percent: 100, collection: selfCollection })
241
- expectProgress(child2ALC, { percent: 100, collection: selfCollection })
242
- expect(orphanALC).toBeNull()
243
- expectProgress(parentALC, { percent: 50, collection: selfCollection })
244
-
245
- expect(learningPathsMock.onLearningPathCompletedActions).toHaveBeenCalledTimes(1)
246
- expect(learningPathsMock.onLearningPathCompletedActions).toHaveBeenCalledWith(999)
247
-
248
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
249
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('set-started-or-completed-status')
250
- })
251
- })
252
- })
253
-
254
- describe('contentStatusStarted', () => {
255
- })
256
- // less important bcs very similar to `complete`. do later.
257
-
258
- describe('contentStatusReset', () => {
259
- describe('a-la-carte collection', () => {
260
- test('reset singular a-la-carte lesson', async () => {
261
- await writeOne(500, 100)
262
- await contentStatusReset(500)
263
-
264
- const record = await getOne(500, null)
265
-
266
- expect(record).toBeNull()
267
-
268
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
269
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('reset-status')
270
- })
271
-
272
- test('reset child a-la-carte lesson', async () => {
273
- setHierarchy({
274
- id: 1, type: 'course', children: [
275
- { id: 100, type: 'lesson' },
276
- { id: 200, type: 'lesson' },
277
- ],
278
- })
279
-
280
- await writeSome({
281
- 100: 100,
282
- 200: 100,
283
- 1: 100,
284
- })
285
- await contentStatusReset(100)
286
-
287
- const child = await getOne(100, null)
288
- const sibling = await getOne(200, null)
289
- const parent = await getOne(1, null)
290
-
291
- expect(child).toBeNull()
292
- expectProgress(sibling, { percent: 100 })
293
- expectProgress(parent, { percent: 50 })
294
-
295
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
296
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('reset-status')
297
- })
298
-
299
- test('reset a-la-carte course within a course-collection', async () => {
300
- setHierarchy({
301
- id: 1, type: 'course-collection', children: [
302
- {
303
- id: 10, type: 'course', children: [
304
- { id: 100, type: 'lesson' },
305
- { id: 200, type: 'lesson' },
306
- ],
307
- },
308
- { id: 20, type: 'course' },
309
- ],
310
- })
311
-
312
- await writeSome({
313
- 100: 100,
314
- 200: 100,
315
- 10: 100,
316
- 20: 100,
317
- 1: 100,
318
- })
319
- await contentStatusReset(10)
320
-
321
- const course = await getOne(10, null)
322
- const child100 = await getOne(100, null)
323
- const child200 = await getOne(200, null)
324
- const sibling = await getOne(20, null)
325
- const collection = await getOne(1, null)
326
-
327
- expect(course).toBeNull()
328
- expect(child100).toBeNull()
329
- expect(child200).toBeNull()
330
- expectProgress(sibling, { percent: 100 })
331
- expectProgress(collection, { percent: 50 })
332
-
333
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
334
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('reset-status')
335
- })
336
- })
337
-
338
- describe('playlist collection', () => {
339
- test('reset singular lesson in playlist', async () => {
340
- await writeOne(500, 100)
341
-
342
- await contentStatusReset(500)
343
-
344
- const aLaCarteRecord = await getOne(500, null)
345
- const playlistRecord = await getOne(500, playlistCollection)
346
-
347
- expect(aLaCarteRecord).toBeNull()
348
- expect(playlistRecord).toBeNull()
349
-
350
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
351
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('reset-status')
352
- })
353
-
354
- test('reset child lesson in playlist', async () => {
355
- setHierarchy({
356
- id: 1, type: 'course', children: [
357
- { id: 100, type: 'lesson' },
358
- { id: 200, type: 'lesson' },
359
- ],
360
- })
361
-
362
- await writeSome({
363
- 100: 100,
364
- 1: 50,
365
- })
366
- await contentStatusReset(100)
367
-
368
- const childALC = await getOne(100, null)
369
- const childPL = await getOne(100, playlistCollection)
370
- const parentALC = await getOne(1, null)
371
-
372
- expect(childALC).toBeNull()
373
- expect(childPL).toBeNull()
374
- expect(parentALC).toBeNull()
375
-
376
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
377
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('reset-status')
378
- })
379
- })
380
-
381
- describe('learning path collection', () => {
382
- test('reset learning path lesson', async () => {
383
- setHierarchy({
384
- id: 50, type: 'course', children: [
385
- { id: 100, type: 'lesson' },
386
- { id: 200, type: 'lesson' },
387
- ],
388
- })
389
- setHierarchy({
390
- id: 999, type: 'learning-path-v2', children: [
391
- { id: 100, type: 'lesson' },
392
- { id: 300, type: 'lesson' },
393
- ],
394
- }, { lp: true })
395
-
396
- await writeSome({
397
- 100: 100,
398
- 999: 50,
399
- }, lpCollection)
400
- await writeSome({
401
- 100: 100,
402
- 50: 50,
403
- })
404
- await contentStatusReset(100, lpCollection)
405
-
406
- const childLP = await getOne(100, lpCollection)
407
- const lpLP = await getOne(999, lpCollection)
408
- const childALC = await getOne(100, null)
409
- const parentALC = await getOne(50, null)
410
- const lpALC = await getOne(999, null)
411
-
412
- expect(childLP).toBeNull()
413
- expect(lpLP).toBeNull()
414
- expectProgress(childALC, { percent: 100 })
415
- expectProgress(parentALC, { percent: 50 })
416
- expect(lpALC).toBeNull()
417
-
418
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
419
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('reset-status')
420
- })
421
-
422
- test('reset learning path', async () => {
423
- setHierarchy({
424
- id: 50, type: 'course', children: [
425
- { id: 100, type: 'lesson' },
426
- { id: 200, type: 'lesson' },
427
- ],
428
- })
429
- setHierarchy({
430
- id: 999, type: 'learning-path-v2', children: [
431
- { id: 100, type: 'lesson' },
432
- { id: 300, type: 'lesson' },
433
- ],
434
- }, { lp: true })
435
-
436
- await writeSome({
437
- 999: 100,
438
- 100: 100,
439
- 300: 100,
440
- }, lpCollection)
441
- await writeSome({
442
- 100: 100,
443
- 50: 50,
444
- })
445
- await contentStatusReset(999, lpCollection)
446
-
447
- const lpLP = await getOne(999, lpCollection)
448
- const child1LP = await getOne(100, lpCollection)
449
- const child2LP = await getOne(300, lpCollection)
450
- const child1ALC = await getOne(100, null)
451
- const child2ALC = await getOne(200, null)
452
- const parentALC = await getOne(50, null)
453
- const lpALC = await getOne(999, null)
454
-
455
- expect(lpLP).toBeNull()
456
- expect(child1LP).toBeNull()
457
- expect(child2LP).toBeNull()
458
- expectProgress(child1ALC, { percent: 100 })
459
- expect(child2ALC).toBeNull()
460
- expectProgress(parentALC, { percent: 50 })
461
- expect(lpALC).toBeNull()
462
-
463
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledTimes(1)
464
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('reset-status')
465
- })
466
- })
467
- })
468
-
469
- describe('recordWatchSession', () => {
470
-
471
- describe('a-la-carte collection', () => {
472
- test('singular a-la-carte lesson, halfway', async () => {
473
- await recordWatchSession(500, null, 200, 100, 30)
474
-
475
- const record = await getOne(500, null)
476
- expectProgress(record, { percent: 50, collection: selfCollection })
477
- expect(ctx.pushSpies.contentProgress).not.toHaveBeenCalled()
478
- })
479
-
480
- test('singular a-la-carte lesson, watched to end clamps at 99', async () => {
481
- await recordWatchSession(500, null, 200, 200, 60)
482
-
483
- const record = await getOne(500, null)
484
- expectProgress(record, { percent: 99 })
485
- expect(ctx.pushSpies.contentProgress).not.toHaveBeenCalled()
486
- })
487
-
488
- test('child a-la-carte lesson bubbles to parent', async () => {
489
- setHierarchy({
490
- id: 1, type: 'course', children: [
491
- { id: 100, type: 'lesson' },
492
- { id: 200, type: 'lesson' },
493
- ],
494
- })
495
-
496
- await recordWatchSession(100, null, 200, 100, 30)
497
-
498
- const child = await getOne(100, null)
499
- const sibling = await getOne(200, null)
500
- const parent = await getOne(1, null)
501
-
502
- expectProgress(child, { percent: 50 })
503
- expect(sibling).toBeNull()
504
- expectProgress(parent, { percent: 25 })
505
-
506
- expect(ctx.pushSpies.contentProgress).not.toHaveBeenCalled()
507
- })
508
-
509
- test('flushWatchSession triggers push after watch', async () => {
510
- await recordWatchSession(500, null, 200, 100, 30)
511
- expect(ctx.pushSpies.contentProgress).not.toHaveBeenCalled()
512
-
513
- await flushWatchSession()
514
- expect(ctx.pushSpies.contentProgress).toHaveBeenCalledWith('flush-watch-session')
515
- })
516
- })
517
-
518
- describe('playlist collection', () => {
519
- test('singular lesson in playlist duplicates progress to a-la-carte via nested saveContentProgress', async () => {
520
- const playlistCollection = { type: COLLECTION_TYPE.PLAYLIST, id: 123 }
521
-
522
- await recordWatchSession(500, playlistCollection, 200, 100, 30)
523
-
524
- const aLaCarte = await getOne(500, null)
525
- const playlistRec = await getOne(500, playlistCollection)
526
-
527
- expectProgress(aLaCarte, { percent: 50, collection: selfCollection })
528
- expect(playlistRec).toBeNull()
529
- expect(ctx.pushSpies.contentProgress).not.toHaveBeenCalled()
530
- })
531
-
532
- test('child lesson in playlist duplicates and bubbles in a-la-carte', async () => {
533
- setHierarchy({
534
- id: 1, type: 'course', children: [
535
- { id: 100, type: 'lesson' },
536
- { id: 200, type: 'lesson' },
537
- ],
538
- })
539
- const playlistCollection = { type: COLLECTION_TYPE.PLAYLIST, id: 123 }
540
-
541
- await recordWatchSession(100, playlistCollection, 200, 100, 30)
542
-
543
- const childALC = await getOne(100, null)
544
- const childPL = await getOne(100, playlistCollection)
545
- const sibling = await getOne(200, null)
546
- const parentALC = await getOne(1, null)
547
-
548
- expectProgress(childALC, { percent: 50, collection: selfCollection })
549
- expect(childPL).toBeNull()
550
- expect(sibling).toBeNull()
551
- expectProgress(parentALC, { percent: 25, collection: selfCollection })
552
-
553
- expect(ctx.pushSpies.contentProgress).not.toHaveBeenCalled()
554
- })
555
- })
556
-
557
- describe('learning path collection', () => {
558
- test('child lesson in LP writes LP self+bubble, duplicates to a-la-carte and bubbles via nested saveContentProgress', async () => {
559
- setHierarchy({
560
- id: 50, type: 'course', children: [
561
- { id: 100, type: 'lesson' },
562
- { id: 200, type: 'lesson' },
563
- ],
564
- })
565
- setHierarchy({
566
- id: 999, type: 'learning-path-v2', children: [
567
- { id: 100, type: 'lesson' },
568
- { id: 300, type: 'lesson' },
569
- ],
570
- }, { lp: true })
571
-
572
- await recordWatchSession(100, lpCollection, 200, 100, 30)
573
-
574
- const childLP = await getOne(100, lpCollection)
575
- const lpLP = await getOne(999, lpCollection)
576
- const childALC = await getOne(100, null)
577
- const parentALC = await getOne(50, null)
578
- const lpALC = await getOne(999, null)
579
-
580
- expectProgress(childLP, { percent: 50, collection: lpCollection })
581
- expectProgress(lpLP, { percent: 25, collection: lpCollection })
582
- expectProgress(childALC, { percent: 50, collection: selfCollection })
583
- expectProgress(parentALC, { percent: 25, collection: selfCollection })
584
- expect(lpALC).toBeNull()
585
-
586
- expect(learningPathsMock.onLearningPathCompletedActions).not.toHaveBeenCalled()
587
- expect(ctx.pushSpies.contentProgress).not.toHaveBeenCalled()
588
- })
589
-
590
- test('watch session does not trickle: parent watch leaves children untouched', async () => {
591
- setHierarchy({
592
- id: 999, type: 'learning-path-v2', children: [
593
- { id: 100, type: 'lesson' },
594
- { id: 300, type: 'lesson' },
595
- ],
596
- }, { lp: true })
597
-
598
- await recordWatchSession(999, lpCollection, 200, 100, 30)
599
-
600
- const lpLP = await getOne(999, lpCollection)
601
- const child1LP = await getOne(100, lpCollection)
602
- const child2LP = await getOne(300, lpCollection)
603
-
604
- expectProgress(lpLP, { percent: 50, collection: lpCollection })
605
- expect(child1LP).toBeNull()
606
- expect(child2LP).toBeNull()
607
-
608
- expect(learningPathsMock.onLearningPathCompletedActions).not.toHaveBeenCalled()
609
- expect(ctx.pushSpies.contentProgress).not.toHaveBeenCalled()
610
- })
611
- })
612
- })