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.
Files changed (131) hide show
  1. package/.agent/decisions/2026-07-20-mu2-1724-songs-lessons-counts.md +33 -0
  2. package/.agent/decisions/2026-07-20-query-builder-tostring.md +37 -0
  3. package/CHANGELOG.md +8 -0
  4. package/package.json +2 -1
  5. package/src/contentTypeConfig.js +1 -0
  6. package/src/lib/sanity/query.ts +5 -0
  7. package/src/services/config.js +15 -0
  8. package/src/services/content/artist.ts +1 -3
  9. package/src/services/content/counts.ts +47 -0
  10. package/src/services/content/genre.ts +1 -3
  11. package/src/services/content/instructor.ts +1 -3
  12. package/src/services/userActivity.js +2 -0
  13. package/src/version-info.js +1 -0
  14. package/.claude/settings.local.json +0 -53
  15. package/test/initializeTests.js +0 -60
  16. package/test/integration/awards/award-exclusion-handling.test.ts +0 -275
  17. package/test/integration/awards/internal/image-utils.test.ts +0 -86
  18. package/test/integration/content-progress/__mocks__/mocks.ts +0 -104
  19. package/test/integration/content-progress/contentProgress.test.ts +0 -335
  20. package/test/integration/content-progress/e2eOfflineProgress.test.ts +0 -352
  21. package/test/integration/content-progress/e2eProgress.test.ts +0 -612
  22. package/test/integration/content-progress/getters.test.ts +0 -334
  23. package/test/integration/content-progress/helpers.test.ts +0 -263
  24. package/test/integration/content-progress/offlineContentProgress.test.ts +0 -226
  25. package/test/integration/forums.test.ts +0 -209
  26. package/test/integration/infrastructure/FetchRequestExecutor.test.ts +0 -88
  27. package/test/integration/initializeTestDB.ts +0 -80
  28. package/test/integration/learning-paths.test.ts +0 -854
  29. package/test/integration/notifications.test.ts +0 -178
  30. package/test/integration/progress-row/content-card.test.ts +0 -283
  31. package/test/integration/sync/adapters/idb-errors.test.ts +0 -144
  32. package/test/integration/sync/adapters/sqlite-errors.test.ts +0 -173
  33. package/test/integration/sync/fetch.test.ts +0 -224
  34. package/test/integration/sync/repositories/content-likes.test.ts +0 -99
  35. package/test/integration/sync/repositories/practices.test.ts +0 -179
  36. package/test/integration/sync/repositories/progress.test.ts +0 -245
  37. package/test/integration/sync/repositories/user-award-progress.static.test.ts +0 -68
  38. package/test/integration/sync/repositories/user-award-progress.test.ts +0 -387
  39. package/test/integration/sync/store/cross-user-protection.test.ts +0 -217
  40. package/test/integration/sync/store/store-idb.test.ts +0 -180
  41. package/test/integration/sync/store/store.test.ts +0 -361
  42. package/test/integration/user/permissions.test.js +0 -20
  43. package/test/integration/userActivity.test.ts +0 -102
  44. package/test/live/README.md +0 -29
  45. package/test/live/content.test.js +0 -116
  46. package/test/localStorageMock.js +0 -21
  47. package/test/log.js +0 -5
  48. package/test/mockData/award-definitions.js +0 -171
  49. package/test/mockData/mockData_fetchByRailContentIds_one_content.json +0 -35
  50. package/test/mockData/mockData_progress_content.json +0 -182
  51. package/test/mockData/mockData_sanity_progress_content.json +0 -1451
  52. package/test/mockData/mockData_user_practices.json +0 -9
  53. package/test/setupConsole.js +0 -6
  54. package/test/setupNetworkGuard.js +0 -3
  55. package/test/setupTimers.js +0 -13
  56. package/test/unit/HttpClient.test.ts +0 -267
  57. package/test/unit/awards/award-alacarte-observer.test.ts +0 -199
  58. package/test/unit/awards/award-auto-refresh.test.ts +0 -84
  59. package/test/unit/awards/award-calculations.test.ts +0 -34
  60. package/test/unit/awards/award-callbacks.test.ts +0 -144
  61. package/test/unit/awards/award-certificate-display.test.ts +0 -330
  62. package/test/unit/awards/award-collection-edge-cases.test.ts +0 -212
  63. package/test/unit/awards/award-collection-filtering.test.ts +0 -287
  64. package/test/unit/awards/award-completion-flow.test.ts +0 -306
  65. package/test/unit/awards/award-multi-lesson.test.ts +0 -243
  66. package/test/unit/awards/award-observer-integration.test.ts +0 -327
  67. package/test/unit/awards/award-query-messages.test.ts +0 -448
  68. package/test/unit/awards/award-user-collection.test.ts +0 -416
  69. package/test/unit/awards/duplicate-prevention.test.ts +0 -120
  70. package/test/unit/awards/helpers/completion-mock.ts +0 -56
  71. package/test/unit/awards/helpers/index.ts +0 -3
  72. package/test/unit/awards/helpers/mock-setup.ts +0 -79
  73. package/test/unit/awards/helpers/progress-emitter.ts +0 -45
  74. package/test/unit/awards/message-generator.test.ts +0 -162
  75. package/test/unit/content-progress/bubbleTrickle.test.ts +0 -322
  76. package/test/unit/content-progress/helpers.test.ts +0 -329
  77. package/test/unit/content-progress/navigateTo.test.ts +0 -392
  78. package/test/unit/contentLikes.test.ts +0 -62
  79. package/test/unit/contentMetaData.test.ts +0 -58
  80. package/test/unit/dataContext.test.ts +0 -38
  81. package/test/unit/dateUtils.test.ts +0 -188
  82. package/test/unit/endScreen.test.js +0 -712
  83. package/test/unit/eventsAPI.test.ts +0 -159
  84. package/test/unit/imageSRCBuilder.test.ts +0 -37
  85. package/test/unit/imageSRCVerify.test.ts +0 -155
  86. package/test/unit/infrastructure/DefaultHeaderProvider.test.ts +0 -39
  87. package/test/unit/infrastructure/sanity/ContentClient.test.ts +0 -168
  88. package/test/unit/infrastructure/sanity/DefaultConfigProvider.test.ts +0 -93
  89. package/test/unit/infrastructure/sanity/FetchQueryExecutor.test.ts +0 -174
  90. package/test/unit/infrastructure/sanity/SanityClient.test.ts +0 -140
  91. package/test/unit/lib/__snapshots__/filter.test.ts.snap +0 -5
  92. package/test/unit/lib/filter.test.ts +0 -1154
  93. package/test/unit/lib/lastUpdated.test.ts +0 -21
  94. package/test/unit/lib/query.test.ts +0 -1469
  95. package/test/unit/lib/sanity/decorators/base.test.ts +0 -368
  96. package/test/unit/lib/sanity/decorators/navigate-to.test.ts +0 -361
  97. package/test/unit/lib/sanity/decorators/need-access.test.ts +0 -89
  98. package/test/unit/lib/sanity/decorators/need-lifetime-upgrade.test.ts +0 -85
  99. package/test/unit/lib/sanity/decorators/page-type.test.ts +0 -81
  100. package/test/unit/playerSettings.test.ts +0 -73
  101. package/test/unit/progress-row/content-card.test.ts +0 -314
  102. package/test/unit/progress-row/playlist-card.test.ts +0 -104
  103. package/test/unit/progressRows.test.ts +0 -243
  104. package/test/unit/recommendations.test.js +0 -47
  105. package/test/unit/sanityQueryService.test.ts +0 -200
  106. package/test/unit/search.test.ts +0 -44
  107. package/test/unit/sentry.test.ts +0 -62
  108. package/test/unit/services/progress-internal/bubble.test.ts +0 -279
  109. package/test/unit/services/progress.test.ts +0 -396
  110. package/test/unit/streakMessage.test.ts +0 -251
  111. package/test/unit/sync/context.test.ts +0 -51
  112. package/test/unit/sync/effects/logout-warning.test.ts +0 -158
  113. package/test/unit/sync/effects/push-failure-notification.test.ts +0 -196
  114. package/test/unit/sync/errors/sync-errors.test.ts +0 -106
  115. package/test/unit/sync/errors/validators.test.ts +0 -61
  116. package/test/unit/sync/helpers/TestModel.ts +0 -44
  117. package/test/unit/sync/helpers/index.ts +0 -172
  118. package/test/unit/sync/manager.test.ts +0 -303
  119. package/test/unit/sync/models/user-award-progress.test.ts +0 -82
  120. package/test/unit/sync/resolver.test.ts +0 -229
  121. package/test/unit/sync/retry.test.ts +0 -314
  122. package/test/unit/sync/run-scope.test.ts +0 -23
  123. package/test/unit/sync/stale-record-cleanup.test.ts +0 -107
  124. package/test/unit/sync/store/push-coalescer.test.ts +0 -156
  125. package/test/unit/sync/store-configs.test.ts +0 -37
  126. package/test/unit/sync/telemetry/sync-telemetry.test.ts +0 -118
  127. package/test/unit/sync/utils/event-emitter.test.ts +0 -64
  128. package/test/unit/sync/utils/throttle.test.ts +0 -245
  129. package/test/unit/url-builder.test.ts +0 -72
  130. package/test/unit/user/account.test.ts +0 -66
  131. package/test/unit/user/permissions.test.js +0 -191
@@ -0,0 +1,33 @@
1
+ ---
2
+ date: 2026-07-20
3
+ branch: chore/MU2-1724-songs-lessons-counts
4
+ pr: https://github.com/railroadmedia/musora-content-services/pull/1012
5
+ status: open
6
+ tags: [[chore]]
7
+ ---
8
+
9
+ # Song and lesson counts query
10
+
11
+ ## Context
12
+ Needed a way to get the total number of songs vs. individual playable lessons in Sanity, globally or scoped to a brand. Content types don't map 1:1 onto "song" vs "lesson" — songs include `song`, `play-along`, `jam-track`, `song-tutorial-lesson` per `SONG_TYPES` in `contentTypeConfig.js`, and a "lesson" is any published, top-level (no `parent_type` / empty `parent_content_reference`) document with a `railcontent_id`, regardless of `_type`. The final filter definitions came out of a discussion with teammates, converging on `status == 'published' && defined(railcontent_id)` plus the parent-less check for lessons.
13
+
14
+ ## Decision
15
+ Added `fetchSongAndLessonCounts(brand?)` in `src/services/content/counts.ts`, returning `{ songs, lessons, total }`.
16
+ - Filter logic built with the `Filters` helper (`src/lib/sanity/filter.ts`) and `query()` builder (`src/lib/sanity/query.ts`) instead of hand-interpolated GROQ strings, for consistency with `artist.ts`/`genre.ts`/`instructor.ts`.
17
+ - Query executed via `SanityClient.executeQuery` (`src/infrastructure/sanity/SanityClient.ts`) rather than the legacy `fetchSanity` in `sanity.js` — `executeQuery` returns the raw object result directly, which fits an object-shaped `{songs, lessons}` GROQ query better than `fetchSanity`'s array-oriented `isList` handling.
18
+ - `total` is computed in application code (`songs + lessons`) after the query resolves, not inside GROQ, keeping the query itself to two independent counts.
19
+ - Kept `content.ts` as a types-only file (its original purpose) — the new function and its `SongAndLessonCounts` interface live in the new `counts.ts` file instead, matching the one-file-per-concern convention in `src/services/content/`.
20
+
21
+ ## Alternatives Considered
22
+ - Hand-built GROQ query with `${brand}` string interpolation (the version worked out iteratively with the Sanity MCP) — rejected in favor of the `Filters`/`query` builder for composability and to match existing code style.
23
+ - A fluent `.then().then()` chain for the `total` calculation — tried during review, rejected as unnecessary indirection versus a plain `await` + object literal; reverted to match house style (`artist.ts`, `sanity.js` use plain `await` throughout).
24
+ - Putting the function directly in `content.ts` — rejected once it became clear that file is types-only elsewhere in the codebase; moved to a dedicated `counts.ts`.
25
+
26
+ ## Process Notes
27
+ - `course` vs `course-lesson`: `course` is the parent course entity, `course-lesson` is the individual playable video inside it — easy to conflate when first scoping "lesson" types.
28
+ - Lesson types span several groupings in `contentTypeConfig.js` (`individualLessonsTypes`, `entertainmentLessonTypes`, `skill-pack-lesson`, `guided-course-lesson`, `pack-bundle-lesson`, live/student archive types) — rather than enumerate all `_type` values, the final query avoids the type-list entirely and instead filters on the structural "no parent" condition, which is more robust to new content types being added later.
29
+ - `pack-bundle-lesson` appears in `SINGLE_PARENT_TYPES` but nowhere else in `contentTypeConfig.js` — possibly legacy/unused; not specifically verified against the live Sanity schema.
30
+
31
+ ## Consequences
32
+ - New public function `fetchSongAndLessonCounts` exported from `src/services/content/counts.ts`; needs `npm run build-index` to surface in the generated package index/types.
33
+ - Introduces the first consumer of `SanityClient.executeQuery` outside `src/infrastructure/sanity/` — establishes a pattern for future count/aggregate-style queries to use the client class over `fetchSanity`.
@@ -0,0 +1,37 @@
1
+ ---
2
+ date: 2026-07-20
3
+ branch: chore/query-builder-tostring
4
+ pr: https://github.com/railroadmedia/musora-content-services/pull/1013
5
+ status: open
6
+ tags: [[chore]]
7
+ related: [[2026-07-20-mu2-1724-songs-lessons-counts]]
8
+ ---
9
+
10
+ # QueryBuilder toString()
11
+
12
+ ## Context
13
+ `fetchSongAndLessonCounts` (added in `chore/MU2-1724-songs-lessons-counts`) interpolates `query().and(filter)` builders directly into a GROQ template literal, e.g. `` count(${query().and(songsFilter).build()}) ``. The trailing `.build()` at each interpolation site is boilerplate — the same pattern repeats in `artist.ts`, `genre.ts`, and `instructor.ts` wherever a builder's output lands inside a template literal.
14
+
15
+ ## Decision
16
+ Added `toString(): string` to `QueryBuilder` (`src/lib/sanity/query.ts`), implemented as `return builder.build()`. JS automatically calls `toString()` during string coercion — template literals, `+` concat, `String(x)` — so a builder can now be interpolated directly: `` count(${query().and(filter)}) ``. This mirrors PHP's `Stringable` interface / Java's `toString()` override.
17
+
18
+ Swept the existing call sites to drop the now-redundant `.build()`:
19
+ - `counts.ts`: both `count(${...})` interpolations.
20
+ - `artist.ts`, `genre.ts`, `instructor.ts`: the `data`/`total` variables that are built once and interpolated later into a `q` template literal.
21
+
22
+ Left `.build()` in place at the one call shape that isn't string interpolation: `fetchArtistBySlug`/`fetchGenreBySlug`/`fetchInstructorBySlug` build `q` and pass it directly as `fetchSanity(q, ...)`'s first argument. Runtime-wise this would also work fine without `.build()` (`encodeURIComponent` inside `fetchSanity` coerces via `ToString` too), but keeping the explicit call there reads clearer for a variable that's a function argument rather than a string-interpolation target.
23
+
24
+ `.build()` itself was not removed or deprecated — this is purely additive, both call styles remain valid.
25
+
26
+ ## Alternatives Considered
27
+ - Removing `.build()` everywhere unconditionally, including the `fetchArtistBySlug`-style direct-argument calls — rejected to keep those call sites' typing/intent explicit (a `q` meant to be "the query string" reads oddly as a `QueryBuilder` object until it's coerced at the call boundary).
28
+ - `Symbol.toPrimitive` instead of plain `toString()` — unnecessary; nothing here needs numeric coercion, and plain `toString()` fully covers the template-literal/`String()`/concat cases that matter.
29
+
30
+ ## Process Notes
31
+ - Caveat surfaced during review: `JSON.stringify(builder)` does NOT trigger `toString()` — it serializes the object's own enumerable properties instead. Anywhere a builder might end up inside `JSON.stringify`, this would silently produce the wrong output. Not currently a problem (no such call site exists), but worth remembering if a future call site does this.
32
+ - Equality checks (`===`) never coerce, so comparing two builders directly still won't compare their query strings.
33
+ - This PR is stacked on `chore/MU2-1724-songs-lessons-counts` (PR #1012, unmerged) rather than targeting `main` directly, since it builds on that branch's `counts.ts`. PR base should be retargeted to `main` once #1012 merges.
34
+
35
+ ## Consequences
36
+ - `QueryBuilder` consumers can now interpolate a builder directly into a template literal without remembering to call `.build()` — reduces boilerplate at future call sites.
37
+ - No behavior change: verified via the full test suite (70 suites) after the sweep, plus an intentional break-and-revert of both `toString()` and the `counts.ts` total-summation logic to confirm the new tests actually catch regressions.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
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.167.3](https://github.com/railroadmedia/musora-content-services/compare/v2.167.2...v2.167.3) (2026-07-22)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * add gen-version script ([#1015](https://github.com/railroadmedia/musora-content-services/issues/1015)) ([c047e38](https://github.com/railroadmedia/musora-content-services/commit/c047e38f5a20d34dc9a69e2eb3cf3f31861aa8f1))
11
+ * **BR-819:** add learning path id for learning path intro in recent a… ([#1008](https://github.com/railroadmedia/musora-content-services/issues/1008)) ([267423f](https://github.com/railroadmedia/musora-content-services/commit/267423f525ee12824acfe45e771fd2271d566ed6))
12
+
5
13
  ### [2.167.2](https://github.com/railroadmedia/musora-content-services/compare/v2.167.1...v2.167.2) (2026-07-17)
6
14
 
7
15
 
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "2.167.2",
3
+ "version": "2.167.3",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
+ "prepare": "node scripts/gen-version.cjs",
8
9
  "build-index": "node tools/generate-index.cjs",
9
10
  "release": "standard-version",
10
11
  "doc": "jsdoc -c jsdoc.json --verbose",
@@ -433,6 +433,7 @@ export let contentTypeConfig = {
433
433
  `"badge" : ${contentAwardField}.badge.asset->url`,
434
434
  `"badge_rear" : ${contentAwardField}.badge_rear.asset->url`,
435
435
  `"badge_logo" : ${contentAwardField}.logo.asset->url`,
436
+ '"learning_path_id": *[_type == "learning-path-v2" && references(^._id)][0].railcontent_id',
436
437
  ],
437
438
  includeChildFields: true,
438
439
  },
@@ -32,6 +32,7 @@ export interface QueryBuilder {
32
32
  dereference(): QueryBuilder
33
33
  postFilter(expr: string): QueryBuilder
34
34
  build(): string
35
+ toString(): string
35
36
 
36
37
  _state(): QueryBuilderState
37
38
  }
@@ -148,6 +149,10 @@ export const query = (selector?: string): QueryBuilder => {
148
149
  `.trim()
149
150
  },
150
151
 
152
+ toString() {
153
+ return builder.build()
154
+ },
155
+
151
156
  _state() {
152
157
  return state
153
158
  },
@@ -72,6 +72,21 @@ const excludeFromGeneratedIndex = []
72
72
  * appEnv: 'local'
73
73
  * });
74
74
  */
75
+ export async function getMCSVersion() {
76
+ try {
77
+ const { MCS_VERSION } = await import('../version-info.js')
78
+ return MCS_VERSION
79
+ } catch {
80
+ return null
81
+ }
82
+ }
83
+
84
+ if (process.env.NODE_ENV === 'development') {
85
+ getMCSVersion().then(v => v && console.log('[MCS] last tagged version:', v))
86
+ } else {
87
+ getMCSVersion().then(v => v && console.log('[MCS] version:', v))
88
+ }
89
+
75
90
  export function initializeService(config) {
76
91
  globalConfig.sanityConfig = config.sanityConfig
77
92
  globalConfig.railcontentConfig = config.railcontentConfig
@@ -50,7 +50,6 @@ export async function fetchArtists(
50
50
  `"lesson_count": ${await f.lessonCount(brand)}`
51
51
  )
52
52
  .postFilter(postFilter)
53
- .build()
54
53
 
55
54
  const q = `{
56
55
  "data": ${data},
@@ -152,9 +151,8 @@ export async function fetchArtistLessons(
152
151
  .order(sort)
153
152
  .slice(offset, limit)
154
153
  .select((await getFieldsForContentTypeWithFilteredChildren(contentType, true)) as string)
155
- .build()
156
154
 
157
- const total = query().and(restrictions).build()
155
+ const total = query().and(restrictions)
158
156
 
159
157
  const q = `{
160
158
  "data": ${data},
@@ -0,0 +1,47 @@
1
+ import { SONG_TYPES } from '../../contentTypeConfig.js'
2
+ import { SanityClient } from '../../infrastructure/sanity/SanityClient'
3
+ import { Brands } from '../../lib/brands'
4
+ import { Filters as f } from '../../lib/sanity/filter'
5
+ import { query } from '../../lib/sanity/query'
6
+
7
+ const sanityClient = new SanityClient()
8
+
9
+ export interface SongAndLessonCounts {
10
+ songs: number
11
+ lessons: number
12
+ total: number
13
+ }
14
+
15
+ /**
16
+ * @param {Brands|string} [brand] - Filters by brand; omit for a global count.
17
+ * @returns {Promise<SongAndLessonCounts>}
18
+ */
19
+ export async function fetchSongAndLessonCounts(
20
+ brand?: Brands | string
21
+ ): Promise<SongAndLessonCounts> {
22
+ const songsFilter = await f.combineAsync(
23
+ f.typeIn(SONG_TYPES),
24
+ f.statusIn(['published']),
25
+ f.defined('railcontent_id'),
26
+ brand ? f.brand(brand) : f.empty
27
+ )
28
+
29
+ const lessonsFilter = await f.combineAsync(
30
+ f.defined('railcontent_id'),
31
+ f.statusIn(['published']),
32
+ f.combineOr(f.notDefined('parent_type'), 'count(parent_content_reference) == 0'),
33
+ brand ? f.brand(brand) : f.empty
34
+ )
35
+
36
+ const q = `{
37
+ "songs": count(${query().and(songsFilter)}),
38
+ "lessons": count(${query().and(lessonsFilter)})
39
+ }`
40
+
41
+ const counts = (await sanityClient.executeQuery<Omit<SongAndLessonCounts, 'total'>>(q)) ?? {
42
+ songs: 0,
43
+ lessons: 0,
44
+ }
45
+
46
+ return { ...counts, total: counts.songs + counts.lessons }
47
+ }
@@ -50,7 +50,6 @@ export async function fetchGenres(
50
50
  `"lesson_count": ${await f.lessonCount(brand)}`
51
51
  )
52
52
  .postFilter(postFilter)
53
- .build()
54
53
 
55
54
  const q = `{
56
55
  "data": ${data},
@@ -151,9 +150,8 @@ export async function fetchGenreLessons(
151
150
  .order(sort)
152
151
  .slice(offset, limit)
153
152
  .select((await getFieldsForContentTypeWithFilteredChildren(contentType, true)) as string)
154
- .build()
155
153
 
156
- const total = query().and(restrictions).build()
154
+ const total = query().and(restrictions)
157
155
 
158
156
  const q = `{
159
157
  "data": ${data},
@@ -51,7 +51,6 @@ export async function fetchInstructors(
51
51
  `"lesson_count": ${await f.lessonCount(brand)}`
52
52
  )
53
53
  .postFilter(postFilter)
54
- .build()
55
54
 
56
55
  const q = `{
57
56
  "data": ${data},
@@ -151,9 +150,8 @@ export async function fetchInstructorLessons(
151
150
  .order(sort)
152
151
  .slice(offset, limit)
153
152
  .select((await getFieldsForContentTypeWithFilteredChildren(contentType, true)) as string)
154
- .build()
155
153
 
156
- const total = query().and(restrictions).build()
154
+ const total = query().and(restrictions)
157
155
 
158
156
  const q = `{
159
157
  "data": ${data},
@@ -526,6 +526,7 @@ export async function getRecentActivity({ page = 1, limit = 5, tabName = null }
526
526
  thumbnail: content.thumbnail || null,
527
527
  title: content.title || practice.title,
528
528
  parent_id: content.parent_id || null,
529
+ learningPathId: content.learning_path_id || null,
529
530
  navigateTo: content.navigateTo || null,
530
531
  sanityType: content.type || null,
531
532
  artist_name: content.artist_name || null,
@@ -820,6 +821,7 @@ async function formatPracticeMeta(practices = []) {
820
821
  sanity_type: content?.type || null,
821
822
  content_slug: content?.slug || null,
822
823
  parent_id: content?.parent_id || null,
824
+ learningPathId: content?.learning_path_id || null,
823
825
  navigateTo: content?.navigateTo || null,
824
826
  artist_name: content?.artist_name || null,
825
827
  }
@@ -0,0 +1 @@
1
+ export const MCS_VERSION = '2.167.3'
@@ -1,53 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npx jest *)",
5
- "Bash(npx tsc *)",
6
- "Skill(counselors)",
7
- "Bash(counselors ls *)",
8
- "Bash(counselors groups *)",
9
- "Bash(counselors run *)",
10
- "Bash(npm test *)",
11
- "Bash(gh pr *)",
12
- "Bash(gh api *)",
13
- "Bash(mkdir -p /tmp/pr-review-v2)",
14
- "Read(//tmp/pr-review-v2/**)",
15
- "Bash(cat /home/alesevero/railenvironment/applications/musora-content-services/AGENTS.md)",
16
- "Bash(echo \"no AGENTS.md\")",
17
- "Bash(echo \"exit=$?\")",
18
- "Bash(git checkout *)",
19
- "Skill(pr)",
20
- "Skill(create-decision)",
21
- "mcp__github__pull_request_read",
22
- "mcp__github__push_files",
23
- "Bash(git push *)",
24
- "mcp__github__create_pull_request",
25
- "mcp__github__search_pull_requests",
26
- "Bash(git commit *)",
27
- "Bash(git add *)",
28
- "mcp__github__list_pull_requests"
29
- ]
30
- },
31
- "model": "sonnet",
32
- "enabledMcpjsonServers": [
33
- "atlassian",
34
- "figma",
35
- "google-workspace",
36
- "snowflake",
37
- "aws",
38
- "hex",
39
- "sanity",
40
- "mysql",
41
- "slack",
42
- "langfuse",
43
- "chrome-devtools",
44
- "railway",
45
- "github",
46
- "asana"
47
- ],
48
- "disabledMcpjsonServers": [
49
- "nightwatch",
50
- "1password"
51
- ],
52
- "effortLevel": "medium"
53
- }
@@ -1,60 +0,0 @@
1
- import { globalConfig, initializeService } from '../src'
2
- import { LocalStorageMock } from './localStorageMock'
3
- const railContentModule = require('../src/services/railcontent.js')
4
- const awardDefsModule = require('../src/services/awards/internal/award-definitions.js')
5
- let token = null
6
- let userId = process.env.RAILCONTENT_USER_ID ?? null
7
-
8
- export async function initializeTestService(useLive = false, isAdmin = false) {
9
- let token, userId
10
- if (useLive && !token && process.env.RAILCONTENT_BASE_URL) {
11
- const baseUrl = `${process.env.RAILCONTENT_BASE_URL}/api/user-management-system`
12
- const response = await fetch(`${baseUrl}/v1/sessions`, {
13
- method: 'POST',
14
- headers: {
15
- 'X-Client-Platform': 'mobile',
16
- 'Content-Type': 'application/json',
17
- Authorization: null,
18
- },
19
- body: JSON.stringify({
20
- email: process.env.RAILCONTENT_EMAIL,
21
- password: process.env.RAILCONTENT_PASSWORD,
22
- device_name: 'test',
23
- device_token: '',
24
- platform: '',
25
- }),
26
- })
27
-
28
- let data = await response.json() // Parse the JSON body
29
- token = data['token']
30
- userId = data['user']['id']
31
- }
32
-
33
- const config = {
34
- sanityConfig: {
35
- token: process.env.SANITY_API_TOKEN,
36
- projectId: process.env.SANITY_PROJECT_ID,
37
- dataset: process.env.SANITY_DATASET,
38
- useCachedAPI: process.env.SANITY_USE_CACHED_API === 'true' || true,
39
- version: '2021-06-07',
40
- debug: process.env.DEBUG === 'true' || false,
41
- useDummyRailContentMethods: true,
42
- },
43
- railcontentConfig: {
44
- baseUrl: process.env.RAILCONTENT_BASE_URL || 'https://test.musora.com',
45
- token: token,
46
- userId: userId,
47
- authToken: token,
48
- },
49
- sessionConfig: { token: token, userId: userId, authToken: token },
50
- baseUrl: process.env.RAILCONTENT_BASE_URL,
51
- localStorage: new LocalStorageMock(),
52
- isMA: true,
53
- }
54
- jest.spyOn(awardDefsModule.awardDefinitions, 'initialize').mockResolvedValue()
55
- initializeService(config)
56
- // Mock user permissions
57
- let permissionsMock = jest.spyOn(railContentModule, 'fetchUserPermissionsData')
58
- let permissionsData = { permissions: [108, 91, 92], isAdmin: isAdmin }
59
- permissionsMock.mockImplementation(() => permissionsData)
60
- }
@@ -1,275 +0,0 @@
1
- import { awardManager } from '../../../src/services/awards/internal/award-manager.js'
2
- import { awardEvents } from '../../../src/services/awards/internal/award-events.js'
3
- import { mockAwardDefinitions, getAwardByContentId } from '../../mockData/award-definitions.js'
4
- import { globalConfig } from '../../../src/services/config.js'
5
- import { LocalStorageMock } from '../../localStorageMock.js'
6
- import { setupDefaultMocks, setupAwardEventListeners } from '../../unit/awards/helpers/index'
7
- import { mockCompletionStates, mockAllCompleted, mockNoneCompleted } from '../../unit/awards/helpers/completion-mock'
8
-
9
- jest.mock('../../../src/services/sanity.js', () => ({
10
- ...jest.requireActual('../../../src/services/sanity'),
11
- default: { fetch: jest.fn() },
12
- fetchSanity: jest.fn()
13
- }))
14
-
15
- jest.mock('../../../src/services/railcontent.js', () => ({
16
- ...jest.requireActual('../../../src/services/railcontent'),
17
- fetchUserPermissionsData: jest.fn().mockResolvedValue({ permissions: [108, 91, 92], isAdmin: false })
18
- }))
19
-
20
- jest.mock('../../../src/services/sync/repository-proxy.ts', () => {
21
- const mockFns = {
22
- contentProgress: {
23
- getOneProgressByContentId: jest.fn(),
24
- getSomeProgressByContentIds: jest.fn(),
25
- queryOne: jest.fn(),
26
- queryAll: jest.fn()
27
- },
28
- practices: {
29
- sumPracticeMinutesForContent: jest.fn()
30
- },
31
- userAwardProgress: {
32
- hasCompletedAward: jest.fn(),
33
- recordAwardProgress: jest.fn(),
34
- getByAwardId: jest.fn(),
35
- completeAward: jest.fn()
36
- }
37
- }
38
- return { default: mockFns, ...mockFns }
39
- })
40
-
41
- import sanityClient, { fetchSanity } from '../../../src/services/sanity.js'
42
- import db_ from '../../../src/services/sync/repository-proxy'
43
- const db = db_ as any
44
- import { awardDefinitions } from '../../../src/services/awards/internal/award-definitions.js'
45
-
46
- describe('Award Content Exclusion Handling - E2E Scenarios', () => {
47
- let listeners
48
-
49
- beforeEach(async () => {
50
- jest.clearAllMocks()
51
- globalConfig.localStorage = new LocalStorageMock()
52
- awardEvents.removeAllListeners()
53
-
54
- sanityClient.fetch = jest.fn().mockResolvedValue(mockAwardDefinitions)
55
- setupDefaultMocks(db, fetchSanity, { practiceMinutes: 150 })
56
-
57
- db.userAwardProgress.completeAward = jest.fn().mockResolvedValue({ data: {}, status: 'synced' })
58
-
59
- db.contentProgress.getSomeProgressByContentIds.mockResolvedValue({
60
- data: [{ created_at: Math.floor(Date.now() / 1000) - 86400 * 7 }]
61
- })
62
-
63
- await awardDefinitions.refresh()
64
-
65
- listeners = setupAwardEventListeners(awardEvents)
66
- })
67
-
68
- afterEach(() => {
69
- awardEvents.removeAllListeners()
70
- awardDefinitions.clear()
71
- })
72
-
73
- describe('Scenario: Guided course with excluded intro video (416446 - 1 eligible lesson)', () => {
74
- const testAward = getAwardByContentId(416446)
75
- const courseId = 416446
76
-
77
- test('completing the single eligible lesson grants award at 100%', async () => {
78
- mockAllCompleted(db)
79
-
80
- await awardManager.onContentCompleted(courseId)
81
-
82
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
83
- expect.any(String),
84
- 100,
85
- expect.objectContaining({
86
- completedAt: expect.any(String),
87
- immediate: true
88
- })
89
- )
90
- expect(listeners.granted).toHaveBeenCalledTimes(1)
91
- })
92
-
93
- test('shows 0% progress when eligible lesson not completed', async () => {
94
- mockNoneCompleted(db)
95
-
96
- await awardManager.onContentCompleted(courseId)
97
-
98
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
99
- testAward._id,
100
- 0,
101
- expect.objectContaining({
102
- progressData: expect.any(Object)
103
- })
104
- )
105
- })
106
- })
107
-
108
- describe('Scenario: Course with 4 eligible lessons (417049 - intro excluded)', () => {
109
- const testAward = getAwardByContentId(417049)
110
- const courseId = 417049
111
-
112
- test('completing 1 of 4 lessons shows 25% progress', async () => {
113
- mockCompletionStates(db, [417045])
114
-
115
- await awardManager.onContentCompleted(courseId)
116
-
117
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
118
- testAward._id,
119
- 25,
120
- expect.objectContaining({
121
- progressData: expect.any(Object)
122
- })
123
- )
124
- })
125
-
126
- test('completing 2 of 4 lessons shows 50% progress', async () => {
127
- mockCompletionStates(db, [417045, 417046])
128
-
129
- await awardManager.onContentCompleted(courseId)
130
-
131
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
132
- testAward._id,
133
- 50,
134
- expect.objectContaining({
135
- progressData: expect.any(Object)
136
- })
137
- )
138
- })
139
-
140
- test('must complete all 4 eligible lessons to earn award', async () => {
141
- mockCompletionStates(db, [417045, 417046, 417047, 417048])
142
-
143
- await awardManager.onContentCompleted(courseId)
144
-
145
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
146
- expect.any(String),
147
- 100,
148
- expect.objectContaining({
149
- completedAt: expect.any(String),
150
- immediate: true
151
- })
152
- )
153
- expect(listeners.granted).toHaveBeenCalledTimes(1)
154
- })
155
- })
156
-
157
- describe('Scenario: Large course with 23 eligible lessons (416464 - intro excluded)', () => {
158
- const testAward = getAwardByContentId(416464)
159
- const courseId = 416464
160
- const eligibleLessons = [
161
- 416467, 416468, 416469, 416470, 416471, 416472, 416473,
162
- 416474, 416475, 416476, 416477, 416478, 416479, 416480, 416481,
163
- 416482, 416483, 416484, 416485, 416486, 416487, 416488, 416489
164
- ]
165
-
166
- test('shows 0% progress when no eligible lessons completed', async () => {
167
- mockNoneCompleted(db)
168
-
169
- await awardManager.onContentCompleted(courseId)
170
-
171
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
172
- testAward._id,
173
- 0,
174
- expect.objectContaining({
175
- progressData: expect.any(Object)
176
- })
177
- )
178
- })
179
-
180
- test('completing 12 of 23 lessons shows ~52% progress', async () => {
181
- mockCompletionStates(db, eligibleLessons.slice(0, 12))
182
-
183
- await awardManager.onContentCompleted(courseId)
184
-
185
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
186
- testAward._id,
187
- 52,
188
- expect.objectContaining({
189
- progressData: expect.any(Object)
190
- })
191
- )
192
- })
193
-
194
- test('must complete all 23 eligible lessons to earn award', async () => {
195
- mockCompletionStates(db, eligibleLessons)
196
-
197
- await awardManager.onContentCompleted(courseId)
198
-
199
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
200
- expect.any(String),
201
- 100,
202
- expect.objectContaining({
203
- completedAt: expect.any(String),
204
- immediate: true
205
- })
206
- )
207
- expect(listeners.granted).toHaveBeenCalledTimes(1)
208
- })
209
- })
210
-
211
- describe('Scenario: Course type without excluded content (417039 - all 3 lessons count)', () => {
212
- const testAward = getAwardByContentId(417039)
213
- const courseId = 417039
214
-
215
- test('first lesson counts toward progress', async () => {
216
- mockCompletionStates(db, [417035])
217
-
218
- await awardManager.onContentCompleted(courseId)
219
-
220
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
221
- testAward._id,
222
- 33,
223
- expect.objectContaining({
224
- progressData: expect.any(Object)
225
- })
226
- )
227
- })
228
-
229
- test('all 3 lessons must be completed to earn award', async () => {
230
- mockAllCompleted(db)
231
-
232
- await awardManager.onContentCompleted(courseId)
233
-
234
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
235
- expect.any(String),
236
- 100,
237
- expect.objectContaining({
238
- completedAt: expect.any(String),
239
- immediate: true
240
- })
241
- )
242
- })
243
- })
244
-
245
- describe('Scenario: Learning path content type (417140)', () => {
246
- const testAward = getAwardByContentId(417140)
247
- const courseId = 417140
248
-
249
- test('all child content counts toward progress', async () => {
250
- mockCompletionStates(db, testAward.child_ids.slice(0, 11))
251
-
252
- await awardManager.onContentCompleted(courseId)
253
-
254
- expect(db.userAwardProgress.recordAwardProgress).toHaveBeenCalledWith(
255
- testAward._id,
256
- 50,
257
- expect.objectContaining({
258
- progressData: expect.any(Object)
259
- })
260
- )
261
- })
262
- })
263
-
264
- describe('Scenario: Skill pack content type (418000)', () => {
265
- const courseId = 418000
266
-
267
- test('completing all lessons grants award', async () => {
268
- mockAllCompleted(db)
269
-
270
- await awardManager.onContentCompleted(courseId)
271
-
272
- expect(listeners.granted).toHaveBeenCalledTimes(1)
273
- })
274
- })
275
- })