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,26 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "./railcontent.js";
|
|
4
|
-
import {setLastUpdatedTime, wasLastUpdateOlderThanXSeconds} from "./lastUpdated.js";
|
|
1
|
+
import { fetchUserPermissionsData } from './railcontent.js'
|
|
2
|
+
import { setLastUpdatedTime, wasLastUpdateOlderThanXSeconds } from './lastUpdated.js'
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Exported functions that are excluded from index generation.
|
|
8
6
|
*
|
|
9
7
|
* @type {string[]}
|
|
10
8
|
*/
|
|
11
|
-
const excludeFromGeneratedIndex = []
|
|
12
|
-
let userPermissionsPromise = null
|
|
13
|
-
let lastUpdatedKey = `userPermissions_lastUpdated
|
|
9
|
+
const excludeFromGeneratedIndex = []
|
|
10
|
+
let userPermissionsPromise = null
|
|
11
|
+
let lastUpdatedKey = `userPermissions_lastUpdated`
|
|
14
12
|
|
|
15
13
|
export async function fetchUserPermissions() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (!userPermissionsPromise || wasLastUpdateOlderThanXSeconds(10, lastUpdatedKey)) {
|
|
15
|
+
userPermissionsPromise = fetchUserPermissionsData()
|
|
16
|
+
setLastUpdatedTime(lastUpdatedKey)
|
|
17
|
+
}
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
return await userPermissionsPromise
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
export async function reset() {
|
|
25
|
-
|
|
26
|
-
}
|
|
23
|
+
userPermissionsPromise = null
|
|
24
|
+
}
|
|
@@ -1,90 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
isContentLiked,
|
|
3
|
+
dataContext,
|
|
4
|
+
likeContent,
|
|
5
|
+
unlikeContent,
|
|
6
|
+
} from '../src/services/contentLikes'
|
|
7
|
+
import { initializeTestService } from './initializeTests'
|
|
3
8
|
|
|
4
9
|
const railContentModule = require('../src/services/railcontent.js')
|
|
5
10
|
|
|
6
11
|
describe('contentLikesDataContext', function () {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
12
|
+
let mock = null
|
|
13
|
+
const testVersion = 1
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
initializeTestService()
|
|
17
|
+
mock = jest.spyOn(dataContext, 'fetchData')
|
|
18
|
+
var json = JSON.parse(`{"version":${testVersion},"data":[308516,308515,308514,308518]}`)
|
|
19
|
+
mock.mockImplementation(() => json)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('contentLiked', async () => {
|
|
23
|
+
let result = await isContentLiked(308516)
|
|
24
|
+
expect(result).toBe(true)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('contentLikedStringInput', async () => {
|
|
28
|
+
let result = await isContentLiked('308516')
|
|
29
|
+
expect(result).toBe(true)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('contentNotLiked', async () => {
|
|
33
|
+
let result = await isContentLiked(121111)
|
|
34
|
+
expect(result).toBe(false)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('ensureOnlyOneServerFetchRequest', async () => {
|
|
38
|
+
dataContext.clearCache()
|
|
39
|
+
await isContentLiked(308516)
|
|
40
|
+
await isContentLiked(308514)
|
|
41
|
+
await isContentLiked(121111)
|
|
42
|
+
expect(dataContext.fetchData).toHaveBeenCalledTimes(1)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('ensureDataPulledFromLocalCache', async () => {
|
|
46
|
+
dataContext.clearCache()
|
|
47
|
+
await isContentLiked(308516)
|
|
48
|
+
dataContext.clearContext()
|
|
49
|
+
await isContentLiked(308514)
|
|
50
|
+
expect(dataContext.fetchData).toHaveBeenCalledTimes(1)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('likeContent', async () => {
|
|
54
|
+
mock = jest.spyOn(railContentModule, 'postContentLiked')
|
|
55
|
+
var json = JSON.parse(`{"version":${testVersion + 1}}`)
|
|
56
|
+
mock.mockImplementation(() => json)
|
|
57
|
+
|
|
58
|
+
dataContext.clearCache()
|
|
59
|
+
let isLiked = await isContentLiked(111111)
|
|
60
|
+
expect(isLiked).toBe(false)
|
|
61
|
+
|
|
62
|
+
await likeContent(111111)
|
|
63
|
+
isLiked = await isContentLiked(111111)
|
|
64
|
+
expect(isLiked).toBe(true)
|
|
65
|
+
|
|
66
|
+
dataContext.clearContext()
|
|
67
|
+
isLiked = await isContentLiked(111111)
|
|
68
|
+
expect(isLiked).toBe(true)
|
|
69
|
+
|
|
70
|
+
expect(dataContext.version()).toBe(testVersion + 1)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('unlikeContent', async () => {
|
|
74
|
+
mock = jest.spyOn(railContentModule, 'postContentUnliked')
|
|
75
|
+
var json = JSON.parse(`{"version":${testVersion + 1}}`)
|
|
76
|
+
mock.mockImplementation(() => json)
|
|
77
|
+
|
|
78
|
+
dataContext.clearCache()
|
|
79
|
+
let isLiked = await isContentLiked(308516)
|
|
80
|
+
expect(isLiked).toBe(true)
|
|
81
|
+
|
|
82
|
+
await unlikeContent(308516)
|
|
83
|
+
console.log(dataContext.context)
|
|
84
|
+
isLiked = await isContentLiked(308516)
|
|
85
|
+
expect(isLiked).toBe(false)
|
|
86
|
+
|
|
87
|
+
dataContext.clearContext()
|
|
88
|
+
isLiked = await isContentLiked(308516)
|
|
89
|
+
expect(isLiked).toBe(false)
|
|
90
|
+
|
|
91
|
+
expect(dataContext.version()).toBe(testVersion + 1)
|
|
92
|
+
})
|
|
93
|
+
})
|