musora-content-services 1.0.147 → 1.0.150
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 +6 -0
- package/docs/config.js.html +2 -2
- package/docs/index.html +2 -2
- package/docs/module-Config.html +2 -2
- package/docs/module-Railcontent-Services.html +2593 -221
- package/docs/module-Sanity-Services.html +30 -30
- package/docs/railcontent.js.html +308 -5
- package/docs/sanity.js.html +7 -3
- package/link_mcs.sh +0 -0
- package/package.json +1 -1
- package/src/contentTypeConfig.js +3 -0
- package/src/index.d.ts +61 -4
- package/src/index.js +61 -4
- package/src/services/contentLikes.js +11 -11
- package/src/services/contentProgress.js +153 -0
- package/src/services/dataContext.js +3 -2
- package/src/services/railcontent.js +363 -6
- package/src/services/sanity.js +74 -0
- package/test/contentLikes.test.js +1 -1
- package/test/contentProgress.test.js +56 -0
- package/test/sanityQueryService.test.js +84 -49
|
@@ -2,6 +2,7 @@ import {initializeService} from '../src/services/config.js';
|
|
|
2
2
|
import {getFieldsForContentType} from "../src/contentTypeConfig";
|
|
3
3
|
import {fetchSanity} from "../src/services/sanity";
|
|
4
4
|
import {log} from './log.js';
|
|
5
|
+
import {LocalStorageMock} from "./localStorageMock";
|
|
5
6
|
|
|
6
7
|
const {
|
|
7
8
|
fetchSongById,
|
|
@@ -36,7 +37,9 @@ const {
|
|
|
36
37
|
getSortOrder,
|
|
37
38
|
fetchShowsData,
|
|
38
39
|
fetchMetadata,
|
|
39
|
-
fetchNextPreviousLesson
|
|
40
|
+
fetchNextPreviousLesson,
|
|
41
|
+
fetchHierarchy,
|
|
42
|
+
fetchTopLevelParentId
|
|
40
43
|
} = require('../src/services/sanity.js');
|
|
41
44
|
|
|
42
45
|
const {
|
|
@@ -47,20 +50,25 @@ const {
|
|
|
47
50
|
processMetadata,
|
|
48
51
|
} = require('../src/contentMetaData.js');
|
|
49
52
|
|
|
53
|
+
export function initializeTestService(){
|
|
54
|
+
const config = {
|
|
55
|
+
sanityConfig: {
|
|
56
|
+
token: process.env.SANITY_API_TOKEN,
|
|
57
|
+
projectId: process.env.SANITY_PROJECT_ID,
|
|
58
|
+
dataset: process.env.SANITY_DATASET,
|
|
59
|
+
useCachedAPI: process.env.SANITY_USE_CACHED_API === 'true' || true,
|
|
60
|
+
version: '2021-06-07',
|
|
61
|
+
debug: process.env.DEBUG === 'true' || false,
|
|
62
|
+
useDummyRailContentMethods: true,
|
|
63
|
+
},
|
|
64
|
+
localStorage: new LocalStorageMock()
|
|
65
|
+
};
|
|
66
|
+
initializeService(config);
|
|
67
|
+
}
|
|
68
|
+
|
|
50
69
|
describe('Sanity Queries', function () {
|
|
51
70
|
beforeEach(() => {
|
|
52
|
-
|
|
53
|
-
sanityConfig: {
|
|
54
|
-
token: process.env.SANITY_API_TOKEN,
|
|
55
|
-
projectId: process.env.SANITY_PROJECT_ID,
|
|
56
|
-
dataset: process.env.SANITY_DATASET,
|
|
57
|
-
useCachedAPI: process.env.SANITY_USE_CACHED_API === 'true' || true,
|
|
58
|
-
version: '2021-06-07',
|
|
59
|
-
debug: process.env.DEBUG === 'true' || false,
|
|
60
|
-
useDummyRailContentMethods: true,
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
initializeService(config);
|
|
71
|
+
initializeTestService();
|
|
64
72
|
});
|
|
65
73
|
|
|
66
74
|
test('fetchSongById', async () => {
|
|
@@ -175,7 +183,7 @@ describe('Sanity Queries', function () {
|
|
|
175
183
|
});
|
|
176
184
|
|
|
177
185
|
test('fetchAllSongsGroupByArtist', async () => {
|
|
178
|
-
const response = await fetchAllSongs('drumeo', {groupBy:"artist"});
|
|
186
|
+
const response = await fetchAllSongs('drumeo', {groupBy: "artist"});
|
|
179
187
|
expect(response.entity[0].lessons[0].soundslice).toBeDefined();
|
|
180
188
|
expect(response.entity[0].lessons[0].artist_name).toBeDefined();
|
|
181
189
|
expect(response.entity[0].lessons[0].instrumentless).toBeDefined();
|
|
@@ -189,20 +197,20 @@ describe('Sanity Queries', function () {
|
|
|
189
197
|
});
|
|
190
198
|
|
|
191
199
|
test('fetchAllWorkouts', async () => {
|
|
192
|
-
const response = await fetchAll('drumeo', 'workout',{});
|
|
200
|
+
const response = await fetchAll('drumeo', 'workout', {});
|
|
193
201
|
log(response);
|
|
194
202
|
expect(response.entity[0].id).toBeDefined();
|
|
195
203
|
});
|
|
196
204
|
|
|
197
205
|
test('fetchAllInstructorField', async () => {
|
|
198
|
-
const response = await fetchAll('drumeo', 'quick-tips',{searchTerm: 'Domino Santantonio'});
|
|
206
|
+
const response = await fetchAll('drumeo', 'quick-tips', {searchTerm: 'Domino Santantonio'});
|
|
199
207
|
log(response);
|
|
200
208
|
expect(response.entity[0].id).toBeDefined();
|
|
201
209
|
expect(response.entity[0].instructors).toBeTruthy();
|
|
202
210
|
});
|
|
203
211
|
|
|
204
212
|
test('fetchAllSortField', async () => {
|
|
205
|
-
const response = await fetchAll('drumeo', 'rhythmic-adventures-of-captain-carson',{});
|
|
213
|
+
const response = await fetchAll('drumeo', 'rhythmic-adventures-of-captain-carson', {});
|
|
206
214
|
log(response);
|
|
207
215
|
expect(response.entity[0].id).toBeDefined();
|
|
208
216
|
expect(response.entity[0].sort).toBeDefined();
|
|
@@ -210,7 +218,7 @@ describe('Sanity Queries', function () {
|
|
|
210
218
|
|
|
211
219
|
|
|
212
220
|
test('fetchAllChallenges', async () => {
|
|
213
|
-
const response = await fetchAll('drumeo', 'challenge',{});
|
|
221
|
+
const response = await fetchAll('drumeo', 'challenge', {});
|
|
214
222
|
log(response);
|
|
215
223
|
expect(response.entity[0].registration_url).toBeDefined();
|
|
216
224
|
expect(response.entity[0].enrollment_start_time).toBeDefined();
|
|
@@ -224,12 +232,12 @@ describe('Sanity Queries', function () {
|
|
|
224
232
|
});
|
|
225
233
|
|
|
226
234
|
test('fetchAll-CustomFields', async () => {
|
|
227
|
-
let response = await fetchAll('drumeo', 'challenge',{customFields:['garbage']});
|
|
235
|
+
let response = await fetchAll('drumeo', 'challenge', {customFields: ['garbage']});
|
|
228
236
|
log(response);
|
|
229
237
|
expect(response.entity[0].garbage).toBeDefined();
|
|
230
238
|
expect(response.entity[0].id).toBeDefined();
|
|
231
239
|
|
|
232
|
-
response = await fetchAll('drumeo', 'challenge',{useDefaultFields: false, customFields:['garbage']});
|
|
240
|
+
response = await fetchAll('drumeo', 'challenge', {useDefaultFields: false, customFields: ['garbage']});
|
|
233
241
|
log(response);
|
|
234
242
|
expect(response.entity[0].garbage).toBeDefined();
|
|
235
243
|
expect.not.objectContaining(response.entity[0].id);
|
|
@@ -296,10 +304,10 @@ describe('Sanity Queries', function () {
|
|
|
296
304
|
const response = await fetchChildren(id);
|
|
297
305
|
log('num children', response.length);
|
|
298
306
|
log(response);
|
|
299
|
-
|
|
307
|
+
|
|
300
308
|
expect(response.length > 0).toBeTruthy();
|
|
301
309
|
const foundExpectedChild = response.some((child) => {
|
|
302
|
-
return child['id'] = expectedChildID;
|
|
310
|
+
return child['id'] = expectedChildID;
|
|
303
311
|
});
|
|
304
312
|
expect(foundExpectedChild).toBeTruthy();
|
|
305
313
|
});
|
|
@@ -312,7 +320,7 @@ describe('Sanity Queries', function () {
|
|
|
312
320
|
expect(response['id']).toBe(expectedParent);
|
|
313
321
|
});
|
|
314
322
|
|
|
315
|
-
test('getSortOrder',
|
|
323
|
+
test('getSortOrder', () => {
|
|
316
324
|
let sort = getSortOrder()
|
|
317
325
|
expect(sort).toBe('published_on desc');
|
|
318
326
|
sort = getSortOrder('slug')
|
|
@@ -326,7 +334,8 @@ describe('Sanity Queries', function () {
|
|
|
326
334
|
});
|
|
327
335
|
|
|
328
336
|
test('fetchMethod', async () => {
|
|
329
|
-
const response = await fetchMethod('drumeo', 'drumeo-method');
|
|
337
|
+
const response = await fetchMethod('drumeo', 'drumeo-method');
|
|
338
|
+
log(response);
|
|
330
339
|
expect(response).toBeDefined();
|
|
331
340
|
expect(response.levels.length).toBeGreaterThan(0);
|
|
332
341
|
});
|
|
@@ -366,7 +375,8 @@ describe('Sanity Queries', function () {
|
|
|
366
375
|
});
|
|
367
376
|
|
|
368
377
|
test('fetchFoundation', async () => {
|
|
369
|
-
const response = await fetchFoundation('foundations-2019');
|
|
378
|
+
const response = await fetchFoundation('foundations-2019');
|
|
379
|
+
log(response);
|
|
370
380
|
expect(response.units.length).toBeGreaterThan(0);
|
|
371
381
|
expect(response.type).toBe('foundation');
|
|
372
382
|
});
|
|
@@ -390,7 +400,7 @@ describe('Sanity Queries', function () {
|
|
|
390
400
|
});
|
|
391
401
|
|
|
392
402
|
test('fetchCoachLessons', async () => {
|
|
393
|
-
const response = await fetchCoachLessons('drumeo',411493, {});
|
|
403
|
+
const response = await fetchCoachLessons('drumeo', 411493, {});
|
|
394
404
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
395
405
|
});
|
|
396
406
|
test('fetchCoachLessons-WithTypeFilters', async () => {
|
|
@@ -420,43 +430,43 @@ describe('Sanity Queries', function () {
|
|
|
420
430
|
|
|
421
431
|
|
|
422
432
|
test('fetchAll-IncludedFields', async () => {
|
|
423
|
-
let response = await fetchAll('drumeo', 'instructor',{includedFields: ['is_active']});
|
|
433
|
+
let response = await fetchAll('drumeo', 'instructor', {includedFields: ['is_active']});
|
|
424
434
|
console.log(response);
|
|
425
435
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
426
436
|
});
|
|
427
437
|
|
|
428
438
|
test('fetchAll-IncludedFields-multiple', async () => {
|
|
429
|
-
let response = await fetchAll('drumeo', 'course',{includedFields: ['essential,Dynamics','essential,Timing','difficulty,Beginner']});
|
|
439
|
+
let response = await fetchAll('drumeo', 'course', {includedFields: ['essential,Dynamics', 'essential,Timing', 'difficulty,Beginner']});
|
|
430
440
|
log(response);
|
|
431
441
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
432
442
|
});
|
|
433
443
|
|
|
434
444
|
test('fetchAll-IncludedFields-playalong-multiple', async () => {
|
|
435
|
-
let response = await fetchAll('drumeo', 'play-along',{includedFields: ['bpm,91-120','bpm,181+','genre,Blues']});
|
|
445
|
+
let response = await fetchAll('drumeo', 'play-along', {includedFields: ['bpm,91-120', 'bpm,181+', 'genre,Blues']});
|
|
436
446
|
log(response);
|
|
437
447
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
438
448
|
});
|
|
439
449
|
|
|
440
450
|
test('fetchAll-IncludedFields-rudiment-multiple-gear', async () => {
|
|
441
|
-
let response = await fetchAll('drumeo', 'rudiment',{includedFields: ['gear,Drum-Set','gear,Practice Pad']});
|
|
451
|
+
let response = await fetchAll('drumeo', 'rudiment', {includedFields: ['gear,Drum-Set', 'gear,Practice Pad']});
|
|
442
452
|
log(response);
|
|
443
453
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
444
454
|
});
|
|
445
455
|
|
|
446
456
|
test('fetchAll-IncludedFields-coaches-multiple-focus', async () => {
|
|
447
|
-
let response = await fetchAll('drumeo', 'instructor',{includedFields: ['focus,drumline','focus,recording']});
|
|
457
|
+
let response = await fetchAll('drumeo', 'instructor', {includedFields: ['focus,drumline', 'focus,recording']});
|
|
448
458
|
log(response);
|
|
449
459
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
450
460
|
});
|
|
451
461
|
|
|
452
462
|
test('fetchAll-IncludedFields-songs-multiple-instrumentless', async () => {
|
|
453
|
-
let response = await fetchAll('drumeo', 'song',{includedFields: ['instrumentless,true','instrumentless,false']});
|
|
463
|
+
let response = await fetchAll('drumeo', 'song', {includedFields: ['instrumentless,true', 'instrumentless,false']});
|
|
454
464
|
log(response);
|
|
455
465
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
456
466
|
});
|
|
457
467
|
|
|
458
468
|
test('fetchByReference', async () => {
|
|
459
|
-
const response = await fetchByReference('drumeo', {
|
|
469
|
+
const response = await fetchByReference('drumeo', {includedFields: ['is_featured']});
|
|
460
470
|
expect(response.entity.length).toBeGreaterThan(0);
|
|
461
471
|
});
|
|
462
472
|
|
|
@@ -466,19 +476,19 @@ describe('Sanity Queries', function () {
|
|
|
466
476
|
});
|
|
467
477
|
|
|
468
478
|
test('fetchAll-GroupBy-Genre', async () => {
|
|
469
|
-
let response = await fetchAll('drumeo', 'solo',{groupBy: 'genre'});
|
|
479
|
+
let response = await fetchAll('drumeo', 'solo', {groupBy: 'genre'});
|
|
470
480
|
log(response);
|
|
471
481
|
expect(response.entity[0].web_url_path).toContain('/drumeo/genres/');
|
|
472
482
|
});
|
|
473
483
|
|
|
474
484
|
test('fetchAll-GroupBy-Artists', async () => {
|
|
475
|
-
let response = await fetchAll('drumeo', 'song',{groupBy: 'artist'});
|
|
485
|
+
let response = await fetchAll('drumeo', 'song', {groupBy: 'artist'});
|
|
476
486
|
log(response);
|
|
477
487
|
expect(response.entity[0].web_url_path).toContain('/drumeo/artists/');
|
|
478
488
|
});
|
|
479
489
|
|
|
480
490
|
test('fetchAll-GroupBy-Instructors', async () => {
|
|
481
|
-
let response = await fetchAll('drumeo', 'course',{groupBy: 'instructor'});
|
|
491
|
+
let response = await fetchAll('drumeo', 'course', {groupBy: 'instructor'});
|
|
482
492
|
log(response);
|
|
483
493
|
expect(response.entity[0].web_url_path).toContain('/drumeo/coaches/');
|
|
484
494
|
});
|
|
@@ -492,7 +502,7 @@ describe('Sanity Queries', function () {
|
|
|
492
502
|
});
|
|
493
503
|
|
|
494
504
|
test('fetchMetadata', async () => {
|
|
495
|
-
const response = await fetchMetadata('drumeo','song');
|
|
505
|
+
const response = await fetchMetadata('drumeo', 'song');
|
|
496
506
|
log(response);
|
|
497
507
|
expect(response.tabs.length).toBeGreaterThan(0);
|
|
498
508
|
});
|
|
@@ -557,6 +567,28 @@ describe('Sanity Queries', function () {
|
|
|
557
567
|
expect(documentPublishedOn.getTime()).toBeLessThan(nextDocumentPublishedOn.getTime());
|
|
558
568
|
});
|
|
559
569
|
|
|
570
|
+
test('fetchTopLevelParentId', async () => {
|
|
571
|
+
let contentId = await fetchTopLevelParentId(241250);
|
|
572
|
+
expect(contentId).toBe(241247);
|
|
573
|
+
contentId = await fetchTopLevelParentId(241249);
|
|
574
|
+
expect(contentId).toBe(241247);
|
|
575
|
+
contentId = await fetchTopLevelParentId(241248);
|
|
576
|
+
expect(contentId).toBe(241247);
|
|
577
|
+
contentId = await fetchTopLevelParentId(241247);
|
|
578
|
+
expect(contentId).toBe(241247);
|
|
579
|
+
contentId = await fetchTopLevelParentId(0);
|
|
580
|
+
expect(contentId).toBe(null);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
test('fetchHierarchy', async () => {
|
|
584
|
+
let hierarchy = await fetchHierarchy(241250);
|
|
585
|
+
expect(hierarchy.parents[241250]).toBe(241249);
|
|
586
|
+
expect(hierarchy.parents[241249]).toBe(241248);
|
|
587
|
+
expect(hierarchy.parents[241248]).toBe(241247);
|
|
588
|
+
expect(hierarchy.children[241250]).toStrictEqual([]);
|
|
589
|
+
expect(hierarchy.children[243085]).toStrictEqual([ 243170, 243171, 243172, 243174, 243176 ]);
|
|
590
|
+
});
|
|
591
|
+
|
|
560
592
|
});
|
|
561
593
|
|
|
562
594
|
describe('Filter Builder', function () {
|
|
@@ -578,7 +610,7 @@ describe('Filter Builder', function () {
|
|
|
578
610
|
|
|
579
611
|
test('withOnlyFilterAvailableStatuses', async () => {
|
|
580
612
|
const filter = 'railcontent_id = 111'
|
|
581
|
-
const builder =
|
|
613
|
+
const builder = FilterBuilder.withOnlyFilterAvailableStatuses(filter, ['published', 'unlisted']);
|
|
582
614
|
const finalFilter = builder.buildFilter();
|
|
583
615
|
const clauses = spliceFilterForAnds(finalFilter);
|
|
584
616
|
expect(clauses[0].phrase).toBe(filter);
|
|
@@ -591,9 +623,10 @@ describe('Filter Builder', function () {
|
|
|
591
623
|
|
|
592
624
|
test('withContentStatusAndFutureScheduledContent', async () => {
|
|
593
625
|
const filter = 'railcontent_id = 111'
|
|
594
|
-
const builder =
|
|
626
|
+
const builder = new FilterBuilder(filter, {
|
|
595
627
|
availableContentStatuses: ['published', 'unlisted', 'scheduled'],
|
|
596
|
-
getFutureScheduledContentsOnly: true
|
|
628
|
+
getFutureScheduledContentsOnly: true
|
|
629
|
+
});
|
|
597
630
|
const finalFilter = builder.buildFilter();
|
|
598
631
|
const clauses = spliceFilterForAnds(finalFilter);
|
|
599
632
|
expect(clauses[0].phrase).toBe(filter);
|
|
@@ -610,10 +643,12 @@ describe('Filter Builder', function () {
|
|
|
610
643
|
test('withUserPermissions', async () => {
|
|
611
644
|
const filter = 'railcontent_id = 111'
|
|
612
645
|
const builder = new FilterBuilder(filter,
|
|
613
|
-
{
|
|
646
|
+
{
|
|
647
|
+
user: {
|
|
614
648
|
user: {},
|
|
615
649
|
permissions: [91, 92],
|
|
616
|
-
}
|
|
650
|
+
}
|
|
651
|
+
});
|
|
617
652
|
const finalFilter = builder.buildFilter();
|
|
618
653
|
const expected = "references(*[_type == 'permission' && railcontent_id in [91,92]]._id)"
|
|
619
654
|
const isMatch = finalFilter.includes(expected);
|
|
@@ -637,7 +672,7 @@ describe('Filter Builder', function () {
|
|
|
637
672
|
const builder = new FilterBuilder(filter,
|
|
638
673
|
{
|
|
639
674
|
user: getPlusUser(),
|
|
640
|
-
bypassPermissions:true
|
|
675
|
+
bypassPermissions: true
|
|
641
676
|
});
|
|
642
677
|
const finalFilter = builder.buildFilter();
|
|
643
678
|
const expected = "references(*[_type == 'permission' && railcontent_id in [91,92]]._id)"
|
|
@@ -653,7 +688,7 @@ describe('Filter Builder', function () {
|
|
|
653
688
|
// testing dates is a pain more frustration than I'm willing to deal with, so I'm just testing operators.
|
|
654
689
|
|
|
655
690
|
const filter = 'railcontent_id = 111'
|
|
656
|
-
let builder =
|
|
691
|
+
let builder = new FilterBuilder(filter, {
|
|
657
692
|
user: {},
|
|
658
693
|
pullFutureContent: true,
|
|
659
694
|
});
|
|
@@ -672,7 +707,7 @@ describe('Filter Builder', function () {
|
|
|
672
707
|
{
|
|
673
708
|
user: {},
|
|
674
709
|
getFutureContentOnly: true,
|
|
675
|
-
|
|
710
|
+
});
|
|
676
711
|
finalFilter = builder.buildFilter();
|
|
677
712
|
clauses = spliceFilterForAnds(finalFilter);
|
|
678
713
|
expect(clauses[0].phrase).toBe(filter);
|
|
@@ -682,16 +717,16 @@ describe('Filter Builder', function () {
|
|
|
682
717
|
|
|
683
718
|
function getPlusUser() {
|
|
684
719
|
return {
|
|
685
|
-
permissions: [91,92],
|
|
720
|
+
permissions: [91, 92],
|
|
686
721
|
}
|
|
687
722
|
}
|
|
688
723
|
|
|
689
724
|
function spliceFilterForAnds(filter) {
|
|
690
725
|
// this will not correctly split complex filters with && and || conditions.
|
|
691
726
|
let phrases = filter.split(' && ');
|
|
692
|
-
let clauses= [];
|
|
727
|
+
let clauses = [];
|
|
693
728
|
phrases.forEach((phrase) => {
|
|
694
|
-
let
|
|
729
|
+
let field = phrase.substring(0, phrase.indexOf(' '));
|
|
695
730
|
//if(field.charAt(0) === '(' ) field = field.substring(1);
|
|
696
731
|
const temp = phrase.substring(phrase.indexOf(' ') + 1);
|
|
697
732
|
const operator = temp.substring(0, temp.indexOf(' '));
|
|
@@ -736,7 +771,7 @@ describe('Filter Builder', function () {
|
|
|
736
771
|
});
|
|
737
772
|
|
|
738
773
|
test('fetchAllFilterOptions-filter-selected', async () => {
|
|
739
|
-
let response = await fetchAllFilterOptions('drumeo', ['theory,notation','theory,time signatures','creativity,Grooves','creativity,Fills & Chops','difficulty,Beginner','difficulty,Intermediate','difficulty,Expert'], '', '', 'course', '');
|
|
774
|
+
let response = await fetchAllFilterOptions('drumeo', ['theory,notation', 'theory,time signatures', 'creativity,Grooves', 'creativity,Fills & Chops', 'difficulty,Beginner', 'difficulty,Intermediate', 'difficulty,Expert'], '', '', 'course', '');
|
|
740
775
|
log(response);
|
|
741
776
|
expect(response.meta.filterOptions).toBeDefined();
|
|
742
777
|
});
|