musora-content-services 2.104.0 → 2.104.2
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 +8 -5
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/contentTypeConfig.js +1 -1
- package/src/filterBuilder.js +0 -0
- package/src/index.d.ts +3 -1
- package/src/index.js +3 -1
- package/src/lib/ads/monoid.ts +0 -0
- package/src/lib/ads/semigroup.ts +0 -0
- package/src/lib/httpHelper.js +0 -0
- package/src/services/awards/award-query.js +13 -0
- package/src/services/awards/internal/award-manager.js +5 -0
- package/src/services/contentAggregator.js +0 -0
- package/src/services/progress-events.js +0 -0
- package/src/services/railcontent.js +0 -0
- package/src/services/sync/fetch.ts +0 -0
- package/src/services/sync/manager.ts +0 -0
- package/src/services/sync/models/ContentProgress.ts +0 -0
- package/src/services/sync/repositories/user-award-progress.ts +26 -0
- package/src/services/sync/store/index.ts +0 -0
- package/src/services/user/memberships.ts +0 -0
- package/src/services/user/onboarding.ts +0 -0
- package/src/services/userActivity.js +0 -0
- package/test/awards/award-completion-flow.test.js +90 -0
- package/test/initializeTests.js +0 -0
- package/test/learningPaths.test.js +0 -0
- package/test/sanityQueryService.test.js +0 -0
- package/test/sync/adapter.ts +0 -0
- package/test/sync/initialize-sync-manager.js +0 -0
- package/.yarnrc.yml +0 -1
- package/test/reporting.test.js +0 -132
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"permissions": {
|
|
3
3
|
"allow": [
|
|
4
|
-
"Read(//app/musora-platform-backend/**)",
|
|
5
|
-
"Read(//app/musora-platform-frontend/**)",
|
|
6
4
|
"Bash(find:*)",
|
|
7
|
-
"Bash(
|
|
8
|
-
"
|
|
5
|
+
"Bash(docker exec:*)",
|
|
6
|
+
"Bash(npm test:*)",
|
|
7
|
+
"WebSearch",
|
|
8
|
+
"WebFetch(domain:watermelondb.dev)",
|
|
9
|
+
"WebFetch(domain:github.com)",
|
|
10
|
+
"Bash(git checkout:*)",
|
|
11
|
+
"Bash(npm run doc:*)",
|
|
9
12
|
"Bash(cat:*)",
|
|
10
|
-
"Bash(
|
|
13
|
+
"Bash(tr:*)"
|
|
11
14
|
],
|
|
12
15
|
"deny": [],
|
|
13
16
|
"ask": []
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [2.104.2](https://github.com/railroadmedia/musora-content-services/compare/v2.104.1...v2.104.2) (2025-12-12)
|
|
6
|
+
|
|
7
|
+
### [2.104.1](https://github.com/railroadmedia/musora-content-services/compare/v2.104.0...v2.104.1) (2025-12-12)
|
|
8
|
+
|
|
5
9
|
## [2.104.0](https://github.com/railroadmedia/musora-content-services/compare/v2.100.3...v2.104.0) (2025-12-12)
|
|
6
10
|
|
|
7
11
|
|
package/package.json
CHANGED
package/src/contentTypeConfig.js
CHANGED
|
@@ -862,7 +862,7 @@ export function getChildFieldsForContentType(contentType, asQueryString = true)
|
|
|
862
862
|
export function getFieldsForContentType(contentType, asQueryString = true) {
|
|
863
863
|
const fields = contentType
|
|
864
864
|
? DEFAULT_FIELDS.concat(contentTypeConfig?.[contentType]?.fields ?? [])
|
|
865
|
-
: DEFAULT_FIELDS
|
|
865
|
+
: DEFAULT_FIELDS.slice() // ensure copy, not original reference
|
|
866
866
|
return asQueryString ? fields.toString() + ',' : fields
|
|
867
867
|
}
|
|
868
868
|
|
package/src/filterBuilder.js
CHANGED
|
File without changes
|
package/src/index.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
getAwardStatistics,
|
|
10
10
|
getCompletedAwards,
|
|
11
11
|
getContentAwards,
|
|
12
|
-
getInProgressAwards
|
|
12
|
+
getInProgressAwards,
|
|
13
|
+
resetAllAwards
|
|
13
14
|
} from './services/awards/award-query.js';
|
|
14
15
|
|
|
15
16
|
import {
|
|
@@ -683,6 +684,7 @@ declare module 'musora-content-services' {
|
|
|
683
684
|
reportPlaylist,
|
|
684
685
|
requestEmailChange,
|
|
685
686
|
reset,
|
|
687
|
+
resetAllAwards,
|
|
686
688
|
resetAllLearningPaths,
|
|
687
689
|
resetPassword,
|
|
688
690
|
restoreComment,
|
package/src/index.js
CHANGED
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
getAwardStatistics,
|
|
14
14
|
getCompletedAwards,
|
|
15
15
|
getContentAwards,
|
|
16
|
-
getInProgressAwards
|
|
16
|
+
getInProgressAwards,
|
|
17
|
+
resetAllAwards
|
|
17
18
|
} from './services/awards/award-query.js';
|
|
18
19
|
|
|
19
20
|
import {
|
|
@@ -682,6 +683,7 @@ export {
|
|
|
682
683
|
reportPlaylist,
|
|
683
684
|
requestEmailChange,
|
|
684
685
|
reset,
|
|
686
|
+
resetAllAwards,
|
|
685
687
|
resetAllLearningPaths,
|
|
686
688
|
resetPassword,
|
|
687
689
|
restoreComment,
|
package/src/lib/ads/monoid.ts
CHANGED
|
File without changes
|
package/src/lib/ads/semigroup.ts
CHANGED
|
File without changes
|
package/src/lib/httpHelper.js
CHANGED
|
File without changes
|
|
@@ -493,3 +493,16 @@ export async function getAwardStatistics(brand = null) {
|
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* @returns {Promise<{ deletedCount: number }>}
|
|
499
|
+
*/
|
|
500
|
+
export async function resetAllAwards() {
|
|
501
|
+
try {
|
|
502
|
+
const result = await db.userAwardProgress.deleteAllAwards()
|
|
503
|
+
return result
|
|
504
|
+
} catch (error) {
|
|
505
|
+
console.error('Failed to reset awards:', error)
|
|
506
|
+
return { deletedCount: 0 }
|
|
507
|
+
}
|
|
508
|
+
}
|
|
@@ -129,6 +129,11 @@ export class AwardManager {
|
|
|
129
129
|
const completedCount = completedLessonIds.length
|
|
130
130
|
const progressPercentage = Math.round((completedCount / childIds.length) * 100)
|
|
131
131
|
|
|
132
|
+
if (progressPercentage === 100) {
|
|
133
|
+
await this.grantAward(award, collection)
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
132
137
|
const progressData = {
|
|
133
138
|
completedLessonIds,
|
|
134
139
|
totalLessons: childIds.length,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -130,4 +130,30 @@ export default class UserAwardProgressRepository extends SyncRepository<UserAwar
|
|
|
130
130
|
|
|
131
131
|
return { definitions, progress: progressMap }
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
async deleteAllAwards() {
|
|
135
|
+
const allProgress = await this.getAll()
|
|
136
|
+
const ids = allProgress.data.map(p => p.id)
|
|
137
|
+
|
|
138
|
+
if (ids.length === 0) {
|
|
139
|
+
return { deletedCount: 0 }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
await this.deleteSome(ids)
|
|
143
|
+
|
|
144
|
+
const response = await this.store.pushRecordIdsImpatiently(ids)
|
|
145
|
+
|
|
146
|
+
if (response && response.ok) {
|
|
147
|
+
await this.store.db.write(async () => {
|
|
148
|
+
const collection = this.store.db.get<UserAwardProgress>(UserAwardProgress.table)
|
|
149
|
+
const deletedRecords = await collection
|
|
150
|
+
.query(Q.where('id', Q.oneOf(ids)))
|
|
151
|
+
.fetch()
|
|
152
|
+
|
|
153
|
+
await Promise.all(deletedRecords.map(record => record.destroyPermanently()))
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return { deletedCount: ids.length }
|
|
158
|
+
}
|
|
133
159
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -210,4 +210,94 @@ describe('Award Completion Flow - E2E Scenarios', () => {
|
|
|
210
210
|
expect(db.userAwardProgress.recordAwardProgress).not.toHaveBeenCalled()
|
|
211
211
|
})
|
|
212
212
|
})
|
|
213
|
+
|
|
214
|
+
describe('Scenario: Race condition - eligibility check fails but progress reaches 100%', () => {
|
|
215
|
+
const multiLessonAward = getAwardByContentId(417049)
|
|
216
|
+
const parentCourseId = 417049
|
|
217
|
+
|
|
218
|
+
test('grants award with completedAt when updateAwardProgress calculates 100%', async () => {
|
|
219
|
+
let callCount = 0
|
|
220
|
+
|
|
221
|
+
db.contentProgress.getSomeProgressByContentIds.mockImplementation((contentIds) => {
|
|
222
|
+
callCount++
|
|
223
|
+
|
|
224
|
+
if (callCount === 1) {
|
|
225
|
+
const partialRecords = contentIds
|
|
226
|
+
.filter(id => [417045, 417046, 417047].includes(id))
|
|
227
|
+
.map(id => ({
|
|
228
|
+
content_id: id,
|
|
229
|
+
state: 'completed',
|
|
230
|
+
created_at: Math.floor(Date.now() / 1000)
|
|
231
|
+
}))
|
|
232
|
+
return Promise.resolve({ data: partialRecords })
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const allRecords = contentIds.map(id => ({
|
|
236
|
+
content_id: id,
|
|
237
|
+
state: 'completed',
|
|
238
|
+
created_at: Math.floor(Date.now() / 1000)
|
|
239
|
+
}))
|
|
240
|
+
return Promise.resolve({ data: allRecords })
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
await awardManager.onContentCompleted(parentCourseId)
|
|
244
|
+
|
|
245
|
+
expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
|
|
246
|
+
multiLessonAward._id,
|
|
247
|
+
100,
|
|
248
|
+
expect.objectContaining({
|
|
249
|
+
completedAt: expect.any(Number),
|
|
250
|
+
completionData: expect.objectContaining({
|
|
251
|
+
completed_at: expect.any(String)
|
|
252
|
+
}),
|
|
253
|
+
immediate: true
|
|
254
|
+
})
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
expect(listeners.granted).toHaveBeenCalledTimes(1)
|
|
258
|
+
expect(listeners.progress).not.toHaveBeenCalled()
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
test('emits awardGranted event when race condition triggers completion', async () => {
|
|
262
|
+
let callCount = 0
|
|
263
|
+
|
|
264
|
+
db.contentProgress.getSomeProgressByContentIds.mockImplementation((contentIds) => {
|
|
265
|
+
callCount++
|
|
266
|
+
|
|
267
|
+
if (callCount === 1) {
|
|
268
|
+
const partialRecords = contentIds
|
|
269
|
+
.filter(id => [417045, 417046].includes(id))
|
|
270
|
+
.map(id => ({
|
|
271
|
+
content_id: id,
|
|
272
|
+
state: 'completed',
|
|
273
|
+
created_at: Math.floor(Date.now() / 1000)
|
|
274
|
+
}))
|
|
275
|
+
return Promise.resolve({ data: partialRecords })
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const allRecords = contentIds.map(id => ({
|
|
279
|
+
content_id: id,
|
|
280
|
+
state: 'completed',
|
|
281
|
+
created_at: Math.floor(Date.now() / 1000)
|
|
282
|
+
}))
|
|
283
|
+
return Promise.resolve({ data: allRecords })
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
await awardManager.onContentCompleted(parentCourseId)
|
|
287
|
+
|
|
288
|
+
expect(listeners.granted).toHaveBeenCalledTimes(1)
|
|
289
|
+
expect(listeners.granted).toHaveBeenCalledWith(
|
|
290
|
+
expect.objectContaining({
|
|
291
|
+
awardId: multiLessonAward._id,
|
|
292
|
+
definition: expect.objectContaining({
|
|
293
|
+
name: multiLessonAward.name
|
|
294
|
+
}),
|
|
295
|
+
completionData: expect.objectContaining({
|
|
296
|
+
completed_at: expect.any(String)
|
|
297
|
+
}),
|
|
298
|
+
timestamp: expect.any(Number)
|
|
299
|
+
})
|
|
300
|
+
)
|
|
301
|
+
})
|
|
302
|
+
})
|
|
213
303
|
})
|
package/test/initializeTests.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/test/sync/adapter.ts
CHANGED
|
File without changes
|
|
File without changes
|
package/.yarnrc.yml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
nodeLinker: node-modules
|
package/test/reporting.test.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for Reporting Service
|
|
3
|
-
*
|
|
4
|
-
* Note: These tests use mocked HTTP calls. For integration tests,
|
|
5
|
-
* ensure the backend API is running at the configured baseUrl.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { initializeTestService } from './initializeTests.js'
|
|
9
|
-
import {
|
|
10
|
-
reportContent,
|
|
11
|
-
reportForumPost,
|
|
12
|
-
submitReport
|
|
13
|
-
} from '../src/services/reporting/reporting.ts'
|
|
14
|
-
|
|
15
|
-
// Mock HttpClient to avoid actual API calls in tests
|
|
16
|
-
jest.mock('../src/infrastructure/http/HttpClient', () => {
|
|
17
|
-
return {
|
|
18
|
-
HttpClient: jest.fn().mockImplementation(() => ({
|
|
19
|
-
post: jest.fn().mockResolvedValue({
|
|
20
|
-
report_id: 12345,
|
|
21
|
-
message: 'Report submitted successfully',
|
|
22
|
-
is_duplicate: false
|
|
23
|
-
})
|
|
24
|
-
}))
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe('Reporting Service', () => {
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
initializeTestService()
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
describe('reportContent', () => {
|
|
34
|
-
test('should submit a content report with video_not_working category', async () => {
|
|
35
|
-
const result = await reportContent({
|
|
36
|
-
contentId: 123,
|
|
37
|
-
category: 'video_not_working',
|
|
38
|
-
description: 'Video freezes at 2:30'
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
expect(result).toBeDefined()
|
|
42
|
-
expect(result.report_id).toBe(12345)
|
|
43
|
-
expect(result.message).toBe('Report submitted successfully')
|
|
44
|
-
expect(result.is_duplicate).toBe(false)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('should submit a content report without description', async () => {
|
|
48
|
-
const result = await reportContent({
|
|
49
|
-
contentId: 456,
|
|
50
|
-
category: 'incorrect_content'
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
expect(result).toBeDefined()
|
|
54
|
-
expect(result.report_id).toBeDefined()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('should submit a content report with other category and description', async () => {
|
|
58
|
-
const result = await reportContent({
|
|
59
|
-
contentId: 789,
|
|
60
|
-
category: 'other',
|
|
61
|
-
description: 'Audio quality is very poor'
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
expect(result).toBeDefined()
|
|
65
|
-
expect(result.report_id).toBeDefined()
|
|
66
|
-
expect(result.message).toBeDefined()
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
describe('reportForumPost', () => {
|
|
71
|
-
test('should submit a forum post report with required brand', async () => {
|
|
72
|
-
const result = await reportForumPost({
|
|
73
|
-
postId: 555,
|
|
74
|
-
brand: 'drumeo',
|
|
75
|
-
category: 'spam'
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
expect(result).toBeDefined()
|
|
79
|
-
expect(result.report_id).toBeDefined()
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
test('should submit a forum post report with description', async () => {
|
|
83
|
-
const result = await reportForumPost({
|
|
84
|
-
postId: 666,
|
|
85
|
-
brand: 'pianote',
|
|
86
|
-
category: 'harassment',
|
|
87
|
-
description: 'User is harassing other members'
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
expect(result).toBeDefined()
|
|
91
|
-
expect(result.report_id).toBeDefined()
|
|
92
|
-
expect(result.message).toBeDefined()
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
describe('submitReport', () => {
|
|
97
|
-
test('should submit a generic report for content', async () => {
|
|
98
|
-
const result = await submitReport({
|
|
99
|
-
reportableType: 'content',
|
|
100
|
-
reportableId: 999,
|
|
101
|
-
category: 'technical_issue',
|
|
102
|
-
description: 'Page not loading'
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
expect(result).toBeDefined()
|
|
106
|
-
expect(result.report_id).toBeDefined()
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
test('should submit a generic report for playlist', async () => {
|
|
110
|
-
const result = await submitReport({
|
|
111
|
-
reportableType: 'playlist',
|
|
112
|
-
reportableId: 777,
|
|
113
|
-
category: 'incorrect_content'
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
expect(result).toBeDefined()
|
|
117
|
-
expect(result.report_id).toBeDefined()
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
test('should submit a generic report for comment', async () => {
|
|
121
|
-
const result = await submitReport({
|
|
122
|
-
reportableType: 'comment',
|
|
123
|
-
reportableId: 888,
|
|
124
|
-
category: 'inappropriate',
|
|
125
|
-
description: 'Comment contains offensive language'
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
expect(result).toBeDefined()
|
|
129
|
-
expect(result.report_id).toBeDefined()
|
|
130
|
-
})
|
|
131
|
-
})
|
|
132
|
-
})
|