diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-26 13:13:39 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-07-26 15:18:30 +0200 |
commit | ee286591a5b740702bad66c55cc900740f749e9a (patch) | |
tree | 16503d1299a107c5972ba16f95228b1ebce20f79 /server/tests | |
parent | 16d54696294d15f8ab6ba3a6bcfac21528fec2f2 (diff) | |
download | PeerTube-ee286591a5b740702bad66c55cc900740f749e9a.tar.gz PeerTube-ee286591a5b740702bad66c55cc900740f749e9a.tar.zst PeerTube-ee286591a5b740702bad66c55cc900740f749e9a.zip |
Plugins can update video constants
Categories, licences and languages
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-three/main.js | 39 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-three/package.json | 19 | ||||
-rw-r--r-- | server/tests/plugins/index.ts | 1 | ||||
-rw-r--r-- | server/tests/plugins/video-constants.ts | 140 |
4 files changed, 199 insertions, 0 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-three/main.js b/server/tests/fixtures/peertube-plugin-test-three/main.js new file mode 100644 index 000000000..4945feb55 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-three/main.js | |||
@@ -0,0 +1,39 @@ | |||
1 | async function register ({ | ||
2 | registerHook, | ||
3 | registerSetting, | ||
4 | settingsManager, | ||
5 | storageManager, | ||
6 | videoCategoryManager, | ||
7 | videoLicenceManager, | ||
8 | videoLanguageManager | ||
9 | }) { | ||
10 | videoLanguageManager.addLanguage('al_bhed', 'Al Bhed') | ||
11 | videoLanguageManager.addLanguage('al_bhed2', 'Al Bhed 2') | ||
12 | videoLanguageManager.deleteLanguage('en') | ||
13 | videoLanguageManager.deleteLanguage('fr') | ||
14 | |||
15 | videoCategoryManager.addCategory(42, 'Best category') | ||
16 | videoCategoryManager.addCategory(43, 'High best category') | ||
17 | videoCategoryManager.deleteCategory(1) // Music | ||
18 | videoCategoryManager.deleteCategory(2) // Films | ||
19 | |||
20 | videoLicenceManager.addLicence(42, 'Best licence') | ||
21 | videoLicenceManager.addLicence(43, 'High best licence') | ||
22 | videoLicenceManager.deleteLicence(1) // Attribution | ||
23 | videoLicenceManager.deleteLicence(7) // Public domain | ||
24 | } | ||
25 | |||
26 | async function unregister () { | ||
27 | return | ||
28 | } | ||
29 | |||
30 | module.exports = { | ||
31 | register, | ||
32 | unregister | ||
33 | } | ||
34 | |||
35 | // ############################################################################ | ||
36 | |||
37 | function addToCount (obj) { | ||
38 | return Object.assign({}, obj, { count: obj.count + 1 }) | ||
39 | } | ||
diff --git a/server/tests/fixtures/peertube-plugin-test-three/package.json b/server/tests/fixtures/peertube-plugin-test-three/package.json new file mode 100644 index 000000000..3f7819db3 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-three/package.json | |||
@@ -0,0 +1,19 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-three", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Plugin test 3", | ||
5 | "engine": { | ||
6 | "peertube": ">=1.3.0" | ||
7 | }, | ||
8 | "keywords": [ | ||
9 | "peertube", | ||
10 | "plugin" | ||
11 | ], | ||
12 | "homepage": "https://github.com/Chocobozzz/PeerTube", | ||
13 | "author": "Chocobozzz", | ||
14 | "bugs": "https://github.com/Chocobozzz/PeerTube/issues", | ||
15 | "library": "./main.js", | ||
16 | "staticDirs": {}, | ||
17 | "css": [], | ||
18 | "clientScripts": [] | ||
19 | } | ||
diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts index d97ca1515..95e358732 100644 --- a/server/tests/plugins/index.ts +++ b/server/tests/plugins/index.ts | |||
@@ -1,2 +1,3 @@ | |||
1 | import './action-hooks' | 1 | import './action-hooks' |
2 | import './filter-hooks' | 2 | import './filter-hooks' |
3 | import './video-constants' | ||
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts new file mode 100644 index 000000000..6562e2b45 --- /dev/null +++ b/server/tests/plugins/video-constants.ts | |||
@@ -0,0 +1,140 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | flushAndRunMultipleServers, | ||
8 | flushAndRunServer, killallServers, reRunServer, | ||
9 | ServerInfo, | ||
10 | waitUntilLog | ||
11 | } from '../../../shared/extra-utils/server/servers' | ||
12 | import { | ||
13 | addVideoCommentReply, | ||
14 | addVideoCommentThread, | ||
15 | deleteVideoComment, | ||
16 | getPluginTestPath, | ||
17 | getVideosList, | ||
18 | installPlugin, | ||
19 | removeVideo, | ||
20 | setAccessTokensToServers, | ||
21 | updateVideo, | ||
22 | uploadVideo, | ||
23 | viewVideo, | ||
24 | getVideosListPagination, | ||
25 | getVideo, | ||
26 | getVideoCommentThreads, | ||
27 | getVideoThreadComments, | ||
28 | getVideoWithToken, | ||
29 | setDefaultVideoChannel, | ||
30 | waitJobs, | ||
31 | doubleFollow, getVideoLanguages, getVideoLicences, getVideoCategories, uninstallPlugin | ||
32 | } from '../../../shared/extra-utils' | ||
33 | import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' | ||
34 | import { VideoDetails } from '../../../shared/models/videos' | ||
35 | import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports' | ||
36 | |||
37 | const expect = chai.expect | ||
38 | |||
39 | describe('Test plugin altering video constants', function () { | ||
40 | let server: ServerInfo | ||
41 | |||
42 | before(async function () { | ||
43 | this.timeout(30000) | ||
44 | |||
45 | server = await flushAndRunServer(1) | ||
46 | await setAccessTokensToServers([ server ]) | ||
47 | |||
48 | await installPlugin({ | ||
49 | url: server.url, | ||
50 | accessToken: server.accessToken, | ||
51 | path: getPluginTestPath('-three') | ||
52 | }) | ||
53 | }) | ||
54 | |||
55 | it('Should have updated languages', async function () { | ||
56 | const res = await getVideoLanguages(server.url) | ||
57 | const languages = res.body | ||
58 | |||
59 | expect(languages['en']).to.not.exist | ||
60 | expect(languages['fr']).to.not.exist | ||
61 | |||
62 | expect(languages['al_bhed']).to.equal('Al Bhed') | ||
63 | expect(languages['al_bhed2']).to.equal('Al Bhed 2') | ||
64 | }) | ||
65 | |||
66 | it('Should have updated categories', async function () { | ||
67 | const res = await getVideoCategories(server.url) | ||
68 | const categories = res.body | ||
69 | |||
70 | expect(categories[1]).to.not.exist | ||
71 | expect(categories[2]).to.not.exist | ||
72 | |||
73 | expect(categories[42]).to.equal('Best category') | ||
74 | expect(categories[43]).to.equal('High best category') | ||
75 | }) | ||
76 | |||
77 | it('Should have updated licences', async function () { | ||
78 | const res = await getVideoLicences(server.url) | ||
79 | const licences = res.body | ||
80 | |||
81 | expect(licences[1]).to.not.exist | ||
82 | expect(licences[7]).to.not.exist | ||
83 | |||
84 | expect(licences[42]).to.equal('Best licence') | ||
85 | expect(licences[43]).to.equal('High best licence') | ||
86 | }) | ||
87 | |||
88 | it('Should be able to upload a video with these values', async function () { | ||
89 | const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } | ||
90 | const resUpload = await uploadVideo(server.url, server.accessToken, attrs) | ||
91 | |||
92 | const res = await getVideo(server.url, resUpload.body.video.uuid) | ||
93 | |||
94 | const video: VideoDetails = res.body | ||
95 | expect(video.language.label).to.equal('Al Bhed 2') | ||
96 | expect(video.licence.label).to.equal('Best licence') | ||
97 | expect(video.category.label).to.equal('Best category') | ||
98 | }) | ||
99 | |||
100 | it('Should uninstall the plugin and reset languages, categories and licences', async function () { | ||
101 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-three' }) | ||
102 | |||
103 | { | ||
104 | const res = await getVideoLanguages(server.url) | ||
105 | const languages = res.body | ||
106 | |||
107 | expect(languages[ 'en' ]).to.equal('English') | ||
108 | expect(languages[ 'fr' ]).to.equal('French') | ||
109 | |||
110 | expect(languages[ 'al_bhed' ]).to.not.exist | ||
111 | expect(languages[ 'al_bhed2' ]).to.not.exist | ||
112 | } | ||
113 | |||
114 | { | ||
115 | const res = await getVideoCategories(server.url) | ||
116 | const categories = res.body | ||
117 | |||
118 | expect(categories[ 1 ]).to.equal('Music') | ||
119 | expect(categories[ 2 ]).to.equal('Films') | ||
120 | |||
121 | expect(categories[ 42 ]).to.not.exist | ||
122 | expect(categories[ 43 ]).to.not.exist | ||
123 | } | ||
124 | |||
125 | { | ||
126 | const res = await getVideoLicences(server.url) | ||
127 | const licences = res.body | ||
128 | |||
129 | expect(licences[ 1 ]).to.equal('Attribution') | ||
130 | expect(licences[ 7 ]).to.equal('Public Domain Dedication') | ||
131 | |||
132 | expect(licences[ 42 ]).to.not.exist | ||
133 | expect(licences[ 43 ]).to.not.exist | ||
134 | } | ||
135 | }) | ||
136 | |||
137 | after(async function () { | ||
138 | await cleanupTests([ server ]) | ||
139 | }) | ||
140 | }) | ||