musora-content-services 1.2.4 → 1.3.1
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/.prettierignore +5 -0
- package/.prettierrc +8 -0
- package/CHANGELOG.md +11 -0
- package/babel.config.cjs +1 -1
- package/jest.config.js +9 -10
- package/jsdoc.json +17 -12
- package/package.json +2 -1
- package/src/contentMetaData.js +1190 -1131
- package/src/contentTypeConfig.js +492 -387
- package/src/filterBuilder.js +163 -145
- package/src/index.d.ts +227 -237
- package/src/index.js +226 -236
- package/src/services/config.js +12 -12
- package/src/services/contentLikes.js +33 -32
- package/src/services/contentProgress.js +233 -200
- package/src/services/dataContext.js +99 -93
- package/src/services/lastUpdated.js +7 -7
- package/src/services/railcontent.js +368 -364
- package/src/services/sanity.js +975 -955
- package/src/services/userPermissions.js +12 -14
- package/test/contentLikes.test.js +89 -86
- package/test/contentProgress.test.js +229 -236
- package/test/initializeTests.js +54 -51
- package/test/lastUpdated.test.js +20 -18
- package/test/live/contentProgressLive.test.js +135 -137
- package/test/live/railcontentLive.test.js +12 -14
- package/test/localStorageMock.js +16 -16
- package/test/log.js +5 -5
- package/test/sanityQueryService.test.js +857 -821
- package/test/userPermissions.test.js +15 -15
- package/tools/generate-index.cjs +108 -111
- package/.yarnrc.yml +0 -1
|
@@ -1,834 +1,870 @@
|
|
|
1
|
-
import {getFieldsForContentType} from
|
|
1
|
+
import { getFieldsForContentType } from '../src/contentTypeConfig'
|
|
2
2
|
const railContentModule = require('../src/services/railcontent.js')
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from
|
|
9
|
-
import {log} from './log.js'
|
|
10
|
-
import {initializeTestService} from
|
|
11
|
-
import {dataContext} from
|
|
12
|
-
import {fetchOwnedChallenges} from
|
|
5
|
+
fetchCommentModContentData,
|
|
6
|
+
fetchMethodPreviousNextLesson,
|
|
7
|
+
fetchSanity,
|
|
8
|
+
} from '../src/services/sanity'
|
|
9
|
+
import { log } from './log.js'
|
|
10
|
+
import { initializeTestService } from './initializeTests'
|
|
11
|
+
import { dataContext } from '../src/services/contentProgress'
|
|
12
|
+
import { fetchOwnedChallenges } from '../src'
|
|
13
13
|
|
|
14
14
|
const {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} = require('../src/services/sanity.js')
|
|
43
|
-
|
|
44
|
-
const {
|
|
45
|
-
|
|
46
|
-
} = require('../src/
|
|
47
|
-
|
|
48
|
-
const {
|
|
49
|
-
processMetadata,
|
|
50
|
-
} = require('../src/contentMetaData.js');
|
|
15
|
+
fetchSongById,
|
|
16
|
+
fetchArtists,
|
|
17
|
+
fetchSongArtistCount,
|
|
18
|
+
fetchRelatedSongs,
|
|
19
|
+
fetchNewReleases,
|
|
20
|
+
fetchUpcomingEvents,
|
|
21
|
+
fetchByRailContentId,
|
|
22
|
+
fetchByRailContentIds,
|
|
23
|
+
fetchAll,
|
|
24
|
+
fetchAllOld,
|
|
25
|
+
fetchAllFilterOptions,
|
|
26
|
+
fetchFoundation,
|
|
27
|
+
fetchMethod,
|
|
28
|
+
fetchRelatedLessons,
|
|
29
|
+
fetchAllPacks,
|
|
30
|
+
fetchPackAll,
|
|
31
|
+
fetchLessonContent,
|
|
32
|
+
fetchLiveEvent,
|
|
33
|
+
fetchCoachLessons,
|
|
34
|
+
fetchByReference,
|
|
35
|
+
fetchScheduledReleases,
|
|
36
|
+
getSortOrder,
|
|
37
|
+
fetchShowsData,
|
|
38
|
+
fetchMetadata,
|
|
39
|
+
fetchNextPreviousLesson,
|
|
40
|
+
fetchHierarchy,
|
|
41
|
+
fetchTopLevelParentId,
|
|
42
|
+
} = require('../src/services/sanity.js')
|
|
43
|
+
|
|
44
|
+
const { FilterBuilder } = require('../src/filterBuilder.js')
|
|
45
|
+
|
|
46
|
+
const { processMetadata } = require('../src/contentMetaData.js')
|
|
51
47
|
|
|
52
48
|
describe('Sanity Queries', function () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
test('fetchSanity-WithPostProcess', async () => {
|
|
79
|
-
const id = 380094;
|
|
80
|
-
const query = `*[railcontent_id == ${id}]{
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
initializeTestService()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('fetchSongById', async () => {
|
|
54
|
+
const id = 380094
|
|
55
|
+
const response = await fetchSongById(id)
|
|
56
|
+
expect(response.id).toBe(id)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('fetchArtists', async () => {
|
|
60
|
+
const response = await fetchArtists('drumeo')
|
|
61
|
+
const artistNames = response.map((x) => x.name)
|
|
62
|
+
expect(artistNames).toContain('Audioslave')
|
|
63
|
+
}, 10000)
|
|
64
|
+
|
|
65
|
+
test('fetchSongArtistCount', async () => {
|
|
66
|
+
const response = await fetchSongArtistCount('drumeo')
|
|
67
|
+
log(response)
|
|
68
|
+
expect(response).toBeGreaterThan(1000)
|
|
69
|
+
}, 10000)
|
|
70
|
+
|
|
71
|
+
test('fetchSanity-WithPostProcess', async () => {
|
|
72
|
+
const id = 380094
|
|
73
|
+
const query = `*[railcontent_id == ${id}]{
|
|
81
74
|
${getFieldsForContentType('song')}
|
|
82
75
|
}`
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
};
|
|
90
|
-
const response = await fetchSanity(query, false, {customPostProcess: postProcess});
|
|
91
|
-
log(response);
|
|
92
|
-
expect(response.id).toBe(id);
|
|
93
|
-
expect(response.new_field).toBe(newField);
|
|
94
|
-
expect(response.slug).toBe(newSlug);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
test('fetchSanityPostProcess', async () => {
|
|
99
|
-
const id = 380094;
|
|
100
|
-
const response = await fetchByRailContentId(id, "song");
|
|
101
|
-
expect(response.id).toBe(id);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('fetchByRailContentIds', async () => {
|
|
105
|
-
const id = 380094;
|
|
106
|
-
const id2 = 402204;
|
|
107
|
-
const response = await fetchByRailContentIds([id, id2]);
|
|
108
|
-
const returnedIds = response.map((x) => x.id);
|
|
109
|
-
expect(returnedIds[0]).toBe(id);
|
|
110
|
-
expect(returnedIds[1]).toBe(id2);
|
|
111
|
-
expect(returnedIds.length).toBe(2);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('fetchByRailContentIds_Order', async () => {
|
|
115
|
-
const id = 380094;
|
|
116
|
-
const id2 = 402204;
|
|
117
|
-
const response = await fetchByRailContentIds([id2, id]);
|
|
118
|
-
const returnedIds = response.map((x) => x.id);
|
|
119
|
-
expect(returnedIds[0]).toBe(id2);
|
|
120
|
-
expect(returnedIds[1]).toBe(id);
|
|
121
|
-
expect(returnedIds.length).toBe(2);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('fetchUpcomingEvents', async () => {
|
|
125
|
-
const response = await fetchUpcomingEvents('drumeo', {});
|
|
126
|
-
expect(response.length).toBeGreaterThan(0);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('fetchUpcomingNewReleases', async () => {
|
|
130
|
-
const response = await fetchNewReleases('drumeo');
|
|
131
|
-
expect(response.length).toBeGreaterThan(0);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
test('fetchLessonContent', async () => {
|
|
136
|
-
const id = 380094;
|
|
137
|
-
const response = await fetchLessonContent(id);
|
|
138
|
-
expect(response.id).toBe(id);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('fetchAllSongsInProgress', async () => {
|
|
142
|
-
var mock = jest.spyOn(dataContext, 'fetchData');
|
|
143
|
-
var json = JSON.parse(`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"412941":{"s":"started","p":6,"t":20,"u":1731108082}}}`);
|
|
144
|
-
mock.mockImplementation(() =>
|
|
145
|
-
json);
|
|
146
|
-
const response = await fetchAll('drumeo', 'song',{progress:"in progress"});
|
|
147
|
-
expect(response.entity[0].id).toBe(412941);
|
|
148
|
-
expect(response.entity.length).toBe(1);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
// test('fetchAllSongsCompleted', async () => {
|
|
152
|
-
// var mock = jest.spyOn(dataContext, 'fetchData');
|
|
153
|
-
// var json = JSON.parse(`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"232979":{"s":"completed","p":100,"t":20,"u":1731108082}}}`);
|
|
154
|
-
// mock.mockImplementation(() =>
|
|
155
|
-
// json);
|
|
156
|
-
// const response = await fetchAll('drumeo', 'song', {progress:"completed"});
|
|
157
|
-
// expect(response.entity[0].id).toBe(232979);
|
|
158
|
-
// expect(response.entity.length).toBe(1);
|
|
159
|
-
// });
|
|
160
|
-
//
|
|
161
|
-
// test('fetchAllSongsNotStarted', async () => {
|
|
162
|
-
// var mock = jest.spyOn(dataContext, 'fetchData');
|
|
163
|
-
// var json = JSON.parse(`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"198122":{"s":"started","p":100,"t":20,"u":1731108082},"231622":{"s":"completed","p":100,"t":20,"u":1731108082}}}`);
|
|
164
|
-
// mock.mockImplementation(() =>
|
|
165
|
-
// json); const response = await fetchAll('drumeo', 'song', {progress:"not started"});
|
|
166
|
-
// expect(response.entity[0].id).not.toBe(198122);
|
|
167
|
-
// expect(response.entity[0].id).not.toBe(231622);
|
|
168
|
-
// });
|
|
169
|
-
|
|
170
|
-
test('fetchNewReleases', async () => {
|
|
171
|
-
const response = await fetchNewReleases('drumeo');
|
|
172
|
-
log(response);
|
|
173
|
-
expect(response[0].id).toBeDefined();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
test('fetchAllWorkouts', async () => {
|
|
177
|
-
const response = await fetchAll('drumeo', 'workout', {});
|
|
178
|
-
log(response);
|
|
179
|
-
expect(response.entity[0].id).toBeDefined();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test('fetchAllInstructorField', async () => {
|
|
183
|
-
const response = await fetchAll('drumeo', 'quick-tips', {searchTerm: 'Domino Santantonio'});
|
|
184
|
-
log(response);
|
|
185
|
-
expect(response.entity[0].id).toBeDefined();
|
|
186
|
-
expect(response.entity[0].instructors).toBeTruthy();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
test('fetchAllInstructors', async () => {
|
|
190
|
-
const response = await fetchAll('drumeo', 'instructor');
|
|
191
|
-
log(response);
|
|
192
|
-
expect(response.entity[0].name).toBeDefined();
|
|
193
|
-
expect(response.entity[0].coach_card_image).toBeTruthy();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test('fetchAllSortField', async () => {
|
|
197
|
-
const response = await fetchAll('drumeo', 'rhythmic-adventures-of-captain-carson', {});
|
|
198
|
-
log(response);
|
|
199
|
-
expect(response.entity[0].id).toBeDefined();
|
|
200
|
-
expect(response.entity[0].sort).toBeDefined();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
test('fetchAllChallenges', async () => {
|
|
205
|
-
const response = await fetchAll('drumeo', 'challenge', {});
|
|
206
|
-
log(response);
|
|
207
|
-
expect(response.entity[0].registration_url).toBeDefined();
|
|
208
|
-
expect(response.entity[0].enrollment_start_time).toBeDefined();
|
|
209
|
-
expect(response.entity[0].enrollment_end_time).toBeDefined();
|
|
210
|
-
|
|
211
|
-
expect(response.entity[0].lesson_count).toBeDefined();
|
|
212
|
-
expect(response.entity[0].primary_cta_text).toBeDefined();
|
|
213
|
-
expect(response.entity[0].challenge_state).toBeDefined();
|
|
214
|
-
expect(response.entity[0].challenge_state_text).toBeDefined();
|
|
215
|
-
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test('fetchAllChallengesByGenre', async () => {
|
|
219
|
-
const response = await fetchAll('drumeo', 'challenge', {groupBy:'genre'});
|
|
220
|
-
expect(response.entity[0].type).toBe('genre');
|
|
221
|
-
expect(response.entity[0].lessons).toBeDefined();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('fetchAllChallengesByDifficulty', async () => {
|
|
225
|
-
const response = await fetchAll('drumeo', 'challenge', {groupBy:'difficulty_string'});
|
|
226
|
-
expect(response.entity[0].name).toBeDefined();
|
|
227
|
-
expect(response.entity[0].lessons).toBeDefined();
|
|
228
|
-
expect(response.entity[0].lessons.length).toBeGreaterThan(0);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test('fetchAllChallengesByCompleted', async () => {
|
|
232
|
-
var mock = jest.spyOn(railContentModule, 'fetchCompletedChallenges');
|
|
233
|
-
mock.mockImplementation(() => [402204]);
|
|
234
|
-
const response = await fetchAll('drumeo', 'challenge', {groupBy:'completed'});
|
|
235
|
-
expect(response.entity.length).toBe(1);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
test('fetchAllChallengesByOwned', async () => {
|
|
239
|
-
var mock = jest.spyOn(railContentModule, 'fetchOwnedChallenges');
|
|
240
|
-
mock.mockImplementation(() => [402204]);
|
|
241
|
-
const response = await fetchAll('drumeo', 'challenge', {groupBy:'owned'});
|
|
242
|
-
expect(response.entity.length).toBe(1);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
test('fetchAll-CustomFields', async () => {
|
|
246
|
-
let response = await fetchAll('drumeo', 'challenge', {customFields: ['garbage']});
|
|
247
|
-
log(response);
|
|
248
|
-
expect(response.entity[0].garbage).toBeDefined();
|
|
249
|
-
expect(response.entity[0].id).toBeDefined();
|
|
250
|
-
|
|
251
|
-
response = await fetchAll('drumeo', 'challenge', {useDefaultFields: false, customFields: ['garbage']});
|
|
252
|
-
log(response);
|
|
253
|
-
expect(response.entity[0].garbage).toBeDefined();
|
|
254
|
-
expect.not.objectContaining(response.entity[0].id);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
test('fetchRelatedLessons', async () => {
|
|
258
|
-
const id = 380094;
|
|
259
|
-
const document = await fetchByRailContentId(id, 'song');
|
|
260
|
-
let artist = document.artist.name;
|
|
261
|
-
const response = await fetchRelatedLessons(id, 'singeo');
|
|
262
|
-
let relatedDoc = await fetchByRailContentId(response.related_lessons[0].id, 'song');
|
|
263
|
-
// match on artist or any genre
|
|
264
|
-
let isMatch = artist === relatedDoc.artist.name;
|
|
265
|
-
isMatch = isMatch || document.genre.some((genre) => {
|
|
266
|
-
return relatedDoc.genre.some((relatedGenre) => {
|
|
267
|
-
return genre._ref === relatedGenre._ref;
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
expect(isMatch).toBeTruthy();
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
test('fetchRelatedLessons-quick-tips', async () => {
|
|
274
|
-
const id = 406213;
|
|
275
|
-
const response = await fetchRelatedLessons(id, 'singeo');
|
|
276
|
-
log(response);
|
|
277
|
-
const relatedLessons = response.related_lessons;
|
|
278
|
-
expect(Array.isArray(relatedLessons)).toBe(true);
|
|
279
|
-
relatedLessons.forEach(lesson => {
|
|
280
|
-
expect(lesson._type).toBe('quick-tips');
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
test('fetchRelatedLessons-in-rhythm', async () => {
|
|
285
|
-
const id = 236677;
|
|
286
|
-
const response = await fetchRelatedLessons(id, 'drumeo');
|
|
287
|
-
log(response);
|
|
288
|
-
const relatedLessons = response.related_lessons;
|
|
289
|
-
let episode = 0;
|
|
290
|
-
expect(Array.isArray(relatedLessons)).toBe(true);
|
|
291
|
-
relatedLessons.forEach(lesson => {
|
|
292
|
-
expect(lesson._type).toBe('in-rhythm');
|
|
293
|
-
expect(lesson.sort).toBeGreaterThan(episode);
|
|
294
|
-
episode = lesson.sort;
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test('fetchRelatedLessons-child', async () => {
|
|
299
|
-
const id = 362278;
|
|
300
|
-
const course = await fetchByRailContentId(362277, 'course');
|
|
301
|
-
const lessonIds = course.lessons.map((doc) => doc.id);
|
|
302
|
-
const response = await fetchRelatedLessons(id, 'drumeo');
|
|
303
|
-
log(response.related_lessons);
|
|
304
|
-
const relatedLessons = response.related_lessons;
|
|
305
|
-
expect(Array.isArray(relatedLessons)).toBe(true);
|
|
306
|
-
expect(relatedLessons.some(
|
|
307
|
-
lesson => lessonIds.includes(lesson.id)
|
|
308
|
-
)).toBe(true);
|
|
309
|
-
}, 10000);
|
|
310
|
-
|
|
311
|
-
test('getSortOrder', () => {
|
|
312
|
-
let sort = getSortOrder()
|
|
313
|
-
expect(sort).toBe('published_on desc');
|
|
314
|
-
sort = getSortOrder('slug')
|
|
315
|
-
expect(sort).toBe('title asc');
|
|
316
|
-
sort = getSortOrder('-slug')
|
|
317
|
-
expect(sort).toBe('title desc');
|
|
318
|
-
sort = getSortOrder('-slug', 'drumeo', true);
|
|
319
|
-
expect(sort).toBe('name desc');
|
|
320
|
-
sort = getSortOrder('published-on')
|
|
321
|
-
expect(sort).toBe('published_on asc');
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
test('fetchMethod', async () => {
|
|
325
|
-
const response = await fetchMethod('drumeo', 'drumeo-method');
|
|
326
|
-
log(response);
|
|
327
|
-
expect(response).toBeDefined();
|
|
328
|
-
expect(response.levels.length).toBeGreaterThan(0);
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
test('fetchAll-WithProgress', async () => {
|
|
332
|
-
const ids = [410213, 410215];
|
|
333
|
-
let response = await fetchAll('drumeo', 'song', {
|
|
334
|
-
sort: 'slug',
|
|
335
|
-
progressIds: ids,
|
|
336
|
-
});
|
|
337
|
-
expect(response.entity.length).toBe(2);
|
|
338
|
-
expect(response.entity[0].id = 410215);
|
|
339
|
-
expect(response.entity[1].id = 410213);
|
|
340
|
-
// change the type and we expect no results
|
|
341
|
-
response = await fetchAll('drumeo', 'quick-tip', {
|
|
342
|
-
sort: 'slug',
|
|
343
|
-
progressIds: ids,
|
|
344
|
-
});
|
|
345
|
-
expect(response.entity.length).toBe(0);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
test('fetchAllFilterOptions-WithProgress', async () => {
|
|
349
|
-
const ids = [410213, 413851];
|
|
350
|
-
let response = await fetchAllFilterOptions('drumeo', '', '', '', 'song', '', ids);
|
|
351
|
-
expect(response.meta.totalResults).toBe(2);
|
|
352
|
-
// change the brand and we expect no results
|
|
353
|
-
response = await fetchAllFilterOptions('singeo', '', '', '', 'song', '', ids);
|
|
354
|
-
expect(response.meta.totalResults).toBe(0);
|
|
355
|
-
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
test('fetchFoundation', async () => {
|
|
359
|
-
const response = await fetchFoundation('foundations-2019');
|
|
360
|
-
log(response);
|
|
361
|
-
expect(response.units.length).toBeGreaterThan(0);
|
|
362
|
-
expect(response.type).toBe('foundation');
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
test('fetchPackAll', async () => {
|
|
366
|
-
const response = await fetchPackAll(212899); //https://web-staging-one.musora.com/admin/studio/publishing/structure/pack;pack_212899%2Cinspect%3Don
|
|
367
|
-
log(response);
|
|
368
|
-
expect(response.slug).toBe('creative-control');
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
test('fetchAllPacks', async () => {
|
|
372
|
-
let response = await fetchAllPacks('drumeo');
|
|
373
|
-
response = await fetchAllPacks('drumeo', 'slug');
|
|
374
|
-
const titles = response.map((doc) => doc.title);
|
|
375
|
-
|
|
376
|
-
const sortedTitles = [...titles].sort((a, b) => a === b ? 0 : a > b ? 1 : -1);
|
|
377
|
-
|
|
378
|
-
expect(titles).toStrictEqual(sortedTitles);
|
|
379
|
-
response = await fetchAllPacks('drumeo', 'slug', 'Creative Control');
|
|
380
|
-
expect(response[0].id).toBe(212899);
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
test('fetchCoachLessons', async () => {
|
|
384
|
-
const response = await fetchCoachLessons('drumeo', 411493, {});
|
|
385
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
386
|
-
});
|
|
387
|
-
test('fetchCoachLessons-WithTypeFilters', async () => {
|
|
388
|
-
const response = await fetchAllFilterOptions('drumeo', ['type,course', 'type,live'], '', '', 'coach-lessons', '', [], 31880);
|
|
389
|
-
log(response);
|
|
390
|
-
expect(response.meta.filterOptions.difficulty).toBeDefined();
|
|
391
|
-
expect(response.meta.filterOptions.type).toBeDefined();
|
|
392
|
-
expect(response.meta.filterOptions.lifestyle).toBeDefined();
|
|
393
|
-
expect(response.meta.filterOptions.genre).toBeDefined();
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
test('fetchCoachLessons-WithTypeFilters-InvalidContentType', async () => {
|
|
397
|
-
const brand = 'drumeo';
|
|
398
|
-
const coachId = 31880;
|
|
399
|
-
const invalidContentType = 'course'; // Not 'coach-lessons'
|
|
400
|
-
|
|
401
|
-
await expect(fetchAllFilterOptions(brand, ['type,course', 'type,live'], '', '', invalidContentType, '', [], coachId))
|
|
402
|
-
.rejects
|
|
403
|
-
.toThrow("Invalid contentType: 'course' for coachId. It must be 'coach-lessons'.");
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
test('fetchCoachLessons-IncludedFields', async () => {
|
|
407
|
-
const response = await fetchCoachLessons('drumeo', 31880, {includedFields: ['genre,Pop/Rock', 'difficulty,Beginner']});
|
|
408
|
-
log(response);
|
|
409
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
test('fetchAll-IncludedFields', async () => {
|
|
414
|
-
let response = await fetchAll('drumeo', 'instructor', {includedFields: ['is_active']});
|
|
415
|
-
console.log(response);
|
|
416
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
test('fetchAll-IncludedFields-multiple', async () => {
|
|
420
|
-
let response = await fetchAll('drumeo', 'course', {includedFields: ['essential,Dynamics', 'essential,Timing', 'difficulty,Beginner']});
|
|
421
|
-
log(response);
|
|
422
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
test('fetchAll-IncludedFields-playalong-multiple', async () => {
|
|
426
|
-
let response = await fetchAll('drumeo', 'play-along', {includedFields: ['bpm,91-120', 'bpm,181+', 'genre,Blues']});
|
|
427
|
-
log(response);
|
|
428
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
test('fetchAll-IncludedFields-rudiment-multiple-gear', async () => {
|
|
432
|
-
let response = await fetchAll('drumeo', 'rudiment', {includedFields: ['gear,Drum-Set', 'gear,Practice Pad']});
|
|
433
|
-
log(response);
|
|
434
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
test('fetchAll-IncludedFields-coaches-multiple-focus', async () => {
|
|
438
|
-
let response = await fetchAll('drumeo', 'instructor', {includedFields: ['focus,Drumline', 'focus,Recording']});
|
|
439
|
-
log(response);
|
|
440
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
test('fetchAll-IncludedFields-songs-multiple-instrumentless', async () => {
|
|
444
|
-
let response = await fetchAll('drumeo', 'song', {includedFields: ['instrumentless,true', 'instrumentless,false']});
|
|
445
|
-
log(response);
|
|
446
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
test('fetchByReference', async () => {
|
|
450
|
-
const response = await fetchByReference('drumeo', {includedFields: ['is_featured']});
|
|
451
|
-
expect(response.entity.length).toBeGreaterThan(0);
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
test('fetchScheduledReleases', async () => {
|
|
455
|
-
const response = await fetchScheduledReleases('drumeo', {});
|
|
456
|
-
expect(response.length).toBeGreaterThan(0);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
test('fetchAll-GroupBy-Genre', async () => {
|
|
460
|
-
let response = await fetchAll('drumeo', 'solo', {groupBy: 'genre'});
|
|
461
|
-
log(response);
|
|
462
|
-
expect(response.entity[0].web_url_path).toContain('/drumeo/genres/');
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
test('fetchAll-GroupBy-Artists', async () => {
|
|
466
|
-
let response = await fetchAll('drumeo', 'song', {groupBy: 'artist'});
|
|
467
|
-
log(response);
|
|
468
|
-
expect(response.entity[0].web_url_path).toContain('/drumeo/artists/');
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
test('fetchAll-GroupBy-Instructors', async () => {
|
|
472
|
-
let response = await fetchAll('drumeo', 'course', {groupBy: 'instructor'});
|
|
473
|
-
log(response);
|
|
474
|
-
expect(response.entity[0].web_url_path).toContain('/drumeo/coaches/');
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
test('fetchShowsData', async () => {
|
|
478
|
-
const response = await fetchShowsData('drumeo');
|
|
479
|
-
log(response);
|
|
480
|
-
expect(response.length).toBeGreaterThan(0);
|
|
481
|
-
const showTypes = response.map((x) => x.type);
|
|
482
|
-
expect(showTypes).toContain('live');
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
test('fetchMetadata', async () => {
|
|
486
|
-
const response = await fetchMetadata('drumeo', 'song');
|
|
487
|
-
log(response);
|
|
488
|
-
expect(response.tabs.length).toBeGreaterThan(0);
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
test('fetchShowsData-OddTimes', async () => {
|
|
492
|
-
const response = await fetchShowsData('drumeo');
|
|
493
|
-
log(response);
|
|
494
|
-
expect(response.length).toBeGreaterThan(0);
|
|
495
|
-
const showTypes = response.map((x) => x.type);
|
|
496
|
-
expect(showTypes).toContain('odd-times');
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
test('fetchMetadata-Coach-Lessons', async () => {
|
|
500
|
-
const response = await fetchMetadata('drumeo', 'coach-lessons');
|
|
501
|
-
log(response);
|
|
502
|
-
expect(response).toBeDefined();
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
test('fetchNextPreviousLesson-Show-With-Episodes', async () => {
|
|
506
|
-
const id = 227136;
|
|
507
|
-
const document = await fetchByRailContentId(id, 'behind-the-scenes');
|
|
508
|
-
const response = await fetchNextPreviousLesson(id);
|
|
509
|
-
log(response);
|
|
510
|
-
expect(response.prevLesson).toBeDefined();
|
|
511
|
-
expect(response.prevLesson.sort).toBeLessThanOrEqual(document.sort);
|
|
512
|
-
expect(response.nextLesson).toBeDefined();
|
|
513
|
-
expect(response.nextLesson.sort).toBeGreaterThanOrEqual(document.sort);
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
test('fetchMethodNextPreviousLesson-Last', async () => {
|
|
517
|
-
const id = 260171;
|
|
518
|
-
const methodId = 259060;
|
|
519
|
-
const response = await fetchMethodPreviousNextLesson(id, methodId);
|
|
520
|
-
log(response);
|
|
521
|
-
expect(response.prevLesson).toBeDefined();
|
|
522
|
-
expect(response.prevLesson.id).toBe(260170);
|
|
523
|
-
expect(response.prevLesson.type).toBe('course-part');
|
|
524
|
-
expect(response.nextLesson).not.toBeDefined();
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
test('fetchNextPreviousLesson-Method-Lesson', async () => {
|
|
528
|
-
const id = 241265;
|
|
529
|
-
const response = await fetchNextPreviousLesson(id);
|
|
530
|
-
log(response);
|
|
531
|
-
expect(response.prevLesson).toBeDefined();
|
|
532
|
-
expect(response.prevLesson.id).toBe(241264);
|
|
533
|
-
expect(response.prevLesson.type).toBe('learning-path-lesson');
|
|
534
|
-
expect(response.nextLesson).toBeDefined();
|
|
535
|
-
expect(response.nextLesson.id).toBe(241267);
|
|
536
|
-
expect(response.nextLesson.type).toBe('learning-path-lesson');
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
test('fetchNextPreviousLesson-Quick-Tips', async () => {
|
|
540
|
-
const id = 412277;
|
|
541
|
-
const response = await fetchNextPreviousLesson(id);
|
|
542
|
-
const document = await fetchByRailContentId(id, 'quick-tips');
|
|
543
|
-
const documentPublishedOn = new Date(document.published_on);
|
|
544
|
-
const prevDocumentPublishedOn = new Date(response.prevLesson.published_on);
|
|
545
|
-
const nextDocumentPublishedOn = new Date(response.nextLesson.published_on);
|
|
546
|
-
expect(response.prevLesson).toBeDefined();
|
|
547
|
-
expect(prevDocumentPublishedOn.getTime()).toBeLessThan(documentPublishedOn.getTime());
|
|
548
|
-
expect(response.nextLesson).toBeDefined();
|
|
549
|
-
expect(documentPublishedOn.getTime()).toBeLessThan(nextDocumentPublishedOn.getTime());
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
test('fetchNextPreviousLesson-Song', async () => {
|
|
553
|
-
const id = 414041;
|
|
554
|
-
const response = await fetchNextPreviousLesson(id);
|
|
555
|
-
const document = await fetchByRailContentId(id, 'song');
|
|
556
|
-
const documentPublishedOn = new Date(document.published_on);
|
|
557
|
-
const prevDocumentPublishedOn = new Date(response.prevLesson.published_on);
|
|
558
|
-
const nextDocumentPublishedOn = new Date(response.nextLesson.published_on);
|
|
559
|
-
expect(response.prevLesson).toBeDefined();
|
|
560
|
-
expect(prevDocumentPublishedOn.getTime()).toBeLessThanOrEqual(documentPublishedOn.getTime());
|
|
561
|
-
expect(response.nextLesson).toBeDefined();
|
|
562
|
-
expect(documentPublishedOn.getTime()).toBeLessThanOrEqual(nextDocumentPublishedOn.getTime());
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
test('fetchTopLevelParentId', async () => {
|
|
566
|
-
let contentId = await fetchTopLevelParentId(241250);
|
|
567
|
-
expect(contentId).toBe(241247);
|
|
568
|
-
contentId = await fetchTopLevelParentId(241249);
|
|
569
|
-
expect(contentId).toBe(241247);
|
|
570
|
-
contentId = await fetchTopLevelParentId(241248);
|
|
571
|
-
expect(contentId).toBe(241247);
|
|
572
|
-
contentId = await fetchTopLevelParentId(241247);
|
|
573
|
-
expect(contentId).toBe(241247);
|
|
574
|
-
contentId = await fetchTopLevelParentId(0);
|
|
575
|
-
expect(contentId).toBe(null);
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
test('fetchHierarchy', async () => {
|
|
579
|
-
let hierarchy = await fetchHierarchy(241250);
|
|
580
|
-
expect(hierarchy.parents[241250]).toBe(241249);
|
|
581
|
-
expect(hierarchy.parents[241249]).toBe(241248);
|
|
582
|
-
expect(hierarchy.parents[241248]).toBe(241247);
|
|
583
|
-
expect(hierarchy.children[241250]).toStrictEqual([241676]);
|
|
584
|
-
expect(hierarchy.children[243085]).toStrictEqual([243170, 243171, 243172, 243174, 243176]);
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
test('fetchTopLeveldrafts', async () => {
|
|
588
|
-
let id = await fetchTopLevelParentId(401999);
|
|
589
|
-
expect(id).toBe(401999);
|
|
590
|
-
});
|
|
591
|
-
|
|
592
|
-
test('fetchCommentData', async()=>{
|
|
593
|
-
let data = await fetchCommentModContentData([241251,241252, 211153]);
|
|
594
|
-
expect(data[241251].title).toBe("Setting Up Your Space");
|
|
595
|
-
expect(data[241251].type).toBe("learning-path-lesson");
|
|
596
|
-
expect(data[241251].url).toBe( "/drumeo/method/drumeo-method/241247/getting-started-on-the-drums/241248/gear/241249/setting-up-your-space/241251");
|
|
597
|
-
expect(data[241251].parentTitle).toBe("Gear");
|
|
598
|
-
expect(data[241252].title).toBe("Setting Up Your Pedals & Throne");
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
describe('Filter Builder', function () {
|
|
603
|
-
|
|
604
|
-
beforeEach(() => {
|
|
605
|
-
initializeTestService();
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
test('baseConstructor', async () => {
|
|
609
|
-
const filter = 'railcontent_id = 111'
|
|
610
|
-
let builder = new FilterBuilder(filter, {bypassPermissions: true});
|
|
611
|
-
let finalFilter = await builder.buildFilter(filter);
|
|
612
|
-
let clauses = spliceFilterForAnds(finalFilter);
|
|
613
|
-
expect(clauses[0].phrase).toBe(filter);
|
|
614
|
-
expect(clauses[1].field).toBe('(status');
|
|
615
|
-
expect(clauses[3].field).toBe('published_on');
|
|
616
|
-
|
|
617
|
-
builder = new FilterBuilder('', {bypassPermissions: true});
|
|
618
|
-
finalFilter = await builder.buildFilter(filter);
|
|
619
|
-
clauses = spliceFilterForAnds(finalFilter);
|
|
620
|
-
expect(clauses[0].field).toBe('(status');
|
|
621
|
-
expect(clauses[0].operator).toBe('in');
|
|
622
|
-
expect(clauses[2].field).toBe('published_on');
|
|
623
|
-
expect(clauses[2].operator).toBe('>=');
|
|
624
|
-
});
|
|
625
|
-
|
|
626
|
-
test('withOnlyFilterAvailableStatuses', async () => {
|
|
627
|
-
const filter = 'railcontent_id = 111'
|
|
628
|
-
const builder = FilterBuilder.withOnlyFilterAvailableStatuses(filter, ['published', 'unlisted'], true);
|
|
629
|
-
const finalFilter = await builder.buildFilter();
|
|
630
|
-
const clauses = spliceFilterForAnds(finalFilter);
|
|
631
|
-
expect(clauses[0].phrase).toBe(filter);
|
|
632
|
-
expect(clauses[1].field).toBe('status');
|
|
633
|
-
expect(clauses[1].operator).toBe('in');
|
|
634
|
-
// not sure I like this
|
|
635
|
-
expect(clauses[1].condition).toBe("['published','unlisted']");
|
|
636
|
-
expect(clauses[2].field).toBe('published_on');
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
test('withContentStatusAndFutureScheduledContent', async () => {
|
|
640
|
-
const filter = 'railcontent_id = 111'
|
|
641
|
-
const builder = new FilterBuilder(filter, {
|
|
642
|
-
availableContentStatuses: ['published', 'unlisted', 'scheduled'],
|
|
643
|
-
getFutureScheduledContentsOnly: true
|
|
644
|
-
});
|
|
645
|
-
const finalFilter = await builder.buildFilter();
|
|
646
|
-
const clauses = spliceFilterForAnds(finalFilter);
|
|
647
|
-
expect(clauses[0].phrase).toBe(filter);
|
|
648
|
-
expect(clauses[1].field).toBe('(status'); // extra ( because it's a multi part filter
|
|
649
|
-
expect(clauses[1].operator).toBe('in');
|
|
650
|
-
// getFutureScheduledContentsOnly doesn't make a filter that's splicable, so we match on the more static string
|
|
651
|
-
const expected = "['published','unlisted'] || (status == 'scheduled' && defined(published_on) && published_on >=";
|
|
652
|
-
const isMatch = finalFilter.includes(expected);
|
|
653
|
-
expect(isMatch).toBeTruthy();
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
test('withUserPermissions', async () => {
|
|
657
|
-
const filter = 'railcontent_id = 111'
|
|
658
|
-
const builder = new FilterBuilder(filter);
|
|
659
|
-
const finalFilter = await builder.buildFilter();
|
|
660
|
-
const expected = "references(*[_type == 'permission' && railcontent_id in [78,91,92]]._id)"
|
|
661
|
-
const isMatch = finalFilter.includes(expected);
|
|
662
|
-
expect(isMatch).toBeTruthy();
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
test('withUserPermissionsForPlusUser', async () => {
|
|
666
|
-
const filter = 'railcontent_id = 111'
|
|
667
|
-
const builder = new FilterBuilder(filter);
|
|
668
|
-
const finalFilter = await builder.buildFilter();
|
|
669
|
-
const expected = "references(*[_type == 'permission' && railcontent_id in [78,91,92]]._id)"
|
|
670
|
-
const isMatch = finalFilter.includes(expected);
|
|
671
|
-
expect(isMatch).toBeTruthy();
|
|
672
|
-
});
|
|
673
|
-
|
|
674
|
-
test('withPermissionBypass', async () => {
|
|
675
|
-
const filter = 'railcontent_id = 111'
|
|
676
|
-
const builder = new FilterBuilder(filter,
|
|
677
|
-
{
|
|
678
|
-
bypassPermissions: true,
|
|
679
|
-
pullFutureContent: false
|
|
680
|
-
});
|
|
681
|
-
const finalFilter = await builder.buildFilter();
|
|
682
|
-
const expected = "references(*[_type == 'permission' && railcontent_id in [78,91,92]]._id)"
|
|
683
|
-
const isMatch = finalFilter.includes(expected);
|
|
684
|
-
expect(isMatch).toBeFalsy();
|
|
685
|
-
const clauses = spliceFilterForAnds(finalFilter);
|
|
686
|
-
expect(clauses[0].field).toBe('railcontent_id');
|
|
687
|
-
expect(clauses[1].field).toBe('(status');
|
|
688
|
-
expect(clauses[3].field).toBe('published_on');
|
|
689
|
-
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
test('withPublishOnRestrictions', async () => {
|
|
694
|
-
// testing dates is a pain more frustration than I'm willing to deal with, so I'm just testing operators.
|
|
695
|
-
|
|
696
|
-
const filter = 'railcontent_id = 111'
|
|
697
|
-
let builder = new FilterBuilder(filter, {
|
|
698
|
-
pullFutureContent: true,
|
|
699
|
-
bypassPermissions: true
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
let finalFilter = await builder.buildFilter();
|
|
703
|
-
let clauses = spliceFilterForAnds(finalFilter);
|
|
704
|
-
expect(clauses[0].phrase).toBe(filter);
|
|
705
|
-
expect(clauses[1].field).toBe('(status');
|
|
706
|
-
expect(clauses[1].operator).toBe('in');
|
|
707
|
-
expect(clauses[2].phrase).toBe('defined(published_on)');
|
|
708
|
-
expect(clauses[3].field).toBe('published_on');
|
|
709
|
-
|
|
710
|
-
builder = new FilterBuilder(filter,
|
|
711
|
-
{
|
|
712
|
-
getFutureContentOnly: true,
|
|
713
|
-
bypassPermissions: true
|
|
714
|
-
});
|
|
715
|
-
finalFilter = await builder.buildFilter();
|
|
716
|
-
clauses = spliceFilterForAnds(finalFilter);
|
|
717
|
-
expect(clauses[0].phrase).toBe(filter);
|
|
718
|
-
expect(clauses[3].field).toBe('published_on');
|
|
719
|
-
expect(clauses[3].operator).toBe('>=');
|
|
720
|
-
});
|
|
721
|
-
|
|
722
|
-
function spliceFilterForAnds(filter) {
|
|
723
|
-
// this will not correctly split complex filters with && and || conditions.
|
|
724
|
-
let phrases = filter.split(' && ');
|
|
725
|
-
let clauses = [];
|
|
726
|
-
phrases.forEach((phrase) => {
|
|
727
|
-
let field = phrase.substring(0, phrase.indexOf(' '));
|
|
728
|
-
//if(field.charAt(0) === '(' ) field = field.substring(1);
|
|
729
|
-
const temp = phrase.substring(phrase.indexOf(' ') + 1);
|
|
730
|
-
const operator = temp.substring(0, temp.indexOf(' '));
|
|
731
|
-
let condition = temp.substring(temp.indexOf(' ') + 1);
|
|
732
|
-
//if(condition.charAt(condition.length) === ')') condition = condition.slice(-1);
|
|
733
|
-
clauses.push({phrase, field, operator, condition});
|
|
734
|
-
});
|
|
735
|
-
return clauses;
|
|
76
|
+
const newSlug = 'keysmash1'
|
|
77
|
+
const newField = 1
|
|
78
|
+
const postProcess = (result) => {
|
|
79
|
+
result['new_field'] = newField
|
|
80
|
+
result['slug'] = newSlug
|
|
81
|
+
return result
|
|
736
82
|
}
|
|
83
|
+
const response = await fetchSanity(query, false, { customPostProcess: postProcess })
|
|
84
|
+
log(response)
|
|
85
|
+
expect(response.id).toBe(id)
|
|
86
|
+
expect(response.new_field).toBe(newField)
|
|
87
|
+
expect(response.slug).toBe(newSlug)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('fetchSanityPostProcess', async () => {
|
|
91
|
+
const id = 380094
|
|
92
|
+
const response = await fetchByRailContentId(id, 'song')
|
|
93
|
+
expect(response.id).toBe(id)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('fetchByRailContentIds', async () => {
|
|
97
|
+
const id = 380094
|
|
98
|
+
const id2 = 402204
|
|
99
|
+
const response = await fetchByRailContentIds([id, id2])
|
|
100
|
+
const returnedIds = response.map((x) => x.id)
|
|
101
|
+
expect(returnedIds[0]).toBe(id)
|
|
102
|
+
expect(returnedIds[1]).toBe(id2)
|
|
103
|
+
expect(returnedIds.length).toBe(2)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test('fetchByRailContentIds_Order', async () => {
|
|
107
|
+
const id = 380094
|
|
108
|
+
const id2 = 402204
|
|
109
|
+
const response = await fetchByRailContentIds([id2, id])
|
|
110
|
+
const returnedIds = response.map((x) => x.id)
|
|
111
|
+
expect(returnedIds[0]).toBe(id2)
|
|
112
|
+
expect(returnedIds[1]).toBe(id)
|
|
113
|
+
expect(returnedIds.length).toBe(2)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('fetchUpcomingEvents', async () => {
|
|
117
|
+
const response = await fetchUpcomingEvents('drumeo', {})
|
|
118
|
+
expect(response.length).toBeGreaterThan(0)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('fetchUpcomingNewReleases', async () => {
|
|
122
|
+
const response = await fetchNewReleases('drumeo')
|
|
123
|
+
expect(response.length).toBeGreaterThan(0)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
test('fetchLessonContent', async () => {
|
|
127
|
+
const id = 380094
|
|
128
|
+
const response = await fetchLessonContent(id)
|
|
129
|
+
expect(response.id).toBe(id)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('fetchAllSongsInProgress', async () => {
|
|
133
|
+
var mock = jest.spyOn(dataContext, 'fetchData')
|
|
134
|
+
var json = JSON.parse(
|
|
135
|
+
`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"412941":{"s":"started","p":6,"t":20,"u":1731108082}}}`
|
|
136
|
+
)
|
|
137
|
+
mock.mockImplementation(() => json)
|
|
138
|
+
const response = await fetchAll('drumeo', 'song', { progress: 'in progress' })
|
|
139
|
+
expect(response.entity[0].id).toBe(412941)
|
|
140
|
+
expect(response.entity.length).toBe(1)
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// test('fetchAllSongsCompleted', async () => {
|
|
144
|
+
// var mock = jest.spyOn(dataContext, 'fetchData');
|
|
145
|
+
// var json = JSON.parse(`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"232979":{"s":"completed","p":100,"t":20,"u":1731108082}}}`);
|
|
146
|
+
// mock.mockImplementation(() =>
|
|
147
|
+
// json);
|
|
148
|
+
// const response = await fetchAll('drumeo', 'song', {progress:"completed"});
|
|
149
|
+
// expect(response.entity[0].id).toBe(232979);
|
|
150
|
+
// expect(response.entity.length).toBe(1);
|
|
151
|
+
// });
|
|
152
|
+
//
|
|
153
|
+
// test('fetchAllSongsNotStarted', async () => {
|
|
154
|
+
// var mock = jest.spyOn(dataContext, 'fetchData');
|
|
155
|
+
// var json = JSON.parse(`{"version":1,"config":{"key":1,"enabled":1,"checkInterval":1,"refreshInterval":2},"data":{"198122":{"s":"started","p":100,"t":20,"u":1731108082},"231622":{"s":"completed","p":100,"t":20,"u":1731108082}}}`);
|
|
156
|
+
// mock.mockImplementation(() =>
|
|
157
|
+
// json); const response = await fetchAll('drumeo', 'song', {progress:"not started"});
|
|
158
|
+
// expect(response.entity[0].id).not.toBe(198122);
|
|
159
|
+
// expect(response.entity[0].id).not.toBe(231622);
|
|
160
|
+
// });
|
|
161
|
+
|
|
162
|
+
test('fetchNewReleases', async () => {
|
|
163
|
+
const response = await fetchNewReleases('drumeo')
|
|
164
|
+
log(response)
|
|
165
|
+
expect(response[0].id).toBeDefined()
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
test('fetchAllWorkouts', async () => {
|
|
169
|
+
const response = await fetchAll('drumeo', 'workout', {})
|
|
170
|
+
log(response)
|
|
171
|
+
expect(response.entity[0].id).toBeDefined()
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('fetchAllInstructorField', async () => {
|
|
175
|
+
const response = await fetchAll('drumeo', 'quick-tips', { searchTerm: 'Domino Santantonio' })
|
|
176
|
+
log(response)
|
|
177
|
+
expect(response.entity[0].id).toBeDefined()
|
|
178
|
+
expect(response.entity[0].instructors).toBeTruthy()
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
test('fetchAllInstructors', async () => {
|
|
182
|
+
const response = await fetchAll('drumeo', 'instructor')
|
|
183
|
+
log(response)
|
|
184
|
+
expect(response.entity[0].name).toBeDefined()
|
|
185
|
+
expect(response.entity[0].coach_card_image).toBeTruthy()
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
test('fetchAllSortField', async () => {
|
|
189
|
+
const response = await fetchAll('drumeo', 'rhythmic-adventures-of-captain-carson', {})
|
|
190
|
+
log(response)
|
|
191
|
+
expect(response.entity[0].id).toBeDefined()
|
|
192
|
+
expect(response.entity[0].sort).toBeDefined()
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('fetchAllChallenges', async () => {
|
|
196
|
+
const response = await fetchAll('drumeo', 'challenge', {})
|
|
197
|
+
log(response)
|
|
198
|
+
expect(response.entity[0].registration_url).toBeDefined()
|
|
199
|
+
expect(response.entity[0].enrollment_start_time).toBeDefined()
|
|
200
|
+
expect(response.entity[0].enrollment_end_time).toBeDefined()
|
|
201
|
+
|
|
202
|
+
expect(response.entity[0].lesson_count).toBeDefined()
|
|
203
|
+
expect(response.entity[0].primary_cta_text).toBeDefined()
|
|
204
|
+
expect(response.entity[0].challenge_state).toBeDefined()
|
|
205
|
+
expect(response.entity[0].challenge_state_text).toBeDefined()
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
test('fetchAllChallengesByGenre', async () => {
|
|
209
|
+
const response = await fetchAll('drumeo', 'challenge', { groupBy: 'genre' })
|
|
210
|
+
expect(response.entity[0].type).toBe('genre')
|
|
211
|
+
expect(response.entity[0].lessons).toBeDefined()
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('fetchAllChallengesByDifficulty', async () => {
|
|
215
|
+
const response = await fetchAll('drumeo', 'challenge', { groupBy: 'difficulty_string' })
|
|
216
|
+
expect(response.entity[0].name).toBeDefined()
|
|
217
|
+
expect(response.entity[0].lessons).toBeDefined()
|
|
218
|
+
expect(response.entity[0].lessons.length).toBeGreaterThan(0)
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
test('fetchAllChallengesByCompleted', async () => {
|
|
222
|
+
var mock = jest.spyOn(railContentModule, 'fetchCompletedChallenges')
|
|
223
|
+
mock.mockImplementation(() => [402204])
|
|
224
|
+
const response = await fetchAll('drumeo', 'challenge', { groupBy: 'completed' })
|
|
225
|
+
expect(response.entity.length).toBe(1)
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test('fetchAllChallengesByOwned', async () => {
|
|
229
|
+
var mock = jest.spyOn(railContentModule, 'fetchOwnedChallenges')
|
|
230
|
+
mock.mockImplementation(() => [402204])
|
|
231
|
+
const response = await fetchAll('drumeo', 'challenge', { groupBy: 'owned' })
|
|
232
|
+
expect(response.entity.length).toBe(1)
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('fetchAll-CustomFields', async () => {
|
|
236
|
+
let response = await fetchAll('drumeo', 'challenge', { customFields: ['garbage'] })
|
|
237
|
+
log(response)
|
|
238
|
+
expect(response.entity[0].garbage).toBeDefined()
|
|
239
|
+
expect(response.entity[0].id).toBeDefined()
|
|
240
|
+
|
|
241
|
+
response = await fetchAll('drumeo', 'challenge', {
|
|
242
|
+
useDefaultFields: false,
|
|
243
|
+
customFields: ['garbage'],
|
|
244
|
+
})
|
|
245
|
+
log(response)
|
|
246
|
+
expect(response.entity[0].garbage).toBeDefined()
|
|
247
|
+
expect.not.objectContaining(response.entity[0].id)
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
test('fetchRelatedLessons', async () => {
|
|
251
|
+
const id = 380094
|
|
252
|
+
const document = await fetchByRailContentId(id, 'song')
|
|
253
|
+
let artist = document.artist.name
|
|
254
|
+
const response = await fetchRelatedLessons(id, 'singeo')
|
|
255
|
+
let relatedDoc = await fetchByRailContentId(response.related_lessons[0].id, 'song')
|
|
256
|
+
// match on artist or any genre
|
|
257
|
+
let isMatch = artist === relatedDoc.artist.name
|
|
258
|
+
isMatch =
|
|
259
|
+
isMatch ||
|
|
260
|
+
document.genre.some((genre) => {
|
|
261
|
+
return relatedDoc.genre.some((relatedGenre) => {
|
|
262
|
+
return genre._ref === relatedGenre._ref
|
|
263
|
+
})
|
|
264
|
+
})
|
|
265
|
+
expect(isMatch).toBeTruthy()
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
test('fetchRelatedLessons-quick-tips', async () => {
|
|
269
|
+
const id = 406213
|
|
270
|
+
const response = await fetchRelatedLessons(id, 'singeo')
|
|
271
|
+
log(response)
|
|
272
|
+
const relatedLessons = response.related_lessons
|
|
273
|
+
expect(Array.isArray(relatedLessons)).toBe(true)
|
|
274
|
+
relatedLessons.forEach((lesson) => {
|
|
275
|
+
expect(lesson._type).toBe('quick-tips')
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
test('fetchRelatedLessons-in-rhythm', async () => {
|
|
280
|
+
const id = 236677
|
|
281
|
+
const response = await fetchRelatedLessons(id, 'drumeo')
|
|
282
|
+
log(response)
|
|
283
|
+
const relatedLessons = response.related_lessons
|
|
284
|
+
let episode = 0
|
|
285
|
+
expect(Array.isArray(relatedLessons)).toBe(true)
|
|
286
|
+
relatedLessons.forEach((lesson) => {
|
|
287
|
+
expect(lesson._type).toBe('in-rhythm')
|
|
288
|
+
expect(lesson.sort).toBeGreaterThan(episode)
|
|
289
|
+
episode = lesson.sort
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
test('fetchRelatedLessons-child', async () => {
|
|
294
|
+
const id = 362278
|
|
295
|
+
const course = await fetchByRailContentId(362277, 'course')
|
|
296
|
+
const lessonIds = course.lessons.map((doc) => doc.id)
|
|
297
|
+
const response = await fetchRelatedLessons(id, 'drumeo')
|
|
298
|
+
log(response.related_lessons)
|
|
299
|
+
const relatedLessons = response.related_lessons
|
|
300
|
+
expect(Array.isArray(relatedLessons)).toBe(true)
|
|
301
|
+
expect(relatedLessons.some((lesson) => lessonIds.includes(lesson.id))).toBe(true)
|
|
302
|
+
}, 10000)
|
|
303
|
+
|
|
304
|
+
test('getSortOrder', () => {
|
|
305
|
+
let sort = getSortOrder()
|
|
306
|
+
expect(sort).toBe('published_on desc')
|
|
307
|
+
sort = getSortOrder('slug')
|
|
308
|
+
expect(sort).toBe('title asc')
|
|
309
|
+
sort = getSortOrder('-slug')
|
|
310
|
+
expect(sort).toBe('title desc')
|
|
311
|
+
sort = getSortOrder('-slug', 'drumeo', true)
|
|
312
|
+
expect(sort).toBe('name desc')
|
|
313
|
+
sort = getSortOrder('published-on')
|
|
314
|
+
expect(sort).toBe('published_on asc')
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
test('fetchMethod', async () => {
|
|
318
|
+
const response = await fetchMethod('drumeo', 'drumeo-method')
|
|
319
|
+
log(response)
|
|
320
|
+
expect(response).toBeDefined()
|
|
321
|
+
expect(response.levels.length).toBeGreaterThan(0)
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
test('fetchAll-WithProgress', async () => {
|
|
325
|
+
const ids = [410213, 410215]
|
|
326
|
+
let response = await fetchAll('drumeo', 'song', {
|
|
327
|
+
sort: 'slug',
|
|
328
|
+
progressIds: ids,
|
|
329
|
+
})
|
|
330
|
+
expect(response.entity.length).toBe(2)
|
|
331
|
+
expect((response.entity[0].id = 410215))
|
|
332
|
+
expect((response.entity[1].id = 410213))
|
|
333
|
+
// change the type and we expect no results
|
|
334
|
+
response = await fetchAll('drumeo', 'quick-tip', {
|
|
335
|
+
sort: 'slug',
|
|
336
|
+
progressIds: ids,
|
|
337
|
+
})
|
|
338
|
+
expect(response.entity.length).toBe(0)
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
test('fetchAllFilterOptions-WithProgress', async () => {
|
|
342
|
+
const ids = [410213, 413851]
|
|
343
|
+
let response = await fetchAllFilterOptions('drumeo', '', '', '', 'song', '', ids)
|
|
344
|
+
expect(response.meta.totalResults).toBe(2)
|
|
345
|
+
// change the brand and we expect no results
|
|
346
|
+
response = await fetchAllFilterOptions('singeo', '', '', '', 'song', '', ids)
|
|
347
|
+
expect(response.meta.totalResults).toBe(0)
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
test('fetchFoundation', async () => {
|
|
351
|
+
const response = await fetchFoundation('foundations-2019')
|
|
352
|
+
log(response)
|
|
353
|
+
expect(response.units.length).toBeGreaterThan(0)
|
|
354
|
+
expect(response.type).toBe('foundation')
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
test('fetchPackAll', async () => {
|
|
358
|
+
const response = await fetchPackAll(212899) //https://web-staging-one.musora.com/admin/studio/publishing/structure/pack;pack_212899%2Cinspect%3Don
|
|
359
|
+
log(response)
|
|
360
|
+
expect(response.slug).toBe('creative-control')
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
test('fetchAllPacks', async () => {
|
|
364
|
+
let response = await fetchAllPacks('drumeo')
|
|
365
|
+
response = await fetchAllPacks('drumeo', 'slug')
|
|
366
|
+
const titles = response.map((doc) => doc.title)
|
|
367
|
+
|
|
368
|
+
const sortedTitles = [...titles].sort((a, b) => (a === b ? 0 : a > b ? 1 : -1))
|
|
369
|
+
|
|
370
|
+
expect(titles).toStrictEqual(sortedTitles)
|
|
371
|
+
response = await fetchAllPacks('drumeo', 'slug', 'Creative Control')
|
|
372
|
+
expect(response[0].id).toBe(212899)
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
test('fetchCoachLessons', async () => {
|
|
376
|
+
const response = await fetchCoachLessons('drumeo', 411493, {})
|
|
377
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
378
|
+
})
|
|
379
|
+
test('fetchCoachLessons-WithTypeFilters', async () => {
|
|
380
|
+
const response = await fetchAllFilterOptions(
|
|
381
|
+
'drumeo',
|
|
382
|
+
['type,course', 'type,live'],
|
|
383
|
+
'',
|
|
384
|
+
'',
|
|
385
|
+
'coach-lessons',
|
|
386
|
+
'',
|
|
387
|
+
[],
|
|
388
|
+
31880
|
|
389
|
+
)
|
|
390
|
+
log(response)
|
|
391
|
+
expect(response.meta.filterOptions.difficulty).toBeDefined()
|
|
392
|
+
expect(response.meta.filterOptions.type).toBeDefined()
|
|
393
|
+
expect(response.meta.filterOptions.lifestyle).toBeDefined()
|
|
394
|
+
expect(response.meta.filterOptions.genre).toBeDefined()
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
test('fetchCoachLessons-WithTypeFilters-InvalidContentType', async () => {
|
|
398
|
+
const brand = 'drumeo'
|
|
399
|
+
const coachId = 31880
|
|
400
|
+
const invalidContentType = 'course' // Not 'coach-lessons'
|
|
401
|
+
|
|
402
|
+
await expect(
|
|
403
|
+
fetchAllFilterOptions(
|
|
404
|
+
brand,
|
|
405
|
+
['type,course', 'type,live'],
|
|
406
|
+
'',
|
|
407
|
+
'',
|
|
408
|
+
invalidContentType,
|
|
409
|
+
'',
|
|
410
|
+
[],
|
|
411
|
+
coachId
|
|
412
|
+
)
|
|
413
|
+
).rejects.toThrow("Invalid contentType: 'course' for coachId. It must be 'coach-lessons'.")
|
|
414
|
+
})
|
|
415
|
+
|
|
416
|
+
test('fetchCoachLessons-IncludedFields', async () => {
|
|
417
|
+
const response = await fetchCoachLessons('drumeo', 31880, {
|
|
418
|
+
includedFields: ['genre,Pop/Rock', 'difficulty,Beginner'],
|
|
419
|
+
})
|
|
420
|
+
log(response)
|
|
421
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
test('fetchAll-IncludedFields', async () => {
|
|
425
|
+
let response = await fetchAll('drumeo', 'instructor', { includedFields: ['is_active'] })
|
|
426
|
+
console.log(response)
|
|
427
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
428
|
+
})
|
|
429
|
+
|
|
430
|
+
test('fetchAll-IncludedFields-multiple', async () => {
|
|
431
|
+
let response = await fetchAll('drumeo', 'course', {
|
|
432
|
+
includedFields: ['essential,Dynamics', 'essential,Timing', 'difficulty,Beginner'],
|
|
433
|
+
})
|
|
434
|
+
log(response)
|
|
435
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
436
|
+
})
|
|
437
|
+
|
|
438
|
+
test('fetchAll-IncludedFields-playalong-multiple', async () => {
|
|
439
|
+
let response = await fetchAll('drumeo', 'play-along', {
|
|
440
|
+
includedFields: ['bpm,91-120', 'bpm,181+', 'genre,Blues'],
|
|
441
|
+
})
|
|
442
|
+
log(response)
|
|
443
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
test('fetchAll-IncludedFields-rudiment-multiple-gear', async () => {
|
|
447
|
+
let response = await fetchAll('drumeo', 'rudiment', {
|
|
448
|
+
includedFields: ['gear,Drum-Set', 'gear,Practice Pad'],
|
|
449
|
+
})
|
|
450
|
+
log(response)
|
|
451
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
test('fetchAll-IncludedFields-coaches-multiple-focus', async () => {
|
|
455
|
+
let response = await fetchAll('drumeo', 'instructor', {
|
|
456
|
+
includedFields: ['focus,Drumline', 'focus,Recording'],
|
|
457
|
+
})
|
|
458
|
+
log(response)
|
|
459
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
test('fetchAll-IncludedFields-songs-multiple-instrumentless', async () => {
|
|
463
|
+
let response = await fetchAll('drumeo', 'song', {
|
|
464
|
+
includedFields: ['instrumentless,true', 'instrumentless,false'],
|
|
465
|
+
})
|
|
466
|
+
log(response)
|
|
467
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
test('fetchByReference', async () => {
|
|
471
|
+
const response = await fetchByReference('drumeo', { includedFields: ['is_featured'] })
|
|
472
|
+
expect(response.entity.length).toBeGreaterThan(0)
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
test('fetchScheduledReleases', async () => {
|
|
476
|
+
const response = await fetchScheduledReleases('drumeo', {})
|
|
477
|
+
expect(response.length).toBeGreaterThan(0)
|
|
478
|
+
})
|
|
479
|
+
|
|
480
|
+
test('fetchAll-GroupBy-Genre', async () => {
|
|
481
|
+
let response = await fetchAll('drumeo', 'solo', { groupBy: 'genre' })
|
|
482
|
+
log(response)
|
|
483
|
+
expect(response.entity[0].web_url_path).toContain('/drumeo/genres/')
|
|
484
|
+
})
|
|
485
|
+
|
|
486
|
+
test('fetchAll-GroupBy-Artists', async () => {
|
|
487
|
+
let response = await fetchAll('drumeo', 'song', { groupBy: 'artist' })
|
|
488
|
+
log(response)
|
|
489
|
+
expect(response.entity[0].web_url_path).toContain('/drumeo/artists/')
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
test('fetchAll-GroupBy-Instructors', async () => {
|
|
493
|
+
let response = await fetchAll('drumeo', 'course', { groupBy: 'instructor' })
|
|
494
|
+
log(response)
|
|
495
|
+
expect(response.entity[0].web_url_path).toContain('/drumeo/coaches/')
|
|
496
|
+
})
|
|
497
|
+
|
|
498
|
+
test('fetchShowsData', async () => {
|
|
499
|
+
const response = await fetchShowsData('drumeo')
|
|
500
|
+
log(response)
|
|
501
|
+
expect(response.length).toBeGreaterThan(0)
|
|
502
|
+
const showTypes = response.map((x) => x.type)
|
|
503
|
+
expect(showTypes).toContain('live')
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
test('fetchMetadata', async () => {
|
|
507
|
+
const response = await fetchMetadata('drumeo', 'song')
|
|
508
|
+
log(response)
|
|
509
|
+
expect(response.tabs.length).toBeGreaterThan(0)
|
|
510
|
+
})
|
|
511
|
+
|
|
512
|
+
test('fetchShowsData-OddTimes', async () => {
|
|
513
|
+
const response = await fetchShowsData('drumeo')
|
|
514
|
+
log(response)
|
|
515
|
+
expect(response.length).toBeGreaterThan(0)
|
|
516
|
+
const showTypes = response.map((x) => x.type)
|
|
517
|
+
expect(showTypes).toContain('odd-times')
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
test('fetchMetadata-Coach-Lessons', async () => {
|
|
521
|
+
const response = await fetchMetadata('drumeo', 'coach-lessons')
|
|
522
|
+
log(response)
|
|
523
|
+
expect(response).toBeDefined()
|
|
524
|
+
})
|
|
525
|
+
|
|
526
|
+
test('fetchNextPreviousLesson-Show-With-Episodes', async () => {
|
|
527
|
+
const id = 227136
|
|
528
|
+
const document = await fetchByRailContentId(id, 'behind-the-scenes')
|
|
529
|
+
const response = await fetchNextPreviousLesson(id)
|
|
530
|
+
log(response)
|
|
531
|
+
expect(response.prevLesson).toBeDefined()
|
|
532
|
+
expect(response.prevLesson.sort).toBeLessThanOrEqual(document.sort)
|
|
533
|
+
expect(response.nextLesson).toBeDefined()
|
|
534
|
+
expect(response.nextLesson.sort).toBeGreaterThanOrEqual(document.sort)
|
|
535
|
+
})
|
|
536
|
+
|
|
537
|
+
test('fetchMethodNextPreviousLesson-Last', async () => {
|
|
538
|
+
const id = 260171
|
|
539
|
+
const methodId = 259060
|
|
540
|
+
const response = await fetchMethodPreviousNextLesson(id, methodId)
|
|
541
|
+
log(response)
|
|
542
|
+
expect(response.prevLesson).toBeDefined()
|
|
543
|
+
expect(response.prevLesson.id).toBe(260170)
|
|
544
|
+
expect(response.prevLesson.type).toBe('course-part')
|
|
545
|
+
expect(response.nextLesson).not.toBeDefined()
|
|
546
|
+
})
|
|
547
|
+
|
|
548
|
+
test('fetchNextPreviousLesson-Method-Lesson', async () => {
|
|
549
|
+
const id = 241265
|
|
550
|
+
const response = await fetchNextPreviousLesson(id)
|
|
551
|
+
log(response)
|
|
552
|
+
expect(response.prevLesson).toBeDefined()
|
|
553
|
+
expect(response.prevLesson.id).toBe(241264)
|
|
554
|
+
expect(response.prevLesson.type).toBe('learning-path-lesson')
|
|
555
|
+
expect(response.nextLesson).toBeDefined()
|
|
556
|
+
expect(response.nextLesson.id).toBe(241267)
|
|
557
|
+
expect(response.nextLesson.type).toBe('learning-path-lesson')
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
test('fetchNextPreviousLesson-Quick-Tips', async () => {
|
|
561
|
+
const id = 412277
|
|
562
|
+
const response = await fetchNextPreviousLesson(id)
|
|
563
|
+
const document = await fetchByRailContentId(id, 'quick-tips')
|
|
564
|
+
const documentPublishedOn = new Date(document.published_on)
|
|
565
|
+
const prevDocumentPublishedOn = new Date(response.prevLesson.published_on)
|
|
566
|
+
const nextDocumentPublishedOn = new Date(response.nextLesson.published_on)
|
|
567
|
+
expect(response.prevLesson).toBeDefined()
|
|
568
|
+
expect(prevDocumentPublishedOn.getTime()).toBeLessThan(documentPublishedOn.getTime())
|
|
569
|
+
expect(response.nextLesson).toBeDefined()
|
|
570
|
+
expect(documentPublishedOn.getTime()).toBeLessThan(nextDocumentPublishedOn.getTime())
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
test('fetchNextPreviousLesson-Song', async () => {
|
|
574
|
+
const id = 414041
|
|
575
|
+
const response = await fetchNextPreviousLesson(id)
|
|
576
|
+
const document = await fetchByRailContentId(id, 'song')
|
|
577
|
+
const documentPublishedOn = new Date(document.published_on)
|
|
578
|
+
const prevDocumentPublishedOn = new Date(response.prevLesson.published_on)
|
|
579
|
+
const nextDocumentPublishedOn = new Date(response.nextLesson.published_on)
|
|
580
|
+
expect(response.prevLesson).toBeDefined()
|
|
581
|
+
expect(prevDocumentPublishedOn.getTime()).toBeLessThanOrEqual(documentPublishedOn.getTime())
|
|
582
|
+
expect(response.nextLesson).toBeDefined()
|
|
583
|
+
expect(documentPublishedOn.getTime()).toBeLessThanOrEqual(nextDocumentPublishedOn.getTime())
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
test('fetchTopLevelParentId', async () => {
|
|
587
|
+
let contentId = await fetchTopLevelParentId(241250)
|
|
588
|
+
expect(contentId).toBe(241247)
|
|
589
|
+
contentId = await fetchTopLevelParentId(241249)
|
|
590
|
+
expect(contentId).toBe(241247)
|
|
591
|
+
contentId = await fetchTopLevelParentId(241248)
|
|
592
|
+
expect(contentId).toBe(241247)
|
|
593
|
+
contentId = await fetchTopLevelParentId(241247)
|
|
594
|
+
expect(contentId).toBe(241247)
|
|
595
|
+
contentId = await fetchTopLevelParentId(0)
|
|
596
|
+
expect(contentId).toBe(null)
|
|
597
|
+
})
|
|
598
|
+
|
|
599
|
+
test('fetchHierarchy', async () => {
|
|
600
|
+
let hierarchy = await fetchHierarchy(241250)
|
|
601
|
+
expect(hierarchy.parents[241250]).toBe(241249)
|
|
602
|
+
expect(hierarchy.parents[241249]).toBe(241248)
|
|
603
|
+
expect(hierarchy.parents[241248]).toBe(241247)
|
|
604
|
+
expect(hierarchy.children[241250]).toStrictEqual([241676])
|
|
605
|
+
expect(hierarchy.children[243085]).toStrictEqual([243170, 243171, 243172, 243174, 243176])
|
|
606
|
+
})
|
|
607
|
+
|
|
608
|
+
test('fetchTopLeveldrafts', async () => {
|
|
609
|
+
let id = await fetchTopLevelParentId(401999)
|
|
610
|
+
expect(id).toBe(401999)
|
|
611
|
+
})
|
|
612
|
+
|
|
613
|
+
test('fetchCommentData', async () => {
|
|
614
|
+
let data = await fetchCommentModContentData([241251, 241252, 211153])
|
|
615
|
+
expect(data[241251].title).toBe('Setting Up Your Space')
|
|
616
|
+
expect(data[241251].type).toBe('learning-path-lesson')
|
|
617
|
+
expect(data[241251].url).toBe(
|
|
618
|
+
'/drumeo/method/drumeo-method/241247/getting-started-on-the-drums/241248/gear/241249/setting-up-your-space/241251'
|
|
619
|
+
)
|
|
620
|
+
expect(data[241251].parentTitle).toBe('Gear')
|
|
621
|
+
expect(data[241252].title).toBe('Setting Up Your Pedals & Throne')
|
|
622
|
+
})
|
|
623
|
+
})
|
|
737
624
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
})
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
})
|
|
777
|
-
|
|
625
|
+
describe('Filter Builder', function () {
|
|
626
|
+
beforeEach(() => {
|
|
627
|
+
initializeTestService()
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
test('baseConstructor', async () => {
|
|
631
|
+
const filter = 'railcontent_id = 111'
|
|
632
|
+
let builder = new FilterBuilder(filter, { bypassPermissions: true })
|
|
633
|
+
let finalFilter = await builder.buildFilter(filter)
|
|
634
|
+
let clauses = spliceFilterForAnds(finalFilter)
|
|
635
|
+
expect(clauses[0].phrase).toBe(filter)
|
|
636
|
+
expect(clauses[1].field).toBe('(status')
|
|
637
|
+
expect(clauses[3].field).toBe('published_on')
|
|
638
|
+
|
|
639
|
+
builder = new FilterBuilder('', { bypassPermissions: true })
|
|
640
|
+
finalFilter = await builder.buildFilter(filter)
|
|
641
|
+
clauses = spliceFilterForAnds(finalFilter)
|
|
642
|
+
expect(clauses[0].field).toBe('(status')
|
|
643
|
+
expect(clauses[0].operator).toBe('in')
|
|
644
|
+
expect(clauses[2].field).toBe('published_on')
|
|
645
|
+
expect(clauses[2].operator).toBe('>=')
|
|
646
|
+
})
|
|
647
|
+
|
|
648
|
+
test('withOnlyFilterAvailableStatuses', async () => {
|
|
649
|
+
const filter = 'railcontent_id = 111'
|
|
650
|
+
const builder = FilterBuilder.withOnlyFilterAvailableStatuses(
|
|
651
|
+
filter,
|
|
652
|
+
['published', 'unlisted'],
|
|
653
|
+
true
|
|
654
|
+
)
|
|
655
|
+
const finalFilter = await builder.buildFilter()
|
|
656
|
+
const clauses = spliceFilterForAnds(finalFilter)
|
|
657
|
+
expect(clauses[0].phrase).toBe(filter)
|
|
658
|
+
expect(clauses[1].field).toBe('status')
|
|
659
|
+
expect(clauses[1].operator).toBe('in')
|
|
660
|
+
// not sure I like this
|
|
661
|
+
expect(clauses[1].condition).toBe("['published','unlisted']")
|
|
662
|
+
expect(clauses[2].field).toBe('published_on')
|
|
663
|
+
})
|
|
664
|
+
|
|
665
|
+
test('withContentStatusAndFutureScheduledContent', async () => {
|
|
666
|
+
const filter = 'railcontent_id = 111'
|
|
667
|
+
const builder = new FilterBuilder(filter, {
|
|
668
|
+
availableContentStatuses: ['published', 'unlisted', 'scheduled'],
|
|
669
|
+
getFutureScheduledContentsOnly: true,
|
|
670
|
+
})
|
|
671
|
+
const finalFilter = await builder.buildFilter()
|
|
672
|
+
const clauses = spliceFilterForAnds(finalFilter)
|
|
673
|
+
expect(clauses[0].phrase).toBe(filter)
|
|
674
|
+
expect(clauses[1].field).toBe('(status') // extra ( because it's a multi part filter
|
|
675
|
+
expect(clauses[1].operator).toBe('in')
|
|
676
|
+
// getFutureScheduledContentsOnly doesn't make a filter that's splicable, so we match on the more static string
|
|
677
|
+
const expected =
|
|
678
|
+
"['published','unlisted'] || (status == 'scheduled' && defined(published_on) && published_on >="
|
|
679
|
+
const isMatch = finalFilter.includes(expected)
|
|
680
|
+
expect(isMatch).toBeTruthy()
|
|
681
|
+
})
|
|
682
|
+
|
|
683
|
+
test('withUserPermissions', async () => {
|
|
684
|
+
const filter = 'railcontent_id = 111'
|
|
685
|
+
const builder = new FilterBuilder(filter)
|
|
686
|
+
const finalFilter = await builder.buildFilter()
|
|
687
|
+
const expected = "references(*[_type == 'permission' && railcontent_id in [78,91,92]]._id)"
|
|
688
|
+
const isMatch = finalFilter.includes(expected)
|
|
689
|
+
expect(isMatch).toBeTruthy()
|
|
690
|
+
})
|
|
691
|
+
|
|
692
|
+
test('withUserPermissionsForPlusUser', async () => {
|
|
693
|
+
const filter = 'railcontent_id = 111'
|
|
694
|
+
const builder = new FilterBuilder(filter)
|
|
695
|
+
const finalFilter = await builder.buildFilter()
|
|
696
|
+
const expected = "references(*[_type == 'permission' && railcontent_id in [78,91,92]]._id)"
|
|
697
|
+
const isMatch = finalFilter.includes(expected)
|
|
698
|
+
expect(isMatch).toBeTruthy()
|
|
699
|
+
})
|
|
700
|
+
|
|
701
|
+
test('withPermissionBypass', async () => {
|
|
702
|
+
const filter = 'railcontent_id = 111'
|
|
703
|
+
const builder = new FilterBuilder(filter, {
|
|
704
|
+
bypassPermissions: true,
|
|
705
|
+
pullFutureContent: false,
|
|
706
|
+
})
|
|
707
|
+
const finalFilter = await builder.buildFilter()
|
|
708
|
+
const expected = "references(*[_type == 'permission' && railcontent_id in [78,91,92]]._id)"
|
|
709
|
+
const isMatch = finalFilter.includes(expected)
|
|
710
|
+
expect(isMatch).toBeFalsy()
|
|
711
|
+
const clauses = spliceFilterForAnds(finalFilter)
|
|
712
|
+
expect(clauses[0].field).toBe('railcontent_id')
|
|
713
|
+
expect(clauses[1].field).toBe('(status')
|
|
714
|
+
expect(clauses[3].field).toBe('published_on')
|
|
715
|
+
})
|
|
716
|
+
|
|
717
|
+
test('withPublishOnRestrictions', async () => {
|
|
718
|
+
// testing dates is a pain more frustration than I'm willing to deal with, so I'm just testing operators.
|
|
719
|
+
|
|
720
|
+
const filter = 'railcontent_id = 111'
|
|
721
|
+
let builder = new FilterBuilder(filter, {
|
|
722
|
+
pullFutureContent: true,
|
|
723
|
+
bypassPermissions: true,
|
|
724
|
+
})
|
|
725
|
+
|
|
726
|
+
let finalFilter = await builder.buildFilter()
|
|
727
|
+
let clauses = spliceFilterForAnds(finalFilter)
|
|
728
|
+
expect(clauses[0].phrase).toBe(filter)
|
|
729
|
+
expect(clauses[1].field).toBe('(status')
|
|
730
|
+
expect(clauses[1].operator).toBe('in')
|
|
731
|
+
expect(clauses[2].phrase).toBe('defined(published_on)')
|
|
732
|
+
expect(clauses[3].field).toBe('published_on')
|
|
733
|
+
|
|
734
|
+
builder = new FilterBuilder(filter, {
|
|
735
|
+
getFutureContentOnly: true,
|
|
736
|
+
bypassPermissions: true,
|
|
737
|
+
})
|
|
738
|
+
finalFilter = await builder.buildFilter()
|
|
739
|
+
clauses = spliceFilterForAnds(finalFilter)
|
|
740
|
+
expect(clauses[0].phrase).toBe(filter)
|
|
741
|
+
expect(clauses[3].field).toBe('published_on')
|
|
742
|
+
expect(clauses[3].operator).toBe('>=')
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
function spliceFilterForAnds(filter) {
|
|
746
|
+
// this will not correctly split complex filters with && and || conditions.
|
|
747
|
+
let phrases = filter.split(' && ')
|
|
748
|
+
let clauses = []
|
|
749
|
+
phrases.forEach((phrase) => {
|
|
750
|
+
let field = phrase.substring(0, phrase.indexOf(' '))
|
|
751
|
+
//if(field.charAt(0) === '(' ) field = field.substring(1);
|
|
752
|
+
const temp = phrase.substring(phrase.indexOf(' ') + 1)
|
|
753
|
+
const operator = temp.substring(0, temp.indexOf(' '))
|
|
754
|
+
let condition = temp.substring(temp.indexOf(' ') + 1)
|
|
755
|
+
//if(condition.charAt(condition.length) === ')') condition = condition.slice(-1);
|
|
756
|
+
clauses.push({ phrase, field, operator, condition })
|
|
757
|
+
})
|
|
758
|
+
return clauses
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
test('fetchAllFilterOptions', async () => {
|
|
762
|
+
let response = await fetchAllFilterOptions('drumeo', [], '', '', 'song', '')
|
|
763
|
+
log(response)
|
|
764
|
+
expect(response.meta.filterOptions.difficulty).toBeDefined()
|
|
765
|
+
expect(response.meta.filterOptions.genre).toBeDefined()
|
|
766
|
+
expect(response.meta.filterOptions.lifestyle).toBeDefined()
|
|
767
|
+
expect(response.meta.filterOptions.instrumentless).toBeDefined()
|
|
768
|
+
})
|
|
769
|
+
|
|
770
|
+
test('fetchAllFilterOptions-Rudiment', async () => {
|
|
771
|
+
let response = await fetchAllFilterOptions('drumeo', [], '', '', 'rudiment', '')
|
|
772
|
+
log(response)
|
|
773
|
+
expect(response.meta.filterOptions.gear).toBeDefined()
|
|
774
|
+
expect(response.meta.filterOptions.genre).toBeDefined()
|
|
775
|
+
expect(response.meta.filterOptions.topic).toBeDefined()
|
|
776
|
+
})
|
|
777
|
+
test('fetchAllFilterOptions-PlayAlong', async () => {
|
|
778
|
+
let response = await fetchAllFilterOptions('drumeo', [], '', '', 'play-along', '')
|
|
779
|
+
log(response)
|
|
780
|
+
expect(response.meta.filterOptions.difficulty).toBeDefined()
|
|
781
|
+
expect(response.meta.filterOptions.genre).toBeDefined()
|
|
782
|
+
expect(response.meta.filterOptions.bpm).toBeDefined()
|
|
783
|
+
})
|
|
784
|
+
|
|
785
|
+
test('fetchAllFilterOptions-Coaches', async () => {
|
|
786
|
+
let response = await fetchAllFilterOptions('drumeo', [], '', '', 'instructor', '')
|
|
787
|
+
log(response)
|
|
788
|
+
expect(response.meta.filterOptions.focus).toBeDefined()
|
|
789
|
+
expect(response.meta.filterOptions.focus.length).toBeGreaterThan(0)
|
|
790
|
+
expect(response.meta.filterOptions.genre).toBeDefined()
|
|
791
|
+
expect(response.meta.filterOptions.genre.length).toBeGreaterThan(0)
|
|
792
|
+
})
|
|
793
|
+
|
|
794
|
+
test('fetchAllFilterOptions-filter-selected', async () => {
|
|
795
|
+
let response = await fetchAllFilterOptions(
|
|
796
|
+
'drumeo',
|
|
797
|
+
[
|
|
798
|
+
'theory,notation',
|
|
799
|
+
'theory,time signatures',
|
|
800
|
+
'creativity,Grooves',
|
|
801
|
+
'creativity,Fills & Chops',
|
|
802
|
+
'difficulty,Beginner',
|
|
803
|
+
'difficulty,Intermediate',
|
|
804
|
+
'difficulty,Expert',
|
|
805
|
+
],
|
|
806
|
+
'',
|
|
807
|
+
'',
|
|
808
|
+
'course',
|
|
809
|
+
''
|
|
810
|
+
)
|
|
811
|
+
log(response)
|
|
812
|
+
expect(response.meta.filterOptions).toBeDefined()
|
|
813
|
+
})
|
|
814
|
+
})
|
|
778
815
|
|
|
779
816
|
describe('MetaData', function () {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
});
|
|
817
|
+
test('customBrandTypeExists', async () => {
|
|
818
|
+
const metaData = processMetadata('guitareo', 'recording')
|
|
819
|
+
expect(metaData.type).toBe('recording')
|
|
820
|
+
expect(metaData.name).toBe('Archives')
|
|
821
|
+
expect(metaData.description).toBeDefined()
|
|
822
|
+
})
|
|
823
|
+
|
|
824
|
+
test('invalidContentType', async () => {
|
|
825
|
+
const metaData = processMetadata('guitareo', 'not a real type')
|
|
826
|
+
expect(metaData).toBeNull()
|
|
827
|
+
})
|
|
828
|
+
|
|
829
|
+
test('onlyCommon', async () => {
|
|
830
|
+
const guitareoMetaData = processMetadata('guitareo', 'challenge')
|
|
831
|
+
const drumeoMetaData = processMetadata('drumeo', 'challenge')
|
|
832
|
+
guitareoMetaData.url = ''
|
|
833
|
+
drumeoMetaData.url = ''
|
|
834
|
+
expect(guitareoMetaData).toStrictEqual(drumeoMetaData)
|
|
835
|
+
expect(guitareoMetaData.type).toBe('challenge')
|
|
836
|
+
expect(guitareoMetaData.name).toBe('Challenges')
|
|
837
|
+
})
|
|
838
|
+
|
|
839
|
+
test('withCommon', async () => {
|
|
840
|
+
const guitareoMetaData = processMetadata('guitareo', 'instructor')
|
|
841
|
+
const drumeoMetaData = processMetadata('drumeo', 'instructor')
|
|
842
|
+
expect(guitareoMetaData.description).not.toBe(drumeoMetaData.description)
|
|
843
|
+
guitareoMetaData.description = ''
|
|
844
|
+
drumeoMetaData.description = ''
|
|
845
|
+
guitareoMetaData.url = ''
|
|
846
|
+
drumeoMetaData.url = ''
|
|
847
|
+
expect(guitareoMetaData).toStrictEqual(drumeoMetaData)
|
|
848
|
+
})
|
|
849
|
+
|
|
850
|
+
test('withWithoutFilters', async () => {
|
|
851
|
+
let metaData = processMetadata('singeo', 'student-review', true)
|
|
852
|
+
expect(metaData.type).toBeDefined()
|
|
853
|
+
expect(metaData.name).toBeDefined()
|
|
854
|
+
expect(metaData.description).toBeDefined()
|
|
855
|
+
expect(metaData.thumbnailUrl).toBeDefined()
|
|
856
|
+
expect(metaData.tabs).toBeDefined()
|
|
857
|
+
metaData = processMetadata('singeo', 'student-review', false)
|
|
858
|
+
expect(metaData.type).toBeDefined()
|
|
859
|
+
expect(metaData.name).toBeDefined()
|
|
860
|
+
expect(metaData.description).toBeDefined()
|
|
861
|
+
expect(metaData.tabs).not.toBeDefined()
|
|
862
|
+
})
|
|
863
|
+
|
|
864
|
+
test('nulled', async () => {
|
|
865
|
+
let metaData = processMetadata('drumeo', 'student-review')
|
|
866
|
+
expect(metaData).toBeNull()
|
|
867
|
+
metaData = processMetadata('singeo', 'student-review')
|
|
868
|
+
expect(metaData).not.toBeNull()
|
|
869
|
+
})
|
|
870
|
+
})
|