musora-content-services 1.0.120 → 1.0.122

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 (59) hide show
  1. package/.github/workflows/node.js.yml +0 -0
  2. package/CHANGELOG.md +4 -0
  3. package/README.md +0 -0
  4. package/babel.config.js +0 -0
  5. package/docs/config.js.html +7 -3
  6. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  7. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  8. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  9. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  10. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  11. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  12. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  13. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  14. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  15. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +0 -0
  16. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  17. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  18. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  19. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  20. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +0 -0
  21. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  24. package/docs/index.html +1 -1
  25. package/docs/module-Config.html +28 -3
  26. package/docs/module-Railcontent-Services.html +7 -7
  27. package/docs/module-Sanity-Services.html +426 -48
  28. package/docs/railcontent.js.html +37 -47
  29. package/docs/sanity.js.html +69 -12
  30. package/docs/scripts/collapse.js +0 -0
  31. package/docs/scripts/commonNav.js +0 -0
  32. package/docs/scripts/linenumber.js +0 -0
  33. package/docs/scripts/nav.js +0 -0
  34. package/docs/scripts/polyfill.js +0 -0
  35. package/docs/scripts/prettify/Apache-License-2.0.txt +0 -0
  36. package/docs/scripts/prettify/lang-css.js +0 -0
  37. package/docs/scripts/prettify/prettify.js +0 -0
  38. package/docs/scripts/search.js +0 -0
  39. package/docs/styles/jsdoc.css +0 -0
  40. package/docs/styles/prettify.css +0 -0
  41. package/jest.config.js +0 -0
  42. package/jsdoc.json +0 -0
  43. package/package.json +1 -1
  44. package/src/contentMetaData.js +11 -0
  45. package/src/contentTypeConfig.js +6 -2
  46. package/src/index.d.ts +11 -21
  47. package/src/index.js +11 -21
  48. package/src/services/config.js +6 -2
  49. package/src/services/contentLikes.js +38 -0
  50. package/src/services/dataContext.js +88 -0
  51. package/src/services/railcontent.js +36 -46
  52. package/src/services/sanity.js +64 -10
  53. package/test/contentLikes.test.js +86 -0
  54. package/test/localStorageMock.js +0 -0
  55. package/test/log.js +0 -0
  56. package/test/sanityQueryService.test.js +39 -0
  57. package/tools/generate-index.js +0 -0
  58. package/src/services/userContext.js +0 -105
  59. package/test/userContext.test.js +0 -86
@@ -0,0 +1,86 @@
1
+ import {isContentLiked, dataContext, likeContent, unlikeContent} from "../src/services/contentLikes";
2
+ import {LocalStorageMock} from "./localStorageMock";
3
+ import {initializeService} from "../src";
4
+
5
+ const railContentModule = require('../src/services/railcontent.js')
6
+
7
+ describe('commentLikesDataContext', function () {
8
+ let mock = null;
9
+ const testVersion = 1;
10
+
11
+ beforeEach(() => {
12
+ initializeService({localStorage: new LocalStorageMock()});
13
+ mock = jest.spyOn(dataContext, 'fetchData');
14
+ var json = JSON.parse(`{"version":${testVersion},"data":[308516,308515,308514,308518]}`);
15
+ mock.mockImplementation(() => json);
16
+ });
17
+
18
+ test('contentLiked', async () => {
19
+ let result = await isContentLiked(308516);
20
+ expect(result).toBe(true);
21
+ });
22
+
23
+ test('contentNotLiked', async () => {
24
+ let result = await isContentLiked(121111);
25
+ expect(result).toBe(false);
26
+ });
27
+
28
+ test('ensureOnlyOneServerFetchRequest', async () => {
29
+ dataContext.clearCache();
30
+ await isContentLiked(308516);
31
+ await isContentLiked(308514);
32
+ await isContentLiked(121111);
33
+ expect(dataContext.fetchData).toHaveBeenCalledTimes(1);
34
+ });
35
+
36
+ test('ensureDataPulledFromLocalCache', async () => {
37
+ dataContext.clearCache();
38
+ await isContentLiked(308516);
39
+ dataContext.clearContext();
40
+ await isContentLiked(308514);
41
+ expect(dataContext.fetchData).toHaveBeenCalledTimes(1);
42
+ });
43
+
44
+ test('likeContent', async () => {
45
+ mock = jest.spyOn(railContentModule, 'postContentLiked');
46
+ var json = JSON.parse(`{"version":${testVersion + 1}}`);
47
+ mock.mockImplementation(() => json);
48
+
49
+ dataContext.clearCache();
50
+ let isLiked = await isContentLiked(111111);
51
+ expect(isLiked).toBe(false);
52
+
53
+ await likeContent(111111);
54
+ isLiked = await isContentLiked(111111);
55
+ expect(isLiked).toBe(true);
56
+
57
+ dataContext.clearContext();
58
+ isLiked = await isContentLiked(111111);
59
+ expect(isLiked).toBe(true);
60
+
61
+ expect(dataContext.version()).toBe(testVersion + 1);
62
+ });
63
+
64
+
65
+ test('unlikeContent', async () => {
66
+ mock = jest.spyOn(railContentModule, 'postContentUnliked');
67
+ var json = JSON.parse(`{"version":${testVersion + 1}}`);
68
+ mock.mockImplementation(() => json);
69
+
70
+ dataContext.clearCache();
71
+ let isLiked = await isContentLiked(308516);
72
+ expect(isLiked).toBe(true);
73
+
74
+ await unlikeContent(308516);
75
+ console.log(dataContext.context);
76
+ isLiked = await isContentLiked(308516);
77
+ expect(isLiked).toBe(false);
78
+
79
+ dataContext.clearContext();
80
+ isLiked = await isContentLiked(308516);
81
+ expect(isLiked).toBe(false);
82
+
83
+ expect(dataContext.version()).toBe(testVersion + 1);
84
+ });
85
+
86
+ });
File without changes
package/test/log.js CHANGED
File without changes
@@ -354,6 +354,31 @@ describe('Sanity Queries', function () {
354
354
  const response = await fetchCoachLessons('drumeo',411493, {});
355
355
  expect(response.entity.length).toBeGreaterThan(0);
356
356
  });
357
+ test('fetchCoachLessons-WithTypeFilters', async () => {
358
+ const response = await fetchAllFilterOptions('drumeo',['type,course','type,live'], '','','coach-lessons','',[],31880);
359
+ log(response);
360
+ expect(response.meta.filterOptions.difficulty).toBeDefined();
361
+ expect(response.meta.filterOptions.type).toBeDefined();
362
+ expect(response.meta.filterOptions.lifestyle).toBeDefined();
363
+ expect(response.meta.filterOptions.genre).toBeDefined();
364
+ });
365
+
366
+ test('fetchCoachLessons-WithTypeFilters-InvalidContentType', async () => {
367
+ const brand = 'drumeo';
368
+ const coachId = 31880;
369
+ const invalidContentType = 'course'; // Not 'coach-lessons'
370
+
371
+ await expect(fetchAllFilterOptions(brand, ['type,course', 'type,live'], '', '', invalidContentType, '', [], coachId))
372
+ .rejects
373
+ .toThrow("Invalid contentType: 'course' for coachId. It must be 'coach-lessons'.");
374
+ });
375
+
376
+ test('fetchCoachLessons-IncludedFields', async () => {
377
+ const response = await fetchCoachLessons('drumeo',31880, {includedFields: ['genre,Pop/Rock','difficulty,Beginner']});
378
+ log(response);
379
+ expect(response.entity.length).toBeGreaterThan(0);
380
+ });
381
+
357
382
 
358
383
  test('fetchAll-IncludedFields', async () => {
359
384
  let response = await fetchAll('drumeo', 'instructor',{includedFields: ['is_active']});
@@ -443,6 +468,20 @@ describe('Sanity Queries', function () {
443
468
  expect(response.lessons[0].is_bonus_content).toBeDefined();
444
469
  });
445
470
 
471
+ test('fetchShowsData-OddTimes', async () => {
472
+ const response = await fetchShowsData('drumeo');
473
+ log(response);
474
+ expect(response.length).toBeGreaterThan(0);
475
+ const showTypes = response.map((x) => x.type);
476
+ expect(showTypes).toContain('odd-times');
477
+ });
478
+
479
+ test('fetchMetadata-Coach-Lessons', async () => {
480
+ const response = await fetchMetadata('drumeo','coach-lessons');
481
+ log(response);
482
+ expect(response).toBeDefined();
483
+ });
484
+
446
485
  });
447
486
 
448
487
  describe('Filter Builder', function () {
File without changes
@@ -1,105 +0,0 @@
1
- import {fetchUserContext, fetchLikeContent, fetchUnlikeContent} from "./railcontent";
2
-
3
- const StorageKey = "userContext";
4
- let userContext = null;
5
- let cache = null;
6
-
7
- export function init(localCache) {
8
- cache = localCache;
9
- }
10
-
11
- export function version() {
12
- ensureLocalContextLoaded();
13
- return userContext.version;
14
- }
15
-
16
- async function getUserContext() {
17
- ensureLocalContextLoaded();
18
- if (userContext) {
19
- verifyContextIsValid();
20
- }
21
- if (!userContext) {
22
- await fetchFromServer();
23
- }
24
- return userContext;
25
- }
26
-
27
- function verifyContextIsValid() {
28
-
29
- }
30
-
31
- function ensureLocalContextLoaded() {
32
- if (userContext) return;
33
- let localData = cache.getItem(StorageKey);
34
- if (localData) {
35
- userContext = JSON.parse(localData);
36
- }
37
- }
38
-
39
- function updateLocalContext(contentId, updateFunction) {
40
- ensureLocalContextLoaded();
41
- if (userContext) {
42
- let contentData = userContext.data[contentId] ?? [];
43
- updateFunction(contentData);
44
- userContext.data[contentId] = contentData;
45
- userContext.version++;
46
- let data = JSON.stringify(userContext);
47
- cache.setItem(StorageKey, data);
48
- }
49
- }
50
-
51
- async function fetchFromServer() {
52
- let data = await fetchUserContext();
53
- userContext = JSON.parse(data);
54
- cache.setItem(StorageKey, data);
55
- }
56
-
57
-
58
- function transformData(data, contentId) {
59
- let transformed = [];
60
- transformed["contentId"] = contentId;
61
- transformed["liked"] = (data && data.l) ?? 0;
62
- return transformed;
63
- }
64
-
65
- export async function fetchContentData(contentId) {
66
- let userContext = await getUserContext();
67
- let data = userContext.data[contentId];
68
- data = transformData(data, contentId);
69
- return data;
70
- }
71
-
72
- export function clearCache() {
73
- userContext = null;
74
- cache.setItem(StorageKey, null);
75
- }
76
-
77
- export function testClearLocal() {
78
- userContext = null;
79
- }
80
-
81
- export async function likeContent(contentId) {
82
- updateLocalContext(contentId,
83
- function (contentData) {
84
- contentData.l = 1;
85
- }
86
- );
87
-
88
- let result = await fetchLikeContent(contentId);
89
- if (result.version !== userContext.version) {
90
- clearCache();
91
- }
92
- }
93
-
94
- export async function unlikeContent(contentId) {
95
- updateLocalContext(contentId,
96
- function (contentData) {
97
- contentData.l = 0;
98
- }
99
- );
100
-
101
- let result = await fetchUnlikeContent(contentId);
102
- if (result.version !== userContext.version) {
103
- clearCache();
104
- }
105
- }
@@ -1,86 +0,0 @@
1
- const railContentModule = require('../src/services/railcontent.js')
2
- const userContextModule = require('../src/services/userContext.js');
3
- import {LocalStorageMock} from "./localStorageMock";
4
-
5
- describe('userContext', function () {
6
- let mock = null;
7
- const testVersion = 1;
8
- beforeEach(() => {
9
- userContextModule.init(new LocalStorageMock());
10
- mock = jest.spyOn(railContentModule, 'fetchUserContext');
11
- var json = `{"version":${testVersion},"data":{"308516":{"l":1},"308515":{"p":100},"308514":{"p":13},"308518":{"p":100}}}`;
12
- mock.mockImplementation(() => json);
13
- });
14
-
15
- test('contentLiked', async () => {
16
- let contentData = await userContextModule.fetchContentData(308516);
17
- expect(contentData.liked).toBe(1);
18
- });
19
-
20
- test('contentDoesNotExist', async () => {
21
- //fetch content that does not exist
22
- let contentData = await userContextModule.fetchContentData(121111);
23
- expect(contentData.liked).toBe(0);
24
- });
25
-
26
- test('ensureOnlyOneServerFetchRequest', async () => {
27
- userContextModule.clearCache();
28
- await userContextModule.fetchContentData(308516);
29
- await userContextModule.fetchContentData(308514);
30
- expect(railContentModule.fetchUserContext).toHaveBeenCalledTimes(1);
31
- });
32
-
33
- test('ensureDataPulledFromLocalCache', async () => {
34
- userContextModule.clearCache();
35
- await userContextModule.fetchContentData(308516);
36
- userContextModule.testClearLocal();
37
- await userContextModule.fetchContentData(308514);
38
- expect(railContentModule.fetchUserContext).toHaveBeenCalledTimes(1);
39
- });
40
-
41
- // test('hashExpiration', async () => {
42
- // userContextModule.clearCache();
43
- // await userContextModule.fetchContentData(testHash308516);
44
- // let newHash = "8g9qg5wn3e5s5oi69q6g22et9w6g34t5";
45
- // await userContextModule.fetchContentData(newHash, 308516);
46
- // expect(railContentModule.fetchUserContext).toHaveBeenCalledTimes(2);
47
- // });
48
-
49
- test('likeContent', async () => {
50
- mock = jest.spyOn(railContentModule, 'fetchLikeContent');
51
- var json = JSON.parse(`{"version":${testVersion + 1}}`);
52
- mock.mockImplementation(() => json);
53
-
54
- userContextModule.clearCache();
55
- await userContextModule.fetchContentData(308515);
56
- await userContextModule.likeContent(308515);
57
- let contentData = await userContextModule.fetchContentData(308515);
58
- expect(contentData.liked).toBe(1);
59
-
60
- userContextModule.testClearLocal();
61
- contentData = await userContextModule.fetchContentData(308515);
62
- expect(contentData.liked).toBe(1);
63
-
64
- expect(userContextModule.version()).toBe(testVersion + 1);
65
- });
66
-
67
-
68
- test('unlikeContent', async () => {
69
- mock = jest.spyOn(railContentModule, 'fetchUnlikeContent');
70
- var json = JSON.parse(`{"version":${testVersion + 1}}`);
71
- mock.mockImplementation(() => json);
72
-
73
- userContextModule.clearCache();
74
- await userContextModule.fetchContentData(308516);
75
- await userContextModule.unlikeContent(308516);
76
- let contentData = await userContextModule.fetchContentData(308516);
77
- expect(contentData.liked).toBe(0);
78
-
79
- userContextModule.testClearLocal();
80
- contentData = await userContextModule.fetchContentData(308516);
81
- expect(contentData.liked).toBe(0);
82
-
83
- expect(userContextModule.version()).toBe(testVersion + 1);
84
- });
85
-
86
- });