musora-content-services 2.158.2 → 2.159.0
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.
- package/.claude/settings.local.json +12 -0
- package/.github/workflows/automated-testing.yml +21 -1
- package/CHANGELOG.md +15 -0
- package/README.md +21 -2
- package/jest.config.js +1 -4
- package/jest.integration.config.js +6 -0
- package/jest.live.config.js +1 -5
- package/package.json +5 -2
- package/src/contentTypeConfig.js +8 -5
- package/src/index.d.ts +2 -6
- package/src/index.js +2 -6
- package/src/services/content-org/learning-paths.ts +44 -39
- package/src/services/contentAggregator.js +1 -1
- package/src/services/contentProgress.js +216 -207
- package/src/services/offline/progress.ts +107 -27
- package/src/services/sanity.js +55 -64
- package/src/services/sync/models/ContentProgress.ts +50 -34
- package/src/services/sync/repositories/content-progress.ts +105 -92
- package/test/{unit → integration}/awards/award-exclusion-handling.test.ts +2 -2
- package/test/integration/content-progress/__mocks__/mocks.ts +104 -0
- package/test/integration/content-progress/contentProgress.test.ts +335 -0
- package/test/integration/content-progress/e2eOfflineProgress.test.ts +352 -0
- package/test/integration/content-progress/e2eProgress.test.ts +612 -0
- package/test/integration/content-progress/getters.test.ts +334 -0
- package/test/integration/content-progress/helpers.test.ts +263 -0
- package/test/integration/content-progress/offlineContentProgress.test.ts +226 -0
- package/test/integration/forums.test.ts +209 -0
- package/test/integration/initializeTestDB.ts +80 -0
- package/test/{unit → integration}/sync/fetch.test.ts +1 -1
- package/test/{unit → integration}/sync/repositories/content-likes.test.ts +1 -1
- package/test/{unit → integration}/sync/repositories/practices.test.ts +1 -1
- package/test/{unit → integration}/sync/repositories/progress.test.ts +1 -1
- package/test/{unit → integration}/sync/repositories/user-award-progress.test.ts +1 -1
- package/test/{unit → integration}/sync/store/cross-user-protection.test.ts +2 -2
- package/test/{unit → integration}/sync/store/store-idb.test.ts +2 -2
- package/test/{unit → integration}/sync/store/store.test.ts +2 -2
- package/test/unit/content-progress/bubbleTrickle.test.ts +322 -0
- package/test/unit/content-progress/helpers.test.ts +329 -0
- package/test/unit/content-progress/navigateTo.test.ts +381 -0
- package/test/unit/contentMetaData.test.ts +58 -0
- package/tools/generate-index.cjs +6 -3
- package/test/SKIPPED_TESTS.md +0 -151
- package/test/integration/content.test.js +0 -107
- package/test/integration/contentProgress.test.js +0 -73
- package/test/integration/forum.test.js +0 -16
- package/test/integration/sanityQueryService.test.js +0 -681
- package/test/unit/contentProgress.test.ts +0 -81
- /package/test/{unit → integration}/awards/internal/image-utils.test.ts +0 -0
- /package/test/{unit → integration}/infrastructure/FetchRequestExecutor.test.ts +0 -0
- /package/test/{unit → integration}/notifications.test.ts +0 -0
- /package/test/{unit → integration}/sync/adapters/idb-errors.test.ts +0 -0
- /package/test/{unit → integration}/sync/adapters/sqlite-errors.test.ts +0 -0
- /package/test/{unit → integration}/sync/repositories/user-award-progress.static.test.ts +0 -0
- /package/test/{unit → integration}/userActivity.test.ts +0 -0
|
@@ -0,0 +1,612 @@
|
|
|
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
|
+
})
|