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.
- package/.agent/decisions/2026-07-20-mu2-1724-songs-lessons-counts.md +33 -0
- package/.agent/decisions/2026-07-20-query-builder-tostring.md +37 -0
- package/.idea/codeStyles/Project.xml +61 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/modules.xml +8 -0
- package/.idea/musora-content-services.iml +8 -0
- package/.idea/php.xml +19 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +7 -0
- package/.yarn/install-state.gz +0 -0
- package/CHANGELOG.md +10 -0
- package/package.json +2 -1
- package/src/contentTypeConfig.js +1 -0
- package/src/lib/sanity/query.ts +5 -0
- package/src/services/config.js +15 -0
- package/src/services/content/artist.ts +1 -3
- package/src/services/content/counts.ts +47 -0
- package/src/services/content/genre.ts +1 -3
- package/src/services/content/instructor.ts +1 -3
- package/src/services/multi-user-accounts/multi-user-accounts.ts +1 -0
- package/src/services/userActivity.js +2 -0
- package/src/version-info.js +1 -0
- package/.claude/settings.local.json +0 -53
- package/test/initializeTests.js +0 -60
- package/test/integration/awards/award-exclusion-handling.test.ts +0 -275
- package/test/integration/awards/internal/image-utils.test.ts +0 -86
- package/test/integration/content-progress/__mocks__/mocks.ts +0 -104
- package/test/integration/content-progress/contentProgress.test.ts +0 -335
- package/test/integration/content-progress/e2eOfflineProgress.test.ts +0 -352
- package/test/integration/content-progress/e2eProgress.test.ts +0 -612
- package/test/integration/content-progress/getters.test.ts +0 -334
- package/test/integration/content-progress/helpers.test.ts +0 -263
- package/test/integration/content-progress/offlineContentProgress.test.ts +0 -226
- package/test/integration/forums.test.ts +0 -209
- package/test/integration/infrastructure/FetchRequestExecutor.test.ts +0 -88
- package/test/integration/initializeTestDB.ts +0 -80
- package/test/integration/learning-paths.test.ts +0 -854
- package/test/integration/notifications.test.ts +0 -178
- package/test/integration/progress-row/content-card.test.ts +0 -283
- package/test/integration/sync/adapters/idb-errors.test.ts +0 -144
- package/test/integration/sync/adapters/sqlite-errors.test.ts +0 -173
- package/test/integration/sync/fetch.test.ts +0 -224
- package/test/integration/sync/repositories/content-likes.test.ts +0 -99
- package/test/integration/sync/repositories/practices.test.ts +0 -179
- package/test/integration/sync/repositories/progress.test.ts +0 -245
- package/test/integration/sync/repositories/user-award-progress.static.test.ts +0 -68
- package/test/integration/sync/repositories/user-award-progress.test.ts +0 -387
- package/test/integration/sync/store/cross-user-protection.test.ts +0 -217
- package/test/integration/sync/store/store-idb.test.ts +0 -180
- package/test/integration/sync/store/store.test.ts +0 -361
- package/test/integration/user/permissions.test.js +0 -20
- package/test/integration/userActivity.test.ts +0 -102
- package/test/live/README.md +0 -29
- package/test/live/content.test.js +0 -116
- package/test/localStorageMock.js +0 -21
- package/test/log.js +0 -5
- package/test/mockData/award-definitions.js +0 -171
- package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -35
- package/test/mockData/mockData_progress_content.json +0 -182
- package/test/mockData/mockData_sanity_progress_content.json +0 -1451
- package/test/mockData/mockData_user_practices.json +0 -9
- package/test/setupConsole.js +0 -6
- package/test/setupNetworkGuard.js +0 -3
- package/test/setupTimers.js +0 -13
- package/test/unit/HttpClient.test.ts +0 -267
- package/test/unit/awards/award-alacarte-observer.test.ts +0 -199
- package/test/unit/awards/award-auto-refresh.test.ts +0 -84
- package/test/unit/awards/award-calculations.test.ts +0 -34
- package/test/unit/awards/award-callbacks.test.ts +0 -144
- package/test/unit/awards/award-certificate-display.test.ts +0 -330
- package/test/unit/awards/award-collection-edge-cases.test.ts +0 -212
- package/test/unit/awards/award-collection-filtering.test.ts +0 -287
- package/test/unit/awards/award-completion-flow.test.ts +0 -306
- package/test/unit/awards/award-multi-lesson.test.ts +0 -243
- package/test/unit/awards/award-observer-integration.test.ts +0 -327
- package/test/unit/awards/award-query-messages.test.ts +0 -448
- package/test/unit/awards/award-user-collection.test.ts +0 -416
- package/test/unit/awards/duplicate-prevention.test.ts +0 -120
- package/test/unit/awards/helpers/completion-mock.ts +0 -56
- package/test/unit/awards/helpers/index.ts +0 -3
- package/test/unit/awards/helpers/mock-setup.ts +0 -79
- package/test/unit/awards/helpers/progress-emitter.ts +0 -45
- package/test/unit/awards/message-generator.test.ts +0 -162
- package/test/unit/content-progress/bubbleTrickle.test.ts +0 -322
- package/test/unit/content-progress/helpers.test.ts +0 -329
- package/test/unit/content-progress/navigateTo.test.ts +0 -392
- package/test/unit/contentLikes.test.ts +0 -62
- package/test/unit/contentMetaData.test.ts +0 -58
- package/test/unit/dataContext.test.ts +0 -38
- package/test/unit/dateUtils.test.ts +0 -188
- package/test/unit/endScreen.test.js +0 -712
- package/test/unit/eventsAPI.test.ts +0 -159
- package/test/unit/imageSRCBuilder.test.ts +0 -37
- package/test/unit/imageSRCVerify.test.ts +0 -155
- package/test/unit/infrastructure/DefaultHeaderProvider.test.ts +0 -39
- package/test/unit/infrastructure/sanity/ContentClient.test.ts +0 -168
- package/test/unit/infrastructure/sanity/DefaultConfigProvider.test.ts +0 -93
- package/test/unit/infrastructure/sanity/FetchQueryExecutor.test.ts +0 -174
- package/test/unit/infrastructure/sanity/SanityClient.test.ts +0 -140
- package/test/unit/lib/__snapshots__/filter.test.ts.snap +0 -5
- package/test/unit/lib/filter.test.ts +0 -1154
- package/test/unit/lib/lastUpdated.test.ts +0 -21
- package/test/unit/lib/query.test.ts +0 -1469
- package/test/unit/lib/sanity/decorators/base.test.ts +0 -368
- package/test/unit/lib/sanity/decorators/navigate-to.test.ts +0 -361
- package/test/unit/lib/sanity/decorators/need-access.test.ts +0 -89
- package/test/unit/lib/sanity/decorators/need-lifetime-upgrade.test.ts +0 -85
- package/test/unit/lib/sanity/decorators/page-type.test.ts +0 -81
- package/test/unit/playerSettings.test.ts +0 -73
- package/test/unit/progress-row/content-card.test.ts +0 -314
- package/test/unit/progress-row/playlist-card.test.ts +0 -104
- package/test/unit/progressRows.test.ts +0 -243
- package/test/unit/recommendations.test.js +0 -47
- package/test/unit/sanityQueryService.test.ts +0 -200
- package/test/unit/search.test.ts +0 -44
- package/test/unit/sentry.test.ts +0 -62
- package/test/unit/services/progress-internal/bubble.test.ts +0 -279
- package/test/unit/services/progress.test.ts +0 -396
- package/test/unit/streakMessage.test.ts +0 -251
- package/test/unit/sync/context.test.ts +0 -51
- package/test/unit/sync/effects/logout-warning.test.ts +0 -158
- package/test/unit/sync/effects/push-failure-notification.test.ts +0 -196
- package/test/unit/sync/errors/sync-errors.test.ts +0 -106
- package/test/unit/sync/errors/validators.test.ts +0 -61
- package/test/unit/sync/helpers/TestModel.ts +0 -44
- package/test/unit/sync/helpers/index.ts +0 -172
- package/test/unit/sync/manager.test.ts +0 -303
- package/test/unit/sync/models/user-award-progress.test.ts +0 -82
- package/test/unit/sync/resolver.test.ts +0 -229
- package/test/unit/sync/retry.test.ts +0 -314
- package/test/unit/sync/run-scope.test.ts +0 -23
- package/test/unit/sync/stale-record-cleanup.test.ts +0 -107
- package/test/unit/sync/store/push-coalescer.test.ts +0 -156
- package/test/unit/sync/store-configs.test.ts +0 -37
- package/test/unit/sync/telemetry/sync-telemetry.test.ts +0 -118
- package/test/unit/sync/utils/event-emitter.test.ts +0 -64
- package/test/unit/sync/utils/throttle.test.ts +0 -245
- package/test/unit/url-builder.test.ts +0 -72
- package/test/unit/user/account.test.ts +0 -66
- package/test/unit/user/permissions.test.js +0 -191
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
import { mockAwardDefinitions } from '../../mockData/award-definitions.js'
|
|
2
|
-
|
|
3
|
-
jest.mock('../../../src/services/sanity.js', () => ({
|
|
4
|
-
...jest.requireActual('../../../src/services/sanity'),
|
|
5
|
-
default: {
|
|
6
|
-
fetch: jest.fn()
|
|
7
|
-
},
|
|
8
|
-
fetchSanity: jest.fn()
|
|
9
|
-
}))
|
|
10
|
-
|
|
11
|
-
jest.mock('../../../src/services/sync/repository-proxy.ts', () => {
|
|
12
|
-
const mockFns = {
|
|
13
|
-
userAwardProgress: {
|
|
14
|
-
getAll: jest.fn(),
|
|
15
|
-
getCompleted: jest.fn(),
|
|
16
|
-
getByAwardId: jest.fn(),
|
|
17
|
-
getAwardsForContent: jest.fn()
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return { default: mockFns, ...mockFns }
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
import sanityClient, { fetchSanity } from '../../../src/services/sanity.js'
|
|
24
|
-
import db_ from '../../../src/services/sync/repository-proxy'
|
|
25
|
-
const db = db_ as any
|
|
26
|
-
import { awardDefinitions } from '../../../src/services/awards/internal/award-definitions.js'
|
|
27
|
-
import { getCompletedAwards, getContentAwards, getInProgressAwards } from '../../../src/services/awards/award-query.js'
|
|
28
|
-
|
|
29
|
-
describe('Award Query Message Generation', () => {
|
|
30
|
-
beforeEach(async () => {
|
|
31
|
-
jest.clearAllMocks()
|
|
32
|
-
|
|
33
|
-
sanityClient.fetch = jest.fn().mockResolvedValue(mockAwardDefinitions)
|
|
34
|
-
fetchSanity.mockResolvedValue(mockAwardDefinitions)
|
|
35
|
-
|
|
36
|
-
await awardDefinitions.refresh()
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
afterEach(() => {
|
|
40
|
-
awardDefinitions.clear()
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
describe('getCompletedAwards', () => {
|
|
44
|
-
test('includes message in completionData for guided course awards', async () => {
|
|
45
|
-
const mockProgress = [{
|
|
46
|
-
award_id: 'award-1',
|
|
47
|
-
progress_percentage: 100,
|
|
48
|
-
completed_at: 1672531200,
|
|
49
|
-
completion_data: {
|
|
50
|
-
content_title: 'Blues Foundations',
|
|
51
|
-
completed_at: '2023-01-01T00:00:00.000Z',
|
|
52
|
-
days_user_practiced: 14,
|
|
53
|
-
practice_minutes: 180
|
|
54
|
-
}
|
|
55
|
-
}]
|
|
56
|
-
|
|
57
|
-
const mockDefinition = {
|
|
58
|
-
_id: 'award-1',
|
|
59
|
-
name: 'Blues Master',
|
|
60
|
-
badge: 'https://example.com/badge.png',
|
|
61
|
-
award: 'certificate',
|
|
62
|
-
brand: 'drumeo',
|
|
63
|
-
instructor_name: 'Mike Johnston',
|
|
64
|
-
content_type: 'guided-course',
|
|
65
|
-
type: 'content-award',
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
jest.spyOn(db.userAwardProgress, 'getCompleted').mockResolvedValue({
|
|
69
|
-
data: mockProgress
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
73
|
-
|
|
74
|
-
const awards = await getCompletedAwards()
|
|
75
|
-
|
|
76
|
-
expect(awards).toHaveLength(1)
|
|
77
|
-
expect(awards[0].completionData).toHaveProperty('message')
|
|
78
|
-
expect(awards[0].completionData.message).toContain('Blues Foundations')
|
|
79
|
-
expect(awards[0].completionData.message).toContain('14 days')
|
|
80
|
-
expect(awards[0].completionData.message).toContain('180 minutes')
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test('includes message in completionData for learning path awards', async () => {
|
|
84
|
-
const mockProgress = [{
|
|
85
|
-
award_id: 'award-2',
|
|
86
|
-
progress_percentage: 100,
|
|
87
|
-
completed_at: 1672531200,
|
|
88
|
-
completion_data: {
|
|
89
|
-
content_title: 'Jazz Essentials',
|
|
90
|
-
completed_at: '2023-01-01T00:00:00.000Z',
|
|
91
|
-
days_user_practiced: 30,
|
|
92
|
-
practice_minutes: 450
|
|
93
|
-
}
|
|
94
|
-
}]
|
|
95
|
-
|
|
96
|
-
const mockDefinition = {
|
|
97
|
-
_id: 'award-2',
|
|
98
|
-
name: 'Jazz Journey',
|
|
99
|
-
badge: 'https://example.com/badge2.png',
|
|
100
|
-
award: 'certificate',
|
|
101
|
-
brand: 'pianote',
|
|
102
|
-
instructor_name: 'Lisa Witt',
|
|
103
|
-
content_type: 'learning-path-v2',
|
|
104
|
-
type: 'content-award',
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
jest.spyOn(db.userAwardProgress, 'getCompleted').mockResolvedValue({
|
|
108
|
-
data: mockProgress
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
112
|
-
|
|
113
|
-
const awards = await getCompletedAwards()
|
|
114
|
-
|
|
115
|
-
expect(awards).toHaveLength(1)
|
|
116
|
-
expect(awards[0].completionData).toHaveProperty('message')
|
|
117
|
-
expect(awards[0].completionData.message).toContain('Jazz Essentials')
|
|
118
|
-
expect(awards[0].completionData.message).toContain('30 days')
|
|
119
|
-
expect(awards[0].completionData.message).toContain('450 minutes')
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
test('uses correct practice statistics in message', async () => {
|
|
123
|
-
const mockProgress = [{
|
|
124
|
-
award_id: 'award-3',
|
|
125
|
-
progress_percentage: 100,
|
|
126
|
-
completed_at: 1672531200,
|
|
127
|
-
completion_data: {
|
|
128
|
-
content_title: 'Rock Foundations',
|
|
129
|
-
completed_at: '2023-01-01T00:00:00.000Z',
|
|
130
|
-
days_user_practiced: 7,
|
|
131
|
-
practice_minutes: 90
|
|
132
|
-
}
|
|
133
|
-
}]
|
|
134
|
-
|
|
135
|
-
const mockDefinition = {
|
|
136
|
-
_id: 'award-3',
|
|
137
|
-
name: 'Rock Star',
|
|
138
|
-
badge: 'https://example.com/badge3.png',
|
|
139
|
-
award: 'badge',
|
|
140
|
-
brand: 'guitareo',
|
|
141
|
-
instructor_name: 'Steve Stine',
|
|
142
|
-
content_type: 'guided-course',
|
|
143
|
-
type: 'content-award',
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
jest.spyOn(db.userAwardProgress, 'getCompleted').mockResolvedValue({
|
|
147
|
-
data: mockProgress
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
151
|
-
|
|
152
|
-
const awards = await getCompletedAwards()
|
|
153
|
-
|
|
154
|
-
expect(awards[0].completionData.message).toContain('7 days')
|
|
155
|
-
expect(awards[0].completionData.message).toContain('90 minutes')
|
|
156
|
-
expect(awards[0].completionData.message).not.toContain('180 minutes')
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
test('handles awards with zero practice minutes', async () => {
|
|
160
|
-
const mockProgress = [{
|
|
161
|
-
award_id: 'award-4',
|
|
162
|
-
progress_percentage: 100,
|
|
163
|
-
completed_at: 1672531200,
|
|
164
|
-
completion_data: {
|
|
165
|
-
content_title: 'Quick Course',
|
|
166
|
-
completed_at: '2023-01-01T00:00:00.000Z',
|
|
167
|
-
days_user_practiced: 1,
|
|
168
|
-
practice_minutes: 0
|
|
169
|
-
}
|
|
170
|
-
}]
|
|
171
|
-
|
|
172
|
-
const mockDefinition = {
|
|
173
|
-
_id: 'award-4',
|
|
174
|
-
name: 'Quick Learner',
|
|
175
|
-
badge: 'https://example.com/badge4.png',
|
|
176
|
-
award: 'badge',
|
|
177
|
-
brand: 'singeo',
|
|
178
|
-
instructor_name: 'Camille van Niekerk',
|
|
179
|
-
content_type: 'guided-course',
|
|
180
|
-
type: 'content-award',
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
jest.spyOn(db.userAwardProgress, 'getCompleted').mockResolvedValue({
|
|
184
|
-
data: mockProgress
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
188
|
-
|
|
189
|
-
const awards = await getCompletedAwards()
|
|
190
|
-
|
|
191
|
-
expect(awards[0].completionData.message).toContain('0 minutes')
|
|
192
|
-
expect(awards[0].completionData.message).toContain('1 day')
|
|
193
|
-
expect(awards[0].completionData.message).not.toContain('1 days')
|
|
194
|
-
})
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
describe('getContentAwards', () => {
|
|
198
|
-
test('includes message in completionData when award is completed', async () => {
|
|
199
|
-
const mockDefinitions = [{
|
|
200
|
-
_id: 'award-5',
|
|
201
|
-
name: 'Content Award',
|
|
202
|
-
badge: 'https://example.com/badge5.png',
|
|
203
|
-
award: 'certificate',
|
|
204
|
-
brand: 'drumeo',
|
|
205
|
-
instructor_name: 'Jared Falk',
|
|
206
|
-
content_type: 'guided-course'
|
|
207
|
-
}]
|
|
208
|
-
|
|
209
|
-
const mockProgress = new Map()
|
|
210
|
-
mockProgress.set('award-5', {
|
|
211
|
-
progress_percentage: 100,
|
|
212
|
-
isCompleted: true,
|
|
213
|
-
completed_at: 1672531200,
|
|
214
|
-
completion_data: {
|
|
215
|
-
content_title: 'Advanced Techniques',
|
|
216
|
-
completed_at: '2023-01-01T00:00:00.000Z',
|
|
217
|
-
days_user_practiced: 21,
|
|
218
|
-
practice_minutes: 300
|
|
219
|
-
}
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
jest.spyOn(db.userAwardProgress, 'getAwardsForContent').mockResolvedValue({
|
|
223
|
-
definitions: mockDefinitions,
|
|
224
|
-
progress: mockProgress
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
jest.spyOn(awardDefinitions, 'hasAwards').mockResolvedValue(true)
|
|
228
|
-
|
|
229
|
-
const result = await getContentAwards(12345)
|
|
230
|
-
|
|
231
|
-
expect(result.hasAwards).toBe(true)
|
|
232
|
-
expect(result.awards).toHaveLength(1)
|
|
233
|
-
expect(result.awards[0].completionData).toHaveProperty('message')
|
|
234
|
-
expect(result.awards[0].completionData.message).toContain('21 days')
|
|
235
|
-
expect(result.awards[0].completionData.message).toContain('300 minutes')
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
test('handles awards without completion data gracefully', async () => {
|
|
239
|
-
const mockDefinitions = [{
|
|
240
|
-
_id: 'award-6',
|
|
241
|
-
name: 'In Progress Award',
|
|
242
|
-
badge: 'https://example.com/badge6.png',
|
|
243
|
-
award: 'badge',
|
|
244
|
-
brand: 'pianote',
|
|
245
|
-
instructor_name: 'Lisa Witt',
|
|
246
|
-
content_type: 'learning-path-v2'
|
|
247
|
-
}]
|
|
248
|
-
|
|
249
|
-
const mockProgress = new Map()
|
|
250
|
-
mockProgress.set('award-6', {
|
|
251
|
-
progress_percentage: 50,
|
|
252
|
-
isCompleted: false,
|
|
253
|
-
completed_at: null,
|
|
254
|
-
completion_data: null
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
jest.spyOn(db.userAwardProgress, 'getAwardsForContent').mockResolvedValue({
|
|
258
|
-
definitions: mockDefinitions,
|
|
259
|
-
progress: mockProgress
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
jest.spyOn(awardDefinitions, 'hasAwards').mockResolvedValue(true)
|
|
263
|
-
|
|
264
|
-
const result = await getContentAwards(12345)
|
|
265
|
-
|
|
266
|
-
expect(result.hasAwards).toBe(true)
|
|
267
|
-
expect(result.awards).toHaveLength(1)
|
|
268
|
-
expect(result.awards[0].completionData).toBeNull()
|
|
269
|
-
})
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
describe('getInProgressAwards', () => {
|
|
273
|
-
test('handles in-progress awards with partial completion data', async () => {
|
|
274
|
-
const mockProgress = [{
|
|
275
|
-
award_id: 'award-7',
|
|
276
|
-
progress_percentage: 75,
|
|
277
|
-
completed_at: null,
|
|
278
|
-
completion_data: {
|
|
279
|
-
content_title: 'Intermediate Skills',
|
|
280
|
-
completed_at: null,
|
|
281
|
-
days_user_practiced: 10,
|
|
282
|
-
practice_minutes: 150
|
|
283
|
-
}
|
|
284
|
-
}]
|
|
285
|
-
|
|
286
|
-
const mockDefinition = {
|
|
287
|
-
_id: 'award-7',
|
|
288
|
-
name: 'Progress Champion',
|
|
289
|
-
badge: 'https://example.com/badge7.png',
|
|
290
|
-
award: 'badge',
|
|
291
|
-
brand: 'guitareo',
|
|
292
|
-
instructor_name: 'Anders Mouridsen',
|
|
293
|
-
content_type: 'guided-course'
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
jest.spyOn(db.userAwardProgress, 'getAll').mockResolvedValue({
|
|
297
|
-
data: mockProgress
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
301
|
-
|
|
302
|
-
const awards = await getInProgressAwards()
|
|
303
|
-
|
|
304
|
-
expect(awards).toHaveLength(1)
|
|
305
|
-
expect(awards[0].isCompleted).toBe(false)
|
|
306
|
-
expect(awards[0].completionData).toHaveProperty('message')
|
|
307
|
-
expect(awards[0].completionData.message).toContain('10 days')
|
|
308
|
-
expect(awards[0].completionData.message).toContain('150 minutes')
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
test('handles in-progress awards without completion data', async () => {
|
|
312
|
-
const mockProgress = [{
|
|
313
|
-
award_id: 'award-8',
|
|
314
|
-
progress_percentage: 25,
|
|
315
|
-
completed_at: null,
|
|
316
|
-
completion_data: null
|
|
317
|
-
}]
|
|
318
|
-
|
|
319
|
-
const mockDefinition = {
|
|
320
|
-
_id: 'award-8',
|
|
321
|
-
name: 'Just Started',
|
|
322
|
-
badge: 'https://example.com/badge8.png',
|
|
323
|
-
award: 'badge',
|
|
324
|
-
brand: 'singeo',
|
|
325
|
-
instructor_name: 'Ramsey Voice Studio',
|
|
326
|
-
content_type: 'learning-path-v2'
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
jest.spyOn(db.userAwardProgress, 'getAll').mockResolvedValue({
|
|
330
|
-
data: mockProgress
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
334
|
-
|
|
335
|
-
const awards = await getInProgressAwards()
|
|
336
|
-
|
|
337
|
-
expect(awards).toHaveLength(1)
|
|
338
|
-
expect(awards[0].completionData).toBeNull()
|
|
339
|
-
})
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
describe('Award type determination', () => {
|
|
343
|
-
test('generates message with content title for guided-course type', async () => {
|
|
344
|
-
const mockProgress = [{
|
|
345
|
-
award_id: 'gc-award',
|
|
346
|
-
progress_percentage: 100,
|
|
347
|
-
completed_at: 1672531200,
|
|
348
|
-
completion_data: {
|
|
349
|
-
content_title: 'Test Course',
|
|
350
|
-
completed_at: '2023-01-01T00:00:00.000Z',
|
|
351
|
-
days_user_practiced: 5,
|
|
352
|
-
practice_minutes: 60
|
|
353
|
-
}
|
|
354
|
-
}]
|
|
355
|
-
|
|
356
|
-
const mockDefinition = {
|
|
357
|
-
_id: 'gc-award',
|
|
358
|
-
name: 'Guided Course Award',
|
|
359
|
-
badge: 'https://example.com/gc-badge.png',
|
|
360
|
-
award: 'certificate',
|
|
361
|
-
brand: 'drumeo',
|
|
362
|
-
instructor_name: 'Test Instructor',
|
|
363
|
-
content_type: 'guided-course',
|
|
364
|
-
type: 'content-award',
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
jest.spyOn(db.userAwardProgress, 'getCompleted').mockResolvedValue({
|
|
368
|
-
data: mockProgress
|
|
369
|
-
})
|
|
370
|
-
|
|
371
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
372
|
-
|
|
373
|
-
const awards = await getCompletedAwards()
|
|
374
|
-
|
|
375
|
-
expect(awards[0].completionData.message).toContain('Test Course')
|
|
376
|
-
})
|
|
377
|
-
|
|
378
|
-
test('generates message with content title for learning-path-v2 type', async () => {
|
|
379
|
-
const mockProgress = [{
|
|
380
|
-
award_id: 'lp-award',
|
|
381
|
-
progress_percentage: 100,
|
|
382
|
-
completed_at: 1672531200,
|
|
383
|
-
completion_data: {
|
|
384
|
-
content_title: 'Test Path',
|
|
385
|
-
completed_at: '2023-01-01T00:00:00.000Z',
|
|
386
|
-
days_user_practiced: 5,
|
|
387
|
-
practice_minutes: 60
|
|
388
|
-
}
|
|
389
|
-
}]
|
|
390
|
-
|
|
391
|
-
const mockDefinition = {
|
|
392
|
-
_id: 'lp-award',
|
|
393
|
-
name: 'Learning Path Award',
|
|
394
|
-
badge: 'https://example.com/lp-badge.png',
|
|
395
|
-
award: 'certificate',
|
|
396
|
-
brand: 'pianote',
|
|
397
|
-
instructor_name: 'Test Instructor',
|
|
398
|
-
content_type: 'learning-path-v2',
|
|
399
|
-
type: 'content-award',
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
jest.spyOn(db.userAwardProgress, 'getCompleted').mockResolvedValue({
|
|
403
|
-
data: mockProgress
|
|
404
|
-
})
|
|
405
|
-
|
|
406
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
407
|
-
|
|
408
|
-
const awards = await getCompletedAwards()
|
|
409
|
-
|
|
410
|
-
expect(awards[0].completionData.message).toContain('Test Path')
|
|
411
|
-
})
|
|
412
|
-
|
|
413
|
-
test('generates message for unknown content types', async () => {
|
|
414
|
-
const mockProgress = [{
|
|
415
|
-
award_id: 'unknown-award',
|
|
416
|
-
progress_percentage: 100,
|
|
417
|
-
completed_at: 1672531200,
|
|
418
|
-
completion_data: {
|
|
419
|
-
content_title: 'Test Content',
|
|
420
|
-
completed_at: '2023-01-01T00:00:00.000Z',
|
|
421
|
-
days_user_practiced: 5,
|
|
422
|
-
practice_minutes: 60
|
|
423
|
-
}
|
|
424
|
-
}]
|
|
425
|
-
|
|
426
|
-
const mockDefinition = {
|
|
427
|
-
_id: 'unknown-award',
|
|
428
|
-
name: 'Unknown Type Award',
|
|
429
|
-
badge: 'https://example.com/unknown-badge.png',
|
|
430
|
-
award: 'certificate',
|
|
431
|
-
brand: 'guitareo',
|
|
432
|
-
instructor_name: 'Test Instructor',
|
|
433
|
-
content_type: 'some-unknown-type',
|
|
434
|
-
type: 'content-award',
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
jest.spyOn(db.userAwardProgress, 'getCompleted').mockResolvedValue({
|
|
438
|
-
data: mockProgress
|
|
439
|
-
})
|
|
440
|
-
|
|
441
|
-
jest.spyOn(awardDefinitions, 'getById').mockResolvedValue(mockDefinition)
|
|
442
|
-
|
|
443
|
-
const awards = await getCompletedAwards()
|
|
444
|
-
|
|
445
|
-
expect(awards[0].completionData.message).toContain('Test Content')
|
|
446
|
-
})
|
|
447
|
-
})
|
|
448
|
-
})
|