musora-content-services 2.167.1 → 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 (136) hide show
  1. package/.agent/decisions/2026-07-17-onboarding-statuses.md +21 -0
  2. package/.agent/decisions/2026-07-20-mu2-1724-songs-lessons-counts.md +33 -0
  3. package/.agent/decisions/2026-07-20-query-builder-tostring.md +37 -0
  4. package/CHANGELOG.md +15 -0
  5. package/package.json +2 -1
  6. package/src/contentTypeConfig.js +2 -0
  7. package/src/index.d.ts +2 -0
  8. package/src/index.js +2 -0
  9. package/src/lib/sanity/query.ts +5 -0
  10. package/src/services/config.js +15 -0
  11. package/src/services/content/artist.ts +1 -3
  12. package/src/services/content/counts.ts +47 -0
  13. package/src/services/content/genre.ts +1 -3
  14. package/src/services/content/instructor.ts +1 -3
  15. package/src/services/contentProgress.js +1 -1
  16. package/src/services/eventsAPI.js +49 -7
  17. package/src/services/user/onboarding.ts +22 -0
  18. package/src/services/userActivity.js +2 -0
  19. package/src/version-info.js +1 -0
  20. package/.claude/settings.local.json +0 -52
  21. package/test/initializeTests.js +0 -60
  22. package/test/integration/awards/award-exclusion-handling.test.ts +0 -275
  23. package/test/integration/awards/internal/image-utils.test.ts +0 -86
  24. package/test/integration/content-progress/__mocks__/mocks.ts +0 -104
  25. package/test/integration/content-progress/contentProgress.test.ts +0 -335
  26. package/test/integration/content-progress/e2eOfflineProgress.test.ts +0 -352
  27. package/test/integration/content-progress/e2eProgress.test.ts +0 -612
  28. package/test/integration/content-progress/getters.test.ts +0 -334
  29. package/test/integration/content-progress/helpers.test.ts +0 -263
  30. package/test/integration/content-progress/offlineContentProgress.test.ts +0 -226
  31. package/test/integration/forums.test.ts +0 -209
  32. package/test/integration/infrastructure/FetchRequestExecutor.test.ts +0 -88
  33. package/test/integration/initializeTestDB.ts +0 -80
  34. package/test/integration/learning-paths.test.ts +0 -854
  35. package/test/integration/notifications.test.ts +0 -178
  36. package/test/integration/progress-row/content-card.test.ts +0 -283
  37. package/test/integration/sync/adapters/idb-errors.test.ts +0 -144
  38. package/test/integration/sync/adapters/sqlite-errors.test.ts +0 -173
  39. package/test/integration/sync/fetch.test.ts +0 -224
  40. package/test/integration/sync/repositories/content-likes.test.ts +0 -99
  41. package/test/integration/sync/repositories/practices.test.ts +0 -179
  42. package/test/integration/sync/repositories/progress.test.ts +0 -245
  43. package/test/integration/sync/repositories/user-award-progress.static.test.ts +0 -68
  44. package/test/integration/sync/repositories/user-award-progress.test.ts +0 -387
  45. package/test/integration/sync/store/cross-user-protection.test.ts +0 -217
  46. package/test/integration/sync/store/store-idb.test.ts +0 -180
  47. package/test/integration/sync/store/store.test.ts +0 -361
  48. package/test/integration/user/permissions.test.js +0 -20
  49. package/test/integration/userActivity.test.ts +0 -102
  50. package/test/live/README.md +0 -29
  51. package/test/live/content.test.js +0 -116
  52. package/test/localStorageMock.js +0 -21
  53. package/test/log.js +0 -5
  54. package/test/mockData/award-definitions.js +0 -171
  55. package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -35
  56. package/test/mockData/mockData_progress_content.json +0 -182
  57. package/test/mockData/mockData_sanity_progress_content.json +0 -1451
  58. package/test/mockData/mockData_user_practices.json +0 -9
  59. package/test/setupConsole.js +0 -6
  60. package/test/setupNetworkGuard.js +0 -3
  61. package/test/setupTimers.js +0 -13
  62. package/test/unit/HttpClient.test.ts +0 -267
  63. package/test/unit/awards/award-alacarte-observer.test.ts +0 -199
  64. package/test/unit/awards/award-auto-refresh.test.ts +0 -84
  65. package/test/unit/awards/award-calculations.test.ts +0 -34
  66. package/test/unit/awards/award-callbacks.test.ts +0 -144
  67. package/test/unit/awards/award-certificate-display.test.ts +0 -330
  68. package/test/unit/awards/award-collection-edge-cases.test.ts +0 -212
  69. package/test/unit/awards/award-collection-filtering.test.ts +0 -287
  70. package/test/unit/awards/award-completion-flow.test.ts +0 -306
  71. package/test/unit/awards/award-multi-lesson.test.ts +0 -243
  72. package/test/unit/awards/award-observer-integration.test.ts +0 -327
  73. package/test/unit/awards/award-query-messages.test.ts +0 -448
  74. package/test/unit/awards/award-user-collection.test.ts +0 -416
  75. package/test/unit/awards/duplicate-prevention.test.ts +0 -120
  76. package/test/unit/awards/helpers/completion-mock.ts +0 -56
  77. package/test/unit/awards/helpers/index.ts +0 -3
  78. package/test/unit/awards/helpers/mock-setup.ts +0 -79
  79. package/test/unit/awards/helpers/progress-emitter.ts +0 -45
  80. package/test/unit/awards/message-generator.test.ts +0 -162
  81. package/test/unit/content-progress/bubbleTrickle.test.ts +0 -322
  82. package/test/unit/content-progress/helpers.test.ts +0 -329
  83. package/test/unit/content-progress/navigateTo.test.ts +0 -381
  84. package/test/unit/contentLikes.test.ts +0 -62
  85. package/test/unit/contentMetaData.test.ts +0 -58
  86. package/test/unit/dataContext.test.ts +0 -38
  87. package/test/unit/dateUtils.test.ts +0 -188
  88. package/test/unit/endScreen.test.js +0 -712
  89. package/test/unit/imageSRCBuilder.test.ts +0 -37
  90. package/test/unit/imageSRCVerify.test.ts +0 -155
  91. package/test/unit/infrastructure/DefaultHeaderProvider.test.ts +0 -39
  92. package/test/unit/infrastructure/sanity/ContentClient.test.ts +0 -168
  93. package/test/unit/infrastructure/sanity/DefaultConfigProvider.test.ts +0 -93
  94. package/test/unit/infrastructure/sanity/FetchQueryExecutor.test.ts +0 -174
  95. package/test/unit/infrastructure/sanity/SanityClient.test.ts +0 -140
  96. package/test/unit/lib/__snapshots__/filter.test.ts.snap +0 -5
  97. package/test/unit/lib/filter.test.ts +0 -1154
  98. package/test/unit/lib/lastUpdated.test.ts +0 -21
  99. package/test/unit/lib/query.test.ts +0 -1469
  100. package/test/unit/lib/sanity/decorators/base.test.ts +0 -368
  101. package/test/unit/lib/sanity/decorators/navigate-to.test.ts +0 -361
  102. package/test/unit/lib/sanity/decorators/need-access.test.ts +0 -89
  103. package/test/unit/lib/sanity/decorators/need-lifetime-upgrade.test.ts +0 -85
  104. package/test/unit/lib/sanity/decorators/page-type.test.ts +0 -81
  105. package/test/unit/playerSettings.test.ts +0 -73
  106. package/test/unit/progress-row/content-card.test.ts +0 -314
  107. package/test/unit/progress-row/playlist-card.test.ts +0 -104
  108. package/test/unit/progressRows.test.ts +0 -243
  109. package/test/unit/recommendations.test.js +0 -47
  110. package/test/unit/sanityQueryService.test.ts +0 -200
  111. package/test/unit/search.test.ts +0 -44
  112. package/test/unit/sentry.test.ts +0 -62
  113. package/test/unit/services/progress-internal/bubble.test.ts +0 -279
  114. package/test/unit/services/progress.test.ts +0 -396
  115. package/test/unit/streakMessage.test.ts +0 -251
  116. package/test/unit/sync/context.test.ts +0 -51
  117. package/test/unit/sync/effects/logout-warning.test.ts +0 -158
  118. package/test/unit/sync/effects/push-failure-notification.test.ts +0 -196
  119. package/test/unit/sync/errors/sync-errors.test.ts +0 -106
  120. package/test/unit/sync/errors/validators.test.ts +0 -61
  121. package/test/unit/sync/helpers/TestModel.ts +0 -44
  122. package/test/unit/sync/helpers/index.ts +0 -172
  123. package/test/unit/sync/manager.test.ts +0 -303
  124. package/test/unit/sync/models/user-award-progress.test.ts +0 -82
  125. package/test/unit/sync/resolver.test.ts +0 -229
  126. package/test/unit/sync/retry.test.ts +0 -314
  127. package/test/unit/sync/run-scope.test.ts +0 -23
  128. package/test/unit/sync/stale-record-cleanup.test.ts +0 -107
  129. package/test/unit/sync/store/push-coalescer.test.ts +0 -156
  130. package/test/unit/sync/store-configs.test.ts +0 -37
  131. package/test/unit/sync/telemetry/sync-telemetry.test.ts +0 -118
  132. package/test/unit/sync/utils/event-emitter.test.ts +0 -64
  133. package/test/unit/sync/utils/throttle.test.ts +0 -245
  134. package/test/unit/url-builder.test.ts +0 -72
  135. package/test/unit/user/account.test.ts +0 -66
  136. package/test/unit/user/permissions.test.js +0 -191
@@ -1,381 +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('course started lastInteracted completed navigates to first incomplete after lastInteracted', async () => {
258
- mockProgressRecords = [
259
- { content_id: 1, state: 'started', progress_percent: 60, updated_at: 1000 },
260
- { content_id: 101, state: 'completed', progress_percent: 100, updated_at: 900 },
261
- { content_id: 102, state: 'completed', progress_percent: 100, updated_at: 1000 },
262
- { content_id: 103, state: 'started', progress_percent: 20, updated_at: 800 },
263
- ]
264
- mockLastInteracted = 101
265
- const result = await getNavigateTo([{ id: 1, type: 'course', children: [child(101), child(102), child(103)] }])
266
- expect(result[1]).toMatchObject({ id: 103 })
267
- })
268
-
269
- test('course started all children completed wraps to first child', async () => {
270
- mockProgressRecords = [
271
- { content_id: 1, state: 'started', progress_percent: 100, updated_at: 1000 },
272
- { content_id: 101, state: 'completed', progress_percent: 100, updated_at: 900 },
273
- { content_id: 102, state: 'completed', progress_percent: 100, updated_at: 1000 },
274
- ]
275
- mockLastInteracted = 102
276
- const result = await getNavigateTo([{ id: 1, type: 'course', children: [child(101), child(102)] }])
277
- expect(result[1]).toMatchObject({ id: 101 })
278
- })
279
-
280
- test('guided-course started navigates to first incomplete child', async () => {
281
- mockProgressRecords = [
282
- { content_id: 1, state: 'started', progress_percent: 50, updated_at: 1000 },
283
- { content_id: 101, state: 'completed', progress_percent: 100, updated_at: 900 },
284
- ]
285
- mockLastInteracted = 101
286
- const result = await getNavigateTo([{
287
- id: 1,
288
- type: 'guided-course',
289
- children: [child(101), child(102), child(103)],
290
- }])
291
- expect(result[1]).toMatchObject({ id: 102 })
292
- })
293
-
294
- describe.each(['course', 'skill-pack', 'song-tutorial'])('course-flow type %s', (type) => {
295
- test('lastInteracted completed → first incomplete after lastInteracted', async () => {
296
- mockProgressRecords = [
297
- { content_id: 1, state: 'started', progress_percent: 50, updated_at: 1000 },
298
- { content_id: 101, state: '', progress_percent: 0, updated_at: 0 },
299
- { content_id: 102, state: 'completed', progress_percent: 100, updated_at: 1000 },
300
- { content_id: 103, state: '', progress_percent: 0, updated_at: 0 },
301
- ]
302
- mockLastInteracted = 102
303
- const result = await getNavigateTo([{ id: 1, type, children: [child(101), child(102), child(103)] }])
304
- expect(result[1]).toMatchObject({ id: 103 })
305
- })
306
- })
307
-
308
- describe.each(['guided-course', COLLECTION_TYPE.LEARNING_PATH])('guided-course-flow type %s', (type) => {
309
- test('finds first incomplete regardless of lastInteracted position', async () => {
310
- mockProgressRecords = [
311
- { content_id: 1, state: 'started', progress_percent: 50, updated_at: 1000 },
312
- { content_id: 101, state: '', progress_percent: 0, updated_at: 0 },
313
- { content_id: 102, state: 'completed', progress_percent: 100, updated_at: 1000 },
314
- { content_id: 103, state: '', progress_percent: 0, updated_at: 0 },
315
- ]
316
- mockLastInteracted = 102
317
- const result = await getNavigateTo([{ id: 1, type, children: [child(101), child(102), child(103)] }])
318
- expect(result[1]).toMatchObject({ id: 101 })
319
- })
320
- })
321
-
322
- // need more tests to support other types and potentially other logic branches.
323
- })
324
-
325
- // ─── getNavigateToForMethod ───────────────────────────────────────────────────
326
-
327
- describe('getNavigateToForMethod', () => {
328
- const lpContent = (id: number, children: any[]) => ({
329
- id,
330
- brand: 'drumeo',
331
- thumbnail: '',
332
- type: COLLECTION_TYPE.LEARNING_PATH,
333
- published_on: null,
334
- status: 'published',
335
- children,
336
- record_id: `${id}:${COLLECTION_TYPE.LEARNING_PATH}:${id}`,
337
- })
338
-
339
- const nonLpContent = (id: number) => ({
340
- id,
341
- brand: 'drumeo',
342
- thumbnail: '',
343
- type: 'course',
344
- published_on: null,
345
- status: 'published',
346
- children: [child(201), child(202)],
347
- record_id: `${id}:self:0`,
348
- })
349
-
350
- test('non-LP content type returns null', async () => {
351
- const result = await getNavigateToForMethod([nonLpContent(1)])
352
- expect(result[1]).toBeNull()
353
- })
354
-
355
- test('LP type with no daily session navigates to first incomplete child', async () => {
356
- getDailySession.mockResolvedValueOnce(null)
357
- const result = await getNavigateToForMethod([lpContent(10, [child(301), child(302), child(303)])])
358
- expect(result[10]).toMatchObject({ id: 301 })
359
- })
360
-
361
- test('LP type with active learning path and daily session navigates using daily session', async () => {
362
- mockProgressRecords = [
363
- { content_id: 301, state: 'completed', progress_percent: 100, updated_at: 900 },
364
- ]
365
- getDailySession.mockResolvedValueOnce({
366
- active_learning_path_id: 10,
367
- daily_session: [{ content_ids: [301, 302] }],
368
- })
369
- const result = await getNavigateToForMethod([lpContent(10, [child(300), child(301), child(302)])])
370
- expect(result[10]).toMatchObject({ id: 302 })
371
- })
372
-
373
- test('null content entries skipped', async () => {
374
- getDailySession.mockResolvedValueOnce(null)
375
- const validContent = lpContent(10, [child(301)])
376
- const result = await getNavigateToForMethod([validContent, null as any])
377
- expect(Object.keys(result)).toContain('10')
378
- expect(Object.keys(result)).not.toContain('null')
379
- expect(Object.keys(result)).not.toContain('undefined')
380
- })
381
- })
@@ -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
- })