musora-content-services 2.157.2 → 2.158.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 +17 -5
- package/.coderabbit.yaml +0 -0
- package/.editorconfig +0 -0
- package/.github/pull_request_template.md +0 -0
- package/.github/workflows/conventional-commits.yaml +0 -0
- package/.github/workflows/docs.js.yml +1 -1
- package/.prettierignore +0 -0
- package/.prettierrc +0 -0
- package/CHANGELOG.md +30 -0
- package/CLAUDE.md +0 -0
- package/README.md +0 -0
- package/babel.config.cjs +0 -0
- package/jest.live.config.js +10 -0
- package/package.json +1 -1
- package/src/constants/award-assets.js +0 -0
- package/src/constants/membership-permissions.ts +0 -0
- package/src/contentMetaData.js +0 -0
- package/src/contentTypeConfig.js +1 -1
- package/src/filterBuilder.js +0 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -0
- package/src/infrastructure/http/HttpClient.ts +0 -0
- package/src/infrastructure/http/executors/FetchRequestExecutor.ts +0 -0
- package/src/infrastructure/http/index.ts +0 -0
- package/src/infrastructure/http/interfaces/HeaderProvider.ts +0 -0
- package/src/infrastructure/http/interfaces/HttpError.ts +0 -0
- package/src/infrastructure/http/interfaces/NetworkError.ts +0 -0
- package/src/infrastructure/http/interfaces/RequestExecutor.ts +0 -0
- package/src/infrastructure/http/interfaces/RequestOptions.ts +0 -0
- package/src/infrastructure/http/providers/DefaultHeaderProvider.ts +0 -0
- package/src/lib/ads/monoid.ts +0 -0
- package/src/lib/ads/semigroup.ts +0 -0
- package/src/lib/brands.ts +0 -0
- package/src/lib/lastUpdated.js +0 -0
- package/src/lib/sanity/field-access.ts +0 -0
- package/src/lib/sanity/query.ts +0 -0
- package/src/services/api/types.js +0 -0
- package/src/services/api/types.ts +0 -0
- package/src/services/awards/award-callbacks.js +0 -0
- package/src/services/awards/award-query.js +0 -0
- package/src/services/awards/internal/.indexignore +0 -0
- package/src/services/awards/internal/award-definitions.js +0 -0
- package/src/services/awards/internal/award-events.js +0 -0
- package/src/services/awards/internal/award-manager.js +0 -0
- package/src/services/awards/internal/certificate-builder.js +0 -0
- package/src/services/awards/internal/completion-data-generator.js +0 -0
- package/src/services/awards/internal/content-progress-observer.js +0 -0
- package/src/services/awards/internal/image-utils.js +0 -0
- package/src/services/awards/internal/message-generator.js +0 -0
- package/src/services/awards/internal/types.js +0 -0
- package/src/services/awards/types.d.ts +0 -0
- package/src/services/awards/types.js +0 -0
- package/src/services/config.js +0 -0
- package/src/services/content/artist.ts +0 -0
- package/src/services/content/content.ts +0 -0
- package/src/services/content/genre.ts +0 -0
- package/src/services/content/instructor.ts +0 -0
- package/src/services/content-org/content-org.js +0 -0
- package/src/services/content-org/playlists-types.js +0 -0
- package/src/services/content-org/playlists.js +0 -0
- package/src/services/contentAggregator.js +0 -0
- package/src/services/contentLikes.js +0 -0
- package/src/services/dataContext.js +0 -0
- package/src/services/dateUtils.js +0 -0
- package/src/services/endScreen/README.md +62 -0
- package/src/services/endScreen/endScreen.ts +153 -0
- package/src/services/endScreen/types.ts +63 -0
- package/src/services/eventsAPI.js +0 -0
- package/src/services/forums/categories.ts +0 -0
- package/src/services/forums/forums.ts +0 -0
- package/src/services/forums/posts.ts +0 -0
- package/src/services/forums/threads.ts +13 -2
- package/src/services/forums/types.ts +0 -0
- package/src/services/gamification/awards.ts +0 -0
- package/src/services/gamification/gamification.js +0 -0
- package/src/services/imageSRCBuilder.js +0 -0
- package/src/services/imageSRCVerify.js +0 -0
- package/src/services/liveTesting.ts +0 -0
- package/src/services/permissions/PermissionsAdapterFactory.ts +0 -0
- package/src/services/permissions/README.md +0 -0
- package/src/services/progress-events.js +0 -0
- package/src/services/progress-row/base.js +0 -0
- package/src/services/progress-row/rows/.indexignore +0 -0
- package/src/services/progress-row/rows/content-card.js +0 -0
- package/src/services/progress-row/rows/playlist-card.js +0 -0
- package/src/services/railcontent.js +0 -0
- package/src/services/recommendations.js +3 -0
- package/src/services/reporting/README.md +0 -0
- package/src/services/reporting/types.ts +0 -0
- package/src/services/sanity.js +7 -6
- package/src/services/sentry/.indexignore +0 -0
- package/src/services/sentry/index.ts +0 -0
- package/src/services/state.ts +0 -0
- package/src/services/sync/.indexignore +0 -0
- package/src/services/sync/adapters/factory.ts +0 -0
- package/src/services/sync/adapters/lokijs.ts +1 -0
- package/src/services/sync/adapters/sqlite.ts +0 -0
- package/src/services/sync/context/providers/base.ts +0 -0
- package/src/services/sync/context/providers/connectivity.ts +0 -0
- package/src/services/sync/context/providers/durability.ts +0 -0
- package/src/services/sync/context/providers/index.ts +0 -0
- package/src/services/sync/context/providers/session.ts +0 -0
- package/src/services/sync/context/providers/tabs.ts +0 -0
- package/src/services/sync/context/providers/visibility.ts +0 -0
- package/src/services/sync/database/factory.ts +0 -0
- package/src/services/sync/debug.ts +0 -0
- package/src/services/sync/effects/index.ts +0 -0
- package/src/services/sync/effects/logout-warning.ts +0 -0
- package/src/services/sync/errors/boundary.ts +0 -0
- package/src/services/sync/errors/index.ts +0 -0
- package/src/services/sync/errors/validators.ts +0 -0
- package/src/services/sync/fetch.ts +0 -0
- package/src/services/sync/index.ts +0 -0
- package/src/services/sync/manager.ts +0 -0
- package/src/services/sync/models/Base.ts +0 -0
- package/src/services/sync/models/ContentLike.ts +0 -0
- package/src/services/sync/models/ContentProgress.ts +0 -0
- package/src/services/sync/models/Practice.ts +0 -0
- package/src/services/sync/models/PracticeDayNote.ts +0 -0
- package/src/services/sync/models/UserAwardProgress.ts +0 -0
- package/src/services/sync/models/index.ts +0 -0
- package/src/services/sync/repositories/content-likes.ts +0 -0
- package/src/services/sync/repositories/content-progress.ts +0 -0
- package/src/services/sync/repositories/index.ts +0 -0
- package/src/services/sync/repositories/practice-day-notes.ts +0 -0
- package/src/services/sync/repositories/practices.ts +0 -0
- package/src/services/sync/repositories/user-award-progress.ts +0 -0
- package/src/services/sync/repository-proxy.ts +0 -0
- package/src/services/sync/resolver.ts +0 -0
- package/src/services/sync/run-scope.ts +0 -0
- package/src/services/sync/schema/index.ts +0 -0
- package/src/services/sync/serializers/index.ts +0 -0
- package/src/services/sync/serializers/model.ts +0 -0
- package/src/services/sync/serializers/raw.ts +0 -0
- package/src/services/sync/store/index.ts +2 -6
- package/src/services/sync/store-configs.ts +0 -0
- package/src/services/sync/strategies/base.ts +0 -0
- package/src/services/sync/strategies/index.ts +0 -0
- package/src/services/sync/strategies/initial.ts +0 -0
- package/src/services/sync/strategies/polling.ts +0 -0
- package/src/services/sync/telemetry/flood-prevention.ts +0 -0
- package/src/services/sync/telemetry/sampling.ts +0 -0
- package/src/services/sync/utils/event-emitter.ts +0 -0
- package/src/services/sync/utils/index.ts +0 -0
- package/src/services/sync/utils/throttle.ts +0 -0
- package/src/services/sync/utils/timers.ts +0 -0
- package/src/services/types.js +0 -0
- package/src/services/urlBuilder.ts +0 -17
- package/src/services/user/account.ts +0 -0
- package/src/services/user/chat.js +0 -0
- package/src/services/user/interests.js +0 -0
- package/src/services/user/management.js +0 -0
- package/src/services/user/memberships.ts +0 -0
- package/src/services/user/notifications.js +0 -0
- package/src/services/user/payments.ts +0 -0
- package/src/services/user/profile.js +1 -1
- package/src/services/user/sessions.js +0 -0
- package/src/services/user/streakCalculator.ts +0 -0
- package/src/services/user/types.js +0 -0
- package/src/services/user/user-management-system.js +0 -0
- package/test/SKIPPED_TESTS.md +0 -0
- package/test/initializeTests.js +0 -0
- package/test/integration/content.test.js +0 -0
- package/test/integration/contentProgress.test.js +0 -0
- package/test/integration/forum.test.js +0 -0
- package/test/integration/sanityQueryService.test.js +0 -0
- package/test/localStorageMock.js +0 -0
- package/test/log.js +0 -0
- package/test/mockData/award-definitions.js +0 -0
- package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -0
- package/test/mockData/mockData_progress_content.json +0 -0
- package/test/mockData/mockData_sanity_progress_content.json +0 -0
- package/test/mockData/mockData_user_practices.json +0 -0
- package/test/setupConsole.js +0 -0
- package/test/setupNetworkGuard.js +0 -0
- package/test/unit/awards/award-callbacks.test.ts +144 -0
- package/test/unit/awards/internal/image-utils.test.ts +86 -0
- package/test/unit/endScreen.test.js +712 -0
- package/test/unit/infrastructure/DefaultHeaderProvider.test.ts +39 -0
- package/test/unit/infrastructure/FetchRequestExecutor.test.ts +88 -0
- package/test/unit/lib/__snapshots__/filter.test.ts.snap +0 -0
- package/test/unit/lib/query.test.ts +0 -0
- package/test/unit/progress-row/playlist-card.test.ts +104 -0
- package/test/unit/sentry.test.ts +62 -0
- package/test/unit/sync/context.test.ts +51 -0
- package/test/unit/sync/errors/sync-errors.test.ts +106 -0
- package/test/unit/sync/errors/validators.test.ts +61 -0
- package/test/unit/sync/models/user-award-progress.test.ts +82 -0
- package/test/unit/sync/repositories/user-award-progress.static.test.ts +68 -0
- package/test/unit/sync/run-scope.test.ts +23 -0
- package/test/unit/sync/store-configs.test.ts +37 -0
- package/test/unit/sync/telemetry/sync-telemetry.test.ts +118 -0
- package/test/unit/sync/utils/event-emitter.test.ts +64 -0
- package/test/unit/url-builder.test.ts +72 -0
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
// Mock sync module to prevent TypeScript compilation errors
|
|
2
|
+
jest.mock('../../src/services/sync/index.ts', () => ({}))
|
|
3
|
+
jest.mock('../../src/services/sync/manager.ts', () => ({}))
|
|
4
|
+
jest.mock('../../src/services/sync/models/index.ts', () => ({}))
|
|
5
|
+
jest.mock('../../src/services/sync/repositories/index.ts', () => ({}))
|
|
6
|
+
jest.mock('../../src/services/sync/database/factory.ts', () => ({}))
|
|
7
|
+
|
|
8
|
+
// Mock modules that use sync to prevent compilation errors
|
|
9
|
+
jest.mock('../../src/services/user/streakCalculator.ts', () => ({
|
|
10
|
+
calculateStreak: jest.fn(),
|
|
11
|
+
getStreakMessage: jest.fn()
|
|
12
|
+
}))
|
|
13
|
+
jest.mock('../../src/services/contentProgress.js', () => ({
|
|
14
|
+
...jest.requireActual('../../src/services/contentProgress'),
|
|
15
|
+
}))
|
|
16
|
+
jest.mock('../../src/services/contentLikes.js', () => ({
|
|
17
|
+
...jest.requireActual('../../src/services/contentLikes'),
|
|
18
|
+
}))
|
|
19
|
+
jest.mock('../../src/services/userActivity.js', () => ({
|
|
20
|
+
...jest.requireActual('../../src/services/userActivity'),
|
|
21
|
+
}))
|
|
22
|
+
jest.mock('../../src/services/content-org/learning-paths.ts', () => ({
|
|
23
|
+
enrollInLearningPath: jest.fn(),
|
|
24
|
+
getLearningPathProgress: jest.fn()
|
|
25
|
+
}))
|
|
26
|
+
jest.mock('../../src/services/content-org/guided-courses.ts', () => ({
|
|
27
|
+
enrollInGuidedCourse: jest.fn()
|
|
28
|
+
}))
|
|
29
|
+
|
|
30
|
+
// Mock getSanityDate before other modules load to avoid circular dependency issues
|
|
31
|
+
jest.mock('../../src/services/sanity.js', () => ({
|
|
32
|
+
...jest.requireActual('../../src/services/sanity.js'),
|
|
33
|
+
getSanityDate: jest.fn((date) => date.toISOString()),
|
|
34
|
+
fetchByRailContentIds: jest.fn(),
|
|
35
|
+
fetchCourseCollectionData: jest.fn(),
|
|
36
|
+
fetchRelatedLessons: jest.fn()
|
|
37
|
+
}))
|
|
38
|
+
|
|
39
|
+
jest.mock('../../src/services/recommendations.js', () => ({
|
|
40
|
+
...jest.requireActual('../../src/services/recommendations.js'),
|
|
41
|
+
fetchSimilarItems: jest.fn(),
|
|
42
|
+
rankCategories: jest.fn()
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
jest.mock('../../src/services/contentAggregator.js', () => ({
|
|
46
|
+
addContextToContent: jest.fn(async (getter) => getter()),
|
|
47
|
+
}))
|
|
48
|
+
|
|
49
|
+
jest.mock('../../src/services/user/management.js', () => ({
|
|
50
|
+
getUserData: jest.fn(async () => ({ is_admin: false }))
|
|
51
|
+
}))
|
|
52
|
+
|
|
53
|
+
import { getEndScreen } from '../../src/services/endScreen/endScreen.ts'
|
|
54
|
+
import * as recommendationsModule from '../../src/services/recommendations.js'
|
|
55
|
+
import * as sanityModule from '../../src/services/sanity.js'
|
|
56
|
+
|
|
57
|
+
describe('getEndScreen', () => {
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
jest.clearAllMocks()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
describe('Single Lessons', () => {
|
|
63
|
+
test('single lesson without course returns countdown with RecSys recommendation', async () => {
|
|
64
|
+
const mockRecommendation = { id: 999, type: 'lesson', title: 'Recommended Lesson', status: 'published' }
|
|
65
|
+
mockFetchRecommendation([mockRecommendation])
|
|
66
|
+
|
|
67
|
+
const result = await getEndScreen({
|
|
68
|
+
lesson: { id: 123, type: 'quick-tips' },
|
|
69
|
+
course: null,
|
|
70
|
+
collection: null,
|
|
71
|
+
brand: 'drumeo'
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
expect(result).toEqual({
|
|
75
|
+
variant: 'countdown-up-next',
|
|
76
|
+
upNext: mockRecommendation,
|
|
77
|
+
countdownAutoplay: true,
|
|
78
|
+
ctaLabels: { primary: 'Play Now', secondary: 'Replay' }
|
|
79
|
+
})
|
|
80
|
+
expect(recommendationsModule.fetchSimilarItems).toHaveBeenCalledWith(123, 'drumeo', 20)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('single lesson uses fallback lesson when RecSys returns empty array', async () => {
|
|
84
|
+
const fallbackLesson = { id: 373201, type: 'lesson', title: 'Fallback Lesson', status: 'published' }
|
|
85
|
+
jest.spyOn(recommendationsModule, 'fetchSimilarItems').mockResolvedValue([])
|
|
86
|
+
jest.spyOn(sanityModule, 'fetchRelatedLessons').mockResolvedValue({ related_lessons: [{ id: 373201, status: 'published', type: 'lesson', title: 'Fallback Lesson' }] })
|
|
87
|
+
jest.spyOn(sanityModule, 'fetchByRailContentIds').mockResolvedValue([fallbackLesson])
|
|
88
|
+
|
|
89
|
+
const result = await getEndScreen({
|
|
90
|
+
lesson: { id: 123, type: 'lesson' },
|
|
91
|
+
brand: 'drumeo'
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
expect(result.variant).toBe('countdown-up-next')
|
|
95
|
+
expect(result.upNext).toEqual(fallbackLesson)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('single lesson returns null upNext when RecSys throws error', async () => {
|
|
99
|
+
jest.spyOn(recommendationsModule, 'fetchSimilarItems').mockRejectedValue(new Error('API Error'))
|
|
100
|
+
|
|
101
|
+
const result = await getEndScreen({
|
|
102
|
+
lesson: { id: 123, type: 'lesson' },
|
|
103
|
+
brand: 'drumeo'
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
expect(result.variant).toBe('countdown-up-next')
|
|
107
|
+
expect(result.upNext).toBeNull()
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
describe('Single Song Lessons (Play-Along and Jam Tracks)', () => {
|
|
112
|
+
test('play-along lesson returns countdown with RecSys recommendation', async () => {
|
|
113
|
+
const mockRecommendation = { id: 888, type: 'play-along', title: 'Recommended Play-Along', status: 'published' }
|
|
114
|
+
mockFetchRecommendation([mockRecommendation])
|
|
115
|
+
|
|
116
|
+
const result = await getEndScreen({
|
|
117
|
+
lesson: { id: 456, type: 'play-along' },
|
|
118
|
+
course: null,
|
|
119
|
+
brand: 'drumeo'
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
expect(result).toEqual({
|
|
123
|
+
variant: 'countdown-up-next',
|
|
124
|
+
upNext: mockRecommendation,
|
|
125
|
+
countdownAutoplay: true,
|
|
126
|
+
ctaLabels: { primary: 'Play Now', secondary: 'Replay' }
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('jam track lesson returns countdown with RecSys recommendation', async () => {
|
|
131
|
+
const mockRecommendation = { id: 777, type: 'jam-track', title: 'Recommended Jam Track', status: 'published' }
|
|
132
|
+
mockFetchRecommendation([mockRecommendation])
|
|
133
|
+
|
|
134
|
+
const result = await getEndScreen({
|
|
135
|
+
lesson: { id: 789, type: 'jam-track' },
|
|
136
|
+
course: null,
|
|
137
|
+
brand: 'guitareo'
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
expect(result).toEqual({
|
|
141
|
+
variant: 'countdown-up-next',
|
|
142
|
+
upNext: mockRecommendation,
|
|
143
|
+
countdownAutoplay: true,
|
|
144
|
+
ctaLabels: { primary: 'Play Now', secondary: 'Replay' }
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('play-along inside course still uses RecSys (ignores course context)', async () => {
|
|
149
|
+
const mockRecommendation = { id: 999, type: 'play-along', status: 'published' }
|
|
150
|
+
mockFetchRecommendation([mockRecommendation])
|
|
151
|
+
|
|
152
|
+
const result = await getEndScreen({
|
|
153
|
+
lesson: { id: 456, type: 'play-along' },
|
|
154
|
+
course: { id: 100, children: [{ id: 456 }, { id: 457 }] },
|
|
155
|
+
brand: 'drumeo'
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
expect(result.variant).toBe('countdown-up-next')
|
|
159
|
+
expect(result.upNext).toEqual(mockRecommendation)
|
|
160
|
+
expect(recommendationsModule.fetchSimilarItems).toHaveBeenCalled()
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
describe('Course - Not Last Lesson', () => {
|
|
165
|
+
test('returns next lesson in course with countdown', async () => {
|
|
166
|
+
const result = await getEndScreen({
|
|
167
|
+
lesson: { id: 200, type: 'course-lesson' },
|
|
168
|
+
course: {
|
|
169
|
+
id: 100,
|
|
170
|
+
children: [
|
|
171
|
+
{ id: 200, status: 'published' },
|
|
172
|
+
{ id: 201, status: 'published', title: 'Next Lesson' },
|
|
173
|
+
{ id: 202, status: 'published' }
|
|
174
|
+
]
|
|
175
|
+
},
|
|
176
|
+
brand: 'pianote'
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
expect(result).toEqual({
|
|
180
|
+
variant: 'countdown-up-next',
|
|
181
|
+
upNext: { id: 201, status: 'published', title: 'Next Lesson' },
|
|
182
|
+
countdownAutoplay: true,
|
|
183
|
+
ctaLabels: { primary: 'Play Now'}
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('skips unreleased lessons and returns next published lesson', async () => {
|
|
188
|
+
const result = await getEndScreen({
|
|
189
|
+
lesson: { id: 200, type: 'course-lesson' },
|
|
190
|
+
course: {
|
|
191
|
+
id: 100,
|
|
192
|
+
children: [
|
|
193
|
+
{ id: 200, status: 'published' },
|
|
194
|
+
{ id: 201, status: 'draft' },
|
|
195
|
+
{ id: 202, status: 'published', title: 'Next Published Lesson' }
|
|
196
|
+
]
|
|
197
|
+
},
|
|
198
|
+
brand: 'drumeo'
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
expect(result.upNext).toEqual({ id: 202, status: 'published', title: 'Next Published Lesson' })
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
describe('Course - Last Lesson (Not in Collection)', () => {
|
|
206
|
+
test('returns RecSys recommendation with course-complete variant', async () => {
|
|
207
|
+
const mockRecommendation = { id: 888, type: 'course', title: 'Recommended Course', status: 'published' }
|
|
208
|
+
mockFetchRecommendation([mockRecommendation])
|
|
209
|
+
|
|
210
|
+
const result = await getEndScreen({
|
|
211
|
+
lesson: { id: 202, type: 'course-lesson' },
|
|
212
|
+
course: {
|
|
213
|
+
id: 100,
|
|
214
|
+
children: [
|
|
215
|
+
{ id: 200, status: 'published' },
|
|
216
|
+
{ id: 201, status: 'published' },
|
|
217
|
+
{ id: 202, status: 'published' }
|
|
218
|
+
]
|
|
219
|
+
},
|
|
220
|
+
brand: 'drumeo'
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
expect(result).toEqual({
|
|
224
|
+
variant: 'course-complete',
|
|
225
|
+
upNext: mockRecommendation,
|
|
226
|
+
countdownAutoplay: false,
|
|
227
|
+
ctaLabels: { primary: 'Play Now', secondary: 'Back to Home' }
|
|
228
|
+
})
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
test('last lesson with all remaining lessons being drafts uses RecSys', async () => {
|
|
232
|
+
const mockRecommendation = { id: 999, type: 'course', status: 'published' }
|
|
233
|
+
mockFetchRecommendation([mockRecommendation])
|
|
234
|
+
|
|
235
|
+
const result = await getEndScreen({
|
|
236
|
+
lesson: { id: 200, type: 'course-lesson' },
|
|
237
|
+
course: {
|
|
238
|
+
id: 100,
|
|
239
|
+
children: [
|
|
240
|
+
{ id: 200, status: 'published' },
|
|
241
|
+
{ id: 201, status: 'draft' },
|
|
242
|
+
{ id: 202, status: 'draft' }
|
|
243
|
+
]
|
|
244
|
+
},
|
|
245
|
+
brand: 'drumeo'
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
expect(result.variant).toBe('course-complete')
|
|
249
|
+
expect(result.upNext).toEqual(mockRecommendation)
|
|
250
|
+
})
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
describe('Course Collection - Not Last Lesson in Course', () => {
|
|
254
|
+
test('returns next lesson in same course with countdown', async () => {
|
|
255
|
+
const result = await getEndScreen({
|
|
256
|
+
lesson: { id: 300, type: 'course-lesson' },
|
|
257
|
+
course: {
|
|
258
|
+
id: 100,
|
|
259
|
+
children: [
|
|
260
|
+
{ id: 300, status: 'published' },
|
|
261
|
+
{ id: 301, status: 'published', title: 'Next in Course' }
|
|
262
|
+
]
|
|
263
|
+
},
|
|
264
|
+
collection: {
|
|
265
|
+
id: 10,
|
|
266
|
+
type: 'course-collection',
|
|
267
|
+
children: [
|
|
268
|
+
{ id: 100, children: [{ id: 300 }, { id: 301 }] },
|
|
269
|
+
{ id: 101, children: [{ id: 400 }] }
|
|
270
|
+
]
|
|
271
|
+
},
|
|
272
|
+
brand: 'drumeo'
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
expect(result).toEqual({
|
|
276
|
+
variant: 'countdown-up-next',
|
|
277
|
+
upNext: { id: 301, status: 'published', title: 'Next in Course' },
|
|
278
|
+
countdownAutoplay: true,
|
|
279
|
+
ctaLabels: { primary: 'Play Now'}
|
|
280
|
+
})
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
describe('Course Collection - Last Lesson, Not Last Course', () => {
|
|
285
|
+
test('returns first lesson of next course with course-complete (no autoplay)', async () => {
|
|
286
|
+
const result = await getEndScreen({
|
|
287
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
288
|
+
course: {
|
|
289
|
+
id: 100,
|
|
290
|
+
status: 'published',
|
|
291
|
+
children: [
|
|
292
|
+
{ id: 300, status: 'published' },
|
|
293
|
+
{ id: 301, status: 'published' }
|
|
294
|
+
]
|
|
295
|
+
},
|
|
296
|
+
collection: {
|
|
297
|
+
id: 10,
|
|
298
|
+
type: 'course-collection',
|
|
299
|
+
status: 'published',
|
|
300
|
+
children: [
|
|
301
|
+
{ id: 100, status: 'published', children: [{ id: 300, status: 'published' }, { id: 301, status: 'published' }] },
|
|
302
|
+
{ id: 101, status: 'published', children: [{ id: 400, status: 'published', title: 'First Lesson Next Course' }, { id: 401, status: 'published' }] }
|
|
303
|
+
]
|
|
304
|
+
},
|
|
305
|
+
brand: 'drumeo'
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
expect(result).toEqual({
|
|
309
|
+
variant: 'course-complete',
|
|
310
|
+
upNext: { id: 400, status: 'published', title: 'First Lesson Next Course' },
|
|
311
|
+
countdownAutoplay: false,
|
|
312
|
+
ctaLabels: { primary: 'Play Now', secondary: 'Back to Home' }
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
test('fetches collection data if children not provided', async () => {
|
|
317
|
+
const mockCollectionData = {
|
|
318
|
+
id: 10,
|
|
319
|
+
type: 'course-collection',
|
|
320
|
+
children: [
|
|
321
|
+
{ id: 100, status: 'published', children: [{ id: 301, status: 'published' }] },
|
|
322
|
+
{ id: 101, status: 'published', children: [{ id: 400, status: 'published', title: 'Fetched Next Course First Lesson' }] }
|
|
323
|
+
]
|
|
324
|
+
}
|
|
325
|
+
jest.spyOn(sanityModule, 'fetchCourseCollectionData').mockResolvedValue(mockCollectionData)
|
|
326
|
+
|
|
327
|
+
const result = await getEndScreen({
|
|
328
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
329
|
+
course: {
|
|
330
|
+
id: 100,
|
|
331
|
+
children: [{ id: 301 }]
|
|
332
|
+
},
|
|
333
|
+
collection: {
|
|
334
|
+
id: 100,
|
|
335
|
+
type: 'course',
|
|
336
|
+
parent_id: 10
|
|
337
|
+
},
|
|
338
|
+
brand: 'drumeo'
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
expect(sanityModule.fetchCourseCollectionData).toHaveBeenCalledWith(10)
|
|
342
|
+
expect(result.upNext).toEqual({ id: 400, status: 'published', title: 'Fetched Next Course First Lesson' })
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
describe('Course Collection - Last Lesson, Last Course', () => {
|
|
347
|
+
test('returns RecSys recommendation with course-complete', async () => {
|
|
348
|
+
const mockRecommendation = { id: 999, type: 'course', title: 'Recommended After Collection', status: 'published' }
|
|
349
|
+
mockFetchRecommendation([mockRecommendation])
|
|
350
|
+
|
|
351
|
+
const result = await getEndScreen({
|
|
352
|
+
lesson: { id: 401, type: 'course-lesson' },
|
|
353
|
+
course: {
|
|
354
|
+
id: 101,
|
|
355
|
+
children: [
|
|
356
|
+
{ id: 400, status: 'published' },
|
|
357
|
+
{ id: 401, status: 'published' }
|
|
358
|
+
]
|
|
359
|
+
},
|
|
360
|
+
collection: {
|
|
361
|
+
id: 10,
|
|
362
|
+
type: 'course-collection',
|
|
363
|
+
children: [
|
|
364
|
+
{ id: 100, children: [{ id: 300 }, { id: 301 }] },
|
|
365
|
+
{ id: 101, children: [{ id: 400 }, { id: 401 }] }
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
brand: 'drumeo'
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
expect(result).toEqual({
|
|
372
|
+
variant: 'course-complete',
|
|
373
|
+
upNext: mockRecommendation,
|
|
374
|
+
countdownAutoplay: false,
|
|
375
|
+
ctaLabels: { primary: 'Play Now', secondary: 'Back to Home' }
|
|
376
|
+
})
|
|
377
|
+
})
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
describe('Playlists', () => {
|
|
381
|
+
test('returns next item in playlist with countdown', async () => {
|
|
382
|
+
const result = await getEndScreen({
|
|
383
|
+
lesson: { id: 500, type: 'lesson' },
|
|
384
|
+
playlist: {
|
|
385
|
+
id: 10,
|
|
386
|
+
items: [
|
|
387
|
+
{ id: 500, status: 'published' },
|
|
388
|
+
{ id: 501, status: 'published', title: 'Next in Playlist' },
|
|
389
|
+
{ id: 502, status: 'published' }
|
|
390
|
+
]
|
|
391
|
+
},
|
|
392
|
+
brand: 'drumeo'
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
expect(result).toEqual({
|
|
396
|
+
variant: 'countdown-up-next',
|
|
397
|
+
upNext: { id: 501, status: 'published', title: 'Next in Playlist' },
|
|
398
|
+
countdownAutoplay: true,
|
|
399
|
+
ctaLabels: { primary: 'Play Now'}
|
|
400
|
+
})
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
test('skips unreleased items in playlist', async () => {
|
|
404
|
+
const result = await getEndScreen({
|
|
405
|
+
lesson: { id: 500, type: 'lesson' },
|
|
406
|
+
playlist: {
|
|
407
|
+
id: 10,
|
|
408
|
+
items: [
|
|
409
|
+
{ id: 500, status: 'published' },
|
|
410
|
+
{ id: 501, status: 'draft' },
|
|
411
|
+
{ id: 502, status: 'published', title: 'Next Published in Playlist' }
|
|
412
|
+
]
|
|
413
|
+
},
|
|
414
|
+
brand: 'drumeo'
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
expect(result.upNext).toEqual({ id: 502, status: 'published', title: 'Next Published in Playlist' })
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
test('handles playlist with empty items array', async () => {
|
|
421
|
+
const result = await getEndScreen({
|
|
422
|
+
lesson: { id: 500, type: 'lesson' },
|
|
423
|
+
playlist: { id: 10, items: [] },
|
|
424
|
+
brand: 'drumeo'
|
|
425
|
+
})
|
|
426
|
+
|
|
427
|
+
expect(result).toBeNull()
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
test('handles playlist with undefined items', async () => {
|
|
431
|
+
const result = await getEndScreen({
|
|
432
|
+
lesson: { id: 500, type: 'lesson' },
|
|
433
|
+
playlist: { id: 10 },
|
|
434
|
+
brand: 'drumeo'
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
expect(result).toBeNull()
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
test('handles item not found in playlist', async () => {
|
|
441
|
+
const result = await getEndScreen({
|
|
442
|
+
lesson: { id: 999, type: 'lesson' },
|
|
443
|
+
playlist: {
|
|
444
|
+
id: 10,
|
|
445
|
+
items: [{ id: 500 }, { id: 501 }]
|
|
446
|
+
},
|
|
447
|
+
brand: 'drumeo'
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
expect(result).toBeNull()
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
test('transcriptions in playlist still show end screen', async () => {
|
|
454
|
+
const result = await getEndScreen({
|
|
455
|
+
lesson: { id: 500, type: 'lesson' },
|
|
456
|
+
playlist: {
|
|
457
|
+
id: 10,
|
|
458
|
+
items: [
|
|
459
|
+
{ id: 500, type: 'lesson', status: 'published' },
|
|
460
|
+
{ id: 501, type: 'transcription', status: 'published', title: 'Transcription Next' }
|
|
461
|
+
]
|
|
462
|
+
},
|
|
463
|
+
brand: 'drumeo'
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
expect(result.upNext).toEqual({ id: 501, type: 'transcription', status: 'published', title: 'Transcription Next' })
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
test('uses user_playlist_item_index directly instead of searching by lesson id', async () => {
|
|
470
|
+
const result = await getEndScreen({
|
|
471
|
+
lesson: { id: 999, type: 'lesson' },
|
|
472
|
+
playlist: {
|
|
473
|
+
id: 10,
|
|
474
|
+
items: [
|
|
475
|
+
{ id: 500, status: 'published' },
|
|
476
|
+
{ id: 501, status: 'published', title: 'Next in Playlist' },
|
|
477
|
+
{ id: 502, status: 'published' }
|
|
478
|
+
]
|
|
479
|
+
},
|
|
480
|
+
user_playlist_item_index: 0,
|
|
481
|
+
brand: 'drumeo'
|
|
482
|
+
})
|
|
483
|
+
|
|
484
|
+
expect(result).toEqual({
|
|
485
|
+
variant: 'countdown-up-next',
|
|
486
|
+
upNext: { id: 501, status: 'published', title: 'Next in Playlist' },
|
|
487
|
+
countdownAutoplay: true,
|
|
488
|
+
ctaLabels: { primary: 'Play Now'}
|
|
489
|
+
})
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
test('user_playlist_item_index 0 is treated as valid index, not falsy', async () => {
|
|
493
|
+
const result = await getEndScreen({
|
|
494
|
+
lesson: { id: 999, type: 'lesson' },
|
|
495
|
+
playlist: {
|
|
496
|
+
id: 10,
|
|
497
|
+
items: [{ id: 500, status: 'published' }]
|
|
498
|
+
},
|
|
499
|
+
user_playlist_item_index: 0,
|
|
500
|
+
brand: 'drumeo'
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
expect(result).toBeNull()
|
|
504
|
+
})
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
describe('Edge Cases', () => {
|
|
508
|
+
test('handles course with empty children array', async () => {
|
|
509
|
+
const mockRecommendation = { id: 999, type: 'course', status: 'published' }
|
|
510
|
+
mockFetchRecommendation([mockRecommendation])
|
|
511
|
+
|
|
512
|
+
const result = await getEndScreen({
|
|
513
|
+
lesson: { id: 123, type: 'course-lesson' },
|
|
514
|
+
course: { id: 100, children: [] },
|
|
515
|
+
brand: 'drumeo'
|
|
516
|
+
})
|
|
517
|
+
|
|
518
|
+
expect(result.variant).toBe('course-complete')
|
|
519
|
+
expect(result.upNext).toEqual(mockRecommendation)
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
test('handles course with undefined children', async () => {
|
|
523
|
+
const mockRecommendation = { id: 999, type: 'course', status: 'published' }
|
|
524
|
+
mockFetchRecommendation([mockRecommendation])
|
|
525
|
+
|
|
526
|
+
const result = await getEndScreen({
|
|
527
|
+
lesson: { id: 123, type: 'course-lesson' },
|
|
528
|
+
course: { id: 100 },
|
|
529
|
+
brand: 'drumeo'
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
expect(result.variant).toBe('course-complete')
|
|
533
|
+
})
|
|
534
|
+
|
|
535
|
+
test('handles lesson not found in course children', async () => {
|
|
536
|
+
const mockRecommendation = { id: 999, type: 'course', status: 'published' }
|
|
537
|
+
mockFetchRecommendation([mockRecommendation])
|
|
538
|
+
|
|
539
|
+
const result = await getEndScreen({
|
|
540
|
+
lesson: { id: 999, type: 'course-lesson' },
|
|
541
|
+
course: {
|
|
542
|
+
id: 100,
|
|
543
|
+
children: [{ id: 200 }, { id: 201 }]
|
|
544
|
+
},
|
|
545
|
+
brand: 'drumeo'
|
|
546
|
+
})
|
|
547
|
+
|
|
548
|
+
expect(result.variant).toBe('course-complete')
|
|
549
|
+
expect(result.upNext).toEqual(mockRecommendation)
|
|
550
|
+
})
|
|
551
|
+
|
|
552
|
+
test('handles collection with empty children', async () => {
|
|
553
|
+
const mockRecommendation = { id: 999, type: 'course', status: 'published' }
|
|
554
|
+
mockFetchRecommendation([mockRecommendation])
|
|
555
|
+
|
|
556
|
+
const result = await getEndScreen({
|
|
557
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
558
|
+
course: {
|
|
559
|
+
id: 100,
|
|
560
|
+
children: [{ id: 301 }]
|
|
561
|
+
},
|
|
562
|
+
collection: {
|
|
563
|
+
id: 10,
|
|
564
|
+
type: 'course-collection',
|
|
565
|
+
children: []
|
|
566
|
+
},
|
|
567
|
+
brand: 'drumeo'
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
expect(result.variant).toBe('course-complete')
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
test('handles collection with undefined children', async () => {
|
|
574
|
+
const mockRecommendation = { id: 999, type: 'course', status: 'published' }
|
|
575
|
+
mockFetchRecommendation([mockRecommendation])
|
|
576
|
+
|
|
577
|
+
const result = await getEndScreen({
|
|
578
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
579
|
+
course: {
|
|
580
|
+
id: 100,
|
|
581
|
+
children: [{ id: 301 }]
|
|
582
|
+
},
|
|
583
|
+
collection: {
|
|
584
|
+
id: 10,
|
|
585
|
+
type: 'course-collection'
|
|
586
|
+
},
|
|
587
|
+
brand: 'drumeo'
|
|
588
|
+
})
|
|
589
|
+
|
|
590
|
+
expect(result.variant).toBe('course-complete')
|
|
591
|
+
})
|
|
592
|
+
|
|
593
|
+
test('handles course not found in collection children', async () => {
|
|
594
|
+
const mockRecommendation = { id: 999, type: 'course', status: 'published' }
|
|
595
|
+
mockFetchRecommendation([mockRecommendation])
|
|
596
|
+
|
|
597
|
+
const result = await getEndScreen({
|
|
598
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
599
|
+
course: {
|
|
600
|
+
id: 999,
|
|
601
|
+
children: [{ id: 301 }]
|
|
602
|
+
},
|
|
603
|
+
collection: {
|
|
604
|
+
id: 10,
|
|
605
|
+
type: 'course-collection',
|
|
606
|
+
children: [{ id: 100, children: [{ id: 300 }] }]
|
|
607
|
+
},
|
|
608
|
+
brand: 'drumeo'
|
|
609
|
+
})
|
|
610
|
+
|
|
611
|
+
expect(result.variant).toBe('course-complete')
|
|
612
|
+
})
|
|
613
|
+
|
|
614
|
+
test('handles next course with empty children', async () => {
|
|
615
|
+
const mockRecommendation = { id: 999, type: 'course', status: 'published' }
|
|
616
|
+
mockFetchRecommendation([mockRecommendation])
|
|
617
|
+
|
|
618
|
+
const result = await getEndScreen({
|
|
619
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
620
|
+
course: {
|
|
621
|
+
id: 100,
|
|
622
|
+
children: [{ id: 301 }]
|
|
623
|
+
},
|
|
624
|
+
collection: {
|
|
625
|
+
id: 10,
|
|
626
|
+
type: 'course-collection',
|
|
627
|
+
children: [
|
|
628
|
+
{ id: 100, children: [{ id: 301 }] },
|
|
629
|
+
{ id: 101, children: [] }
|
|
630
|
+
]
|
|
631
|
+
},
|
|
632
|
+
brand: 'drumeo'
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
expect(result.variant).toBe('course-complete')
|
|
636
|
+
expect(result.upNext).toEqual(mockRecommendation)
|
|
637
|
+
})
|
|
638
|
+
|
|
639
|
+
test('handles next course with undefined children', async () => {
|
|
640
|
+
const mockRecommendation = { id: 999, type: 'course' }
|
|
641
|
+
mockFetchRecommendation([mockRecommendation])
|
|
642
|
+
|
|
643
|
+
const result = await getEndScreen({
|
|
644
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
645
|
+
course: {
|
|
646
|
+
id: 100,
|
|
647
|
+
children: [{ id: 301 }]
|
|
648
|
+
},
|
|
649
|
+
collection: {
|
|
650
|
+
id: 10,
|
|
651
|
+
type: 'course-collection',
|
|
652
|
+
children: [
|
|
653
|
+
{ id: 100, children: [{ id: 301 }] },
|
|
654
|
+
{ id: 101 }
|
|
655
|
+
]
|
|
656
|
+
},
|
|
657
|
+
brand: 'drumeo'
|
|
658
|
+
})
|
|
659
|
+
|
|
660
|
+
expect(result.variant).toBe('course-complete')
|
|
661
|
+
})
|
|
662
|
+
|
|
663
|
+
test('handles non-course-collection collection type', async () => {
|
|
664
|
+
const mockRecommendation = { id: 999, type: 'course' }
|
|
665
|
+
mockFetchRecommendation([mockRecommendation])
|
|
666
|
+
|
|
667
|
+
const result = await getEndScreen({
|
|
668
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
669
|
+
course: {
|
|
670
|
+
id: 100,
|
|
671
|
+
children: [{ id: 301 }]
|
|
672
|
+
},
|
|
673
|
+
collection: {
|
|
674
|
+
id: 10,
|
|
675
|
+
type: 'learning-path',
|
|
676
|
+
children: [{ id: 100 }, { id: 101 }]
|
|
677
|
+
},
|
|
678
|
+
brand: 'drumeo'
|
|
679
|
+
})
|
|
680
|
+
|
|
681
|
+
expect(result.variant).toBe('course-complete')
|
|
682
|
+
})
|
|
683
|
+
|
|
684
|
+
test('RecSys filters out lessons from the same course (parent_id === excludeId)', async () => {
|
|
685
|
+
// Course 100 is finished (lesson 301 is last). excludeId = course.id = 100.
|
|
686
|
+
// id 888 belongs to course 100 → filtered out. id 999 has no parent → returned.
|
|
687
|
+
const mockContents = [
|
|
688
|
+
{ id: 888, parent_id: 100, type: 'course-lesson' },
|
|
689
|
+
{ id: 999, type: 'course', title: 'Standalone Course', status: 'published' }
|
|
690
|
+
]
|
|
691
|
+
jest.spyOn(recommendationsModule, 'fetchSimilarItems').mockResolvedValue([888, 999])
|
|
692
|
+
jest.spyOn(sanityModule, 'fetchByRailContentIds').mockResolvedValue(mockContents)
|
|
693
|
+
|
|
694
|
+
const result = await getEndScreen({
|
|
695
|
+
lesson: { id: 301, type: 'course-lesson' },
|
|
696
|
+
course: { id: 100, children: [{ id: 301 }] },
|
|
697
|
+
brand: 'drumeo'
|
|
698
|
+
})
|
|
699
|
+
|
|
700
|
+
expect(result.variant).toBe('course-complete')
|
|
701
|
+
expect(result.upNext).toEqual({ id: 999, type: 'course', title: 'Standalone Course', status: 'published'})
|
|
702
|
+
})
|
|
703
|
+
|
|
704
|
+
})
|
|
705
|
+
})
|
|
706
|
+
|
|
707
|
+
function mockFetchRecommendation(contents) {
|
|
708
|
+
const ids = contents.map(c => c.id)
|
|
709
|
+
jest.spyOn(recommendationsModule, 'fetchSimilarItems').mockResolvedValue(ids)
|
|
710
|
+
jest.spyOn(recommendationsModule, 'rankCategories').mockResolvedValue([{ slug: 'recommended', items: ids }])
|
|
711
|
+
jest.spyOn(sanityModule, 'fetchByRailContentIds').mockResolvedValue(contents)
|
|
712
|
+
}
|