aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/peertube-plugin-test-video-constants/main.js58
-rw-r--r--server/tests/lib/plugins/video-constant-registry-factory.test.ts155
-rw-r--r--server/tests/plugins/video-constants.ts37
3 files changed, 219 insertions, 31 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-video-constants/main.js b/server/tests/fixtures/peertube-plugin-test-video-constants/main.js
index 3e650e0a1..f44704a44 100644
--- a/server/tests/fixtures/peertube-plugin-test-video-constants/main.js
+++ b/server/tests/fixtures/peertube-plugin-test-video-constants/main.js
@@ -1,46 +1,44 @@
1async function register ({ 1async function register ({
2 registerHook,
3 registerSetting,
4 settingsManager,
5 storageManager,
6 videoCategoryManager, 2 videoCategoryManager,
7 videoLicenceManager, 3 videoLicenceManager,
8 videoLanguageManager, 4 videoLanguageManager,
9 videoPrivacyManager, 5 videoPrivacyManager,
10 playlistPrivacyManager 6 playlistPrivacyManager,
7 getRouter
11}) { 8}) {
12 videoLanguageManager.addLanguage('al_bhed', 'Al Bhed') 9 videoLanguageManager.addConstant('al_bhed', 'Al Bhed')
13 videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2') 10 videoLanguageManager.addConstant('al_bhed2', 'Al Bhed 2')
14 videoLanguageManager.addLanguage('al_bhed3', 'Al Bhed 3') 11 videoLanguageManager.addConstant('al_bhed3', 'Al Bhed 3')
15 videoLanguageManager.deleteLanguage('en') 12 videoLanguageManager.deleteConstant('en')
16 videoLanguageManager.deleteLanguage('fr') 13 videoLanguageManager.deleteConstant('fr')
17 videoLanguageManager.deleteLanguage('al_bhed3') 14 videoLanguageManager.deleteConstant('al_bhed3')
18 15
19 videoCategoryManager.addCategory(42, 'Best category') 16 videoCategoryManager.addConstant(42, 'Best category')
20 videoCategoryManager.addCategory(43, 'High best category') 17 videoCategoryManager.addConstant(43, 'High best category')
21 videoCategoryManager.deleteCategory(1) // Music 18 videoCategoryManager.deleteConstant(1) // Music
22 videoCategoryManager.deleteCategory(2) // Films 19 videoCategoryManager.deleteConstant(2) // Films
23 20
24 videoLicenceManager.addLicence(42, 'Best licence') 21 videoLicenceManager.addConstant(42, 'Best licence')
25 videoLicenceManager.addLicence(43, 'High best licence') 22 videoLicenceManager.addConstant(43, 'High best licence')
26 videoLicenceManager.deleteLicence(1) // Attribution 23 videoLicenceManager.deleteConstant(1) // Attribution
27 videoLicenceManager.deleteLicence(7) // Public domain 24 videoLicenceManager.deleteConstant(7) // Public domain
28 25
29 videoPrivacyManager.deletePrivacy(2) 26 videoPrivacyManager.deleteConstant(2)
30 playlistPrivacyManager.deletePlaylistPrivacy(3) 27 playlistPrivacyManager.deleteConstant(3)
31} 28
29 {
30 const router = getRouter()
31 router.get('/reset-categories', (req, res) => {
32 videoCategoryManager.resetConstants()
32 33
33async function unregister () { 34 res.sendStatus(204)
34 return 35 })
36 }
35} 37}
36 38
39async function unregister () {}
40
37module.exports = { 41module.exports = {
38 register, 42 register,
39 unregister 43 unregister
40} 44}
41
42// ############################################################################
43
44function addToCount (obj) {
45 return Object.assign({}, obj, { count: obj.count + 1 })
46}
diff --git a/server/tests/lib/plugins/video-constant-registry-factory.test.ts b/server/tests/lib/plugins/video-constant-registry-factory.test.ts
new file mode 100644
index 000000000..e26b286e1
--- /dev/null
+++ b/server/tests/lib/plugins/video-constant-registry-factory.test.ts
@@ -0,0 +1,155 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions */
2import 'mocha'
3import { expect } from 'chai'
4import { VideoConstantManagerFactory } from '@server/lib/plugins/video-constant-manager-factory'
5import {
6 VIDEO_CATEGORIES,
7 VIDEO_LANGUAGES,
8 VIDEO_LICENCES,
9 VIDEO_PLAYLIST_PRIVACIES,
10 VIDEO_PRIVACIES
11} from '@server/initializers/constants'
12import {
13 VideoPlaylistPrivacy,
14 VideoPrivacy
15} from '@shared/models'
16
17describe('VideoConstantManagerFactory', function () {
18 const factory = new VideoConstantManagerFactory('peertube-plugin-constants')
19
20 afterEach(() => {
21 factory.resetVideoConstants('peertube-plugin-constants')
22 })
23
24 describe('VideoCategoryManager', () => {
25 const videoCategoryManager = factory.createVideoConstantManager<number>('category')
26
27 it('Should be able to list all video category constants', () => {
28 const constants = videoCategoryManager.getConstants()
29 expect(constants).to.deep.equal(VIDEO_CATEGORIES)
30 })
31
32 it('Should be able to delete a video category constant', () => {
33 const successfullyDeleted = videoCategoryManager.deleteConstant(1)
34 expect(successfullyDeleted).to.be.true
35 expect(videoCategoryManager.getConstantValue(1)).to.be.undefined
36 })
37
38 it('Should be able to add a video category constant', () => {
39 const successfullyAdded = videoCategoryManager.addConstant(42, 'The meaning of life')
40 expect(successfullyAdded).to.be.true
41 expect(videoCategoryManager.getConstantValue(42)).to.equal('The meaning of life')
42 })
43
44 it('Should be able to reset video category constants', () => {
45 videoCategoryManager.deleteConstant(1)
46 videoCategoryManager.resetConstants()
47 expect(videoCategoryManager.getConstantValue(1)).not.be.undefined
48 })
49 })
50
51 describe('VideoLicenceManager', () => {
52 const videoLicenceManager = factory.createVideoConstantManager<number>('licence')
53 it('Should be able to list all video licence constants', () => {
54 const constants = videoLicenceManager.getConstants()
55 expect(constants).to.deep.equal(VIDEO_LICENCES)
56 })
57
58 it('Should be able to delete a video licence constant', () => {
59 const successfullyDeleted = videoLicenceManager.deleteConstant(1)
60 expect(successfullyDeleted).to.be.true
61 expect(videoLicenceManager.getConstantValue(1)).to.be.undefined
62 })
63
64 it('Should be able to add a video licence constant', () => {
65 const successfullyAdded = videoLicenceManager.addConstant(42, 'European Union Public Licence')
66 expect(successfullyAdded).to.be.true
67 expect(videoLicenceManager.getConstantValue(42)).to.equal('European Union Public Licence')
68 })
69
70 it('Should be able to reset video licence constants', () => {
71 videoLicenceManager.deleteConstant(1)
72 videoLicenceManager.resetConstants()
73 expect(videoLicenceManager.getConstantValue(1)).not.be.undefined
74 })
75 })
76
77 describe('PlaylistPrivacyManager', () => {
78 const playlistPrivacyManager = factory.createVideoConstantManager<VideoPlaylistPrivacy>('playlistPrivacy')
79 it('Should be able to list all video playlist privacy constants', () => {
80 const constants = playlistPrivacyManager.getConstants()
81 expect(constants).to.deep.equal(VIDEO_PLAYLIST_PRIVACIES)
82 })
83
84 it('Should be able to delete a video playlist privacy constant', () => {
85 const successfullyDeleted = playlistPrivacyManager.deleteConstant(1)
86 expect(successfullyDeleted).to.be.true
87 expect(playlistPrivacyManager.getConstantValue(1)).to.be.undefined
88 })
89
90 it('Should be able to add a video playlist privacy constant', () => {
91 const successfullyAdded = playlistPrivacyManager.addConstant(42, 'Friends only')
92 expect(successfullyAdded).to.be.true
93 expect(playlistPrivacyManager.getConstantValue(42)).to.equal('Friends only')
94 })
95
96 it('Should be able to reset video playlist privacy constants', () => {
97 playlistPrivacyManager.deleteConstant(1)
98 playlistPrivacyManager.resetConstants()
99 expect(playlistPrivacyManager.getConstantValue(1)).not.be.undefined
100 })
101 })
102
103 describe('VideoPrivacyManager', () => {
104 const videoPrivacyManager = factory.createVideoConstantManager<VideoPrivacy>('privacy')
105 it('Should be able to list all video privacy constants', () => {
106 const constants = videoPrivacyManager.getConstants()
107 expect(constants).to.deep.equal(VIDEO_PRIVACIES)
108 })
109
110 it('Should be able to delete a video privacy constant', () => {
111 const successfullyDeleted = videoPrivacyManager.deleteConstant(1)
112 expect(successfullyDeleted).to.be.true
113 expect(videoPrivacyManager.getConstantValue(1)).to.be.undefined
114 })
115
116 it('Should be able to add a video privacy constant', () => {
117 const successfullyAdded = videoPrivacyManager.addConstant(42, 'Friends only')
118 expect(successfullyAdded).to.be.true
119 expect(videoPrivacyManager.getConstantValue(42)).to.equal('Friends only')
120 })
121
122 it('Should be able to reset video privacy constants', () => {
123 videoPrivacyManager.deleteConstant(1)
124 videoPrivacyManager.resetConstants()
125 expect(videoPrivacyManager.getConstantValue(1)).not.be.undefined
126 })
127 })
128
129 describe('VideoLanguageManager', () => {
130 const videoLanguageManager = factory.createVideoConstantManager<string>('language')
131 it('Should be able to list all video language constants', () => {
132 const constants = videoLanguageManager.getConstants()
133 expect(constants).to.deep.equal(VIDEO_LANGUAGES)
134 })
135
136 it('Should be able to add a video language constant', () => {
137 const successfullyAdded = videoLanguageManager.addConstant('fr', 'Fr occitan')
138 expect(successfullyAdded).to.be.true
139 expect(videoLanguageManager.getConstantValue('fr')).to.equal('Fr occitan')
140 })
141
142 it('Should be able to delete a video language constant', () => {
143 videoLanguageManager.addConstant('fr', 'Fr occitan')
144 const successfullyDeleted = videoLanguageManager.deleteConstant('fr')
145 expect(successfullyDeleted).to.be.true
146 expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined
147 })
148
149 it('Should be able to reset video language constants', () => {
150 videoLanguageManager.addConstant('fr', 'Fr occitan')
151 videoLanguageManager.resetConstants()
152 expect(videoLanguageManager.getConstantValue('fr')).to.be.undefined
153 })
154 })
155})
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts
index eb014c596..7b1312f88 100644
--- a/server/tests/plugins/video-constants.ts
+++ b/server/tests/plugins/video-constants.ts
@@ -9,8 +9,11 @@ import {
9 getVideo, 9 getVideo,
10 getVideoCategories, 10 getVideoCategories,
11 getVideoLanguages, 11 getVideoLanguages,
12 getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies, 12 getVideoLicences,
13 getVideoPlaylistPrivacies,
14 getVideoPrivacies,
13 installPlugin, 15 installPlugin,
16 makeGetRequest,
14 setAccessTokensToServers, 17 setAccessTokensToServers,
15 uninstallPlugin, 18 uninstallPlugin,
16 uploadVideo 19 uploadVideo
@@ -173,6 +176,38 @@ describe('Test plugin altering video constants', function () {
173 } 176 }
174 }) 177 })
175 178
179 it('Should be able to reset categories', async function () {
180 await installPlugin({
181 url: server.url,
182 accessToken: server.accessToken,
183 path: getPluginTestPath('-video-constants')
184 })
185
186 let { body: categories } = await getVideoCategories(server.url)
187
188 expect(categories[1]).to.not.exist
189 expect(categories[2]).to.not.exist
190
191 expect(categories[42]).to.exist
192 expect(categories[43]).to.exist
193
194 await makeGetRequest({
195 url: server.url,
196 token: server.accessToken,
197 path: '/plugins/test-video-constants/router/reset-categories',
198 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
199 })
200
201 const { body } = await getVideoCategories(server.url)
202 categories = body
203
204 expect(categories[1]).to.exist
205 expect(categories[2]).to.exist
206
207 expect(categories[42]).to.not.exist
208 expect(categories[43]).to.not.exist
209 })
210
176 after(async function () { 211 after(async function () {
177 await cleanupTests([ server ]) 212 await cleanupTests([ server ])
178 }) 213 })