musora-content-services 1.0.193 → 1.0.195

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/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
+ ### [1.0.195](https://github.com/railroadmedia/musora-content-services/compare/v1.0.194...v1.0.195) (2024-11-29)
6
+
7
+ ### [1.0.194](https://github.com/railroadmedia/musora-content-services/compare/v1.0.193...v1.0.194) (2024-11-29)
8
+
5
9
  ### [1.0.193](https://github.com/railroadmedia/musora-content-services/compare/v1.0.192...v1.0.193) (2024-11-28)
6
10
 
7
11
  ### [1.0.192](https://github.com/railroadmedia/musora-content-services/compare/v1.0.191...v1.0.192) (2024-11-28)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musora-content-services",
3
- "version": "1.0.193",
3
+ "version": "1.0.195",
4
4
  "description": "A package for Musoras content services ",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -21,6 +21,7 @@ const excludeFromGeneratedIndex = [
21
21
  'fetchUserPermissionsData'
22
22
  ];
23
23
 
24
+ let challengeIndexMetaDataPromise = null;
24
25
 
25
26
  /**
26
27
  * Fetches the completion status of a specific lesson for the current user.
@@ -396,11 +397,24 @@ export async function fetchUserAward(contentId) {
396
397
  * @returns {Promise<any|null>}
397
398
  */
398
399
  export async function fetchChallengeIndexMetadata(contentIds) {
399
- let idsString = contentIds.toString();
400
- let url = `/challenges/user_progress_for_index_page/get?content_ids=${idsString}`;
401
- return await fetchHandler(url, 'get');
400
+ if (!challengeIndexMetaDataPromise) {
401
+ challengeIndexMetaDataPromise = getChallengeIndexMetadataPromise();
402
+ }
403
+ let results = await challengeIndexMetaDataPromise;
404
+ results = results.filter(function(challenge){
405
+ return contentIds.includes(challenge.content_id);
406
+ });
407
+ return results;
402
408
  }
403
409
 
410
+ async function getChallengeIndexMetadataPromise() {
411
+ let url = `/challenges/user_progress_for_index_page/get`;
412
+ const result = await fetchHandler(url, 'get');
413
+ challengeIndexMetaDataPromise = null;
414
+ return result;
415
+ }
416
+
417
+
404
418
  /**
405
419
  * Get active brand challenges for the authorized user
406
420
  *
@@ -641,7 +641,7 @@ async function handleCustomFetchAll(brand, type, {
641
641
  sort,
642
642
  includedFields,
643
643
  groupBy: '',
644
- completedIds,
644
+ progressIds: completedIds,
645
645
  useDefaultFields,
646
646
  customFields,
647
647
  progress
@@ -656,7 +656,7 @@ async function handleCustomFetchAll(brand, type, {
656
656
  sort,
657
657
  includedFields,
658
658
  groupBy: '',
659
- ownedIds,
659
+ progressIds: ownedIds,
660
660
  useDefaultFields,
661
661
  customFields,
662
662
  progress
@@ -109,7 +109,6 @@ describe('contentProgressDataContextLocal', function () {
109
109
 
110
110
  }, 100000);
111
111
 
112
-
113
112
  //
114
113
  // test('progressBubbling', async () => {
115
114
  // let serverVersion = 2;
@@ -0,0 +1,16 @@
1
+ import {initializeTestService} from "../initializeTests";
2
+ import {fetchChallengeIndexMetadata} from "../../src";
3
+
4
+
5
+ describe('railcontentLive', function () {
6
+ beforeEach(async () => {
7
+ await initializeTestService(true);
8
+ }, 1000000);
9
+
10
+ test('challengeIndexMetadata', async () => {
11
+ let contentId = 281709;
12
+ let results = await fetchChallengeIndexMetadata([contentId]);
13
+ expect(Array.isArray(results)).toBe(true);
14
+ });
15
+
16
+ });
@@ -1,4 +1,6 @@
1
1
  import {getFieldsForContentType} from "../src/contentTypeConfig";
2
+ const railContentModule = require('../src/services/railcontent.js')
3
+
2
4
  import {
3
5
  fetchAssignments,
4
6
  fetchCommentModContentData,
@@ -8,6 +10,7 @@ import {
8
10
  import {log} from './log.js';
9
11
  import {initializeTestService} from "./initializeTests";
10
12
  import {dataContext} from "../src/services/contentProgress";
13
+ import {fetchOwnedChallenges} from "../src";
11
14
 
12
15
  const {
13
16
  fetchSongById,
@@ -266,14 +269,21 @@ describe('Sanity Queries', function () {
266
269
  const response = await fetchAll('drumeo', 'challenge', {groupBy:'difficulty_string'});
267
270
  expect(response.entity[0].name).toBeDefined();
268
271
  expect(response.entity[0].lessons).toBeDefined();
269
- expect(response.entity[0].lessons.length).toBeGreaterThan(0)
272
+ expect(response.entity[0].lessons.length).toBeGreaterThan(0);
270
273
  });
271
274
 
272
- test('fetchAllChallengesByDifficulty', async () => {
273
- const response = await fetchAll('drumeo', 'challenge', {groupBy:'difficulty_string'});
274
- expect(response.entity[0].name).toBeDefined();
275
- expect(response.entity[0].lessons).toBeDefined();
276
- expect(response.entity[0].lessons.length).toBeGreaterThan(0)
275
+ test('fetchAllChallengesByCompleted', async () => {
276
+ var mock = jest.spyOn(railContentModule, 'fetchCompletedChallenges');
277
+ mock.mockImplementation(() => [402204]);
278
+ const response = await fetchAll('drumeo', 'challenge', {groupBy:'completed'});
279
+ expect(response.entity.length).toBe(1);
280
+ });
281
+
282
+ test('fetchAllChallengesByOwned', async () => {
283
+ var mock = jest.spyOn(railContentModule, 'fetchOwnedChallenges');
284
+ mock.mockImplementation(() => [402204]);
285
+ const response = await fetchAll('drumeo', 'challenge', {groupBy:'owned'});
286
+ expect(response.entity.length).toBe(1);
277
287
  });
278
288
 
279
289
  test('fetchAll-CustomFields', async () => {