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.
- 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/CHANGELOG.md +8 -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/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,45 +0,0 @@
|
|
|
1
|
-
import { emitProgressSaved } from '../../../../src/services/progress-events.js'
|
|
2
|
-
import { COLLECTION_TYPE } from '../../../../src/services/sync/models/ContentProgress'
|
|
3
|
-
|
|
4
|
-
export { COLLECTION_TYPE }
|
|
5
|
-
|
|
6
|
-
export const emitProgress = ({
|
|
7
|
-
contentId,
|
|
8
|
-
collectionType = null,
|
|
9
|
-
collectionId = null,
|
|
10
|
-
progressPercent = 100,
|
|
11
|
-
userId = 123
|
|
12
|
-
}: {
|
|
13
|
-
contentId: number
|
|
14
|
-
collectionType?: string | null
|
|
15
|
-
collectionId?: number | null
|
|
16
|
-
progressPercent?: number
|
|
17
|
-
userId?: number
|
|
18
|
-
}) => {
|
|
19
|
-
emitProgressSaved({
|
|
20
|
-
userId,
|
|
21
|
-
contentId,
|
|
22
|
-
progressPercent,
|
|
23
|
-
progressStatus: progressPercent === 100 ? 'completed' : 'started',
|
|
24
|
-
bubble: true,
|
|
25
|
-
collectionType,
|
|
26
|
-
collectionId,
|
|
27
|
-
resumeTimeSeconds: null,
|
|
28
|
-
timestamp: Date.now()
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const emitLearningPathProgress = (contentId: number, learningPathId: number, progressPercent = 100) => {
|
|
33
|
-
emitProgress({
|
|
34
|
-
contentId,
|
|
35
|
-
collectionType: COLLECTION_TYPE.LEARNING_PATH,
|
|
36
|
-
collectionId: learningPathId,
|
|
37
|
-
progressPercent
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const emitAlaCarteProgress = (contentId: number, progressPercent = 100) => {
|
|
42
|
-
emitProgress({ contentId, progressPercent })
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const waitForDebounce = (ms = 100): Promise<void> => new Promise(resolve => setTimeout(resolve, ms))
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { AwardMessageGenerator } from '../../../src/services/awards/internal/message-generator.js'
|
|
2
|
-
|
|
3
|
-
describe('AwardMessageGenerator', () => {
|
|
4
|
-
const mockCompletionData = {
|
|
5
|
-
content_title: 'Blues Foundations',
|
|
6
|
-
completed_at: '2023-09-17T14:19:21.000Z',
|
|
7
|
-
days_user_practiced: 14,
|
|
8
|
-
practice_minutes: 180
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
describe('generatePopupMessage', () => {
|
|
12
|
-
test('generates correct message with content title', () => {
|
|
13
|
-
const message = AwardMessageGenerator.generatePopupMessage(mockCompletionData)
|
|
14
|
-
|
|
15
|
-
expect(message).toContain('Blues Foundations')
|
|
16
|
-
expect(message).toContain('14 days')
|
|
17
|
-
expect(message).toContain('180 minutes')
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
test('uses correct practice time in message', () => {
|
|
21
|
-
const customData = {
|
|
22
|
-
...mockCompletionData,
|
|
23
|
-
practice_minutes: 450
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const message = AwardMessageGenerator.generatePopupMessage(customData)
|
|
27
|
-
|
|
28
|
-
expect(message).toContain('450 minutes')
|
|
29
|
-
expect(message).not.toContain('180 minutes')
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('uses correct days in message', () => {
|
|
33
|
-
const customData = {
|
|
34
|
-
...mockCompletionData,
|
|
35
|
-
days_user_practiced: 30
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const message = AwardMessageGenerator.generatePopupMessage(customData)
|
|
39
|
-
|
|
40
|
-
expect(message).toContain('30 days')
|
|
41
|
-
expect(message).not.toContain('14 days')
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
describe('generateCertificateMessage', () => {
|
|
46
|
-
test('generates certificate message without custom text', () => {
|
|
47
|
-
const message = AwardMessageGenerator.generateCertificateMessage(
|
|
48
|
-
mockCompletionData
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
expect(message).toContain('180 minutes')
|
|
52
|
-
expect(message).toContain('Blues Foundations')
|
|
53
|
-
expect(message).toContain('Well Done!')
|
|
54
|
-
expect(message).toContain('certificate of completion')
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('includes custom text when provided', () => {
|
|
58
|
-
const message = AwardMessageGenerator.generateCertificateMessage(
|
|
59
|
-
mockCompletionData,
|
|
60
|
-
'This is a bonus message.'
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
expect(message).toContain('This is a bonus message.')
|
|
64
|
-
expect(message).toContain('180 minutes')
|
|
65
|
-
expect(message).toContain('Blues Foundations')
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
test('handles custom text with proper spacing', () => {
|
|
69
|
-
const message = AwardMessageGenerator.generateCertificateMessage(
|
|
70
|
-
mockCompletionData,
|
|
71
|
-
'Keep up the great work!'
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
expect(message).toContain('completion. Keep up the great work!')
|
|
75
|
-
expect(message).not.toContain(' ')
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test('works without custom text', () => {
|
|
79
|
-
const message = AwardMessageGenerator.generateCertificateMessage(
|
|
80
|
-
mockCompletionData,
|
|
81
|
-
undefined
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
expect(message).toContain('completion.')
|
|
85
|
-
expect(message).toContain('Well Done!')
|
|
86
|
-
expect(message.includes('completion.. Well Done')).toBe(false)
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
test('includes content title from completion data', () => {
|
|
90
|
-
const customData = {
|
|
91
|
-
...mockCompletionData,
|
|
92
|
-
content_title: 'Advanced Jazz Techniques'
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const message = AwardMessageGenerator.generateCertificateMessage(customData)
|
|
96
|
-
|
|
97
|
-
expect(message).toContain('Advanced Jazz Techniques')
|
|
98
|
-
expect(message).not.toContain('Blues Foundations')
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
test('includes practice minutes from completion data', () => {
|
|
102
|
-
const customData = {
|
|
103
|
-
...mockCompletionData,
|
|
104
|
-
practice_minutes: 500
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const message = AwardMessageGenerator.generateCertificateMessage(customData)
|
|
108
|
-
|
|
109
|
-
expect(message).toContain('500 minutes')
|
|
110
|
-
expect(message).not.toContain('180 minutes')
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
describe('edge cases', () => {
|
|
115
|
-
test('handles zero practice minutes', () => {
|
|
116
|
-
const zeroData = {
|
|
117
|
-
...mockCompletionData,
|
|
118
|
-
practice_minutes: 0
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const popupMessage = AwardMessageGenerator.generatePopupMessage(zeroData)
|
|
122
|
-
const certMessage = AwardMessageGenerator.generateCertificateMessage(zeroData)
|
|
123
|
-
|
|
124
|
-
expect(popupMessage).toContain('0 minutes')
|
|
125
|
-
expect(certMessage).toContain('0 minutes')
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
test('handles single day practiced with correct grammar', () => {
|
|
129
|
-
const oneDayData = {
|
|
130
|
-
...mockCompletionData,
|
|
131
|
-
days_user_practiced: 1
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const message = AwardMessageGenerator.generatePopupMessage(oneDayData)
|
|
135
|
-
|
|
136
|
-
expect(message).toContain('1 day')
|
|
137
|
-
expect(message).not.toContain('1 days')
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
test('handles very large practice times', () => {
|
|
141
|
-
const largeData = {
|
|
142
|
-
...mockCompletionData,
|
|
143
|
-
practice_minutes: 10000
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const message = AwardMessageGenerator.generateCertificateMessage(largeData)
|
|
147
|
-
|
|
148
|
-
expect(message).toContain('10000 minutes')
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
test('handles zero days practiced', () => {
|
|
152
|
-
const zeroDaysData = {
|
|
153
|
-
...mockCompletionData,
|
|
154
|
-
days_user_practiced: 0
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const popupMessage = AwardMessageGenerator.generatePopupMessage(zeroDaysData)
|
|
158
|
-
|
|
159
|
-
expect(popupMessage).toContain('0 days')
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
})
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { initializeTestService } from '../../initializeTests.js'
|
|
2
|
-
import {
|
|
3
|
-
averageProgressesFor,
|
|
4
|
-
bubbleProgress,
|
|
5
|
-
computeBubbleTrickleProgresses,
|
|
6
|
-
getAncestorAndSiblingIds,
|
|
7
|
-
getChildrenToDepth,
|
|
8
|
-
trickleProgress,
|
|
9
|
-
} from '../../../src/services/contentProgress.js'
|
|
10
|
-
import { COLLECTION_ID_SELF, COLLECTION_TYPE } from '../../../src/services/sync/models/ContentProgress'
|
|
11
|
-
|
|
12
|
-
let mockProgressRecords: any[] = []
|
|
13
|
-
|
|
14
|
-
jest.mock('../../../src/services/sync/repository-proxy', () => {
|
|
15
|
-
const mockFns = {
|
|
16
|
-
contentProgress: {
|
|
17
|
-
getSomeProgressByContentIds: jest.fn().mockImplementation((contentIds) => {
|
|
18
|
-
const records = mockProgressRecords.filter(r => contentIds.includes(r.content_id))
|
|
19
|
-
return Promise.resolve({ data: records })
|
|
20
|
-
}),
|
|
21
|
-
},
|
|
22
|
-
practices: {
|
|
23
|
-
queryAll: jest.fn().mockResolvedValue({ data: [] }),
|
|
24
|
-
getAll: jest.fn().mockResolvedValue({ data: [] }),
|
|
25
|
-
},
|
|
26
|
-
}
|
|
27
|
-
return { default: mockFns, ...mockFns }
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
jest.mock('../../../src/services/sanity.js', () => ({
|
|
31
|
-
getHierarchy: jest.fn().mockResolvedValue({ metadata: {}, parents: {}, children: {} }),
|
|
32
|
-
getHierarchies: jest.fn().mockResolvedValue({ metadata: {}, parents: {}, children: {} }),
|
|
33
|
-
getSanityDate: jest.fn((date: Date) => date.toISOString()),
|
|
34
|
-
}))
|
|
35
|
-
|
|
36
|
-
jest.mock('../../../src/services/content-org/learning-paths', () => ({
|
|
37
|
-
getDailySession: jest.fn(),
|
|
38
|
-
onLearningPathCompletedActions: jest.fn(),
|
|
39
|
-
}))
|
|
40
|
-
|
|
41
|
-
const flatHierarchy = {
|
|
42
|
-
parents: {
|
|
43
|
-
200: 100,
|
|
44
|
-
201: 100,
|
|
45
|
-
202: 100,
|
|
46
|
-
},
|
|
47
|
-
children: {
|
|
48
|
-
100: [200, 201, 202],
|
|
49
|
-
},
|
|
50
|
-
metadata: {},
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const deepHierarchy = {
|
|
54
|
-
parents: {
|
|
55
|
-
300: 200,
|
|
56
|
-
301: 200,
|
|
57
|
-
200: 100,
|
|
58
|
-
201: 100,
|
|
59
|
-
},
|
|
60
|
-
children: {
|
|
61
|
-
100: [200, 201],
|
|
62
|
-
200: [300, 301],
|
|
63
|
-
},
|
|
64
|
-
metadata: {},
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const collectionSelf = { type: COLLECTION_TYPE.SELF, id: COLLECTION_ID_SELF }
|
|
68
|
-
|
|
69
|
-
describe('getChildrenToDepth', () => {
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
initializeTestService()
|
|
72
|
-
mockProgressRecords = []
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test('no children returns empty array', () => {
|
|
76
|
-
const result = getChildrenToDepth(200, flatHierarchy, 1)
|
|
77
|
-
expect(result).toEqual([])
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test('direct children at depth 1', () => {
|
|
81
|
-
const result = getChildrenToDepth(100, flatHierarchy, 1)
|
|
82
|
-
expect(result).toEqual([200, 201, 202])
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test('grandchildren included at depth 2', () => {
|
|
86
|
-
const result = getChildrenToDepth(100, deepHierarchy, 2)
|
|
87
|
-
expect(result).toEqual([200, 201, 300, 301])
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
test('depth 0 on leaf node returns empty array', () => {
|
|
91
|
-
const result = getChildrenToDepth(300, deepHierarchy, 0)
|
|
92
|
-
expect(result).toEqual([])
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
describe('getAncestorAndSiblingIds', () => {
|
|
97
|
-
beforeEach(() => {
|
|
98
|
-
initializeTestService()
|
|
99
|
-
mockProgressRecords = []
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
test('no parent returns empty array', () => {
|
|
103
|
-
const result = getAncestorAndSiblingIds(flatHierarchy, 100)
|
|
104
|
-
expect(result).toEqual([])
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
test('returns siblings and parent for direct child', () => {
|
|
108
|
-
const result = getAncestorAndSiblingIds(flatHierarchy, 200)
|
|
109
|
-
expect(result).toContain(100)
|
|
110
|
-
expect(result).toContain(200)
|
|
111
|
-
expect(result).toContain(201)
|
|
112
|
-
expect(result).toContain(202)
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
test('returns siblings, parent, parent siblings, and grandparent for nested child', () => {
|
|
116
|
-
const result = getAncestorAndSiblingIds(deepHierarchy, 300)
|
|
117
|
-
expect(result).toContain(300)
|
|
118
|
-
expect(result).toContain(301)
|
|
119
|
-
expect(result).toContain(200)
|
|
120
|
-
expect(result).toContain(201)
|
|
121
|
-
expect(result).toContain(100)
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
test('circular ref returns empty array and logs error', () => {
|
|
125
|
-
const circularHierarchy = {
|
|
126
|
-
parents: { 100: 100 },
|
|
127
|
-
children: { 100: [100] },
|
|
128
|
-
metadata: {},
|
|
129
|
-
}
|
|
130
|
-
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {
|
|
131
|
-
})
|
|
132
|
-
const result = getAncestorAndSiblingIds(circularHierarchy, 100)
|
|
133
|
-
expect(result).toEqual([])
|
|
134
|
-
expect(errorSpy).toHaveBeenCalled()
|
|
135
|
-
errorSpy.mockRestore()
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
test('stops at MAX_DEPTH of 3', () => {
|
|
139
|
-
const fourLevelHierarchy = {
|
|
140
|
-
parents: {
|
|
141
|
-
400: 300,
|
|
142
|
-
300: 200,
|
|
143
|
-
200: 100,
|
|
144
|
-
100: 50,
|
|
145
|
-
},
|
|
146
|
-
children: {
|
|
147
|
-
50: [100],
|
|
148
|
-
100: [200],
|
|
149
|
-
200: [300],
|
|
150
|
-
300: [400],
|
|
151
|
-
},
|
|
152
|
-
metadata: {},
|
|
153
|
-
}
|
|
154
|
-
const result = getAncestorAndSiblingIds(fourLevelHierarchy, 400)
|
|
155
|
-
expect(result).not.toContain(50)
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
describe('averageProgressesFor', () => {
|
|
160
|
-
beforeEach(() => {
|
|
161
|
-
initializeTestService()
|
|
162
|
-
mockProgressRecords = []
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
test('no parent returns empty object', () => {
|
|
166
|
-
const progressData = new Map([[100, 50]])
|
|
167
|
-
const result = averageProgressesFor(flatHierarchy, 100, progressData)
|
|
168
|
-
expect(result).toEqual({})
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
test('single child average equals that child progress', () => {
|
|
172
|
-
const singleChildHierarchy = {
|
|
173
|
-
parents: { 200: 100 },
|
|
174
|
-
children: { 100: [200] },
|
|
175
|
-
metadata: {},
|
|
176
|
-
}
|
|
177
|
-
const progressData = new Map([[200, 60]])
|
|
178
|
-
const result = averageProgressesFor(singleChildHierarchy, 200, progressData)
|
|
179
|
-
expect(result[100]).toBe(60)
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
test('multiple children average is rounded sum divided by count', () => {
|
|
183
|
-
const progressData = new Map([[200, 50], [201, 70], [202, 90]])
|
|
184
|
-
const result = averageProgressesFor(flatHierarchy, 200, progressData)
|
|
185
|
-
expect(result[100]).toBe(Math.round((50 + 70 + 90) / 3))
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
test('missing child progress defaults to 0', () => {
|
|
189
|
-
const progressData = new Map([[200, 60]])
|
|
190
|
-
const result = averageProgressesFor(flatHierarchy, 200, progressData)
|
|
191
|
-
expect(result[100]).toBe(Math.round((60 + 0 + 0) / 3))
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
test('recurses up to compute grandparent progress', () => {
|
|
195
|
-
const progressData = new Map([[300, 80], [301, 40], [201, 50]])
|
|
196
|
-
const result = averageProgressesFor(deepHierarchy, 300, progressData)
|
|
197
|
-
expect(result[200]).toBeDefined()
|
|
198
|
-
expect(result[100]).toBeDefined()
|
|
199
|
-
})
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
describe('trickleProgress', () => {
|
|
203
|
-
beforeEach(() => {
|
|
204
|
-
initializeTestService()
|
|
205
|
-
mockProgressRecords = []
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
test('no descendants returns empty object', () => {
|
|
209
|
-
const result = trickleProgress(flatHierarchy, 200, collectionSelf, 75)
|
|
210
|
-
expect(result).toEqual({})
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
test('all descendants receive same progress value', () => {
|
|
214
|
-
const result = trickleProgress(flatHierarchy, 100, collectionSelf, 100)
|
|
215
|
-
expect(result[200]).toBe(100)
|
|
216
|
-
expect(result[201]).toBe(100)
|
|
217
|
-
expect(result[202]).toBe(100)
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
test('trickles through multiple levels in deep hierarchy', () => {
|
|
221
|
-
const result = trickleProgress(deepHierarchy, 100, collectionSelf, 50)
|
|
222
|
-
expect(result[200]).toBe(50)
|
|
223
|
-
expect(result[201]).toBe(50)
|
|
224
|
-
expect(result[300]).toBe(50)
|
|
225
|
-
expect(result[301]).toBe(50)
|
|
226
|
-
})
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
describe('bubbleProgress', () => {
|
|
230
|
-
beforeEach(() => {
|
|
231
|
-
initializeTestService()
|
|
232
|
-
mockProgressRecords = []
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
test('no parent returns empty object', () => {
|
|
236
|
-
const result = bubbleProgress(flatHierarchy, 100)
|
|
237
|
-
return expect(result).resolves.toEqual({})
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
test('averages sibling progress for parent', async () => {
|
|
241
|
-
mockProgressRecords = [
|
|
242
|
-
{ content_id: 200, progress_percent: 60 },
|
|
243
|
-
{ content_id: 201, progress_percent: 30 },
|
|
244
|
-
{ content_id: 202, progress_percent: 0 },
|
|
245
|
-
]
|
|
246
|
-
const result = await bubbleProgress(flatHierarchy, 200)
|
|
247
|
-
expect(result[100]).toBe(Math.round((60 + 30 + 0) / 3))
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
test('one sibling with progress and rest at 0 yields rounded average', async () => {
|
|
251
|
-
mockProgressRecords = [
|
|
252
|
-
{ content_id: 201, progress_percent: 90 },
|
|
253
|
-
]
|
|
254
|
-
const result = await bubbleProgress(flatHierarchy, 200)
|
|
255
|
-
expect(result[100]).toBe(Math.round(90 / 3))
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
test('uses contentId own progress in calculation', async () => {
|
|
259
|
-
mockProgressRecords = [
|
|
260
|
-
{ content_id: 200, progress_percent: 100 },
|
|
261
|
-
{ content_id: 201, progress_percent: 100 },
|
|
262
|
-
{ content_id: 202, progress_percent: 100 },
|
|
263
|
-
]
|
|
264
|
-
const result = await bubbleProgress(flatHierarchy, 200)
|
|
265
|
-
expect(result[100]).toBe(100)
|
|
266
|
-
})
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
describe('computeBubbleTrickleProgresses', () => {
|
|
270
|
-
beforeEach(() => {
|
|
271
|
-
initializeTestService()
|
|
272
|
-
mockProgressRecords = []
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
test('both bubble and trickle combine results', async () => {
|
|
276
|
-
mockProgressRecords = [
|
|
277
|
-
{ content_id: 200, progress_percent: 100 },
|
|
278
|
-
{ content_id: 201, progress_percent: 100 },
|
|
279
|
-
{ content_id: 202, progress_percent: 100 },
|
|
280
|
-
]
|
|
281
|
-
const result = await computeBubbleTrickleProgresses(100, 100, collectionSelf, flatHierarchy, {
|
|
282
|
-
bubble: true,
|
|
283
|
-
trickle: true,
|
|
284
|
-
})
|
|
285
|
-
expect(result[200]).toBe(100)
|
|
286
|
-
expect(result[201]).toBe(100)
|
|
287
|
-
expect(result[202]).toBe(100)
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
test('bubble=false returns only trickled descendants', async () => {
|
|
291
|
-
const result = await computeBubbleTrickleProgresses(100, 75, collectionSelf, flatHierarchy, {
|
|
292
|
-
bubble: false,
|
|
293
|
-
trickle: true,
|
|
294
|
-
})
|
|
295
|
-
expect(result[200]).toBe(75)
|
|
296
|
-
expect(result[201]).toBe(75)
|
|
297
|
-
expect(result[202]).toBe(75)
|
|
298
|
-
expect(result[100]).toBeUndefined()
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
test('trickle=false returns only bubbled ancestors', async () => {
|
|
302
|
-
mockProgressRecords = [
|
|
303
|
-
{ content_id: 200, progress_percent: 60 },
|
|
304
|
-
]
|
|
305
|
-
const result = await computeBubbleTrickleProgresses(200, 60, collectionSelf, flatHierarchy, {
|
|
306
|
-
bubble: true,
|
|
307
|
-
trickle: false,
|
|
308
|
-
})
|
|
309
|
-
expect(result[100]).toBeDefined()
|
|
310
|
-
expect(result[200]).toBeUndefined()
|
|
311
|
-
expect(result[201]).toBeUndefined()
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
test('empty hierarchy returns empty object', async () => {
|
|
315
|
-
const emptyHierarchy = { parents: {}, children: {}, metadata: {} }
|
|
316
|
-
const result = await computeBubbleTrickleProgresses(100, 50, collectionSelf, emptyHierarchy, {
|
|
317
|
-
bubble: true,
|
|
318
|
-
trickle: true,
|
|
319
|
-
})
|
|
320
|
-
expect(result).toEqual({})
|
|
321
|
-
})
|
|
322
|
-
})
|