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,392 +0,0 @@
1
- import { initializeTestService } from '../../initializeTests.js'
2
- import {
3
- buildNavigateTo,
4
- findIncompleteLesson,
5
- getNavigateTo,
6
- getNavigateToForMethod,
7
- } from '../../../src/services/contentProgress.js'
8
- import { COLLECTION_TYPE } from '../../../src/services/sync/models/ContentProgress'
9
-
10
- let mockProgressRecords: any[] = []
11
- let mockLastInteracted: number | null = null
12
-
13
- jest.mock('../../../src/services/sync/repository-proxy', () => {
14
- const mockFns = {
15
- contentProgress: {
16
- getOneProgressByContentId: jest.fn().mockImplementation((contentId) => {
17
- const record = mockProgressRecords.find(r => r.content_id === contentId)
18
- return Promise.resolve({ data: record || null })
19
- }),
20
- getSomeProgressByContentIds: jest.fn().mockImplementation((contentIds) => {
21
- const records = mockProgressRecords.filter(r => contentIds.includes(r.content_id))
22
- return Promise.resolve({ data: records })
23
- }),
24
- mostRecentlyUpdatedId: jest.fn().mockImplementation(() => {
25
- return Promise.resolve({ data: mockLastInteracted })
26
- }),
27
- },
28
- practices: {
29
- queryAll: jest.fn().mockResolvedValue({ data: [] }),
30
- getAll: jest.fn().mockResolvedValue({ data: [] }),
31
- },
32
- }
33
- return { default: mockFns, ...mockFns }
34
- })
35
-
36
- jest.mock('../../../src/services/content-org/learning-paths', () => ({
37
- getDailySession: jest.fn().mockResolvedValue(null),
38
- onLearningPathCompletedActions: jest.fn().mockResolvedValue(undefined),
39
- }))
40
-
41
- jest.mock('../../../src/services/sanity.js', () => ({
42
- getHierarchy: jest.fn().mockResolvedValue({ metadata: {}, parents: {}, children: {} }),
43
- getHierarchies: jest.fn().mockResolvedValue({ metadata: {}, parents: {}, children: {} }),
44
- getSanityDate: jest.fn((date: Date) => date.toISOString()),
45
- }))
46
-
47
- const { getDailySession } = jest.requireMock('../../../src/services/content-org/learning-paths')
48
-
49
- const child = (id: number, type = 'lesson') => ({
50
- id,
51
- brand: 'drumeo',
52
- thumbnail: '',
53
- type,
54
- published_on: null,
55
- status: 'published',
56
- children: null as any,
57
- })
58
-
59
- beforeEach(() => {
60
- jest.clearAllMocks()
61
- initializeTestService()
62
- mockProgressRecords = []
63
- mockLastInteracted = null
64
- })
65
-
66
- // ─── buildNavigateTo ──────────────────────────────────────────────────────────
67
-
68
- describe('buildNavigateTo', () => {
69
- test('null content returns null', () => {
70
- expect(buildNavigateTo(null)).toBeNull()
71
- })
72
-
73
- test('valid content returns correct shape', () => {
74
- const content = {
75
- id: 101,
76
- brand: 'drumeo',
77
- thumbnail: 'thumb.jpg',
78
- type: 'lesson',
79
- published_on: '2024-01-01',
80
- status: 'published',
81
- }
82
- const result = buildNavigateTo(content)
83
- expect(result).toEqual({
84
- brand: 'drumeo',
85
- thumbnail: 'thumb.jpg',
86
- id: 101,
87
- type: 'lesson',
88
- published_on: '2024-01-01',
89
- status: 'published',
90
- child: null,
91
- collection: null,
92
- })
93
- })
94
-
95
- test('missing fields fall back to defaults', () => {
96
- const result = buildNavigateTo({ id: 5 })
97
- expect(result).toMatchObject({
98
- brand: '',
99
- thumbnail: '',
100
- id: 5,
101
- type: '',
102
- published_on: null,
103
- status: '',
104
- child: null,
105
- collection: null,
106
- })
107
- })
108
-
109
- test('child and collection args pass through', () => {
110
- const childObj = {
111
- id: 200,
112
- brand: 'drumeo',
113
- thumbnail: '',
114
- type: 'lesson',
115
- published_on: null,
116
- status: 'published',
117
- }
118
- const collection = { type: COLLECTION_TYPE.LEARNING_PATH, id: 999 }
119
- const result = buildNavigateTo({ id: 100 }, childObj, collection)
120
- expect(result?.child).toBe(childObj)
121
- expect(result?.collection).toBe(collection)
122
- })
123
- })
124
-
125
- // ─── findIncompleteLesson ─────────────────────────────────────────────────────
126
-
127
- describe('findIncompleteLesson', () => {
128
- describe('course type', () => {
129
- test('finds first incomplete after currentContentId', () => {
130
- const progresses = new Map([
131
- [101, 'completed'],
132
- [102, 'completed'],
133
- [103, 'started'],
134
- [104, ''],
135
- ])
136
- expect(findIncompleteLesson(progresses, 102, 'course')).toBe(103)
137
- })
138
-
139
- // todo(BEHSTP-325): add a test "returns currentContentId if it's incomplete"
140
-
141
- test('wraps to first when all after current are completed, even if some before are incomplete', () => {
142
- const progresses = new Map([
143
- [101, 'completed'],
144
- [102, 'started'],
145
- [103, 'completed'],
146
- [104, 'completed'],
147
- ])
148
- expect(findIncompleteLesson(progresses, 103, 'course')).toBe(101)
149
- })
150
-
151
- test('returns null when currentContentId not in ids', () => {
152
- const progresses = new Map([
153
- [101, 'started'],
154
- [102, 'completed'],
155
- ])
156
- expect(findIncompleteLesson(progresses, 999, 'course')).toBeNull()
157
- })
158
- })
159
-
160
- describe('guided-course type', () => {
161
- test('finds first incomplete regardless of position', () => {
162
- const progresses = new Map([
163
- [101, 'completed'],
164
- [102, ''],
165
- [103, 'started'],
166
- ])
167
- expect(findIncompleteLesson(progresses, 103, 'guided-course')).toBe(102)
168
- })
169
-
170
- test('returns first id when all completed', () => {
171
- const progresses = new Map([
172
- [101, 'completed'],
173
- [102, 'completed'],
174
- [103, 'completed'],
175
- ])
176
- expect(findIncompleteLesson(progresses, 102, 'guided-course')).toBe(101)
177
- })
178
- })
179
-
180
- describe('learning-path-v2 type', () => {
181
- test('finds first incomplete regardless of position', () => {
182
- const progresses = new Map([
183
- [101, 'completed'],
184
- [102, ''],
185
- [103, 'started'],
186
- ])
187
- expect(findIncompleteLesson(progresses, 103, 'learning-path-v2')).toBe(102)
188
- })
189
-
190
- test('returns first id when all completed', () => {
191
- const progresses = new Map([
192
- [101, 'completed'],
193
- [102, 'completed'],
194
- [103, 'completed'],
195
- ])
196
- expect(findIncompleteLesson(progresses, 102, 'learning-path-v2')).toBe(101)
197
- })
198
- })
199
-
200
- describe('Map vs Object input', () => {
201
- test('works with Map input', () => {
202
- const progresses = new Map([
203
- [101, 'completed'],
204
- [102, ''],
205
- ])
206
- expect(findIncompleteLesson(progresses, 101, 'course')).toBe(102)
207
- })
208
-
209
- test('works with Object input', () => {
210
- const progresses = { 101: 'completed', 102: '' }
211
- expect(findIncompleteLesson(progresses, 101, 'course')).toBe(102)
212
- })
213
- })
214
- })
215
-
216
- // ─── getNavigateTo ────────────────────────────────────────────────────────────
217
-
218
- describe('getNavigateTo', () => {
219
- test('null entry in data array skipped', async () => {
220
- const result = await getNavigateTo([null as any, { id: 1, type: 'lesson', children: [] }])
221
- expect(result[1]).toBeNull()
222
- expect(Object.keys(result)).not.toContain('null')
223
- expect(Object.keys(result)).not.toContain('undefined')
224
- })
225
-
226
- test('non-navigable type returns null', async () => {
227
- const result = await getNavigateTo([{ id: 1, type: 'lesson', children: [child(101)] }])
228
- expect(result[1]).toBeNull()
229
- })
230
-
231
- test('null children returns null', async () => {
232
- const result = await getNavigateTo([{ id: 1, type: 'course', children: null }])
233
- expect(result[1]).toBeNull()
234
- })
235
-
236
- test('empty children after filtering nulls returns null', async () => {
237
- const result = await getNavigateTo([{ id: 1, type: 'course', children: [null, null] }])
238
- expect(result[1]).toBeNull()
239
- })
240
-
241
- test('content not started navigates to first child', async () => {
242
- const result = await getNavigateTo([{ id: 1, type: 'course', children: [child(101), child(102)] }])
243
- expect(result[1]).toMatchObject({ id: 101 })
244
- })
245
-
246
- test('course started lastInteracted started navigates to lastInteracted child', async () => {
247
- mockProgressRecords = [
248
- { content_id: 1, state: 'started', progress_percent: 50, updated_at: 1000 },
249
- { content_id: 101, state: 'started', progress_percent: 100, updated_at: 900 },
250
- { content_id: 102, state: 'started', progress_percent: 30, updated_at: 1000 },
251
- ]
252
- mockLastInteracted = 101
253
- const result = await getNavigateTo([{ id: 1, type: 'course', children: [child(101), child(102)] }])
254
- expect(result[1]).toMatchObject({ id: 101 })
255
- })
256
-
257
- test('documentary started lastInteracted started navigates to lastInteracted child', async () => {
258
- mockProgressRecords = [
259
- { content_id: 1, state: 'started', progress_percent: 50, updated_at: 1000 },
260
- { content_id: 101, state: 'started', progress_percent: 100, updated_at: 900 },
261
- { content_id: 102, state: 'started', progress_percent: 30, updated_at: 1000 },
262
- ]
263
- mockLastInteracted = 101
264
- const result = await getNavigateTo([{ id: 1, type: 'documentary', children: [child(101), child(102)] }])
265
- expect(result[1]).toMatchObject({ id: 101 })
266
- })
267
-
268
- test('course started lastInteracted completed navigates to first incomplete after lastInteracted', async () => {
269
- mockProgressRecords = [
270
- { content_id: 1, state: 'started', progress_percent: 60, updated_at: 1000 },
271
- { content_id: 101, state: 'completed', progress_percent: 100, updated_at: 900 },
272
- { content_id: 102, state: 'completed', progress_percent: 100, updated_at: 1000 },
273
- { content_id: 103, state: 'started', progress_percent: 20, updated_at: 800 },
274
- ]
275
- mockLastInteracted = 101
276
- const result = await getNavigateTo([{ id: 1, type: 'course', children: [child(101), child(102), child(103)] }])
277
- expect(result[1]).toMatchObject({ id: 103 })
278
- })
279
-
280
- test('course started all children completed wraps to first child', async () => {
281
- mockProgressRecords = [
282
- { content_id: 1, state: 'started', progress_percent: 100, updated_at: 1000 },
283
- { content_id: 101, state: 'completed', progress_percent: 100, updated_at: 900 },
284
- { content_id: 102, state: 'completed', progress_percent: 100, updated_at: 1000 },
285
- ]
286
- mockLastInteracted = 102
287
- const result = await getNavigateTo([{ id: 1, type: 'course', children: [child(101), child(102)] }])
288
- expect(result[1]).toMatchObject({ id: 101 })
289
- })
290
-
291
- test('guided-course started navigates to first incomplete child', async () => {
292
- mockProgressRecords = [
293
- { content_id: 1, state: 'started', progress_percent: 50, updated_at: 1000 },
294
- { content_id: 101, state: 'completed', progress_percent: 100, updated_at: 900 },
295
- ]
296
- mockLastInteracted = 101
297
- const result = await getNavigateTo([{
298
- id: 1,
299
- type: 'guided-course',
300
- children: [child(101), child(102), child(103)],
301
- }])
302
- expect(result[1]).toMatchObject({ id: 102 })
303
- })
304
-
305
- describe.each(['course', 'skill-pack', 'song-tutorial'])('course-flow type %s', (type) => {
306
- test('lastInteracted completed → first incomplete after lastInteracted', async () => {
307
- mockProgressRecords = [
308
- { content_id: 1, state: 'started', progress_percent: 50, updated_at: 1000 },
309
- { content_id: 101, state: '', progress_percent: 0, updated_at: 0 },
310
- { content_id: 102, state: 'completed', progress_percent: 100, updated_at: 1000 },
311
- { content_id: 103, state: '', progress_percent: 0, updated_at: 0 },
312
- ]
313
- mockLastInteracted = 102
314
- const result = await getNavigateTo([{ id: 1, type, children: [child(101), child(102), child(103)] }])
315
- expect(result[1]).toMatchObject({ id: 103 })
316
- })
317
- })
318
-
319
- describe.each(['guided-course', COLLECTION_TYPE.LEARNING_PATH])('guided-course-flow type %s', (type) => {
320
- test('finds first incomplete regardless of lastInteracted position', async () => {
321
- mockProgressRecords = [
322
- { content_id: 1, state: 'started', progress_percent: 50, updated_at: 1000 },
323
- { content_id: 101, state: '', progress_percent: 0, updated_at: 0 },
324
- { content_id: 102, state: 'completed', progress_percent: 100, updated_at: 1000 },
325
- { content_id: 103, state: '', progress_percent: 0, updated_at: 0 },
326
- ]
327
- mockLastInteracted = 102
328
- const result = await getNavigateTo([{ id: 1, type, children: [child(101), child(102), child(103)] }])
329
- expect(result[1]).toMatchObject({ id: 101 })
330
- })
331
- })
332
-
333
- // need more tests to support other types and potentially other logic branches.
334
- })
335
-
336
- // ─── getNavigateToForMethod ───────────────────────────────────────────────────
337
-
338
- describe('getNavigateToForMethod', () => {
339
- const lpContent = (id: number, children: any[]) => ({
340
- id,
341
- brand: 'drumeo',
342
- thumbnail: '',
343
- type: COLLECTION_TYPE.LEARNING_PATH,
344
- published_on: null,
345
- status: 'published',
346
- children,
347
- record_id: `${id}:${COLLECTION_TYPE.LEARNING_PATH}:${id}`,
348
- })
349
-
350
- const nonLpContent = (id: number) => ({
351
- id,
352
- brand: 'drumeo',
353
- thumbnail: '',
354
- type: 'course',
355
- published_on: null,
356
- status: 'published',
357
- children: [child(201), child(202)],
358
- record_id: `${id}:self:0`,
359
- })
360
-
361
- test('non-LP content type returns null', async () => {
362
- const result = await getNavigateToForMethod([nonLpContent(1)])
363
- expect(result[1]).toBeNull()
364
- })
365
-
366
- test('LP type with no daily session navigates to first incomplete child', async () => {
367
- getDailySession.mockResolvedValueOnce(null)
368
- const result = await getNavigateToForMethod([lpContent(10, [child(301), child(302), child(303)])])
369
- expect(result[10]).toMatchObject({ id: 301 })
370
- })
371
-
372
- test('LP type with active learning path and daily session navigates using daily session', async () => {
373
- mockProgressRecords = [
374
- { content_id: 301, state: 'completed', progress_percent: 100, updated_at: 900 },
375
- ]
376
- getDailySession.mockResolvedValueOnce({
377
- active_learning_path_id: 10,
378
- daily_session: [{ content_ids: [301, 302] }],
379
- })
380
- const result = await getNavigateToForMethod([lpContent(10, [child(300), child(301), child(302)])])
381
- expect(result[10]).toMatchObject({ id: 302 })
382
- })
383
-
384
- test('null content entries skipped', async () => {
385
- getDailySession.mockResolvedValueOnce(null)
386
- const validContent = lpContent(10, [child(301)])
387
- const result = await getNavigateToForMethod([validContent, null as any])
388
- expect(Object.keys(result)).toContain('10')
389
- expect(Object.keys(result)).not.toContain('null')
390
- expect(Object.keys(result)).not.toContain('undefined')
391
- })
392
- })
@@ -1,62 +0,0 @@
1
- import {
2
- isContentLiked,
3
- likeContent,
4
- unlikeContent,
5
- } from '../../src/services/contentLikes.js'
6
- import { initializeTestService } from '../initializeTests.js'
7
-
8
- let mockLikedIds: Set<number> = new Set()
9
-
10
- jest.mock('../../src/services/sync/repository-proxy.ts', () => {
11
- const mockFns = {
12
- likes: {
13
- isLiked: jest.fn().mockImplementation((contentId) =>
14
- Promise.resolve({ data: mockLikedIds.has(Number(contentId)) })
15
- ),
16
- areLiked: jest.fn().mockImplementation((contentIds) =>
17
- Promise.resolve({ data: contentIds.map(id => mockLikedIds.has(Number(id))) })
18
- ),
19
- like: jest.fn().mockImplementation((contentId) => {
20
- mockLikedIds.add(Number(contentId))
21
- return Promise.resolve({ success: true })
22
- }),
23
- unlike: jest.fn().mockImplementation((contentId) => {
24
- mockLikedIds.delete(Number(contentId))
25
- return Promise.resolve({ success: true })
26
- }),
27
- }
28
- }
29
- return { default: mockFns, ...mockFns }
30
- })
31
-
32
-
33
- describe('contentLikesDataContext', function () {
34
- beforeEach(() => {
35
- initializeTestService()
36
- mockLikedIds = new Set([308516, 308515, 308514, 308518])
37
- })
38
-
39
- test('contentLiked', async () => {
40
- expect(await isContentLiked(308516)).toBe(true)
41
- })
42
-
43
- test('contentLikedStringInput', async () => {
44
- expect(await isContentLiked('308516')).toBe(true)
45
- })
46
-
47
- test('contentNotLiked', async () => {
48
- expect(await isContentLiked(121111)).toBe(false)
49
- })
50
-
51
- test('likeContent', async () => {
52
- expect(await isContentLiked(111111)).toBe(false)
53
- await likeContent(111111)
54
- expect(await isContentLiked(111111)).toBe(true)
55
- })
56
-
57
- test('unlikeContent', async () => {
58
- expect(await isContentLiked(308516)).toBe(true)
59
- await unlikeContent(308516)
60
- expect(await isContentLiked(308516)).toBe(false)
61
- })
62
- })
@@ -1,58 +0,0 @@
1
- import { processMetadata } from '@/contentMetaData'
2
-
3
- describe('processMetadata', () => {
4
- test('returns null for unknown brand and type', () => {
5
- expect(processMetadata('unknown', 'unknown')).toBeNull()
6
- })
7
-
8
- test('returns null for unknown type on known brand', () => {
9
- expect(processMetadata('drumeo', 'unknown-type')).toBeNull()
10
- })
11
-
12
- test('returns expected shape for known brand and type', () => {
13
- const result = processMetadata('drumeo', 'lessons')
14
-
15
- expect(result).not.toBeNull()
16
- expect(result.type).toBe('lessons')
17
- expect(result.name).toBeDefined()
18
- expect(result.sort).toBeDefined()
19
- expect(result.tabs).toBeDefined()
20
- expect(Array.isArray(result.tabs)).toBe(true)
21
- })
22
-
23
- test('does not include filters when withFilters is false', () => {
24
- const result = processMetadata('drumeo', 'lessons')
25
-
26
- expect(result.filters).toBeUndefined()
27
- })
28
-
29
- test('includes filters when withFilters is true', () => {
30
- const result = processMetadata('drumeo', 'lessons', true)
31
-
32
- expect(result.filters).toBeDefined()
33
- })
34
-
35
- test('brand-specific filters differ between brands for the same type', () => {
36
- const drumeo = processMetadata('drumeo', 'lessons', true)
37
- const pianote = processMetadata('pianote', 'lessons', true)
38
-
39
- expect(JSON.stringify(drumeo.filters)).not.toBe(JSON.stringify(pianote.filters))
40
- })
41
-
42
- test('shared structure is consistent across brands for the same type', () => {
43
- const drumeo = processMetadata('drumeo', 'lessons')
44
- const pianote = processMetadata('pianote', 'lessons')
45
-
46
- expect(drumeo.type).toBe(pianote.type)
47
- expect(drumeo.name).toBe(pianote.name)
48
- expect(JSON.stringify(drumeo.tabs)).toBe(JSON.stringify(pianote.tabs))
49
- })
50
-
51
- test('songs tabs are brand-specific based on song types config', () => {
52
- const result = processMetadata('drumeo', 'songs')
53
-
54
- expect(result).not.toBeNull()
55
- expect(result.tabs.length).toBeGreaterThan(0)
56
- expect(result.tabs[0].name).toBe('For You')
57
- })
58
- })
@@ -1,38 +0,0 @@
1
- import { initializeTestService } from '../initializeTests.js'
2
- import { DataContext, verifyLocalDataContext } from '../../src/services/dataContext.js'
3
-
4
- describe('dataContext', function () {
5
- let mock: jest.SpyInstance
6
- let testVersion = 1
7
- const dataVersionKey = 1
8
- const dataContext = new DataContext(dataVersionKey, null)
9
-
10
- beforeEach(() => {
11
- initializeTestService()
12
- mock = jest.spyOn(dataContext, 'fetchData')
13
- mock.mockImplementation(() =>
14
- JSON.parse(`{"version":${testVersion},"data":[308516,308515,308514,308518]}`)
15
- )
16
- })
17
-
18
- test('verifyLocalData', async () => {
19
- //force load data into context and verify version 1 loaded
20
- await dataContext.getData()
21
- expect(dataContext.version()).toBe(1)
22
-
23
- //increment source version and verify data context still uses old version
24
- testVersion++
25
- await dataContext.getData()
26
- expect(dataContext.version()).toBe(1)
27
-
28
- //verifyLocalData with old source version and verify context still uses old version
29
- await verifyLocalDataContext(1, 1)
30
- await dataContext.getData()
31
- expect(dataContext.version()).toBe(1)
32
-
33
- //verifyLocalData with new source version and verify context loads new version
34
- await verifyLocalDataContext(1, 2)
35
- await dataContext.getData()
36
- expect(dataContext.version()).toBe(2)
37
- })
38
- })